4.2.7 About dynamic changes to values set for the input properties for services and plug-ins
The External Resource Provider function is a function that dynamically acquires, from any resource provider (External Resource Provider), the possible values that can be set for the input properties for services and plug-ins. When a person who creates service templates or plug-ins (a user with the Admin role or Develop role) sets an acquisition method for External Resource, users with the Submit role will be able to select the value that was acquired from the External Resource Provider when they execute services.
For example, if you want to perform an operation on a virtual machine on vCenter Server, you will be able to acquire a list of virtual machines from vCenter Server without having to build flows for individual virtual machines when you open the Submit Service window, and you can then execute a service on the virtual machines that you select in the Submit Service window.
The following four methods of acquiring external resources are provided.
External resource acquisition method |
Description |
---|---|
Javascript |
Acquires resource information from an external web service by writing a code that executes a REST API request in JavaScript |
Script |
Acquires resource information from an external web service by writing a code that executes a REST API request in a script. |
CLI Command |
Acquires the execution results of a CLI command as resource information |
File |
Acquires resource information from a specified file |
In addition, built-in External Resource Providers that acquire resources from the JP1/AO server are provided. If you select the following built-in External Resource Providers in External Resource, execute the applicable REST API request on the JP1/AO server to obtain the resource.
The following built-in External Resource Providers are available.
External Resource |
Information that can be acquired |
Request REST API |
---|---|---|
Tasks |
a list of tasks |
GET /Automation/v1/objects/Tasks/ |
TaskLogs |
task logs |
GET /Automation/v1/objects/TaskLogs/ |
TaskHistories |
a list of history records |
GET /Automation/v1/objects/TaskHistories/ |
Tags |
a list of tags |
GET /Automation/v1/objects/Tags/ |
TagGroups |
a list of tag groups |
GET /Automation/v1/objects/TagGroups/ |
Services |
a list of services |
GET /Automation/v1/objects/Services/ |
ServiceTemplates |
a list of service templates |
GET /Automation/v1/objects/ServiceTemplates/ |
ServiceGroups |
a list of service groups |
GET /Automation/v1/objects/ServiceGroups/ |
Schedules |
a list of schedules |
GET /Automation/v1/objects/Schedules/ |
PropertyValues |
a list of property values |
GET /Automation/v1/objects/PropertyValues/ |
PropertyInformations |
lists of property definitions and property values |
GET /Automation/v1/objects/PropertyInformations/ |
PropertyGroups |
a list of property groups |
GET /Automation/v1/objects/PropertyGroups/ |
PropertyDefinitions |
a list of property definitions |
GET /Automation/v1/objects/PropertyDefinitions/ |
- Organization of this subsection
(1) Procedure for using the function
-
In Service Builder Edit, create or edit the input properties for service templates or plug-ins in the following windows.
-
Create Input Property for Service dialog box
-
Edit Input Property for Service dialog box
-
Create Input Property for Plug-in dialog box
-
Edit Input Property for Plug-in dialog box
-
-
In the displayed dialog box, specify the settings of External Resource.
For details, see (2) Procedure for setting External Resource.
-
If there is no external resource, create External Resource.
For details, see (3) Procedure for creating an External Resource.
-
In the Service Definition window and the Submit Service window, select the acquired resource information.
Other operations associated with external resources can be performed from the drop-down list of External Resource or from External Resource Provider on the Administration tab.
-
Editing of External Resource.
Update the settings manually.
-
Update of External Resource.
Overwrite the selected External Resource Provider with the content of the specified external resource provider definition file (zip format). The update possibilities of the External Resource Provider are listed in the following table.
Table 4‒9: Update possibilities of the External Resource Provider (ERP) Case
Update possibility
Error message
If VRS of the update source ERP > VRS of the update destination ERP
Possible
--
If VRS of the update source ERP = VRS of the update destination ERP
Possible
--
If VRS of the update source ERP < VRS of the update destination ERP
Not possible
KNAE01889-E
If UUID of the update source ERP is different from that of the update destination ERP
Not possible
KNAE01890-E
-
Deletion of External Resource
-
Import of External Resource
The external resource provider definition file (zip format) is imported.
In Import of External Resource, if an External Resource Provider with the same UUID as the External Resource Provider to be imported already exists, the content of the existing External Resource Provider is overwritten with the content of the external resource provider definition file (zip format) to be imported, regardless of VRS of the External Resource Providers.
Table 4‒10: Import possibilities of the External Resource Provider (ERP) Case
Import
possibilityRemarks
If an ERP with the same UUID as the ERP to be imported does not exist
Possible
--
If an ERP with the same UUID as the ERP to be imported already exists
Possible
Regardless of VRS of the ERP, the content of the existing ERP is overwritten with the content of the ERP to be imported.
-
Export of External Resource
The external resource provider definition file (zip format) is exported.
(2) Procedure for setting External Resource
The procedure for setting External Resource is as follows.
-
Select Selection or Radio Button as the expression format of the input property for a service or plug-in.
-
In Data source, which is displayed, select Dynamic.
Here, the settings items related to External Resource are explained.
Item |
Description |
---|---|
External resource |
The name of an external resource. Define a label for each external resource acquisition method and acquisition target. |
Additional path |
The value to be passed to requestPath in JavaScript or to REQUEST_PATH in a Python script. Specify this when Type of the external resource provider is JavaScript or when Type of the external resource provider is Script. No specification is required unless necessary. |
Query parameter |
The value to be passed to queryParamMap in JavaScript or QUERY_PARAM_MAP in a script. Specify this when Type of the external resource provider is JavaScript or when Type of the external resource provider is Script. No specification is required unless necessary. To specify this item, use the key=value format. Note that you can use ampersands (&) to specify multiple parameters (key=value&key=value). |
Name field# |
Specify the field name of the acquired external resource. The specified field value will be used as a label of an option that appears in the drop-down list. If omitted, the name field will be specified. |
Value field# |
Specify the field name of the acquired external resource. The specified field value will be set as the property value when the label of name field is selected from the drop-down list. If omitted, the instanceID field will be specified. |
- #:
-
If the data type is the composite type, this item is not displayed.
When the following External Resource Provider is set for an input property of a service component, that service component cannot be used in more than one flow:
-
External Resource Provider that references other properties in the query parameter.
(3) Procedure for creating an External Resource
From the pull-down list of External Resource, select (Add New External Resource Provider), and then, in the Create External Resource Provider dialog box, specify the following setting items.
Item |
Description |
---|---|
Name |
Name of the external resource provider Specified name appears in the drop-down list with "ExternalResources/External-Resource-Provider-ID". |
Version |
Version. Specification format: nn.nn.nn Example: 01.00.00 |
Content type |
Data format to be used with the External Resource Provider (formats of the request body, response body, standard output, and file) The following context types (MINE types) can be selected.
(a) application/json Specify in JSON format. {"data":[ object1, object2, ... ]} (b) text/csv Specify in CSV format. Header line record1 record2 ... Note that, if you select text/csv as the content type, select (3) or (4) as the type. |
Description |
Description of the External Resource Provider |
Type |
An external resource acquisition method You can select one of the following types. You need to specify the necessary information in the input field that appears based on the selected type. (1) Javascript (2) Script (3) CLI Command (4) File Note that the following external resources can be acquired when each type is selected. (1) Return values of the JavaScript function (2) Standard output of the script (3) Execution results of the CLI command (4) File contents |
(a) If you specify JavaScript as the type
You need to define a JavaScript function. The following function is defined by default.
Item |
Description |
||
---|---|---|---|
Function name |
function fn(requestPath, queryParamMap, properties) { } |
||
Arguments |
requestPath |
The information specified for Additional path is passed |
Character string /External-Resource-Provider-ID/The-information-specified-for-Additional-path-is-passed |
queryParamMap |
The information specified for Query parameter is passed. |
JSON object that contains a map of the keys and values {"key":"value", …} |
|
properties |
Shared properties#1 and reserved properties#2 of the service is passed. |
JSON object that contains a map of the property keys and property values {property-key:property-value,...} |
|
Response |
An array of JSON objects is returned as a value of the request body returned by the External Resource Provider. The array must be set for the property named "data". The data format is as follows: Response schema: {"data":[ Object1, Object2, … ]} |
- #1:
-
The following shared property cannot be used:
com.hitachi.software.dna.sys.cm.cache.interval
- #2:
-
For details about the reserved properties, see Table 3‒13: List of reserved properties.
- Javascript library (auto_util library)
The auto_util library can be used in JavaScript. The auto_util library has the following main functions:
-
Sends an HTTP or HTTPS request to any connection destination
-
Retrieves the connection information set for the web service connection
The APIs of the auto_util library are as follows.
Table 4‒14: Details of the APIs of the auto_util library Method name
Argument
Return value
Description
sleep
1
Specifies the time to sleep in the numeric-value format
(unit: milliseconds)
None
Sleeps for the specified time
parseJson
1
Specifies a JSON character string expression in the character-string format
JSON object
Converts character strings to JSON objects
stringifyJson
1
Specifies any JSON object
JSON character string expression
Converts JSON objects to character strings
base64.encode
1
Specifies a character string to be converted to Base64
A character string encoded into Base64
Encodes a character string into Base64
base64.decode
1
Specifies a Base64 character string
A character string decoded from Base64
Decodes a character string from Base64
http.call
1
JSON object of the request
JSON object of the response
Performs an HTTP or HTTPS request and returns a response
http.toRawHeader
1
JSON object of the header
Header character string
Returns the header in a character-string format. In the argument, a JSON object to which a key and its corresponding value are set is specified.
http.defaultErrorHandler
1
Error
None
Throws the HttpError instance
2
JSON object of the request
3
JSON object of the response
http.handleCall
1
httpCall method
None
Calls the httpCall method of the first argument by specifying the request of the second argument.
If the resulting response code is 200 or greater, and less than 400, the third argument is called.
In other cases, the fourth argument is called.
2
JSON object of the request
3
Method that is called when an HTTP call is successful
4
Method that is called when the result status code of the HTTP call is 200 or greater, and less than 400
5
Method that is called when an error occurs before an HTTP call
The arguments and JSON objects of the return values are as follows.
Table 4‒15: Details of JSON objects of requests Member
Type
Description
requestUrl
String
If you are not using a web service connection:
Specify the request URL starting with HTTP or HTTPS.
If you are using a web service connection:
Specify the part of the request URL from the "/" after the host name, to the end.
Example: In the case of http://host:port/Folder/, specify "/Folder".
requestMethod
String
HTTP request method.
Specify the following values in the character string:
-
GET
-
POST
-
PUT
-
DELETE
requestHeaders
String
Request headers.
The setting of the return value of the http.toRawHeader method is assumed.
If you are using a web service connection:
The following values can be used as pad characters for the user ID and password:
-
${connection.username}
-
${connection.password}
requestBody
String
The request body
authScheme
String
If authentication is required, specify one of the following values.
-
basic
-
digest
-
negotiate
productName
String
Specify the category of the web service connection.
Be sure to specify this if you are using a web service connection.
connectionName
String
Specify the name of the web service connection.
Be sure to specify this if you are using a web service connection.
userName
String
Specify the user name if you want to perform authentication on the connection destination.
Do not specify this if you are using a web service connection.
password
String
Specify the password if you want to perform authentication on the connection destination.
useProxy
boolean
Specify this (true/false) if you want to use a proxy.
proxyHost
String
Specify the host name or IP address of the proxy server.
proxyPort
int
Specify the port number of the proxy server.
proxyAuthScheme
String
If authentication is required at the proxy server, specify one of the following values.
-
basic
-
digest
proxyUserName
String
Specify the user name if authentication is required on the proxy server.
proxyPassword
String
Specify the password if authentication is required on the proxy server.
Table 4‒16: Details of JSON objects of responses Member
Type
Description
responseHeaders
String
Response header
responseStatusCode
int
Response code
responseStatusMessage
String
Response message
responseBody
String
Response body
-
-
Sample JavaScript code
The following sample looks up the connection information of the web service connection, acquires a list of service templates from JP1/AO, Note that, in the sample, a web service connection must be registered with the name "view" in the category "Automation" in advance.
(function fn (requestPath, queryParamMap, properties) { return getServiceTemplates('Automation', 'view'); function getServiceTemplates(productname, connectionname) { var respBody = null; var request = { requestMethod: 'GET', requestUrl: '/Automation/v1/objects/ServiceTemplates/', requestHeaders:auto.util.http.toRawHeader({ 'Accept': 'application/json', 'Accept-Language': 'en', 'Content-Type': 'application/json', }), authScheme: 'basic', connectionName: connectionname, productName: productname, }; auto.util.http.handleCall(auto.util.http.call, request, function(resp, req) { respBody = resp.responseBody; }, function(resp, req) { auto.util.http.defaultErrorHandler(null, req, resp); }, function(err, req) { auto.util.http.defaultErrorHandler(err, req); }); return respBody; } })
(b) If you specify Script as the type
Specify the following setting items.
Item |
Description |
---|---|
Interpreter path |
Interpreter path of the script. (1) Python script The supported Python version is the 3.x series. To use this External Resource Provider in a cluster environment, the Python interpreter must be installed in both the active and standby systems. Virtual environments in Python are not supported. Shared properties of services can be specified for the interpreter path. |
Script type |
Script type. Only Python is supported. |
Script |
Script implementation An array of JSON objects is returned as a value of the request body returned by the External Resource Provider. The array must be set for the property named "data". The data format is as follows. Script set the data of following JSON format for the standard output(print()). Response schema: {"data":[ Object1, Object2, … ]} |
By using scripts, the following environment variable values can be acquired in the os.environ["key-name"] or os.environ.get("key-name") format.
Environment variable |
Description |
Format |
---|---|---|
REQUEST_PATH |
The information specified for Additional path is passed |
Character string /External-Resource-Provider-ID/The-information-specified-for-Additional-path-is-passed |
QUERY_PARAM_MAP |
The information specified for Query parameter is passed. |
Character string in JSON format {property-name:value,...} |
SERVICE_TEMPLATE_ID |
Service template ID that belongs to the External Resource Provider |
Numeric value |
SERVICE_ID |
Service ID that executes the External Resource Provider |
Numeric value |
SERVICE_TEMPLATE |
Information about the service template that belongs to the External Resource Provider |
Character string in JSON format {service-template-attribute:value,...} |
SERVICE |
Information about the service that executes the External Resource Provider |
Character string in JSON format {service-attribute:value,...} |
WEB_SERVICE_CONNECTIONS |
Setting information of the web service connection. Information that corresponds to "__webServiceConnectionCategory__" and "__webServiceConnectionName__" as were specified for Query parameter is stored. The information to be stored varies depending on the specification of Query parameter. For information about the values to be stored, see Table 4‒19: Values of the environment variable WEB_SERVICE_CONNECTIONS. |
Character string in JSON format [{attribute-of-web-service-connection:value,…}, …] |
Query parameter |
Reference information |
|
---|---|---|
__webServiceConnectionCategory__ |
__webServiceConnectionName__ |
|
Y |
Y |
Information about the web service connection that matches the specified Category and Name |
Y |
N |
Information about the web service connection that matches the specified Category |
N |
Y |
None |
N |
N |
None |
- Legend:
-
Y: Specified, N: Not specified
(c) If you specify CLI Command as the type
Specify the following setting items.
Item |
Description |
---|---|
CLI Command |
The CLI command to be executed on the JP1/AO server. If the return value of the command is a value other than 0, an error occurs. To specify a script file, use its absolute path to specify it. The upper limit of the standard output is 30 MB. The character set for reading the standard output is read through the system character set. By enclosing property keys with "${" and "}", you can include service shared properties and reserved properties in the CLI command. |
(d) If you specify File as the type
Specify the following setting items.
Item |
Description |
---|---|
File |
The path to a file on the JP1/AO server. By enclosing property keys with "${" and "}", you can include service shared properties and reserved properties in the file path. |