vRealize Orchestrator and Invoke a REST Host Workflow

Continuing my recent work on learning vRealize Orchestrator and ran into some funkiness with the “Invoke REST host” workflow, that I wanted to write down so I don’t forget how I fixed/worked around it (which I suppose is the impetus for basically every post I do). Anyways, I am working on a REST-based package for the FlashArray and I was using that workflow and had some trouble. Basically, any REST call I made through it to a REST host seemed to fail.

schema

The “Invoke a REST host” workflow in the HTTP-REST Samples folder is a way to make a one off REST call to a specific REST host (in this case a FlashArray). So the below screenshot is me making a simple array info call (to get the name, Purity version etc).

getarray

The first line asks for the host and the second is the specific call, so the full API call will be:

https://csg-fa405-1.csg.local/api/1.4/array

When I run the workflow it seems to work, but the logs show the following:

[2015-11-17 09:46:08.768] [I] Host: DynamicWrapper (Instance) : [RESTHost]-[class com.vmware.o11n.plugin.rest.RESTHost] -- VALUE : com.vmware.o11n.plugin.rest.RESTHost@c73dd1c6, operation: /api/1.4/array, Request Type: undefined
[2015-11-17 09:46:08.769] [I] request: DynamicWrapper (Instance) : [RESTRequest]-[class com.vmware.o11n.plugin.rest.Request] -- VALUE : com.vmware.o11n.plugin.rest.Request@293fd502
[2015-11-17 09:46:08.795] [I] response: DynamicWrapper (Instance) : [RESTResponse]-[class com.vmware.o11n.plugin.rest.Response] -- VALUE : com.vmware.o11n.plugin.rest.Response@770a87bf

The “Request type” which was indicated as a GET call in the wizard, is null in the log file (see bolded words above. Plus I didn’t see any response with the array information. I first thought it wasn’t working at all, but if you look at the variables directly you do see the information on the array.

variablerepsone

So must just be logging. I took a look at the Javascript for the workflow, the default javascript is as below:

System.log("Host: " + restHost + ", operation: " + operationUrl + ", Request Type: " + requestType.name);
var request = restHost.createRequest(requestType, operationUrl, requestContent);
System.log("request: " + request);
var response = request.execute();
System.log("response: " + response);
result = new Properties();
result.put("statusCode", response.statusCode);
result.put("contentLength", response.contentLength);
result.put("headers", response.getAllHeaders());
result.put("contentAsString", response.contentAsString);

So the workflow only logs three things:

  1. The first log line should show the selected host, the specific REST call and the type of the REST call (GET, POST etc.)
  2. The full request
  3. The response

Well, at least I think that is what was intended. But definitely not what happens and what the script does.

You can see it seems to log the type or identifier of the variables, like the host and the content type, but not actually the information in it. Basically not helpful whatsoever. The only thing that really logs right is the operation URL. So either I am not getting why they logged it this way, something was changed somehow to break this or this default workflow is just wrong. Anyways, let’s fix it. Duplicate the workflow so you can edit it. I changed the javascript in a few ways.

I removed the second two system.log lines because they don’t really do anything useful. The first one I changed to this:

System.log("Host: " + restHost.url + ", operation: " + operationUrl + ", Request Type: " + requestType);

You can notice two main changes, first the host is now logging the URL of the host instead of what it was before and the Request Type is now requestType instead of requestType.name (because that value doesn’t exist which is why it returned null).

I added this log entry too at end of the script:

System.log("Response" + result.contentAsString);

This will report the actual REST response. So my log file now looks like:

[2015-11-17 10:38:31.780] [I] Host: https://csg-fa405-1.csgvmw.local, operation: /api/1.4/array, Request Type: GET
[2015-11-17 10:38:31.847] [I] Response{"version": "4.5.8", "revision": "201510211326+efc27c1", "array_name": "csg-fa405-1", "id": "73e94022-5a2a-52bb-222b-d4ced012bc6f"}

Ah much more useful! So the workflow “works” but just doesn’t log properly in my opinion.