VMware Cloud Community
bmorbach
Enthusiast
Enthusiast
Jump to solution

VCO REST API - POST - Connection pool shut down

Hello

I am working on an automation scenario where I need a workflow in VCO A to start another workflow in VCO B using the VCO REST Plugin (1.0.2) on VCO 5.1.1.

I have done this successfully while creating a REST Host and a REST Operation using the appropriate workflows. However for my approach this is much to static and I need to create REST operations on the fly. I have peeked at the Plugin workflows and try to do the same in my workflow.

However I am stuck with the "Connection pool shut down" error when trying to execute the actual POST request.

My approach is to store the REST Host object as a static attribute with the VCO configuration and retrieve it from there. I can run GET operations without any problems directly with the host, i.e.


restRequest = restHost.createRequest(restType, restUrl, restContent);

restResponse = restRequest.execute();

My problem is actually running a POST operation. I have prepared the content in XML format, i.e.

<execution-context  xmlns="http://www.vmware.com/vco">
     <parameters>

       <parameter name="param1" type="string">

            <string>value1</string>

       </parameter>

       <parameter name="param2" type="string">

             <string>value2</string>

       </parameter>

      </parameters>

</execution-context>

and use the content type "application/xml". Earlier in my code I run a GET request to retrieve my target workflow ID for creating a Url like this:

/workflows/98c3b8ee-9569-4940-acc1-b8fbc2e64649/executions/

This is code I am using to perform the POST while creating a REST operation when needed and deleting it afterwards.


var restOperation = new RESTOperation(System.nextUUID());

restOperation.method = restType;

restOperation.urlTemplate = restUrl;

restOperation.defaultContentType = restContentType;

restHost.addOperation(restOperation);

RESTHostManager.updateHost(restHost); 

var inputParameters = [];

var restRequest = restOperation.createRequest(inputParameters, restContent);

restRequest.contentType = restContentType;

var restResponse = restRequest.execute();

restHost.removeOperation(restOperation.id);

RESTHostManager.updateHost(restHost);

My code fails when invoking the restRequest.execute throwing: 'InternalError: Connection pool shut down'. Has somebody else tried a similar scenario or has an idea what I may be missing?

Thanks,

Bernd

0 Kudos
1 Solution

Accepted Solutions
bmorbach
Enthusiast
Enthusiast
Jump to solution

Thanks chap - updating the objects did the trick.

In my case that initially caused the problem to travel from PUT to GET. Obviously storing the restHost object in the VCO configuration leads to an outdated version at runtime. I am now storing the restHost ID only. Then this code works:

var restHostId = System.getModule("my.library").myGetConfigAttr("Folder","VCO","restHostId");

var restHost = RESTHostManager.getHost(restHostId);

if ( restType == "GET" ) {
try {
  restRequest = restHost.createRequest(restType, restUrl, restContent);
  restResponse = restRequest.execute();
}
catch ( exp ) { throw("Run REST request: Failed to run '" + restType + "' '" + restUrl + "' request - Reason = '" + exp + "'"); }
}
else {
try {
  var restOperation = new RESTOperation(System.nextUUID());
  restOperation.method = restType;
  restOperation.urlTemplate = restUrl;
  restOperation.defaultContentType = restContentType;
 
  restHost.addOperation(restOperation);
  RESTHostManager.updateHost(restHost);
 
  restHost = RESTHostManager.getHost(restHost.id);
  restOperation = restHost.getOperation(restOperation.id);

  var inputParameters = [];
  var restRequest = restOperation.createRequest(inputParameters, restContent);
  restRequest.contentType = restContentType;

  var restResponse = restRequest.execute();

  restHost.removeOperation(restOperation.id);
  RESTHostManager.updateHost(restHost);
}
catch ( exp ) { throw("Run REST request: Failed to run '" + restType + "' '" + restUrl + "' request - Reason = '" + exp + "'"); }
}

View solution in original post

0 Kudos
2 Replies
igaydajiev
VMware Employee
VMware Employee
Jump to solution

I haven't tested it but you can try refreshing the host and operation  instances after the update.

var restOperationId = System.nextUUID();

var restOperation = new RESTOperation(restOperationId);

restOperation.method = restType;

restOperation.urlTemplate = restUrl;

restOperation.defaultContentType = restContentType;

restHost.addOperation(restOperation);

RESTHostManager.updateHost(restHost);

//Get fresh instance of the host and operation

var updatedHost = RESTHostManager.getHost(restHost.id);

var updatedRestOperation = updatedHost.getOperation(restOperationId);

var inputParameters = [];

var restRequest = updatedRestOperation.createRequest(inputParameters, restContent);

restRequest.contentType = restContentType;

var restResponse = restRequest.execute();

restHost.removeOperation(restOperation.id);

RESTHostManager.updateHost(restHost);

bmorbach
Enthusiast
Enthusiast
Jump to solution

Thanks chap - updating the objects did the trick.

In my case that initially caused the problem to travel from PUT to GET. Obviously storing the restHost object in the VCO configuration leads to an outdated version at runtime. I am now storing the restHost ID only. Then this code works:

var restHostId = System.getModule("my.library").myGetConfigAttr("Folder","VCO","restHostId");

var restHost = RESTHostManager.getHost(restHostId);

if ( restType == "GET" ) {
try {
  restRequest = restHost.createRequest(restType, restUrl, restContent);
  restResponse = restRequest.execute();
}
catch ( exp ) { throw("Run REST request: Failed to run '" + restType + "' '" + restUrl + "' request - Reason = '" + exp + "'"); }
}
else {
try {
  var restOperation = new RESTOperation(System.nextUUID());
  restOperation.method = restType;
  restOperation.urlTemplate = restUrl;
  restOperation.defaultContentType = restContentType;
 
  restHost.addOperation(restOperation);
  RESTHostManager.updateHost(restHost);
 
  restHost = RESTHostManager.getHost(restHost.id);
  restOperation = restHost.getOperation(restOperation.id);

  var inputParameters = [];
  var restRequest = restOperation.createRequest(inputParameters, restContent);
  restRequest.contentType = restContentType;

  var restResponse = restRequest.execute();

  restHost.removeOperation(restOperation.id);
  RESTHostManager.updateHost(restHost);
}
catch ( exp ) { throw("Run REST request: Failed to run '" + restType + "' '" + restUrl + "' request - Reason = '" + exp + "'"); }
}

0 Kudos