VMware Cloud Community
JeanChristopheD
Enthusiast
Enthusiast
Jump to solution

How to send a vCACCAFEReservation from a script to another inside a vRO workflow ?

Hi team,

I'm currently working with vRealize Orchestrator 7.3.1 for some time and I didn't find how to send a vCACCAFEReservation object from a script to another inside a vRO workflow.

Let's review my current path.

I've built a simple workflow :

simple workflow.PNG

The "send" script contains the creation of a fresh new vCACCAFEReservation object, makes some debug and stores it into a workflow attribute.

cafeReservation.PNG

send binding.PNG

According to the type that we are supposed to carry, the attributes is a vCACCAFE:Reservation object :

vcaccafe reservation attribute.PNG

In the same way, the attribute in linked as input in the second script to get back the vCACCAFEReservation object :

get binding.PNG

And now, we end trying some very basic logging.

attempt to log the attribute.PNG

It's now time to start the workflow and to review the logs :

workflow error.PNG

We can see that the object could be logged in the "send" script, even if it is empty.

Once moved in the "get" script, the exact same log operation crashes with the error :

Workflow execution stack:

***

item: 'Enigma 1/item1', state: 'failed', business state: 'null', exception: 'Unable to convert object, 'com.vmware.vcac.reservation.rest.stubs.Reservation@2efbb9e4' plugin exception reason : convertToResult() --> Finder 'vCACCAFE:Reservation' : unexpected error 'ch.dunes.model.sdk.SDKFinderException: convertToResult() --> Finder 'vCACCAFE:Reservation' unable to invoke expression 'getVcoId()' on Finder object 'com.vmware.vcac.reservation.rest.stubs.Reservation@2efbb9e4', reason 'MethodFailedException : Method "getVcoId" failed for object com.vmware.vcac.reservation.rest.stubs.Reservation@2efbb9e4'''

workflow: 'Enigma 1' (aad95865-a6fe-4b72-8c33-e4db381aafd6)

|  'attribute': name=cafeReservation type=vCACCAFE:Reservation value=__NULL__

|  'attribute': name=vraHost type=vCACCAFE:VCACHost value=dunes://service.dunes.ch/CustomSDKObject?id='2dc26458-a566-4266-9b78-32f9ed5a172f'&dunesName='vCACCAFE:VCACHost'

|  'no inputs'

|  'no outputs'

*** End of execution stack.

I'm open to suggestions, thanks for your help !

1 Solution

Accepted Solutions
eoinbyrne
Expert
Expert
Jump to solution

You could have a look at the CAFEReservationClient class maybe? You can retrieve a set of pre-authenticated REST client Wrapper classes from the vCACCAFEHost instance.

i.e., var resClient = host.getReservationClient();

vRO API Explorer by Dr Ruurd and Flores of ITQ - vCACCAFEReservationClient

This would be the same as using the vRA REST API and I've used this approach before for querying the content of Reservations before but not for creating. There is a post method so if you coupled this with some JSON object handling & the vRA Reservation REST API

reservation-service API - vRealize Automation REST API - VMware API Explorer - VMware {code}

The you could probably string together the parts you need to create new Reservations that way?

HTH

View solution in original post

9 Replies
eoinbyrne
Expert
Expert
Jump to solution

Hi

The problem is actually quite simple and is related to the variable scope in your send script

You have the workflow attribute named "cafeReservation" and this creates a global variable with that name for the entire workflow. However in the send script you have this line

var cafeReservation = ....

This is the problem. It is a quirk of the JS implementation (or perhaps JS in general?) that permits you to create the locally scoped variable with the same name. The syntax highlighter in the vRO client is only parsing for value matches and so it looks in the client like you are assigning the same variable but in fact there are two

- the workflow attribute

- the send script locally scoped value that happens to have the same name

The quick fix here is to change the assignment line to this

cafeReservation = ....

I fell into this one a lot in my early days with vRO too Smiley Happy

HTH

0 Kudos
JeanChristopheD
Enthusiast
Enthusiast
Jump to solution

Hi,

Thanks a lot for having an eye on my issue 🙂

I applied the fix you suggested while improving the logging so here are the actual "send" and "get" scripts :

improved send.PNG

improved get.PNG

The issue still occurs and it seems to appear after the end of send script and before the beginning of the get one.

issue at binding time.PNG

From my understanding, the error raises at the time vRO is binding the output values of the script to the workflow attributes as defined in the visual binding tab.

Workflow execution stack:

***

item: 'Enigma 1/item1', state: 'failed', business state: 'null', exception: 'Unable to convert object, 'com.vmware.vcac.reservation.rest.stubs.Reservation@213f41ab' plugin exception reason : convertToResult() --> Finder 'vCACCAFE:Reservation' : unexpected error 'ch.dunes.model.sdk.SDKFinderException: convertToResult() --> Finder 'vCACCAFE:Reservation' unable to invoke expression 'getVcoId()' on Finder object 'com.vmware.vcac.reservation.rest.stubs.Reservation@213f41ab', reason 'MethodFailedException : Method "getVcoId" failed for object com.vmware.vcac.reservation.rest.stubs.Reservation@213f41ab'''

