EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  <2024 Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  <2024
<== Date ==> <== Thread ==>

Subject: Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments
From: Konrad Gajewski via Tech-talk <tech-talk at aps.anl.gov>
To: "Shroff, Kunal" <shroffk at bnl.gov>, "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Mon, 8 Apr 2024 21:38:14 +0200

Hi Kunal,


I'm happy to hear that you're working on a new library. In the meantime, Lin's reply helped me to fix my problem.


Just for the reference, here's the log entry before fixing the problem:

{
    "id": 75,
    "owner": "konrad",
    "source": "New entry using Olog/logs/multipart with one attachment.\n",
    "description": "New entry using Olog/logs/multipart with one attachment.",
    "title": "test4.py",
    "level": "INFO",
    "state": "Active",
    "createdDate": 1712575722373,
    "modifyDate": null,
    "events": null,
    "logbooks": [
        {
            "name": "test",
            "owner": null,
            "state": "Active"
        }
    ],
    "tags": [],
    "properties": [],
    "attachments": []
}


/Konrad


On 4/8/2024 5:48 PM, Shroff, Kunal wrote:
Hi,

We are working on a new helper python library.

In the meanwhile it broadly looks like you request is correct. Can you share a copy of the log entry that is created ( the id 75 )

>>
2024-04-08 13:28:42.406  WARN 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource             : File FREIAlogo-v3_March19.png
not matched with attachment meta-data

While this is the issue resulting in the attachment file not being uploaded, once we see a copy of the log entry created we should have a better idea why.

Kunal

From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Konrad Gajewski via Tech-talk <tech-talk at aps.anl.gov>
Sent: 08 April 2024 07:51
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments
 
Hi,

I'm trying to write a simple python program to create an entry in the
new Olog server (API documented in
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*olog.readthedocs.io/en/latest/index.html__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhJoQQa75$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg8U0SQKs$   ).

I am using PUT https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg2nzFLVA$   request and
all works fine for entries without any attachments. If I try to add an
attachment the entry itself is saved but saving the attachment fails.

I have found pyOlog library but it seems to be the old version written
for Glassfish and mysql architecture.

Does anybody have a python library, or at least an example program
showing how to use the new PUT
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg2nzFLVA$   API for creating the entries
with an attachment.  A curl command showing the use of PUT
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg2nzFLVA$   would also be helpful.

Below is the python code that I've used:

     api_endpoint = "https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*olog-server:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhJIczIfa$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULgp3Hr408$  "

     # Prepare log entry payload
     log_entry = {
         "owner": "dev",
         "description": "New entry using Olog/logs/multipart with one
attachment.\n",
         "level": "INFO",
         "title": "test4.py",
         "logbooks": [{"name": "test"}],
         "attachments":[
             {"id": str(uuid.uuid4()), "name": "FREIAlogo-v3_March19.png"}
         ]
     }

     # Prepare the log entry payload as JSON
     json_data = json.dumps(log_entry)
     json_filename = json.dumps({"filename": "FREIAlogo-v3_March19.png"})
     json_descr = json.dumps({"fileMetadataDescription": "image/png"})

     # Prepare the multipart encoder
     multipart_data = MultipartEncoder(
         fields={
             'logEntry': ('logEntry.json', json_data, 'application/json'),
             'files': ('filename', json_filename, 'application/json'),
             'files': ('fileMetadataDescription', json_descr,
'application/json'),
             'files': ('FREIAlogo-v3_March19.png',
open('FREIAlogo-v3_March19.png', 'rb'), 'application/octet-stream')
         }
     )

     # Set the Content-Type header with the boundary
     headers = {
         'Content-Type': multipart_data.content_type
     }
     try:
         response = requests.put(api_endpoint, headers=headers,
data="" auth=HTTPBasicAuth(username, password))
         if response.status_code == 200:
             print("Log entry created successfully.")
         else:
             print("Failed to create log entry. Status code:
{response.status_code}")
     except Exception as e:
         print("An error occurred: ",{str(e)})

And a log from phoebus-olog server:

2024-04-08 13:28:42.337 DEBUG 1740 --- [nio-8181-exec-4]
o.s.web.servlet.DispatcherServlet        : PUT "/Olog/logs/multipart",
parameters={multipart}
2024-04-08 13:28:42.347 DEBUG 1740 --- [nio-8181-exec-4]
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to
org.phoebus.olog.LogResource#createLog(String, String, String, Log,
MultipartFile[], Principal)
2024-04-08 13:28:42.349 DEBUG 1740 --- [nio-8181-exec-4]
.m.m.a.RequestPartMethodArgumentResolver : Read "application/json" to
[org.phoebus.olog.entity.Log@c517dec8]
2024-04-08 13:28:42.404  INFO 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource             : Entry id 75 created from n/a
2024-04-08 13:28:42.406  WARN 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource             : File FREIAlogo-v3_March19.png
not matched with attachment meta-data
2024-04-08 13:28:42.407  INFO 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource             : Entry id 75 created from n/a
2024-04-08 13:28:42.408 DEBUG 1740 --- [nio-8181-exec-4]
m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json',
given [*/*] and supported [application/json, application/*+json,
application/json, application/*+json]
2024-04-08 13:28:42.408 DEBUG 1740 --- [nio-8181-exec-4]
m.m.a.RequestResponseBodyMethodProcessor : Writing
[org.phoebus.olog.entity.Log@ff3dfa85]
2024-04-08 13:28:42.410 DEBUG 1740 --- [nio-8181-exec-4]
o.s.web.servlet.DispatcherServlet        : Completed 200 OK

Best regards,
Konrad

--
Konrad Gajewski
FREIA Laboratory
https://urldefense.com/v3/__https://urldefense.us/v3/__http:/*www.physics.uu.se/__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhPzk46FZ$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg55JX090$ 









När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: https://urldefense.com/v3/__https://urldefense.us/v3/__http:/*www.uu.se/om-uu/dataskydd-personuppgifter/__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhEJJRf56$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULgzBkyo1w$ 

E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: https://urldefense.com/v3/__https://urldefense.us/v3/__http:/*www.uu.se/en/about-uu/data-protection-policy__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhIzZpdTb$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULgjKtLYtY$ 


VARNING: Klicka inte på länkar och öppna inte bilagor om du inte känner igen avsändaren och vet att innehållet är säkert.
CAUTION: Do not click on links or open attachments unless you recognise the sender and know the content is safe.
-- 
Konrad Gajewski
Senior Research Engineer
Uppsala University                    Tel:    +46-18-4713874
Dept. of Physics and Astronomy,       Mobile: +46-701679193
High Energy Physics                   mailto:konrad.gajewski at physics.uu.se
FREIA Laboratory
Box 516, S-751 20 Uppsala, Sweden
http://www.physics.uu.se/

Replies:
Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk
References:
Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Konrad Gajewski via Tech-talk
Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk

Navigate by Date:
Prev: RE: Alarm Handler Limitations Srinivas, Dhruv via Tech-talk
Next: Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  <2024
Navigate by Thread:
Prev: Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk
Next: Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  <2024
ANJ, 11 Sep 2024 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·