VMware Cloud Community
Windspirit
Hot Shot
Hot Shot

How to get the ResourceActionRequest from the EventManager Payload (reconfigure task)

This is a follow up from Looking for the right Custom Properties for event VMPSMasterWorkflow32.EVENT.ReconfigureVM

I expected that the payload of the request shows me the NEW configuration but it only gives me the current configuration not the one that was submitted in the request

I found what I need in the ResourceActionRequest there I have requestData which is a LiteralMap and has all the changes (see vra7 how to configure subscription for vm reconfigure action? at the end)

I can access the all the requests (type: ResourceActionRequest) in the system and also find (manually ) the one I want...BUT how do i get from the payload I'm given to the correct request?

All the IDs in teh payload as well as the ASD IDs do not match the ActionRequest.ID (or any request IDs I can find).

To get all the Requests an troll them use:

var cafeHost = Server.findAllForType("vCACCAFE:VCACHost")[0];

var reqs = vCACCAFEEntitiesFinder.getResourceActionRequests(cafeHost);

for each (req in reqs){

    System.log(req.requestData);

}

The payload gives me:

  • __api.request.id (no idea)
  • requestId (same as __api.request.id )
  • __Cafe.Root.Request.Id (CatalogRequests, the original request that build the VM)
  • __iaas_request_binding_id (Blueprint ID)
  • __asd_requestInstanceId (no idea)
  • __asd_catalogRequestId (no idea)
  • __asd_correlationId (same as __Cafe.Root.Request.Id)
  • __asd_requestTraceId (no idea)

none of these IDs match any of the IDs in the ReqourceActions

Anyone?

Reply
0 Kudos
4 Replies
Windspirit
Hot Shot
Hot Shot

I found a "dirty" workaround. I store the old configurion of the vm before the change and then check against it in after the change. Here the code:

VRA Config

PreReconfigure

Event Manager subscribe to Lifecycle state name event  = VMPSMasterWorkflow32.VMPSMasterWorkflow32.EVENT.ReconfigureVM.Pending and Machine Type = Virtual Machine

Workflow: PreConfigure

PostReconfigure:

Event Manager subscribe to Lifecycle state name = VMPSMasterWorkflow32.Requested, state phase = Pre and Machine Type = Virtual Machine

Workflow: PostConfigure

Add the following Custom Property to your VM blueprint:

Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.VMPSMasterWorkflow32 with value *

VRO Config

Create a Resource Resource Folder called Customer and then a subfolder temp which I use to save the old configuration.

PreConfigure Workflow:

Input: Payload  (Properties)

network = payload.get("machine").get("properties").get("VirtualMachine.Network0.Name");

cpu=payload.get("machine").get("properties").get("VirtualMachine.CPU.Count");

mem=payload.get("machine").get("properties").get("VirtualMachine.Memory.Size");

resname=payload.get("requestId");

var attachment = new MimeAttachment();

attachment.name = resname;

attachment.mimeType = "text/plain";

attachment.content = cpu+","+mem+","+network;

resourcefolder=Server.getResourceElementCategoryWithPath("Customer/temp/")

Server.createResourceElement(resourcefolder,resname,attachment);

PostConfigure Workflow:

Input: Payload  (Properties)

Output: Chnaged (Array of Strings)

var Changed = new Array();

newNetwork = payload.get("machine").get("properties").get("VirtualMachine.Network0.Name");

newCpu=payload.get("machine").get("properties").get("VirtualMachine.CPU.Count");

newMem=payload.get("machine").get("properties").get("VirtualMachine.Memory.Size");

requestID=payload.get("requestId")

resourcefolder=Server.getResourceElementCategoryWithPath("Customer/temp/")

    for each (resource in resourcefolder.allResourceElements){

        if (resource.name == requestID ){

            attachment = resource.getContentAsMimeAttachment();

            var values=attachment.content;

            Server.removeResourceElement(resource);

        }

    }

Changed=values.split(",");

Changed.push(newCpu);

Changed.push(newMem);

Changed.push(newNetwork);

Result

The result is an array that contains the oldCPU, oldMem, OldNet, newCPU, newMem, newNet which then can be used to check on changes. This wrks ut its not really satisfactory.

I still would like to understand how to get a link between the Request Payload and the ResourceActionRequest which contains better and more information. Please ANYONE?

Reply
0 Kudos
GrantOrchardVMw
Commander
Commander

Paging Burke-

Grant http://grantorchard.com
Reply
0 Kudos
Burke-
VMware Employee
VMware Employee

Ummmm...... yeah, why doesn't the payload have anything to easily link/query the ResourceActionRequest stuff? If it at least had the ResourceACtionRequestId as one of the properties, then we could use the vCACCAFEEntitiesFinder.getResourceActionRequest(vCACCAFEHost,String) method where String is the ID of the ResourceActionRequest object we wish to load... or, better yet - provide the resourceActionRequest object as part of the payload when applicable...

