Problems using the /api/events for scheduling on Opencast 7.2

168 views
Skip to first unread message

Michael Nardell

unread,
Aug 27, 2019, 8:20:41 PM8/27/19
to Opencast Users
Greetings :: In the past we were using the /recordings endpoint on Opencast 3.3. I was having problems getting the /api/events to work on that version, and /recordings endpoint worked well and allowed for automated scheduling of events. We are now working on an upgrade to Opencast 7.2, and due to some changes the the /recordings endpoint the scheduling process does not work. This has been a catalyst to me to look at /api/events which I believe is the preferred (external) API for this use. But so far my attempts are not working; I keep on getting an 400 error. Looking at the logs I am seeing that Opencast is complaining that it cannot parse the ACL:


2019-08-27T23:15:36,115 | WARN | (AclEndpoint$2:286) - Unable to parse ACL
2019-08-27T23:15:36,116 | WARN | (WebApplicationExceptionMapper:73) - javax.ws.rs.WebApplicationException: HTTP 400 Bad Request
at org.opencastproject.adminui.endpoint.AclEndpoint$2.apply(AclEndpoint.java:287)
at org.opencastproject.adminui.endpoint.AclEndpoint$2.apply(AclEndpoint.java:280)
at org.opencastproject.adminui.endpoint.AclEndpoint.createAcl(AclEndpoint.java:236)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
...

In order to work through this problem, I have written a 'mock' create event function (in Python) which uses copies of the  example ACL, Metadata, Scheduling, and Processing data elements as Dictionary literals, like this:
acl = [
{
"allow": True,
"action": "write",
"role": "ROLE_ADMIN"
},
{
"allow": True,
"action": "read",
"role": "ROLE_USER"
}
]

Same copy and paste for Metadata, scheduling and processing. I then use the Python json module to convert the dictionaries to json (with json.dumps). And then assemble the ACL, Metadata, Scheduling, and Processing into the Post data payload:

data = {"metadata": json.dumps(metadata), "processing": json.dumps(processing),
"scheduling": json.dumps(scheduling)}
ut 
Which is then posted to the /api/events endpoint, with no luck. I probably have not provided sufficient info to about what I am doing. Happy to provide any additional information that would help diagnose this issue.

Regards
Michael Nardell







Greg Logan

unread,
Aug 28, 2019, 12:07:31 AM8/28/19
to Opencast Users
Hi Mike,

It's simpler than that: The /api endpoints do not (yet) support scheduling new events.  You can update an existing event, but scheduling is not possible.

There has been quite a bit of change in the recordings endpoint from 3.3 to 7.x, but your existing scripts should be fixable.

G

--
To unsubscribe from this group and stop receiving emails from it, send an email to users+un...@opencast.org.

Maximiliano Lira Del Canto

unread,
Aug 28, 2019, 9:03:35 AM8/28/19
to Opencast Users
The API /api/events/ allows you to schedule new events. Thanks to that I created the Semester scheduler webapp.

Answering the question, the biggest problem to this POST call is how to arrange the data. First, you need to send this as a multipart request (multipart/form-data).

The way I'm doing the request in python is in this way:

def post(args, data):
   url = "https://" + args.serverUrl + "/api/events"

    credentials = (args.username, args.password)

    body = {
       "metadata": (None, data[0]),
       "acl": (None, data[1]),
       "processing": (None, data[2]),
       "scheduling": (None, data[3])
   }

    headers = {
   'content-disposition': "form-data",
   'cache-control': "no-cache",
   'Connection':'close'
    }
    response = requests.post (url, files=body, headers=headers, auth=credentials)

Where is data[x] is a json.dumps(<something>)


Try with this and tell us if works for you.

Also I recomend you to make the tests with Postman, because is very easy to make test and apply different variables when you are testing the API endpoints.

To unsubscribe from this group and stop receiving emails from it, send an email to us...@opencast.org.

Lars Kiesow

