9 Replies Latest reply on Aug 30, 2017 1:36 PM by mknunez

    Orchestrator 7.2 to 7.3 upgrade breaks some scripting

    KRAEMS Novice

      Hi Everyone,

       

      The 7.2 upgrade to 7.3 'broke' some scripting I inherited designed to take input parameters of Datacenter and VM and return the best host on which to clone a VM.  Here is the script (which continues to run fine in 7.2):

       

      System.log( "The value of dataCenter is " + dataCenter);

      System.log( "The value of vm is " + vm);

       

      function getHostFromFolder( folder , vmachine ){

        return folder.clusterComputeResource[0].recommendHostsForVm( vm );

      }

       

      if (!dataCenter)

      {

        return null;

      }

       

      if (!vm)

      {

        return null;

      }

       

      var searchFolder = dataCenter.hostFolder;

       

      foundItems = getHostFromFolder( searchFolder , vm);

       

      var max = Math.max.apply(Math,foundItems.map(function(o){return o.rating;}))

       

      var i = 0;

      for ( i=0; i< foundItems.length; i++ )

      {

        if (foundItems[i].rating == max)

        {

        return foundItems[i].host;

        }

      }

       

       

      ...in troubleshooting, I can see by virtue of writing the values of the dataCenter and vm input parameters out to System.log that the objects seem to have changed.  From 7.2 (which works, the id's,names, and urls below are sanitized): 

      [2017-05-23 10:16:00.786] [I] The value of dataCenter is DynamicWrapper (Instance) : [VcDatacenter]-[class com.vmware.vmo.plugin.vi4.model.VimDatacenter] -- VALUE : Datacenter<datacenter-999999>'SanitizedDatacenter'

      [2017-05-23 10:16:00.790] [I] The value of vm is DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.vmo.plugin.vi4.model.VimVirtualMachine] -- VALUE : VirtualMachine<vm-888888>'vmSanitized'

      and in 7.3 (does not work):

      [2017-05-23 10:13:43.850] [I] The value of dataCenter is DynamicWrapper (Instance) : [VcDatacenter]-[class com.vmware.o11n.plugin.vsphere_gen.Datacenter_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = Datacenter, value = datacenter-999999, serverGuid = null), binding = https://sanitized.vcenterhere.com:443/sdk

      [2017-05-23 10:13:43.852] [I] The value of vm is DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-888888, serverGuid = null), binding = https://sanitized.vcenterhere.com:443/sdk

       

      Can anyone give me some pointers as to what I need to do to get this scripting to run in 7.3?  Thank you. 

       

      7.2 version is Appliance Version: 7.2.0.19944 Build 4629837

      7.3 version is Appliance Version: 7.3.0.21553 Build 5521409

        • 1. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
          iiliev Champion
          Community WarriorsVMware Employees

          Hi,

           

          vRO 7.3 ships with a new vCenter plug-in (by 'new' I mean completely different implementation/code base). That's why when you dump some objects using System.log() the format of the output can be a little bit different.

           

          How exactly your sample script is 'broken' on 7.3? Does it throw an exception? Or return null while you would expect some valid result? Or finds a different 'best host'?

          • 2. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
            KRAEMS Novice

            Hi Ilian - thanks for taking a look at this. 

             

            For the purpose of testing this, I've created a workflow with a single action item that contains the scripting from the original post.  The lone inputs are the datacenter and vm parameters.  Here is the entirety of the log text as dumped to the log tab in the Orchestrator workflow designer (urls and ids sanitized):

             

            [2017-05-23 10:13:43.850] [I] The value of dataCenter is DynamicWrapper (Instance) : [VcDatacenter]-[class com.vmware.o11n.plugin.vsphere_gen.Datacenter_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = Datacenter, value = datacenter-999999, serverGuid = null), binding = https://sanitized.vcenterhere.com:443/sdk

            [2017-05-23 10:13:43.852] [I] The value of vm is DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-888888, serverGuid = null), binding = https://sanitized.vcenterhere.com:443/sdk

            [2017-05-23 10:13:43.856] [E] (com.mycompany.util/getBestHostFromDataCenter) Error in (Dynamic Script Module name : getBestHostFromDataCenter#4) TypeError: Cannot read property "0" from undefined

            [2017-05-23 10:13:43.884] [E] Workflow execution stack:

            ***

            item: 'getHostFromDataCenter/item0', state: 'failed', business state: 'null', exception: 'TypeError: Cannot read property "0" from undefined (Dynamic Script Module name : getBestHostFromDataCenter#4)'

            workflow: 'getHostFromDataCenter' (d0ada83e-e136-4796-9602-e39d6c9929bf)

            |  'input': name=dataCenter type=VC:Datacenter value=dunes://service.dunes.ch/CustomSDKObject?id='sanitized.vcenterhere.com%2Cid:datacenter-999999'&dunesName='VC:Datacenter'

            |  'input': name=vm type=VC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='sanitized.vcenterhere.com%2Cid:vm-888888'&dunesName='VC:VirtualMachine'

            |  'output': name=hostout type=VC:HostSystem value=null

            |  'no attributes'

            *** End of execution stack.

             

            In the working 7.2 environment, a 'best host' is returned by way of of an output parameter of type VC:HostSystem.  In 7.3, the workflow terminates with the logging above. Thank you. 

            1 person found this helpful
            • 3. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
              iiliev Champion
              VMware EmployeesCommunity Warriors

              OK, managed to reproduce the error in my 7.3 environment. Will investigate further and will let you know what is the problem (could be a bug in the plug-in).

              • 4. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
                islavov Novice
                VMware Employees

                Hi KRAEMS,

                We isolated and fixed this error. You can find the fixed plugin published as updated technical preview:

                vRO vCenter plug-in  for vSphere 6.5+ service releases

                1 person found this helpful
                • 5. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
                  KRAEMS Novice

                  Confirmed. 

                   

                  The workflows which worked in 7.2, but failed in 7.3 with it's native plugin, work once again in 7.3 with the newly released plugin. 

                   

                  Thank you, Ilian, and islavov! 

                  • 6. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
                    zipper99 Novice
                    vExpert

                    Hi

                    we have wrote an XtremIO plugin for vRO which worked great with 7.2 but is broken with 7.3

                     

                    We found the reason that the
                    workflow “Host Show” is failing which is being called by the our workflow

                    We found that the
                    vc:sdkconnection scripting class/object has changed between vrealize versions
                    7.2 and 7.3 which is causing the IndexOf check highlighted in yellow below to
                    always return -1 which causes the workflow to fail.  It looks like they
                    added new attributes to the class such as display name and perhaps others

                     

                    if (!host || !vc || !attrHosts || !attrVCs
                    ||

                        (host &&
                    attrHosts && (-1 == attrHosts.indexOf(host))) ||

                        (vc && attrVCs && (-1 ==
                    attrVCs.indexOf(vc)))){

                      System.error("Received invalid
                    input parameter values");

                      throw "Received invalid input
                    parameter values";

                     

                    will the new tech preview 6.5 plugin fix this issue as well??

                     

                    https://communities.vmware.com/docs/DOC-32872

                    • 7. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
                      tschoergez Master
                      User ModeratorsvExpertVMware Employees

                      Hit Itzik,

                      you might replace the equals() check in your logic with explicitly using some ids of the objects you are comparing, like

                      1 == attrVCs.filter(function (item) { return item.about.instanceUuid == vc.about.instanceUuid}).length

                      Not sure if the newest plugin has any change in logic for the equals() comparison. The code above avoids relying on not-documented internal plugin implementation, you explicitly specify the attributes of the objects to compare.

                      Depending on the reasoning and conditions for your validation logic, it might be an idea to alternatively compare vRO ids rather than the "real-world" ids.

                       

                      Regards,

                      Joerg

                      Itzikr

                      • 8. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
                        islavov Novice
                        VMware Employees

                        Hi ,

                         

                        Let me do some clarification about the indexOf issue.

                         

                        The problem is not directly related with the java equals operator; Array.prototype.indexOf uses strict equals operator (===) which for objects will return true, if values compared refer to the same object. But in the new plugin plugin objects returned from plugin factory and from other object's methods are not references to the same java object (as in the old plugin), they are actually different wrapper object, created on the fly, representing the same model object (in our case a SdkConnection).

                         

                        For example consider following , if 'vc' is a Vc:SdkConnection:

                         

                        var connections = [vc];

                        System.log(connections.indexOf(vc)); // This will return a value different from -1

                        var loadedConnections = VcPlugin.allSdkConnections;

                        System.log(loadedConnections.indexOf(vc)); // This will return -1, because the element could not been found

                         

                        This behavior was a base design decision imposed from the model-driven framework upon which the new plugin is based.

                         

                        The problem can be solved with changing the script to compare meaningful properties of the objects, as tschoergez correctly proposed bellow :

                         

                        1 == attrVCs.filter(function (item) { return item.about.instanceUuid == vc.about.instanceUuid}).length

                         

                        As of java equals method, it has the same implementation in the new plugin as in the old plugin

                        • 9. Re: Orchestrator 7.2 to 7.3 upgrade breaks some scripting
                          mknunez Novice

                          We are seeing a bug related to:

                          datacenter.vmFolder return value incorrect type. Should be VcFolder, is returning incorrect value of VcVmFolder

                          sample code:

                          =====

                          Sample code for Vmware SR

                          var dcVmFolder = datacenter.vmFolder;

                          System.log("DataCenter: " + datacenter );

                           

                          var isVcVmFolder = dcVmFolder instanceof VcVmFolder

                          var isVcFolder = dcVmFolder instanceof VcFolder;

                          System.log("dcVmFolder instanceof VcVmFolder:" + isVcVmFolder );

                          System.log("dcVmFolder instanceof VcFolder:" + isVcFolder);

                          =====

                          Prior to vRO7.3 the return value was: VcFolder, now in vRO7.3 the value is: VcVmFolder.

                          The doc for both 6.0 and 6.5 vcenter plugin state a return value of VcFolder.

                           

                          Ref:

                           

                          6.5 API https://www.vmware.com/support/orchestrator/doc/vro-vsphere65-api/html/VcDatacenter.html

                           

                           

                          6.0 API https://www.vmware.com/support/orchestrator/doc/vro-vsphere60-api/html/VcDatacenter.html