POC: Operation scheduling over the REST api

Heiko W.Rupp hrupp at redhat.com
Mon Nov 21 15:12:03 UTC 2011


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-735590344-1321879298180_=_rhq-resource-10001"}
  ]
}

# 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



-- 
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



More information about the rhq-devel mailing list