VMware Cloud Community
balawiz
Enthusiast
Enthusiast

Get Resources from Deployment ID

To generate a report, I am getting the resources using deployment ID with the following code. This code is working, but sometime it's failing (re-running workflow also unsuccessful) as 'Could not find resource with binding to deploymentId: ' + deploymentId. Any help is appreciated and I am using vRA/vRO 7.6.

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;

}

var client = vCACHost.createCatalogClient();

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

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

var resourceId = getResource(deploymentId);

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

Tags (3)
10 Replies
eoinbyrne
Expert
Expert

Are you doing this in an EventBroker subscription? I ask due to this line in you code

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

If this is in the EBS then you need to be aware that you cannot rely on CatalogResources existing within the scope of the VM provisioning lifecycle. The CatalogResource is not available at the Consumer level until after the Deployment request has completed (Note: I've not tried this in 7.6 so perhaps it's different? - can anyone from VMware confirm?)

I can recall from previous projects that the delay between the request completion and the Resource existing in the Consumer catalog might be sometimes in the order of minutes.

If this is not EBS then perhaps you still have a timing/ordering issue since the Consumer service can only report on resources it knows about and your DeploymentID is coming from an external source.

HTH

Reply
0 Kudos
balawiz
Enthusiast
Enthusiast

This was developed from 7.2 and we upgraded to 7.6 recently. Actually, this issue was there in 7.2 as well with more frequent. I thought this issue may be resolved after upgrade but started happening again and is little frequent. Also, sleep (30s) has been set before start gathering the details. Anyhow, I have retried the failed workflow after 15-25 mins of deployment is completed, but still its failing and unable to find the resources with deployment ID.

Reply
0 Kudos
Sany201110141
Contributor
Contributor

@eoinbyrne

"If this is in the EBS then you need to be aware that you cannot rely on CatalogResources existing within the scope of the VM provisioning lifecycle. The CatalogResource is not available at the Consumer level until after the Deployment request has completed"

Is there any EBS event that trigger just after catalog request finished and catalog resource available at consumer level?

Reply
0 Kudos
eoinbyrne
Expert
Expert

I should also that my experience of the CatalogResource delay was in vRA 7.3 or so. I've been doing the same thing in a 7.5 installation (just today in fact Smiley Happy) and have not noticed that lag time. My deployment resource is more or less immediately present after the IaaS request has completed. I'm using the vRO Trigger mechanism to hand off requests using a service account (see the OOTB workflow @ Library / vRealize Automation / Requests / Wait for catalog item request)

Sany201110141​ - Yes, very good point. This is the event you want

pastedImage_0.png

From the schema content there it looks like you will get the ID of the Deployment resource in the event so you'd need to look that up to access any details about it. This was helpful when I was doing working on this today - Finding vRA Virtual Machines upon successful Catalog Item Request Completed event

HTH

Sany201110141
Contributor
Contributor

Thank you eoinbyrne

Reply
0 Kudos
balawiz
Enthusiast
Enthusiast

Sorry for late reply I was tied with other projects. Event after using with "catalog request completed" EBS event, sometimes getting the resource is error out and block subscription is not really working. Can you give more details about the trigger mechanism to handover the requests?

Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot

If you use Blocking for Catalog Item Request Completed the catalog resource will not be available until that blocking subscription completes. Unfortunately the item is not in the inventory until the entire lifecycle is completed. The behaviour is different in vRA 8.0.

Reply
0 Kudos
eoinbyrne
Expert
Expert

Have a look at the OOTB workflow from the vRA Plugin

Library / vRealize Automation / Requests / Wait for catalog item Request

It shows how to create a trigger for the Submitted Request and how to handle the result when it fires.

At the moment I have an XaaS workflow which the provides the User with a form to request their server. When they submit that request, the workflow customizes the IaaS CatalogItem request and submits that as a privileged service account user. The trigger wait is used to do the following

- Keep the XaaS request as InProgress

- Wait until the IaaS trigger fires

- Assess the IaaS result and locate the Deployment to report the name, IP address etc in an email

I use the trigger to keep the XaaS running and to let me know when the IaaS is completed. As I said above, I noticed that there is a delay between the trigger firing to say IaaS completed and the Deployment resource appearing in the Catalaog.

Reply
0 Kudos
balawiz
Enthusiast
Enthusiast

Thank you eoinbyrne​. I will test that workflow.

Reply
0 Kudos
balawiz
Enthusiast
Enthusiast

I will check by not using the Blocking setting. But, when it fails to get the resourceId using deploymentId it never gets the resourceId even after trying some hours/days.

I have also tried when "Deployment action completed" which works for sometime and fails often.

Reply
0 Kudos