VMware Cloud Community
cjoshi
Enthusiast
Enthusiast
Jump to solution

TypeError

I am executing a workflow via vRA as a Resource Action. The workflow succeeds via vRA on a VM unmanaged by vRA. However on trying to execute the workflow on a vRA provisioned item it fails with a TypeError. I am confused and unable think of a logical answer. I guess the custom action called via vRA on a provisioned vRA item is setting the context to something different than what is being expected hence it works on a vCenter managed VM and not a vRA managed VM (both via vRA).

Any help/pointers would be appreciated. Mentioned below is the error stack:

[2018-12-07 23:58:27.166] [E] (bar.foo.vro/getExtendVmDiskConfigSpec) Error in (Dynamic Script Module name : getExtendVmDiskConfigSpec#3) TypeError: Cannot read property "1" from null

[2018-12-07 23:58:27.193] [E] Workflow execution stack:

***

item: 'Extend VM Disk/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot read property "1" from null (Dynamic Script Module name : getExtendVmDiskConfigSpec#3)'

workflow: 'Extend VM Disk' (1b870d49-6e7d-4abb-9dae-66349fbea6b6)

|  'attribute': name=actionResult type=Array/string value=__NULL__

|  'attribute': name=task type=VC:Task value=null

|  'attribute': name=progress type=boolean value=null

|  'attribute': name=pollRate type=number value=null

|  'input': name=vm type=VC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='sa-vcsa-01.vclass.local%2Cid:vm-107'&dunesName='VC:VirtualMachine'

|  'input': name=diskInfo type=string value=Hard disk 1   [ Existing disk size : 0.75 GB ]

|  'input': name=sizeGb type=string value=2

|  'attribute': name=__asd_requestedBy type=string value=Cloud-Op01@vclass.local

|  'attribute': name=__asd_tenantRef type=string value=vsphere.local

|  'attribute': name=__asd_targetResourceInternalId type=string value=90307997-3b80-4799-8aa0-781767b1bd23

|  'attribute': name=__asd_catalogRequestId type=string value=f3203582-1151-4bd6-8da6-3e53036696a7

|  'attribute': name=__asd_subtenantRef type=string value=dfbbdff7-c277-43a9-b6c3-b2edb474a10f

|  'attribute': name=__asd_requestedFor type=string value=Cloud-Op01@vclass.local

|  'attribute': name=__asd_targetResourceId type=string value=d17069f1-341c-417f-a300-5dfc3e9ebf3e

|  'attribute': name=__asd_targetResourceTypeId type=string value=Infrastructure.Virtual

|  'attribute': name=__asd_targetResourceProviderId type=string value=39338711-941f-4b29-9aa9-586be5661faa

|  'no outputs'

*** End of execution stack.

Also the workflow works as expected /correctly when directly called via vRO.

Setup details: vRA 7.4 with Embedded vRO, vSphere 6.5.

I am able to browse the vCenter and vRA inventroy via the vROso I guess the plugins are working as expected.

Thanks.

Regards Shekhar

Reply
0 Kudos
1 Solution

Accepted Solutions
cjoshi
Enthusiast
Enthusiast
Jump to solution

Solved. Looks like there is bug in the vRA presentation layer. If the having multiple fields where some fields are getting dynamic values from an vRO action, the other input fields may fail to send data to vRO.

In case someone comes searching for the issue, the fix: create a new form page and separate data based on the type.

View solution in original post

Reply
0 Kudos
8 Replies
daphnissov
Immortal
Immortal
Jump to solution

Without looking at some code it's impossible to tell why you're getting this error.

Reply
0 Kudos
cjoshi
Enthusiast
Enthusiast
Jump to solution

Adding some more information:

Following is the workflow. Its a disk extend workflow based on the vRealize Orchestrator – Extend Virtual Disk Workflow – Part 1 of 2 | vBombarded blog article.

pastedImage_0.png

I have slightly modified the workflow from a learning perspective. Created 2 Action Items, one to fetch the Disk Info and other to create VMConfigSpec. In the above depicted workflow the VM reconfigure task.

There is a vRO dynamic action to populate the (existing) disks dropdown on the form that is working as expected. What's not working is the submit and that too only for vRA managed items. Relevant code mentioned below:

vRO Action to generate the VMConfigSpec

-- cut --

var devices = vm.config.hardware.device;

var match = diskInfo.match(/\w+\s+\w+\s+(\d+)\s+.+?:\s*(\d+)\s*GB/);

var newDiskSizeKb = newDiskSizeGb * 1024 * 1024;

var diskName = 'Hard disk ' + match[1];

configSpec = new VcVirtualMachineConfigSpec();

configSpec.changeVersion = vm.config.changeVersion;

for (i in devices){

    if (devices[i].deviceInfo.label == diskName){

        var disk = devices[i]

        System.debug("Found '" + disk.deviceInfo.label + "'");

    }

}

var deviceChanges = new Array();

var deviceChange = new VcVirtualDeviceConfigSpec();

deviceChange.operation = VcVirtualDeviceConfigSpecOperation.edit;

deviceChange.device = disk;

deviceChange.device.capacityInKB = newDiskSizeKb;

deviceChanges.push(deviceChange);

configSpec.deviceChange = deviceChanges

var actionResult = [];

actionResult.push(configSpec);

return actionResult;

-- cut --

vRO Action to fetch disk information

-- cut --

var devices = vm.config.hardware.device;

var actionResult = [];

for (i in devices){

    if (devices[i].DeviceInfo.Label.indexOf('Hard disk') >= 0){

        var sizeGb = devices[i].capacityInKB / 1024 / 1024;

        var diskInfo = devices[i].deviceInfo.label + "   [ Existing disk size : " + sizeGb + " GB ]";

        actionResult.push(diskInfo);

    }

}

return actionResult;

-- cut --

Reconfigure VM Scriptable task

-- cut --

var configSpec = actionResult[0];

if (configSpec != null && (configSpec instanceof VcVirtualMachineConfigSpec) == false) throw "configSpec must be of type 'VcVirtualMachineConfigSpec'";

task = vm.reconfigVM_Task(configSpec);

-- cut --

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

This error is happening because the regular expression matching does not return what you are expecting. Check the following lines

var match = diskInfo.match(/\w+\s+\w+\s+(\d+)\s+.+?:\s*(\d+)\s*GB/);

var newDiskSizeKb = newDiskSizeGb * 1024 * 1024;

var diskName = 'Hard disk ' + match[1];

So, on the first line you are trying to match diskInfo value with some regular expression, and you assign the result from this matching to the match variable. Then, on the third line, you are accessing the second element from the match variable array, and you get the error because either the match variable is null or it is an array with less than 2 elements.

To find the reason for matching not working, you need to provide the value of diskInfo value at this point. Probably it is some string value that has different format than what the regular expression expects. You can try to dump diskInfo value using System.log(diskInfo) to see what is its value and then we can reason why this value does not match the regular expression.

cjoshi
Enthusiast
Enthusiast
Jump to solution

Hi Ilian and others,

Before I go further, let me just say thanks to everyone on this community. It was late yesterday and I was sleepy/frustrated hence did not do that with my first question/reply. I have learnt much of orchestrator (and many other VMware products) by looking at questions and answers posted on this community. Back to question :-).

