VMware {code} Community
Yeonki
Contributor
Contributor

Error: InvalidRequest when WaitForUpdatesEx is executing

Hi, all.

I'd like to get vm information when VM's events are occured.

I wrote a test code using WaitForUpdatesEx (vSphere 5.0) method.

When I ran this, I got the following error:

"com.vmware.vim25.InvalidRequest

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

at java.lang.Class.newInstance0(Class.java:355)

at java.lang.Class.newInstance(Class.java:308)

at com.vmware.vim25.ws.XmlGen.fromXml(XmlGen.java:201)

at com.vmware.vim25.ws.XmlGen.parseSoapFault(XmlGen.java:80)

at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:132)

at com.vmware.vim25.ws.VimStub.waitForUpdatesEx(VimStub.java:105)

at com.vmware.vim25.mo.PropertyCollector.waitForUpdatesEx(PropertyCollector.java:125)

at com.apexcns.test.AsyncPropsCollection.test(AsyncPropsCollection.java:170)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Below is my test code:
---------------------------------------------------------------------------------

EventFilterSpecByEntity entitySpec = new EventFilterSpecByEntity();
entitySpec.setEntity(serviceInstance.getRootFolder().getMOR());
entitySpec.setRecursion(EventFilterSpecRecursionOption.children);
// set the entity spec in the EventFilter
EventFilterSpec eventFilter = new EventFilterSpec();
eventFilter.setEntity(entitySpec);
eventFilter.setType( new String[] {"VmPoweredOffEvent", "VmPoweredOnEvent", "VmSuspendedEvent", "VmResettingEvent"} );
EventManager eventManager = serviceInstance.getEventManager();
EventHistoryCollector eventHistoryCollector = eventManager.createCollectorForEvents(eventFilter);
// PropertyFilterSpec Setting
PropertySpec propertySpec = new PropertySpec();
propertySpec.setAll(new Boolean(false));
propertySpec.setPathSet(new String[] { "latestPage" });
propertySpec.setType(eventHistoryCollector.getMOR().getType());
PropertySpec[] propertySpecAry = new PropertySpec[] {propertySpec};
ObjectSpec objSpec = new ObjectSpec();
objSpec.setObj(eventHistoryCollector.getMOR());
objSpec.setSkip(new Boolean(false));
objSpec.setSelectSet(new SelectionSpec[] { });
ObjectSpec[] objSpecAry = new ObjectSpec[] { objSpec };
   
PropertyFilterSpec spec = new PropertyFilterSpec();
spec.setPropSet(propertySpecAry);
spec.setObjectSet(objSpecAry);
                       
PropertyCollector propColl =  serviceInstance.getPropertyCollector();             
PropertyFilter propFilter = propColl.createFilter(spec, true);
                 
Integer MAX_WAIT_TIME = 60;
String version = "";
WaitOptions options = new WaitOptions();
options.setMaxWaitSeconds( MAX_WAIT_TIME );
options.setMaxObjectUpdates(0);
while (true) {
  
   logger.debug("Waiting for new Updates.");
   UpdateSet update =  propColl.waitForUpdatesEx(version, options);    // <= the error location was here.

  if ( update != null && update.getFilterSet() != null ) {

       .......

       version = update.getVersion();                         

  } else {

      logger.debug("No update is present!");                  

  }

}

.....

Please let me know if anyting is wrong in my code.

Thank you.

Yeonki.

Tech Blog: http://hyper-choi.blogspot.com
0 Kudos
3 Replies
togtog
Hot Shot
Hot Shot

Hi Yeonki,

I have not tried to run your code but the InvalidRequest Fault is likely to be a pointer to a malformed SOAP XML body. Now looking at your code the following line:

eventFilter.setType( new String[] {"VmPoweredOffEvent", "VmPoweredOnEvent", "VmSuspendedEvent", "VmResettingEvent"} );

catches my eye as property EventFilterSpec.type has been deprecated. As of vSphere API 4.0 the docs suggest using property EventFilterSpec.eventTypeId instead.

As you indicate you are running against vSphere 5.0 this might be the reason why the server rejects the request.

Could you please change the above line to

eventFilter.setEventTypeId( new String[] {"VmPoweredOffEvent", "VmPoweredOnEvent", "VmSuspendedEvent", "VmResettingEvent"} );

and let me know whether this cures the problem ...

Thomas G.
0 Kudos
Yeonki
Contributor
Contributor

Hi, Thomas

Thanks for the reponse.

I got the same error (InvalidRequest) after I changed code like you intructed.

eventFilter.setType( new String[] {"VmPoweredOffEvent", "VmPoweredOnEvent", "VmSuspendedEvent", "VmResettingEvent"} );

eventFilter.setEventTypeId( new String[] {"VmPoweredOffEvent", "VmPoweredOnEvent", "VmSuspendedEvent", "VmResettingEvent"} );

But, when I invoked waitforUpdates intead, my code worked and it returned proper result whenever VM's power state is changed.

update = service.waitForUpdatesEx(propColl, version, options);  
update = service.waitForUpdates(propColl, version);
I knew this method was deprecated, VMware recommends use waitForUpdatesEx instead of waitForUpdates.
Yeonki.
Tech Blog: http://hyper-choi.blogspot.com
0 Kudos
Yeonki
Contributor
Contributor

This is worked code after I changed some parts.

............

PropertyFilterSpec spec = new PropertyFilterSpec();
spec.setPropSet(propertySpecAry);
spec.setObjectSet(objSpecAry);
//PropertyCollector propColl =  serviceInstance.getPropertyCollector();            
//PropertyFilter propFilter = propColl.createFilter(spec, true);                              
VimPortType service = serviceInstance.getServerConnection().getVimService();             
ManagedObjectReference propColl = serviceInstance.getServiceContent().getPropertyCollector();  
        
ManagedObjectReference propFilter = null;
try {
     //propFilter = propColl.createFilter(spec, true);
     propFilter = service.createFilter(propColl, spec, true);   
} catch (Exception e1) {
     e1.printStackTrace();
}                           
                
String version = "";
// WaitOptions options = new WaitOptions();
// options.setMaxWaitSeconds(20);
// options.setMaxObjectUpdates(20);
UpdateSet update = null;
while (true) {
try {
        logger.debug("Waiting for new Updates.");
       // update = propColl.waitForUpdatesEx(propColl, version, options);  
       // update = propColl.waitForUpdates(propColl, version);
        update = service.waitForUpdates(propColl, version);
        if(update != null && update.getFilterSet() != null) {         
              this.handleUpdate(update);                              
              version = update.getVersion();
              logger.debug(" Current Version: " + version);      
        } else {
              logger.debug("No update is present!");
        }
     } catch (Exception e) {                                     
       e.printStackTrace();                      
     }
}

The point is that I use VimPortType.waitForUpdates, not ProprortyCollector.waitForUpdates.

VimPortType.waitForUpdates is not marked as deprecated.

Although its compile & run works fine, Can I say that this is safe code or not?

Yeonki.

Tech Blog: http://hyper-choi.blogspot.com
0 Kudos