Heads up: Updated REST api in master -- rebuild the dev-container
by Heiko W.Rupp
Hello,
I've just merged the changes from the feature/rest branch into master.
As the way the library dependencies are handled has changed, you need
to rebuild the dev-container.
Heiko
--
Reg. Adresse: Red Hat GmbH, Technopark II, Haus C,
Werner-von-Siemens-Ring 14, D-85630 Grasbrunn
Handelsregister: Amtsgericht München HRB 153243
Geschaeftsführer: Mark Hegarty, Charlie Peters, Michael Cunningham, Charles Cachera
12 years, 5 months
POC: Operation scheduling over the REST api
by Heiko W.Rupp
Hi,
feature/rest branch now has the ability to schedule resource operations. This is still very limited as it
only allows for parameter-less operations at the moment and also only reports the operation status,
but show how this can be done in a way that can be done from a variety of languages.
I've tried to use the linking in this approach to start with one public endpoint for a client to know
Here is a log of the actions done with some comments.
For those less familiar with rest, the links below sometimes have some "standard"-rel:
- a rel of "edit" means rud (PUT,GET,DELETE)
- a rel of "self" gives the location of an edit
- a rel of "create" means POST (could also mean PUT when the id of the object to create is known to the client)
Heiko
# Getting the platforms
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/resource/platforms -HContent-Type:application/json
[{"typeName":"Mac OS X",
"resourceName":"snert",
"parentId":0,
"pluginName":"Platforms",
"resourceId":"10001",
"typeId":10020}]
# Getting one resource
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/resource/10001 -HContent-Type:application/json
{"typeName":"Mac OS X",
"resourceName":"snert",
"parentId":0,
"pluginName":"Platforms",
"resourceId":"10001",
"links":[
{"rel":"operationDefinitions",
"href":"http://localhost:7080/rest/1/operation/definitions?resourceId=10001"},
{"rel":"self",
"href":"http://localhost:7080/rest/1/resource/10001"},
{"rel":"schedules",
"href":"http://localhost:7080/rest/1/resource/10001/schedules"},
{"rel":"children",
"href":"http://localhost:7080/rest/1/resource/10001/children"}
],
"typeId":10020}
# Get the operation definitions for that resource
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/operation/definitions\?resourceId=10001 -HContent-Type:application/json
[
{"name":"discovery",
"id":10024,
"links":[
{"rel":"create",
"href":"http://localhost:7080/rest/1/operation/definition/10024?resourceId=10001"}
]
},
{"name":"viewProcessList",
"id":10025,
"links":[
{"rel":"create",
"href":"http://localhost:7080/rest/1/operation/definition/10025?resourceId=10001"}
]
}
]
# 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-Typcation/json -X POST
{"name":"viewProcessList",
"id":-970811016,
"state":"creating",
"params":{},
"resourceId":10001,
"definitionId":10025,
"links":[
{"rel":"edit",
"href":"http://localhost:7080/rest/1/operation/-982775384"}
]
}
# View the draft (not necessary for scheduling)
$ curl --user rhqadmin:rhqadmin http://localhost:7080/rest/1/operation/-970811016 -HContent-Type:application/json -X GET
{"name":"viewProcessList",
"id":-970811016,
"state":"creating",
"params":{},
"resourceId":10001,
"definitionId":10025,
"links":[
{"rel":"edit",
"href":"http://localhost:7080/rest/1/operation/-982775384"}
]
}
# 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",
"href":"http://localhost:7080/rest/1/operation/history/rhq-resource-10001-7355903..."}
]
}
# 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-7355903...
Successs
--
Reg. Adresse: Red Hat GmbH, Technopark II, Haus C,
Werner-von-Siemens-Ring 14, D-85630 Grasbrunn
Handelsregister: Amtsgericht München HRB 153243
Geschaeftsführer: Brendan Lane, Charlie Peters, Michael Cunningham, Charles Cachera
12 years, 5 months