-
1. Re: Scheduling operations through REST
pilhuhn Sep 26, 2012 8:59 AM (in response to josepho)Hey,
this is a good question and you are already on the right track.
First you need a POST operation to create a new operation schedule from a definition:
# Get one operation definition
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/operation/definition/10025\?resourceId=10001 -HContent-Type:application/json
{"name":"viewProcessList",
"id":10025,
"links":[
{"rel":"create",
"href":"http://localhost:7080/rest/1/operation/definition/10025?resourceId=10001"}
]
}
# Create a new (draft) operation from the definition above
# ( use > /tmp/foo to store the json for further local processing )
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/operation/definition/10025\?resourceId=10001 -HContent-Type:application/json -
X POST
{"name":"viewProcessList",
"id":-970811016,
"state":"creating",
"params":{},
...
and then when you have modified the schedule enough you need to set the 'state' to 'ready' so that the server can consider executing it.
# Put an update (state field is "ready" now) and thus schedule the operation to run
# input in /tmp/foo is the (modified) return from the POST above
# Note state has to be "ready" for scheduling
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/operation/-970811016 -HContent-Type:application/json -X PUT -d @/tmp/foo
{
"name":"viewProcessList",
"id":-970811016,
"state":"ready",
"params":{},
"resourceId":10001,
"definitionId":10025,
"links":[
{"rel":"history",
]
}
# See how the edit link is now gone and a history link points to the operation result
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/operation/history/rhq-resource-10001-735590344-1321879298180_=_rq-resource-10001
Successs
-
2. Re: Scheduling operations through REST
josepho Oct 17, 2012 1:17 PM (in response to pilhuhn)Heiko,
Thanks for the instructions, but can you please clarify the part about setting the 'state' to 'ready'?
From your instructions I took the JSON response from creating the draft operation:
{"params":{},"resourceId":11151,"definitionId":10006,"links":[{"href":"http://localhost:7080/rest/1/operation/50311967","rel":"edit"}],"name":"viewProcessList","id":50311967,"state":"creating"}
set the state to ready so the JSON was:
{"params":{},"resourceId":11151,"definitionId":10006,"links":[{"href":"http://localhost:7080/rest/1/operation/50311967","rel":"edit"}],"name":"viewProcessList","id":50311967,"state":"ready"}
then I PUT the JSON with the state set to 'ready' to http://localhost:7080/rest/1/operation/50311967 but the request I get back is the original JSON where the state is 'creating' and the operation does not show up in the RHQ GUI. Am I doing something wrong and do I need to add anything to the 'params' object?
Thanks,
Joseph
EDIT:
I realized that my issue was due to the Restlet client being improperly configured and not sending the PUT request correctly, so now it works exactly as Heiko explained. Also note that with RHQ 4.5.1, maybe before, that the field 'state' is now named 'readyToSubmit' and is a boolean, this is covered in the new rest api documentation with the 4.5.1 release.