emscroger
Contributor
Contributor

Custom Task setTaskState Error example


I'm trying to set error messages for my custom tasks when some unexpected error occurs.   From the vSphere 5.5 docs, I understand I need to invoke Task.setTaskState with the following parameters:


    _this    ManagedObjectReference    // reference to task


    state    TaskInfoState    // must be TaskInfoState.ERROR for errors


    result   xsd:anyType      // valid only if TaskInfo.State.success SKIP


    fault     MethodFault     //  must directly or indirectly extend VimFault


 


In the Eclipse IDE, the method VimPortType.setTaskState says the final argument is of type LocalizedMethodFault, not MethodFault.   So, I created a LocalizedMethodFault variable and set its properties.  One property setter is setFault, which takes a MethodFault.  I know VimFault extends MethodFault, so I create a VimFault instance and use with setFault. 


However, I see VimFault has a setter setFaultCause, which takes an argument of, LocalizedMethodFault.   So this fault assignment is starting to get recursive.


                LocalizedMethodFault fault = new LocalizedMethodFault();
                VimFault vimFault = new VimFault();


            
                fault.setDynamicType("Runtime Error");
                fault.setLocalizedMessage(message);
                fault.setFault(vimFault);


                vimFault.setDynamicType("Runtime Error");
                vimFault.setFaultCause(fault);


In any case, I tried to use this code but it did not work.  Any ideas or example code that works would be greatly appreciated.


-E

0 Kudos
4 Replies
laurentsd
VMware Employee
VMware Employee

I am moving this to the vSphere Management SDK forum because it is a vSphere API question, i.e. not specific to the Web Client SDK

0 Kudos
emscroger
Contributor
Contributor

Does anyone have any information on how to implement Error / Faults for custom tasks.  I posted this question some time ago, and still no answer.  I searched the internet and found nothing except others asking the same question.

0 Kudos
hdesai
Contributor
Contributor

Hi

Were you able to get setTaskState working?

0 Kudos
EchoBravo2
Contributor
Contributor

you just use the vim as below, but returned message is empty 😞

from pyVmomi import vim

vim.LocalizedMethodFault()

(vmodl.LocalizedMethodFault) {

   dynamicType = <unset>,

   dynamicProperty = (vmodl.DynamicProperty) [],

   msg = <unset>,

   faultCause = <unset>,

   faultMessage = (vmodl.LocalizableMessage) [],

   fault = <unset>,

   localizedMessage = <unset>

}

vim.MethodFault()

(vmodl.MethodFault) {

   dynamicType = <unset>,

   dynamicProperty = (vmodl.DynamicProperty) [],

   msg = <unset>,

   faultCause = <unset>,

   faultMessage = (vmodl.LocalizableMessage) []

}

0 Kudos