obiba / opal-python-client

Python command lines for accessing Opal web services.
GNU General Public License v3.0
4 stars 3 forks source link

How to use the opal rest command to add a new resource? #21

Closed IvoLeist closed 3 years ago

IvoLeist commented 3 years ago

Dear Opal developers,

its me again the one who is hoping to use Opal in a web application for biomedical research as part of the 3TR project (https://3tr-imi.eu/).

We finally have Opal up and running and already did our first analysis with it. Before going into production, we would require some further automation. Like adding a resource from the command line. Looking into https://github.com/obiba/opal/wiki/Resource-References#project-resources-web-services and getting the payload from the dev tools/network tab on the opal frontend

We thought this would be straight forward but somehow the command below runs into an error:

opal rest -v /project/test/resources -o http://localhost:8880 -u administrator -p password -m POST -hs '{"name": "t3", "project":
"test", "provider": "resourcer", "factory": "spark","parameters":"{\"url\":\"\",\"rdd\":\"\"}","credentials":"{\"username\":\"\",\"password\":\"\"}"}' 

Failed with:

POST /ws/project/test/resources HTTP/1.1
Host: localhost:8880
User-Agent: PycURL/7.43.0.2 libcurl/7.68.0 GnuTLS/3.6.15 zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh/0.9.3/openssl/zlib nghttp2/1.41.0 librtmp/2.3
Authorization: X-Opal-Auth YWRtaW5pc3RyYXRvcjpwYXNzd29yZA==
Accept: application/json
name: t3
project: test
provider: resourcer
factory: spark
parameters: {"url":"","rdd":""}
credentials: {"username":"","password":""}
* Mark bundle as not supporting multiuse
* The requested URL returned error: 500 Server Error
* Closing connection 0
(22, 'The requested URL returned error: 500 Server Error')

The opal log was unfortunately not really helpful as well. From all the exceptions thrown this one might be the most helpful(?)

ERROR org.obiba.opal.web.provider.ErrorDtoExceptionMapper - System error Internal Server Error: javax.ws.rs.NotSupportedException javax.ws.rs.NotSupportedException: Could not find message body reader for type: class org.obiba.opal.web.model.Projects$ResourceReferenceDto of content type: /

Best regards, Ivo

ymarcon commented 3 years ago
  1. Add content type option (format of the body of your request): -ct "application/json"
  2. Pipe the body in the shell command, so that it is read from the stdin
echo '{"name": "t3", "project": "test", "provider": "resourcer", "factory": "spark","parameters":"{\"url\":\"\",\"rdd\":\"\"}","credentials":"{\"username\":\"\",\"password\":\"\"}"}' | opal rest -v /project/test/resources -o http://localhost:8880 -u administrator -p password -m POST -ct "application/json"

See also http://opaldoc.obiba.org/en/latest/python-user-guide/other/rest.html#options