Sorry I'm not more help here, my experience digging around the vRA API is somewhat limited Smiley Wink

Does Engineering watch/participate in this community the way they do the Orchestrator one??

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
DanieleUlrich
Enthusiast
Enthusiast

This is a quite old thread but I found it having exactly the same issues.

What I have sorted out so far:

a) the correlationId seems to be always the same ID for a given asset pointing to the  "birth" request: the first provisoning request. For each resourceactionrequest this original request will be used - maybe as a locking mechanism - and the pending requests are  added to the resp. variable of the first request.

b) there is no reference back from the catalogItemRequest (birth request) to the provisioned resource, but from the resource to its creation request.

c) in each resourceactionrequest there is a reference to the resource on which the action is executed.

As some operations can trigger a lot of events I decided to cache the results after the frist processing with this handy utility plugin: GitHub - dimitrovvlado/o11n-plugin-cache: Cache plug-in for vRealize Orchestrator

//assert requestId

if (!requestId) {

requestId = __asd_correlationId;

}

//check if already processed and in cache

eventInfos = CacheManager.mapService.get(requestId);

if (!!eventInfo) {

     System.debug("got cached object:" + eventInfos);

//if event comes with machine object, start processing

} else if (!!machine) {

     machineObj = JSON.parse(machine);

     var vcacHosts = Server.findAllForType("VCACCAFE:VCACHost"); 

     var vCacHost;

     for each (var _objCafeHost in vcacHosts){

            if(_objCafeHost.tenant == __asd_tenantRef){

               vCacHost = _objCafeHost;

               break;

            } // end if

     } // end for each

     if (!vCacHost){throw "ERROR - Unable to find a CAFE Host for: " + __asd_tenantRef;}

     try {

          //get root request

          var requestService = vCacHost.createCatalogClient().getCatalogConsumerRequestService();

          var rootRequest = requestService.getRequest(__asd_correlationId);

          if (!!rootRequest) {

          //if the root request is already stopped (provisioning completed), look for resourceActionRequests

          if (rootRequest.executionStatus.value()=="STOPPED") {

          //get machine by name

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

          var filter = new Array();

          filter[0] = vCACCAFEFilterParam.equal("name", vCACCAFEFilterParam.string(machineObj.name));

          var query = vCACCAFEOdataQuery.query().addFilter(filter);

          if (!resourceService) {throw "ERROR - Unable to find a CAFE resourceService for: " + __asd_tenantRef;}

          var machineResource = resourceService.getResourcesList(new vCACCAFEPageOdataRequest(query));

          if (!!machineResource) {

               //get last request for this machine

               var conditions = new Array();

               conditions[0] = vCACCAFEFilterParam.equal("resource", vCACCAFEFilterParam.string(machineResource[0].id));

               conditions[1] = vCACCAFEFilterParam.equal("resource", vCACCAFEFilterParam.string(machineResource[0].parentResourceRef.id));

               filter = new Array();

               filter[0] = vCACCAFEFilterParam.or(conditions);

               query = vCACCAFEOdataQuery.query().addFilter(filter).setTop(1).addDescOrderBy(["requestNumber"]);

               var lastRequests = requestService.getRequests(new vCACCAFEPageOdataRequest(query));

               if (!!lastRequests) {

                    for each (var element in lastRequests.content) {

                         var eventInfo = {};

                         eventInfo.machineId=machineResource[0].id;

                         eventInfo.deploymentId=machineResource[0].parentResourceRef.id;

                         eventInfo.userRequestId=element.id;

                         eventInfo.userRequestType=element.requestedItemDescription;

                         eventInfo.userRequestName=element.requestedItemName;

                         eventInfos = JSON.stringify(eventInfo);

                         CacheManager.mapService.put(requestId, eventInfos, 30, CacheTimeUnit.MINUTES);

                    }

                }

            }

          }

          if (!eventInfos) {

               var eventInfo = {};

               eventInfo.machineId=null;

               eventInfo.deploymentId=null;

               eventInfo.userRequestId=__asd_correlationId;

               eventInfo.userRequestType="CatalogItemRequest";

               eventInfo.userRequestName=rootRequest.requestedItemName;

               eventInfos = JSON.stringify(eventInfo);

               CacheManager.mapService.put(requestId, eventInfos, 30, CacheTimeUnit.MINUTES);

               }

          }

     } catch(ex) {

          var event{};

          eventInfo.machineId=null;

          eventInfo.deploymentId=null;

          eventInfo.userRequestId=__asd_correlationId;

          eventInfo.userRequestType="hooks error";

          eventInfo.userRequestName="could not resolve root request";

          eventInfos = JSON.stringify(eventInfo);

     }

}

This should work but is somewhat fuzzy. You can improve it by checking the timestamps of the event with the requests.

If you have found a better way to solve this problem I would be interested to learn about it...