If regular expression been the problem then the workflow would not have worked directly even from the orchestrator. As hinted by you I am trying this with a simple workflow and only dumping the values. I am now testing a similar user interaction (vRA + vRO) but with simpler workflow. What I observe is the following:

vRO form has 3 fields: vmObject (search/list box), hardDiskList (dynamic drop-down list generated by vRO action via 'Predefined list of elements'), sizeInGb (standard text box). This works as expected from vRO.

vRA custom action form (default auto generated form) has 2 input fields:

hidden vm field (hidden because custom vRA action invoked in that context)

hardDiskList drop-down  (gets input from orchestrator workflow, works as expected)

sizeInGb textbox (on vRO this is a string object).

Now when I call this via vRA, I can reads values from both vm & hardDiskList but sizeInGb is set to null. What is it that I am doing incorrect that this textbox sets the value to null?

On a side question, how do you insert code here in the question/reply as a markup with code formatting?

Thanks.

Regards Shekhar

Reply
0 Kudos
cjoshi
Enthusiast
Enthusiast
Jump to solution

Solved. Looks like there is bug in the vRA presentation layer. If the having multiple fields where some fields are getting dynamic values from an vRO action, the other input fields may fail to send data to vRO.

In case someone comes searching for the issue, the fix: create a new form page and separate data based on the type.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

