2 Replies Latest reply on Sep 10, 2018 12:49 AM by doskiran

    Custom Task - setTaskState to error  - problem setting MethodFault

    CathyBr Enthusiast

      Hi I've found this question in lots of places, but it never seems to be answered.  I'm optimistic...

       

      I am using custom tasks, and am able to set the progress, and the state to "TaskInfoState.SUCCESS" without any problems.

      But if something goes wrong during my task, I want to set the task state to "error" - and add a message why.

       

      so I use vimPort.setTaskState(taskInfo.getTask(), TaskInfoState.ERROR, null, taskMethodFault);

       

      My taskMethodFault is a LocalizedMethodFault -

      It expects a MethodFault, and a localized Message -

       

      The MethodFault expects a FaultCause which is a LocalizedMethodFault - which then expects a never ending number of Faults...

       

      Here's what the soap exception says:

      com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: required tag not seen while processing MethodFault at line 1, column 374 while parsing property "faultCause" of static type MethodFault while parsing serialized DataObject of type vmodl.MethodFault at line 1, column 367 while processing MethodFault at line 1, column 355 while parsing property "faultCause" of static type MethodFault while parsing serialized DataObject of type vmodl.MethodFault at line 1, column 348 while processing MethodFault at line 1, column 341 while parsing call information for method SetTaskState at line 1, column 110 while parsing SOAP body at line 1, column 102 while parsing SOAP envelope at line 1, column 38 while parsing HTTP request for method setState on object of type vim.Task at line 1, column 0 Please see the server log to find more detail regarding exact cause of the failure.

       

      So can someone please publish some sample code which lets you set a task state to TaskInfoState.ERROR that works?  I can't image that it could be so difficult.

       

      thanks

      Cathy

        • 1. Re: Custom Task - setTaskState to error  - problem setting MethodFault
          CathyBr Enthusiast

          I found the solution - at least it worked for me

          it looks something like this

          1) When the extension is registerd, create a Fault resource for "myFaultType";

           

          When the task should fail - use the ExtendedFault -->

           

          ExtendedFault extendedFault = new ExtendedFault();

          extendedFault.setFaultTypeId(myFaultType);

           

          LocalizedMethodFault localizedMethodFault = new LocalizedMethodFault();

          localizedMethodFault.setFault(extendedFault);

          vimPort.setTaskState(taskInfo.getTask(), TaskInfoState.ERROR, null, localizedMethodFault);

           

          so that seems to work

          Could someone verify this - or should it be done another way?

          • 2. Re: Custom Task - setTaskState to error  - problem setting MethodFault
            doskiran Hot Shot
            The way you have done is correct, i usually does this..
                                                                                              
            LocalizedMethodFault fault = new LocalizedMethodFault();
            ManagedObjectNotFound monf = new ManagedObjectNotFound();
            monf.setObj((ManagedObjectReference)vm);
            fault.setFault(monf);
            task.setTaskState(taskInfo.getTask(), TaskInfoState.ERROR, null, fault)