6.6.2
Moab HPC Suite REST Service
The Moab REST service can be used to access the MWS RESTful API (see Chapter 4: Resources) in plugins. All 'requests' made through this service are internal only and no data is actually transmitted over the network. See 6.2.11 Accessing MWS REST Resources for more information.
The moabRestService property will be injected with a class of type IMoabRestService in all plugin types.
Accessing Resources
In order to access a resource, a relative URL matching that in the documentation must be used along with an HTTP method, such as GET, POST, PUT, or DELETE. The method names on IMoabRestService match the HTTP methods directly. For example, to call a GET operation on /rest/jobs, use the following code:
moabRestService.get("/rest/jobs")
Using Parameters Correctly
Although the ordering of the parameters for each method on IMoabRestService may seem confusing at first glance, this is to allow for easy use with Groovy. Examples are given below for each combination of parameters:
String URL ------------------------------------ moabRestService.get("/rest/jobs")
Map options, String URL ------------------------------------ moabRestService.get("/rest/jobs", hooks:true, contentType:"application/json")
String URL, Closure data ------------------------------------ moabRestService.get("/rest/jobs/job.1") { [flags:"RESTARTABLE"] }
Map options, String URL, Closure data ------------------------------------ moabRestService.get("/rest/jobs/job.1", hooks:true, contentType:"application/json") { [flags:"RESTARTABLE"] }
Options
The following options are valid in each method call supporting the options parameter:
Name | Type | Default | Description |
---|---|---|---|
data |
See Valid Data Types |
-- |
The body of the 'request.' This can be overwritten by the data Closure parameter. |
hooks | Boolean | false |
Whether or not hooks are run as part of the 'request' (see 3.7 Pre- and Post-Processing Hooks). |
contentType | String | application/json | Indicates the content type used for the request. |
params | Map | -- |
Indicates URL query parameters to use for the 'request,' such as query, sort, proxy-user, or others. |
If the data Closure parameter is specified, it overwrites the data option. In each case, there are four valid types for the data option or return value of the data closure:
- A non-null JSON instance.
- A valid JSON string. This will be converted into a JSON instance.
- A valid Map instance. This will be converted into a JSONObject instance.
- A valid List instance. This will be converted into a JSONArray instance.

A JSONException may be thrown if the JSON string is invalid or the Map or List contains values that cannot be serialized to JSON.