unread,
Aug 28, 2019, 12:49:18 PM8/28/19
to us...@opencast.org
Scheduling events now works using the ingest endpoints. For a simple
example, have a look at:;

https://github.com/opencast/helper-scripts/tree/master/schedule-now

Best regards,
Lars

Greg Logan

unread,
Aug 28, 2019, 1:21:47 PM8/28/19
to Opencast Users
Ah, I must have been looking at the wrong place in the docs.  This is properly documented at https://docs.opencast.org/r/7.x/developer/api/events-api/#post-apievents

G

To unsubscribe from this group and stop receiving emails from it, send an email to users+un...@opencast.org.

Michael Nardell

unread,
Aug 28, 2019, 4:41:33 PM8/28/19
to us...@opencast.org
Thanks for the help with this. I was able to use Maximiliano's code as as starting point to get me pointed in the right direction. Now able to create events. The one thing that is not working the same as in my old event scheduling - I used to set the ACL in the Series and rely upon the Event to inherit its ACL from the series it is a part of. I cannot seem to get that to work. The /api/event endpoint does not like it if I do provide ACL in the data, or set it to None, an empty list, or empty string. This is something I can work around easily enough but I would be interested to know if there is a way to have ACLs pass down from Series to Events.

Also, thanks for the reminder to use Postman. It certainly is handy for this work.

Michael
--
--------------------------------------------------
J. Michael Nardell
University of California, Santa Cruz
Learning Technologies/Systems

--------------------------------------------------- 

Maximiliano Lira Del Canto

unread,
Aug 29, 2019, 5:27:47 AM8/29/19
to Opencast Users
Hi Michael:

I've glad that my answer was useful for you, now about your problem, I had the same and I solved in this way, before to schedule the event, I ask to the /api/series/ endpoint about the acl that the series had, later I attach that information to the payload.

Here is the code I use to get the ACL from the series:

def get_acl(serverURL, OCUser, OCPass, seriesID):
   url = "https://" + serverURL + "/api/series/"+ seriesID +"/acl"

    credentials = (OCUser, OCPass)

    headers = {
       'Authorization': "Basic",
       'Accept': "*/*",
       'Cache-Control': "no-cache",
       'Host': serverURL,
       'accept-encoding': "gzip, deflate",
       'Connection':'close',
       'cache-control': "no-cache"
       }
   try:
       response = requests.request("GET", url, headers=headers, auth=credentials)
   except requests.exceptions.ConnectionError as e:
       sys.stderr.write('Failed to establish a new connection \n')
       sys.stderr.write('Check the URL and connection of Opencast \n')
       sys.stderr.write("Exception: %s" % str(e))
       sys.exit(1)

    if response.status_code == 401:
       print ('Bad credentials: Please check the username and password')

    try:
       return response.json()
   except json.decoder.JSONDecodeError as e:
       sys.stderr.write('Can\'t parse json output or there is no output \n')
       sys.stderr.write('Check that the seriesID is correct \n')
       sys.stderr.write("Exception: %s" % str(e))
       sys.exit(1)


Then the return from this function you can attach to the payload using json.dumps(get_acl(...))

Warning, this will fail if you have not created a series before.  

To unsubscribe from this group and stop receiving emails from it, send an email to us...@opencast.org.

Michael Nardell

unread,
Sep 6, 2019, 4:54:17 PM9/6/19
to Opencast Users
MaximilianoThanks for confirming that Events do not inherit their ACL from the Series, and for advice on a solution. 

Sven Stauber

unread,
Sep 12, 2019, 1:35:34 PM9/12/19
to Opencast Users
Hi Michael

 
MaximilianoThanks for confirming that Events do not inherit their ACL from the Series, and for advice on a solution. 

That is not true anymore: Since Opencast 7.x you can configure the way ACLs of series and events interact (see https://docs.opencast.org/r/7.x/admin/configuration/acl/).
The merge modes "roles" and "actions" both allow events to inherit from the series ACL.

Best
Sven
Reply all
Reply to author
Forward
0 new messages