My experiments with mTango REST API

Hi,

I’ve done some experiments with mTango REST API, using the Tango9 VM.

It’s working quite well, but I’m facing few issues for which your comments are welcome!

I used the doc from here.

1. Rest services for devices tree

$ curl -v -u “tango-cs:tango” “http://tango9-vm:8080/mtango/rest/families?domain=sim
returns:

HTTP/1.1 500 Internal Server Error

Unknown @PathParam: domain for path: /families

Now, if I’m using the info from this post, I can get my devices tree without problem. Is the doc on the wiki outdated ?

2. Events

$ curl -v -u “tango-cs:tango” "http://tango9-vm:8080/mtango/rest/device/sim/motor/1/position.change »

1st call: OK
{“argout”:61.02,“quality”:“VALID”,“timestamp”:1482416967728}

2nd call: after ~10s, I get:
{“errors”:[“Device threw an exception:\nZmqEventConsumer.checkIfHeartbeatSkipped():API_NoHeartbeat(No heartbeat from dserver/simmotor/test)\n”],“quality”:“INVALID”,“timestamp”:1482417067607}

.. and any other call returns the same error. If I understand correctly, the call should be blocking, until the attribute value changes. Is the 1st call supposed to return the initial value ?
(Note that doing the same thing with the java API, the events are returned correctly when the attribute value change).

  1. Using the latest tango.war (mtango.server-rc3-0.1.zip)

I tried to use the latest version of mTango.
Trying to deploy it, I get:

(extract from catalina.out)

DEBUG 2016-12-22 12:22:17,721 [http-bio-8080-exec-15 - - o.t.c.d.c.DatabaseCache] o.t.c.database.cache.ServerCache.:38 - current database cache version release 1.9
Error Level 0:
- desc: device dserver/tangorestserver/development not defined in the database localhost:10000 !
- origin: DataBase::ImportDevice()
- reason: DB_DeviceNotDefined
- severity: ERROR
Error Level 1:
- desc: Cannot execute command DbImportDevice on sys/database/2
- origin: Connection.command_inout()
- reason: TangoApi_CANNOT_EXECUTE_COMMAND
- severity: PANIC

Thanks for your help,
Jerome

Hi Jerome,

Thanks for giving mTangoREST.server and Tango-VW a try.

Yes, it is outdated. The up-to-date specification is here.

The short answer - call blocks, but not always until value changes.

In REST server due to HTTP limitations a COMET model is used to implement events. For simplicity’s sake, think of it as a blocking call before one of the following happens:

  1. 1) timeout (by default 30s) - server simply returns current value
  1. 2) value changes - server returns new value
  1. 3) error occurs - server returns error

Looks like in your case underlying Tango event system is not configured properly and you get sync value, see below - there is a long discussion on this forum concerning ZMQ’s heartbeat errors (I have not used tango-vm so far, so I can’t say). If Java API works fine REST should also work (it is basically a Java client to Tango). Are you using Java client from within Tango-VM?

Yes. This is a feature/bug in Tango client event’s API - when client subscribes to an event it first gets the result of a sync call to the attribute.

There is no TangoRestServer defined in the Tango database. Please follow this instruction to define rest server using jive.

Hope this helps.

Hi Ingvord,

Thanks for your quick response.

I’m using the Java client from the VM host (i.e. remotely from the VM point of view), as I do for the http request.
Is anybody familiar with the Tango9 VM can comment on this?

Seems ok. This is consistent with the Java API.

Ok, I’ll try this. Seems this is something missing in the Tango9 VM.

Yes, thanks!

Jerome

Hi Ingvord,

After having added TangoRestServer in the Tango database, I was able to use the latest mTango war.
Everything is working fine now :slight_smile:

The events are also working (no ZMQ’s heartbeat errors anymore).
Note that even the first call is blocking (the initial value was expected). This is oviously not an issue though.

Thank you!
Jerome