VMware Cloud Community
balawiz
Enthusiast
Enthusiast

Unable to find resourceID with DeploymentId

We are using vRA7.6 and external vRO 7.6.

I am trying to find the complete deployment data with the following code.

EBS is configured to start the workflow when "catalog request is completed" (tried with deployment action completed as well). The following code search the resources to match the deployment ID with resourceId and get the deployed data. This is working for sometime, but when sometimes it wasn't able find deployment ID even after trying few mins of deployment gets completed. I am scratching my head any help appreciated.

function getResource(deploymentId) {

     const PAGE_LIMIT = 100; 

     var resourceService = vCACHost.createCatalogClient().getCatalogConsumerResourceService(); 

     var query = vCACCAFEOdataQuery.query();

     query.setTop(PAGE_LIMIT); 

     query.setSkip(0); 

     var oDataRequest = new vCACCAFEPageOdataRequest(query); 

     var resources = []; 

            do { 

              var resourcesList = resourceService.getResourcesList(oDataRequest); 

              resources = resources.concat(resourcesList); 

              System.log("Found Resources: " + resourcesList.length); 

              query.setSkip(resources.length); 

              oDataRequest = new vCACCAFEPageOdataRequest(query); 

               } while (resourcesList.length > 0);

          for each(resource in resources) {

               if (resource.providerBinding.bindingId == deploymentId) {

               return resource.id;

               }

          }

throw 'Could not find resource with binding to deploymentId: ' + deploymentId;

}

function parseData(rawData) {

var data = rawData.replace(/\\"/g, "'");

    return JSON.parse(data.replace(/\\/g, ''));

}

//Main

var tempData = [];

var client = vCACHost.createCatalogClient();//vCACCAFE:vCACHost

var deploymentId = payload.get('deploymentId');

System.debug('DeploymentID: ' + deploymentId);

var resourceId = getResource(deploymentId);

System.debug('Resource ID: ' + resourceId);

//check whether any backslash

var checkSlash = client.get('/consumer/resources/' + resourceId);

//System.log('Check: ' + checkSlash);

var bodyAsString = checkSlash.getBodyAsString();

var removedSlash = bodyAsString.replace(/\\/g, "");

//System.log('Removed slash: ' + removedSlash);

var requestId = JSON.parse(removedSlash).requestId;

System.debug('Request ID: ' + requestId);

//with request and resourceId get all data and dump into tempData

tempData.push(parseData(client.get('/consumer/requests/' + requestId).getBodyAsString()));

var resourceData = parseData(client.get("/consumer/resources/?$filter=(parentResource eq '" + resourceId + "')&limit=100").getBodyAsString());

for each(item in resourceData.content) {

tempData.push(parseData(client.get('/consumer/resources/' + item.id).getBodyAsString()));

}

Tags (2)
0 Kudos
0 Replies