workflow: 'Enigma 1' (aad95865-a6fe-4b72-8c33-e4db381aafd6)

|  'attribute': name=cafeReservation type=vCACCAFE:Reservation value=__NULL__

|  'attribute': name=vraHost type=vCACCAFE:VCACHost value=dunes://service.dunes.ch/CustomSDKObject?id='2dc26458-a566-4266-9b78-32f9ed5a172f'&dunesName='vCACCAFE:VCACHost'

|  'attribute': name=test type=string value=

|  'no inputs'

|  'no outputs'

*** End of execution stack.

On another side and just for a good understanding of the product, I made the same "travel" operation on a simple string with and without the "var" and it's working in each case :

working for a string.PNGworking for a string no var.PNG

I'm open to any suggestion, any other idea ?

Thanks !

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

This looks like a problem with the CAFE plug-in; possibly wrong/conflicting Java classes being loaded.

Could you tell me the versions and build numbers of CAFE plug-in and vRA/vRO appliance that you are using?

0 Kudos
JeanChristopheD
Enthusiast
Enthusiast
Jump to solution

Hi,

I got the issue in 7.3.1 now updated in 7.4.

The current build where the error is still there is :

vcaccafe plugin.PNG

Thanks for your help !

0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

I reckon the bind operation where the workflow passes vars between the scripts is the problem too.

I wonder if the fact that vCACCAFEReservation is not in the vRO Inventory is the issue? You've done a "new vCACCAFEReservation()" there so this is a fresh object that might be expected by some part of the workflow handling to be a fully specified instance (have all fields and methods implemented)

It may be that the vRO application (or plugin) creates instances of these objects via a different mechanism ---> the object you actually get from the inventory is more or less a composite object or has sub-objects to which it delegates some of it's methods... Looking at the API doc for the object

here - vRO API Explorer by Dr Ruurd and Flores of ITQ

The method "getVcoId" returns an object. In your case here with your created instance, I'd expect this to be null and so you get the error below.

Anyway enough speculation, can you try this in the send script?

// load all Reservations from inventory

var allReservations = Server.findAllForType("vCACCAFE:Reservation");

if(allReservations == null || allReservations.length == 0)

{

     throw "No reservations found! Cannot continue.....";

}

// take the first available instance for the test

cafeReservation = allReservations[0];

// finish of send script

This should work properly since the object will be a complete instance taken from the vRO inventory

iiliev
VMware Employee
VMware Employee
Jump to solution

After some discussions with vRA team, it seems this error is the expected outcome in this case.

Some types, including vCACCAFEReservation, are stub types that are 'enriched' at runtime by dynamically adding methods to them. In this particular case, the vCACCAFEReservation type does not have method getVcoId by default, so when you try to instantiate it via new operator and then serialize it, you'll end up with the observer error.

When you get an instance of this type by some other means, eg. as a result from some other API call, the object will be 'enriched' by the plug-in runtime, the method getVcoId will be there, and the serialization will complete successfully. So the correct usage pattern for objects of such types is to not instantiate them via new but fetch them somehow using API.

BTW, this is somewhat similar to vCenter plug-in where the so-called 'managed' vCenter objects should be fetched instead of instantiated (although there trying to serialize a managed object should not throw such error).

JeanChristopheD
Enthusiast
Enthusiast
Jump to solution

Hi,

First, thanks for your ideas !

I tested to play with an existing reservation and it is working as suggested :

existing reservation works.PNG

Nevertheless, my final goal is to be able to automate new reservations creation in a clean way and not stacking all the code inside a monolithic script.

That's why I need to be able to send this "under construction" vCACCAFEReservation item from a script to another (and even is possible from a workflow to another) in order to split each phasis :

- compute resource vCACCAFEEntityReference forging,

- quota vCACCAFEIntegerLiteral settings,

- memory vCACCAFEComplexLiteral settings,

- storage vCACCAFEMultipleLiteral forging amoung all datastores,

- network vCACCAFEMultipleLiteral forging with network profiles matching selected network adapters,

- and much more...

It would allow the creation of a modular and easy-to-enhance automated reservation system.

Thus, is-there any way to get this missing new VcoId on a fresh new object to satisfy the requirement of the serialization mecanism ?

Thanks a lot !

0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

You could have a look at the CAFEReservationClient class maybe? You can retrieve a set of pre-authenticated REST client Wrapper classes from the vCACCAFEHost instance.

i.e., var resClient = host.getReservationClient();

vRO API Explorer by Dr Ruurd and Flores of ITQ - vCACCAFEReservationClient

This would be the same as using the vRA REST API and I've used this approach before for querying the content of Reservations before but not for creating. There is a post method so if you coupled this with some JSON object handling & the vRA Reservation REST API

reservation-service API - vRealize Automation REST API - VMware API Explorer - VMware {code}

The you could probably string together the parts you need to create new Reservations that way?

HTH

JeanChristopheD
Enthusiast
Enthusiast
Jump to solution

Hi,

I think I'll dig your option in order to reach my target.

Seems that my first approach is not compatible with the way the product has been designed...

Thanks a lot for your help !

0 Kudos