2.13 API usage example
The procedure below shows an example of using an API function to execute a service. First, check the instanceID of the service you want to execute. Then, specify immediate for the schedule type and execute the service.
Display a list of resources for service functionality (Services), and check the instanceID of the service you want to execute.
GET /Automation/v1/objects/Services/ HTTP/1.1 Host:10.197.112.78:22015 User-Agent:sample rest client/1.00.0 Accept:application/json Accept-Language: ja Authorization: Basic c3lzdGVtOm1hbmFnZXI= User-Agent: useragent1 HTTP/1.1 200 OK Date: Mon, 18 Aug 2014 11:15:01 GMT Server: Cosminexus HTTP Server Access-Control-Expose-Headers: WWW-Authenticate WWW-Authenticate: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS Access-Control-Allow-Credentials: true Cache-Control: no-cache Transfer-Encoding: chunked Content-Type: application/json { "data" : [ { "instanceID" : 2269, <- Check instanceID. "name" : "Execute remote command", "description" : "Executes a command on the remote execution target server.", "tags" : "OS_Operations,Basic", "serviceTemplateName" : "Execute remote command", "createTime" : "2014-08-18T16:53:50.000+0900", "modifyTime" : "2014-08-18T16:53:58.000+0900", "serviceState" : "release", "serviceGroupName" : "DefaultServiceGroup", "iconURL" : "http://10.197.112.78:22015/Automation/icon/services/com.hitachi.software.dna.cts.jp1/remoteCommandExe/01.10.00", "vendorName" : "Hitachi,Ltd.", "version" : "01.10.00", "latest" : true, "imageURL" : "http://10.197.112.78:22015/Automation/resources/images/overview/overview.png", "serviceTemplateID" : 2204, "serviceGroupID" : 2 } ], "count" : 1 }
Acquire a list of operations that can be performed for the resource that has the instanceID you checked above.
GET /Automation/v1/objects/Services/2269/actions HTTP/1.1 Host:10.197.112.78:22015 User-Agent:sample rest client/1.00.0 Accept:application/json Accept-Language: ja Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300 HTTP/1.1 200 OK Date: Mon, 18 Aug 2014 11:24:41 GMT Server: Cosminexus HTTP Server Access-Control-Expose-Headers: WWW-Authenticate WWW-Authenticate: HSSO b365e6a2cda2b4d195d55fee1461a6ed0889927_V0300 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS Access-Control-Allow-Credentials: true Cache-Control: no-cache Transfer-Encoding: chunked Content-Type: application/json { "data" : [ { "name" : "submit", <- Check the href information of submit that is used to execute the service. "href" : "http://10.197.112.78:22015/Automation/v1/objects/Services/2269/actions/submit/invoke", "method" : "POST", "parameters" : [ ] } ], "count" : 1 }
Acquire the request body information that is necessary for the operation to execute the specified service.
GET /Automation/v1/objects/Services/2269/actions/submit HTTP/1.1 Host:10.197.112.78:22015 User-Agent:sample rest client/1.00.0 Accept:application/json Accept-Language: ja Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300 HTTP/1.1 200 OK Date: Mon, 18 Aug 2014 11:26:00 GMT Server: Cosminexus HTTP Server Access-Control-Expose-Headers: WWW-Authenticate WWW-Authenticate: HSSO 1b9b5891c58315e26cd0cca9aac6d43e572e3db_V0300 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS Access-Control-Allow-Credentials: true Cache-Control: no-cache Transfer-Encoding: chunked Content-Type: application/json Output the response to the properties.json file.
Contents of properties.json
{ "name" : "submit", "href" : "http://10.197.112.78:22015/Automation/v1/objects/Services/2269/actions/submit/invoke", "method" : "POST", "parameters" : [ { "name" : "Execute remote command_20140818202600", "submitter" : "System", "scheduleType" : "immediate", "description" : "", "scheduledStartTime" : "2014-08-18T20:26:00.536+09:00", "recurrenceInterval" : "daily", "recurrenceDayOfWeek" : "", "recurrenceDayOfMonth" : "", "recurrenceLastDayOfMonth" : false, "recurrenceStartDate" : "2014-08-18", "recurrenceTime" : "00:00:00", "serviceID" : 2269 }, { "instanceID" : 2275, "type" : "string", "keyName" : "common.targetHost", "value" : "", "serviceID" : 2269 }, { "instanceID" : 2271, "type" : "string", "keyName" : "common.remoteCommand", "value" : "", "serviceID" : 2269 }, { "instanceID" : 2273, "type" : "string", "keyName" : "common.remoteCommandParameter", "value" : "", "serviceID" : 2269 } ] }
Edit the acquired template information as necessary. The following is an example of specifying immediate for the schedule type.
{ "name" : "submit", "href" : "http://10.197.112.78:22015/Automation/v1/objects/Services/2269/actions/submit/invoke", "method" : "POST", "parameters" : [ { "name" : "Execute remote command_20140818202600", "submitter" : "System", "scheduleType" : "immediate", <- Specify "immediate". "description" : "", "scheduledStartTime" : "2014-08-18T20:26:00.536+09:00", "recurrenceInterval" : "daily", "recurrenceDayOfWeek" : "", "recurrenceDayOfMonth" : "", "recurrenceLastDayOfMonth" : false, "recurrenceStartDate" : "2014-08-18", "recurrenceTime" : "00:00:00", "serviceID" : 2269 }, { "instanceID" : 2275, "type" : "string", "keyName" : "common.targetHost", "value" : "", <- Change value as necessary. "serviceID" : 2269 }, { "instanceID" : 2271, "type" : "string", "keyName" : "common.remoteCommand", "value" : "hostname", <- Change value as necessary. "serviceID" : 2269 }, { "instanceID" : 2273, "type" : "string", "keyName" : "common.remoteCommandParameter", "value" : "", <- Change value as necessary. "serviceID" : 2269 } ] }
Execute the service by using the edited information.
POST /Automation/v1/objects/Services/2269/actions/submit/invoke HTTP/1.1 Host:10.197.112.78:22015 User-Agent:sample rest client/1.00.0 Accept:application/json Accept-Language: ja Content-Type: application/json Content-Length: 1087 Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300 Request the contents of properties.json. HTTP/1.1 200 OK Date: Mon, 18 Aug 2014 11:39:03 GMT Server: Cosminexus HTTP Server Access-Control-Expose-Headers: WWW-Authenticate WWW-Authenticate: HSSO 8ba382c1f2e81a65d7a252391b262624c6fa61_V0300 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS Access-Control-Allow-Credentials: true Cache-Control: no-cache Transfer-Encoding: chunked Content-Type: application/json { "instanceID" : "4a9141e4-9566-4e42-af08-0f09926f2a5f", "created" : "2014-08-18T20:39:04.242+0900", "updated" : "2014-08-18T20:39:04.242+0900", "completed" : "2014-08-18T20:39:04.242+0900", "state" : "success", "affectedResource" : [ "http://10.197.112.78:22015/Automation/v1/objects/Schedules/2285" <- URL of the created schedule resource, "http://10.197.112.78:22015/Automation/v1/objects/Tasks/2280" <- URL of the created task resource ], "result" : [ ] }
Acquire the Schedule resource created by execution of the service, and check the contents of the resource.
GET /Automation/v1/objects/Schedules/2285 HTTP/1.1 Host:10.197.112.78:22015 User-Agent:sample rest client/1.00.0 Accept:application/json Accept-Language: ja Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300 HTTP/1.1 200 OK Date: Mon, 18 Aug 2014 11:43:00 GMT Server: Cosminexus HTTP Server Access-Control-Expose-Headers: WWW-Authenticate WWW-Authenticate: HSSO cafcefb87199122267f8ad33772555f9357c8a2_V0300 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS Access-Control-Allow-Credentials: true Cache-Control: no-cache Transfer-Encoding: chunked Content-Type: application/json { "instanceID" : 2285, "name" : "Execute remote command_20140818202600", "submitter" : "System", "scheduleType" : "immediate", "createTime" : "2014-08-18T20:39:03.000+0900", "modifyTime" : "2014-08-18T20:39:03.000+0900", "description" : "", "serviceState" : "release", "serviceID" : 2269 }
Acquire the Task resource created by execution of the service, and check the contents of the resource.
GET /Automation/v1/objects/Tasks/2280 HTTP/1.1 Host:10.197.112.78:22015 User-Agent:sample rest client/1.00.0 Accept:application/json Accept-Language: ja Authorization: HSSO b8712c86fcd026562182a358ea43bb23b09c62_V0300 HTTP/1.1 200 OK Date: Mon, 18 Aug 2014 11:43:59 GMT Server: Cosminexus HTTP Server Access-Control-Expose-Headers: WWW-Authenticate WWW-Authenticate: HSSO 3713abcd1e99d1481c7b92cc9892a95d1a702d6_V0300 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT, HEAD, OPTIONS Access-Control-Allow-Credentials: true Cache-Control: no-cache Transfer-Encoding: chunked Content-Type: application/json { "instanceID" : 2280, "name" : "Execute remote command_20140818202600", "status" : "failed", "startTime" : "2014-08-18T20:39:04.000+0900", "completionTime" : "2014-08-18T20:39:13.000+0900", "submitter" : "System", "submitTime" : "2014-08-18T20:39:03.000+0900", "modifyTime" : "2014-08-18T20:39:19.000+0900", "serviceState" : "release", "scheduleType" : "immediate", "description" : "", "serviceName" : "Execute remote command", "tags" : "", "serviceGroupName" : "DefaultServiceGroup", "serviceTemplateID" : 2204, "scheduleID" : 2285, "serviceGroupID" : 2, "serviceID" : 2269 }