If on vRA 7.4, make sure you've applied the latest available hotfix here.

cjoshi
Enthusiast
Enthusiast
Jump to solution

Thanks. Sure I will check that with the production deploymentand on my test bed where I was trying it.

Reply
0 Kudos
abhi_aaxx
Contributor
Contributor
Jump to solution

Task 'reconfigure' error: Invalid operation for device '0'. (Dynamic Script Module name : vim3WaitTaskEnd#30)

Can anyone help with this

var taskEnd = false;
var error;

var propertyCollector = getPropertyCollector(task)
var filterSpec = getFilterSpec(task)

//force logging
progress = true

try {
var taskInfo = getTaskInfo(propertyCollector, filterSpec);
while (task != null) {
if (taskInfo == null) {
throw "VIM Task info is null";
}
if (taskInfo.state == null) {
throw "VIM Task state is null";
}

var state = taskInfo.state.value;
if (state == "success") {
waitCacheUpdate(state, task);
break;
}
else if (state == "error") {
waitCacheUpdate(state, task);
if (taskInfo.error.localizedMessage == null) {
throw "Task '" + taskInfo.name + "' has encountered an unknown error";
}
else {
throw "Task '" + taskInfo.name + "' error: "+taskInfo.error.localizedMessage;
}
}
else if ((progress) && (state == "running")) {
if (taskInfo.progress == null) {
System.log(taskInfo.name+"/"+task.id+" " + state);
}
else {
System.log(taskInfo.name+"/"+task.id+" "+ state + " "+taskInfo.progress+" %");
}
}
System.sleep(pollRate*1000);
taskInfo = getTaskInfo(propertyCollector, filterSpec);
}

if (task == null) {
throw "VIM Task is null";
}
else if (progress) {
System.log(taskInfo.name+"/"+task.id+" ends with "+taskInfo.state.value);
}

// Return the Task Result
if (task != null && taskInfo != null && taskInfo.result != null) {
return VcPlugin.convertToVimManagedObject(task , taskInfo.result);
}
else {
return null;
}
} finally {
if (propertyCollector != null) {
propertyCollector.destroyPropertyCollector()
}
}

//------------------------------------------------------------------------------------
function waitCacheUpdate(state, taskObj) {
for (var i=0; i<10; i++ ) {
if (state == taskObj.info.state.value) {
return
}
System.sleep(1000);
}
System.error(taskInfo.name + "/" + task.id + " cache OUT OF sync");
}

function getPropertyCollector(taskObj) {
if (taskObj == null) {
return null;
}
var vc = taskObj.sdkConnection
return vc.propertyCollector.createPropertyCollector()
}

function getFilterSpec(taskObj) {
if (taskObj == null) {
return null;
}
var vc = taskObj.sdkConnection
var listView = vc.viewManager.createListView([taskObj.reference])

// create an object spec for the beginning of the traversal;
var oSpec = new VcObjectSpec()
oSpec.obj = listView.reference
oSpec.skip = true

// create a traversal spec to select all objects in the view
var tSpec = new VcTraversalSpec()
tSpec.name = 'traverseEntities'
tSpec.path = 'view'
tSpec.skip = false
tSpec.type = 'ListView'

// add it to the object spec
oSpec.selectSet = [tSpec]

var propertySpecs = new Array()
// specify the properties for retrieval
var pSpec = new VcPropertySpec()
pSpec.type = 'Task'
pSpec.pathSet = ['info']
propertySpecs.push(pSpec)

var fs = new VcPropertyFilterSpec()
fs.objectSet = [ oSpec ]
fs.propSet = propertySpecs
return fs
}

function getTaskInfo(propertyCollector, filterSpec) {
if (propertyCollector == null) {
System.log("Can not get task info - propertyCollector is null")
return null;
}
var vc = propertyCollector.sdkConnection

var retrieveOptions = new VcRetrieveOptions()
retrieveResult = propertyCollector.retrievePropertiesEx([filterSpec], retrieveOptions)
return retrieveResult.objects[0].propSet[0].val
}

Reply
0 Kudos