Subscribe

java.rmi.RemoteException:VI SDK invoke exc...

  1. 2011-10-11 03:33:06 PDT
    Hello, i am New to Vjava SDK and using the latest vijava API. Now trying to write a Program to collect the Inventory of the Vmware devices. If i try to collect the ESX details, no issues. If i try to collect the VCenter details, i getting the following error while making " HostSystem.getSummary()" call java.lang.RuntimeException: java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: null Nested exception: null at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:158) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:179) at com.vmware.vim25.mo.HostSystem.getSummary(HostSystem.java:96) at com.xx.vi.vmware.VMwareMgntServiceImpl.buildHostDevice(VMwareMgntServiceImpl.java:419) at com.xx.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:925) at com.xx.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:905) at com.xx.vi.vmware.VMwareMgntServiceImpl.getAllDataCentersGivenByVC(VMwareMgntServiceImpl.java:878) at com.xx.vi.vmware.VMwareMgntServiceImpl.getVCenter(VMwareMgntServiceImpl.java:779) Caused by: java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: null Nested exception: null at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:182) at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:124) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:77) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155) ... 9 more What could be the issue? i am not able to figure out the issue. It works some times.! i am not able predict a scenario to re-produce all the time. This VCenter contains 150 VMs(most of the them are Powered off). Thanks in Advance.
  2. 2011-10-11 08:32:43 PDT
    HI PC, It seems to me that the cCenter may have returned an empty string which is not a valid XML response, therefore failed the XML parser. What version of vCenter? Did it happen with powered off ESXi host? Steve (http://www.doublecloud.org)
  3. 2011-10-11 09:01:50 PDT
    Hi sjin2008 Thanks for the quick replay. For same Host, it works some times. With 50% probability i am getting this error. I am not able to figure out a use case where we can re-produce this.
  4. 2011-10-12 10:05:31 PDT
    Hello, I found the root cause for this issue. We have to Handle multi part SOAP response in the com.vmware.vim25.ws.WSClient.invoke(String methodName, Argument[] paras). I have debugged the issue and figured out that for some of the SOAP requests, the response will come in parts. So, we have to Handle the multi part stream. We have loop in and read till end of the stream then Parse the Response. Following is the changed method code in the WSClient.java. Please take look and send me your feedback. public Element invoke(String methodName, Argument[] paras) throws RemoteException { String soapMsg = createSoapMessage(methodName, paras); Element root = null; InputStream is = null; StringBuffer buff = new StringBuffer(); try { is = post(soapMsg); SAXReader reader = new SAXReader(); int av = is.available(); while(av > 0) { byte[] data = new byte[av]; int readLen = is.read(data); // EOF if(readLen == -1) { break; } buff.append(new String(data, 0, readLen)); } ByteArrayInputStream bin = new ByteArrayInputStream(buff.toString().getBytes()); Document doc = reader.read(bin); root = doc.getRootElement(); bin.close(); } catch (Exception e) { throw new RemoteException("VI SDK invoke exception:" + e); } finally { if(is!=null) try { is.close(); } catch(IOException ioe) {} } return root; }
  5. 2011-10-14 22:30:25 PDT
    Hi PC, This is a very interesting finding! What version of server did you find problem with? Just want to understand the scope of this problem. Steve
  6. 2011-10-24 02:42:27 PDT
    We are using VCenter VMware vCenter Server 4.1.0 build-258902
  7. 2011-10-24 03:02:25 PDT
    One more interesting finding i have is as follows java.lang.RuntimeException: java.lang.IllegalMonitorStateException at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:158) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:179) at com.vmware.vim25.mo.HostSystem.getConfigManager(HostSystem.java:230) at com.vmware.vim25.mo.HostSystem.getHostNetworkSystem(HostSystem.java:349) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildHostDevice(VMwareMgntServiceImpl.java:426) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildCluster(VMwareMgntServiceImpl.java:1417) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:951) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getAllDataCentersGivenByVC(VMwareMgntServiceImpl.java:916) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getVCenter(VMwareMgntServiceImpl.java:817) at com.netenrich.neprobe.cmd.HypervisorInventoryCmdImpl.executeCommand(HypervisorInventoryCmdImpl.java:102) at com.netenrich.discovery.discover.parser.NEProbeCmdHandelr.run(NEProbeCmdHandelr.java:88) Caused by: java.lang.IllegalMonitorStateException at java.lang.Object.wait(Native Method) at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:135) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:77) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155) ... 10 more
  8. 2011-10-25 23:49:59 PDT
    Are you have multiple threads in your application? Please let me understand how you use them. Thanks! Steve (http://www.doublecloud.org)
  9. 2011-10-26 00:37:27 PDT
    Hi Steve I am trying to collect all the Details of a VCenter 4.1.0 having 20 ESX and 160 VMs. First, I connected to VCenter then, Extracted the Folders/Data Centers then For each DataCenter, extracted the ESX/Clusters then for each ESX/Cluster, extracted the VMs and its Details. NO Threads, a sequential logic one by one. Scary thing is we are NOT getting the response from the Server for some of the SOAP requests Here is the Log ---------------------- java.lang.RuntimeException: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>HostSystem</type><all>false</all><pathSet>runtime</pathSet></propSet><objectSet><obj type="HostSystem">host-1393</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:166) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:187) at com.vmware.vim25.mo.HostSystem.getRuntime(HostSystem.java:91) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildHostDevice(VMwareMgntServiceImpl.java:488) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildCluster(VMwareMgntServiceImpl.java:1459) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:993) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getAllDataCentersGivenByVC(VMwareMgntServiceImpl.java:958) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getVCenter(VMwareMgntServiceImpl.java:859) at com.netenrich.neprobe.cmd.HypervisorInventoryCmdImpl.executeCommand(HypervisorInventoryCmdImpl.java:105) at com.netenrich.discovery.discover.parser.NEProbeCmdHandelr.run(NEProbeCmdHandelr.java:88) Caused by: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>HostSystem</type><all>false</all><pathSet>runtime</pathSet></propSet><objectSet><obj type="HostSystem">host-1393</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:138) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:77) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155) ... 9 more Oct 26, 2011 6:15:05 AM com.netenrich.vi.vmware.VMwareMgntServiceImpl buildHostDevice SEVERE: Not able to get the HOST NIC config java.lang.RuntimeException: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>HostNetworkSystem</type><all>false</all><pathSet>networkInfo</pathSet></propSet><objectSet><obj type="HostNetworkSystem">networkSystem-1393</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:166) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:187) at com.vmware.vim25.mo.HostNetworkSystem.getNetworkInfo(HostNetworkSystem.java:76) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildHostDevice(VMwareMgntServiceImpl.java:496) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildCluster(VMwareMgntServiceImpl.java:1459) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:993) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getAllDataCentersGivenByVC(VMwareMgntServiceImpl.java:958) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getVCenter(VMwareMgntServiceImpl.java:859) at com.netenrich.neprobe.cmd.HypervisorInventoryCmdImpl.executeCommand(HypervisorInventoryCmdImpl.java:105) at com.netenrich.discovery.discover.parser.NEProbeCmdHandelr.run(NEProbeCmdHandelr.java:88) Caused by: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>HostNetworkSystem</type><all>false</all><pathSet>networkInfo</pathSet></propSet><objectSet><obj type="HostNetworkSystem">networkSystem-1393</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:138) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:77) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155) ... 9 more Oct 26, 2011 6:18:29 AM com.netenrich.vi.vmware.VMwareMgntServiceImpl buildHostDevice SEVERE: Not able to get the HOST LIC config java.lang.RuntimeException: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>LicenseManager</type><all>false</all><pathSet>licenses</pathSet></propSet><objectSet><obj type="LicenseManager">LicenseManager</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:166) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:187) at com.vmware.vim25.mo.LicenseManager.getLicenses(LicenseManager.java:69) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildHostDevice(VMwareMgntServiceImpl.java:515) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildCluster(VMwareMgntServiceImpl.java:1459) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:993) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getAllDataCentersGivenByVC(VMwareMgntServiceImpl.java:958) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getVCenter(VMwareMgntServiceImpl.java:859) at com.netenrich.neprobe.cmd.HypervisorInventoryCmdImpl.executeCommand(HypervisorInventoryCmdImpl.java:105) at com.netenrich.discovery.discover.parser.NEProbeCmdHandelr.run(NEProbeCmdHandelr.java:88) Caused by: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>LicenseManager</type><all>false</all><pathSet>licenses</pathSet></propSet><objectSet><obj type="LicenseManager">LicenseManager</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:138) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:77) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155) ... 9 more Oct 26, 2011 6:21:55 AM com.netenrich.vi.vmware.VMwareMgntServiceImpl buildHostDevice SEVERE: Not able to collect the BIOS details Oct 26, 2011 6:25:17 AM com.netenrich.vi.vmware.VMwareMgntServiceImpl getNestedFolderResources SEVERE: Not able to collect the Data Centers. java.lang.RuntimeException: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>HostSystem</type><all>false</all><pathSet>vm</pathSet></propSet><objectSet><obj type="HostSystem">host-1393</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:166) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:187) at com.vmware.vim25.mo.ManagedObject.getManagedObjects(ManagedObject.java:229) at com.vmware.vim25.mo.ManagedObject.getManagedObjects(ManagedObject.java:276) at com.vmware.vim25.mo.ManagedObject.getVms(ManagedObject.java:306) at com.vmware.vim25.mo.HostSystem.getVms(HostSystem.java:106) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildHostDevice(VMwareMgntServiceImpl.java:557) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.buildCluster(VMwareMgntServiceImpl.java:1459) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getNestedFolderResources(VMwareMgntServiceImpl.java:993) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getAllDataCentersGivenByVC(VMwareMgntServiceImpl.java:958) at com.netenrich.vi.vmware.VMwareMgntServiceImpl.getVCenter(VMwareMgntServiceImpl.java:859) at com.netenrich.neprobe.cmd.HypervisorInventoryCmdImpl.executeCommand(HypervisorInventoryCmdImpl.java:105) at com.netenrich.discovery.discover.parser.NEProbeCmdHandelr.run(NEProbeCmdHandelr.java:88) Caused by: java.rmi.RemoteException: WSClient.invoke()# SOAP Req Retry MAX attempts reached#VI SDK invoke exception. ### Failed to Parse SOAP RES: for REQ <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>HostSystem</type><all>false</all><pathSet>vm</pathSet></propSet><objectSet><obj type="HostSystem">host-1393</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></soapenv:Body></soapenv:Envelope> at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:138) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:77) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155) ... 12 more ----------------------------------------------------------------------------------------------------------------------------------- Here is the Piece of code ========================================= try { VMwareHostDevice dev = new VMwareHostDevice(); dev.setHostname(host.getName()); dev.setName(host.getHostNetworkSystem().getDnsConfig().getHostName()); dev.setMor(host.getMOR().getType()); dev.setMoId(host.getMOR().getVal()); dev.setDomain(host.getHostNetworkSystem().getDnsConfig().getDomainName()); try { dev.setOsType(host.getConfig().getProduct().getFullName()); } catch (Exception e) { // ignore //java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException } try { dev.setVcIP(host.getSummary().managementServerIp == null ? this.ipAddr: host.getSummary().managementServerIp); } catch (Exception e) { if(this.isSupervisor()) { dev.setVcIP(this.ipAddr); } } dev.setMgntIP(hostIPAddr); try { HostConfigSummary conf = host.getSummary().getConfig(); dev.setvMotion(conf.isVmotionEnabled()); dev.setFtm(conf.faultToleranceEnabled); } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST config", e); } try { HostHardwareSummary hw = host.getSummary().getHardware(); dev.setNics((short) hw.numNics); dev.setvProc(hw.getNumCpuCores()); dev.setCsock(hw.getNumCpuCores()); dev.setUuid(hw.getUuid()); dev.setVendor(hw.getVendor()); dev.setnCpu(hw.getNumCpuPkgs()); dev.setnCpuCores(hw.getNumCpuCores()); dev.setCpuSpeed(Integer.toString(hw.getCpuMhz())); try { dev.setnCpuCores(hw.getNumCpuCores()/hw.getNumCpuPkgs()); } catch (Exception e) { //ignore } dev.setProcessor(hw.getCpuModel().trim()); dev.setModel(hw.getModel()); dev.setState(host.getOverallStatus().name()); dev.setBootimeMillis(host.getRuntime().getBootTime().getTimeInMillis()); dev.setMemory(hw.getMemorySize()/(1024 * 1024)); } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST H/W config", e); } List<VINIC> _vnic = new ArrayList<VINIC>(); try { PhysicalNic[] nic = host.getHostNetworkSystem().getNetworkInfo().getPnic(); if(nic != null) { for (int j = 0; j < nic.length; j++) { PhysicalNic info = nic[j]; VINIC _hd = new VINIC(info.getMac(), info.getDevice(), info.getDriver() , new String[] { info.getSpec().ip.ipAddress}, 0 ); _vnic.add(_hd); } dev.setNic(_vnic); } // Power state dev.setPowerStatus(host.getRuntime().getPowerState().name()); } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST NIC config", e); } try { if(si.getLicenseManager() != null) { for (int ii = 0; ii < si.getLicenseManager().getLicenses().length; ii++) { LicenseManagerLicenseInfo lic = si.getLicenseManager().getLicenses()[ii]; KeyAnyValue[] kvs = lic.getProperties(); if(kvs != null) { for (int j = 0; j < kvs.length; j++) { KeyAnyValue kv = kvs[j]; if(kv.key.equalsIgnoreCase("ProductName")) { dev.setLicName(kv.getValue().toString()); } else if(kv.key.equalsIgnoreCase("ProductVersion")) { dev.setLicVer(kv.getValue().toString()); } else if(kv.key.equalsIgnoreCase("evaluation")) { dev.setLicEval(kv.getValue().toString()); } else if(kv.key.equalsIgnoreCase("expirationDate")) { dev.setLicExp(((Calendar)kv.getValue()).getTime().toGMTString()); } else if(kv.key.equalsIgnoreCase("system_time")) { dev.setSystime(((Calendar)kv.getValue()).getTime().toGMTString()); } else if(kv.key.equalsIgnoreCase("feature")){ KeyValue _kv = (KeyValue) kv.getValue(); dev.getLicFeature().put(_kv.getKey(), _kv.getValue()); } } } } } } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST LIC config", e); } // BIOS try { HostBIOSInfo bios = host.getHardware().getBiosInfo(); BIOSModule mod = new BIOSModule(); mod.setBiosVendor("VMware"); mod.setReleaseDate(bios.getReleaseDate().getTime().toGMTString()); mod.setSysVer(bios.getBiosVersion()); dev.setBios(mod); } catch (Exception e) { log.log(Level.SEVERE, "Not able to collect the BIOS details"); } // Extract all the Resourve Pools and attached VMs // First get all the VMs VirtualMachine[] vms = host.getVms(); if(vms.length > 0) { for(int v = 0; v < vms.length; v++) { VirtualMachine vm = vms[v]; ResourcePool rp = vm.getResourcePool(); // VMs belongs to a Resource pool if(rp != null && !rp.getName().equalsIgnoreCase("Resources")) { VMwareResourcePool vrp = this.buildResourcePool(rp); if(dev.getRpools().get(vrp.getName()) == null) { // Add the VM to the Resource Pool vrp.getVms().add(this.buildVMwareDevice(vm, dev)); // Add the Resource pool to Host dev.getRpools().put(vrp.getName(), vrp); log.log(Level.SEVERE, "ADDED the ResourcePool: " + vrp.getName()); } else { dev.getRpools().get(vrp.getName()).getVms().add(this.buildVMwareDevice(vm, dev)); } } else { // Add the VM directly to the Host dev.getVms().add(this.buildVMwareDevice(vm, dev)); } log.log(Level.SEVERE, "ADDED the VM: " + vm.getName()); // Collect the Datastores Datastore[] dss = vm.getDatastores(); for (int j = 0; j < dss.length; j++) { DatastoreInfo info = dss[j].getInfo(); String dssUUID = null; if(info instanceof VmfsDatastoreInfo) { VmfsDatastoreInfo vdinfo = (VmfsDatastoreInfo) info; dssUUID = vdinfo.getVmfs().getUuid(); } DataStoreModule _ds = new DataStoreModule(info.getName(), dss[j].getMOR().getType(), dss[j].getMOR().getVal(), info.getMaxFileSize(), info.getFreeSpace(), info.getTimestamp().getTimeInMillis(), dssUUID); dev.getDataStore().put(_ds.getName(), _ds); } } } =========================================
  10. 2011-10-26 08:30:01 PDT
    Hi Steve Thanks for vijava API for Open source world. Ref : http://sourceforge.net/projects/vijava/forums/forum/826592/topic/4751527/index/page/1 We are using latest vijava vijava520110926 API to build a Module to collect the VMware inventory. We are trying to collect the Inventory from the following VMware servers 1. ESX 3.5,4.1 2. VCenter 4.1 & 5.x with 200 VMs and 20 ESX I have found two issues 1. Sometimes SOAP response XML is coming in chunks(not http chuck). So, I fixed this issue by looping and reading the response content and then send same to dom4j parser. I have attached new WSClient.java file. I have changed method invoke(String methodName, Argument[] paras). Issue was fixed with my changes. 2. Sometimes We are not getting the Response for a given SOAP request. I tried to keep a loop for maximum of 5 times and send the SOAP request again if we don’t receive the SOAP response. Again I changed the code to do retry for maximum of 5 times in WSClient.java file, method invoke(String methodName, Argument[] paras, String returnType). Severity was reduced with retry mechanism, but sometimes we are NOT receiving the SOAP response and failed to collect the Inventory. I have also attached my log file and here the Piece of the code to collect the inventory. Please help us out to resolve the issue. try { VMwareHostDevice dev = new VMwareHostDevice(); dev.setHostname(host.getName()); dev.setName(host.getHostNetworkSystem().getDnsConfig().getHostName()); dev.setMor(host.getMOR().getType()); dev.setMoId(host.getMOR().getVal()); dev.setDomain(host.getHostNetworkSystem().getDnsConfig().getDomainName()); try { dev.setOsType(host.getConfig().getProduct().getFullName()); } catch (Exception e) { // ignore //java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException } try { dev.setVcIP(host.getSummary().managementServerIp == null ? this.ipAddr: host.getSummary().managementServerIp); } catch (Exception e) { if(this.isSupervisor()) { dev.setVcIP(this.ipAddr); } } dev.setMgntIP(hostIPAddr); try { HostConfigSummary conf = host.getSummary().getConfig(); dev.setvMotion(conf.isVmotionEnabled()); dev.setFtm(conf.faultToleranceEnabled); } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST config", e); } try { HostHardwareSummary hw = host.getSummary().getHardware(); dev.setNics((short) hw.numNics); dev.setvProc(hw.getNumCpuCores()); dev.setCsock(hw.getNumCpuCores()); dev.setUuid(hw.getUuid()); dev.setVendor(hw.getVendor()); dev.setnCpu(hw.getNumCpuPkgs()); dev.setnCpuCores(hw.getNumCpuCores()); dev.setCpuSpeed(Integer.toString(hw.getCpuMhz())); try { dev.setnCpuCores(hw.getNumCpuCores()/hw.getNumCpuPkgs()); } catch (Exception e) { //ignore } dev.setProcessor(hw.getCpuModel().trim()); dev.setModel(hw.getModel()); dev.setState(host.getOverallStatus().name()); dev.setBootimeMillis(host.getRuntime().getBootTime().getTimeInMillis()); dev.setMemory(hw.getMemorySize()/(1024 * 1024)); } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST H/W config", e); } List<VINIC> _vnic = new ArrayList<VINIC>(); try { PhysicalNic[] nic = host.getHostNetworkSystem().getNetworkInfo().getPnic(); if(nic != null) { for (int j = 0; j < nic.length; j++) { PhysicalNic info = nic[j]; VINIC _hd = new VINIC(info.getMac(), info.getDevice(), info.getDriver() , new String[] { info.getSpec().ip.ipAddress}, 0 ); _vnic.add(_hd); } dev.setNic(_vnic); } // Power state dev.setPowerStatus(host.getRuntime().getPowerState().name()); } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST NIC config", e); } try { if(si.getLicenseManager() != null) { for (int ii = 0; ii < si.getLicenseManager().getLicenses().length; ii++) { LicenseManagerLicenseInfo lic = si.getLicenseManager().getLicenses()[ii]; KeyAnyValue[] kvs = lic.getProperties(); if(kvs != null) { for (int j = 0; j < kvs.length; j++) { KeyAnyValue kv = kvs[j]; if(kv.key.equalsIgnoreCase("ProductName")) { dev.setLicName(kv.getValue().toString()); } else if(kv.key.equalsIgnoreCase("ProductVersion")) { dev.setLicVer(kv.getValue().toString()); } else if(kv.key.equalsIgnoreCase("evaluation")) { dev.setLicEval(kv.getValue().toString()); } else if(kv.key.equalsIgnoreCase("expirationDate")) { dev.setLicExp(((Calendar)kv.getValue()).getTime().toGMTString()); } else if(kv.key.equalsIgnoreCase("system_time")) { dev.setSystime(((Calendar)kv.getValue()).getTime().toGMTString()); } else if(kv.key.equalsIgnoreCase("feature")){ KeyValue _kv = (KeyValue) kv.getValue(); dev.getLicFeature().put(_kv.getKey(), _kv.getValue()); } } } } } } catch (Exception e) { log.log(Level.SEVERE, "Not able to get the HOST LIC config", e); } // BIOS try { HostBIOSInfo bios = host.getHardware().getBiosInfo(); BIOSModule mod = new BIOSModule(); mod.setBiosVendor("VMware"); mod.setReleaseDate(bios.getReleaseDate().getTime().toGMTString()); mod.setSysVer(bios.getBiosVersion()); dev.setBios(mod); } catch (Exception e) { log.log(Level.SEVERE, "Not able to collect the BIOS details"); } // Extract all the Resourve Pools and attached VMs // First get all the VMs VirtualMachine[] vms = host.getVms(); if(vms.length > 0) { for(int v = 0; v < vms.length; v++) { VirtualMachine vm = vms[v]; ResourcePool rp = vm.getResourcePool(); // VMs belongs to a Resource pool if(rp != null && !rp.getName().equalsIgnoreCase("Resources")) { VMwareResourcePool vrp = this.buildResourcePool(rp); if(dev.getRpools().get(vrp.getName()) == null) { // Add the VM to the Resource Pool vrp.getVms().add(this.buildVMwareDevice(vm, dev)); // Add the Resource pool to Host dev.getRpools().put(vrp.getName(), vrp); log.log(Level.SEVERE, "ADDED the ResourcePool: " + vrp.getName()); } else { dev.getRpools().get(vrp.getName()).getVms().add(this.buildVMwareDevice(vm, dev)); } } else { // Add the VM directly to the Host dev.getVms().add(this.buildVMwareDevice(vm, dev)); } log.log(Level.SEVERE, "ADDED the VM: " + vm.getName()); // Collect the Datastores Datastore[] dss = vm.getDatastores(); for (int j = 0; j < dss.length; j++) { DatastoreInfo info = dss[j].getInfo(); String dssUUID = null; if(info instanceof VmfsDatastoreInfo) { VmfsDatastoreInfo vdinfo = (VmfsDatastoreInfo) info; dssUUID = vdinfo.getVmfs().getUuid(); } DataStoreModule _ds = new DataStoreModule(info.getName(), dss[j].getMOR().getType(), dss[j].getMOR().getVal(), info.getMaxFileSize(), info.getFreeSpace(), info.getTimestamp().getTimeInMillis(), dssUUID); dev.getDataStore().put(_ds.getName(), _ds); } } } Thanks & Regards P C Varma | Project Manager, SME Solutions, NETENRICH Inc. Skype:pc.varma | Mobile: +918019016669 | Phone: +(1)310-3627094 x 662
  11. 2011-10-26 08:30:42 PDT
    Changed WSClient.java --------------------------------- /*================================================================================ Copyright (c) 2009 VMware, Inc. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of VMware, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================*/ package com.vmware.vim25.ws; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Date; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import com.vmware.vim25.ManagedObjectReference; import java.rmi.RemoteException; /** * The Web Service Engine * @author Steve Jin (sjin@vmware.com) */ public final class WSClient { private final static String SOAP_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"; xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"; xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body>";; private final static String SOAP_END = "</soapenv:Body></soapenv:Envelope>"; private final static String SOAP_ACTION_HEADER = "SOAPAction"; private final static String SOAP_ACTION_V40 = "urn:vim25/4.0"; private final static String SOAP_ACTION_V41 = "urn:vim25/4.1"; private final static String SOAP_ACTION_V50 = "urn:vim25/5.0"; private URL baseUrl = null; private String cookie = null; private String vimNameSpace = null; private String soapAction = SOAP_ACTION_V40; private int connectTimeout = 0; private int readTimeout = 0; public WSClient(String serverUrl) throws MalformedURLException { this(serverUrl, true); } public WSClient(String serverUrl, boolean ignoreCert) throws MalformedURLException { if(serverUrl.endsWith("/")) { serverUrl = serverUrl.substring(0, serverUrl.length()-1); } this.baseUrl = new URL(serverUrl); if(ignoreCert) { try { trustAllHttpsCertificates(); HttpsURLConnection.setDefaultHostnameVerifier ( new HostnameVerifier() { public boolean verify(String urlHostName, SSLSession session) { return true; } } ); } catch (Exception e) {} } } public Object invoke(ManagedObjectReference mor, String methodName, Argument[] paras, String returnType) throws IOException { Argument[] fullParas = new Argument[paras.length + 1]; fullParas[0] = new Argument("_this", "ManagedObjectReference", mor); System.arraycopy(paras, 0, fullParas, 1, paras.length); return invoke(methodName, fullParas, returnType); } public Object invoke(String methodName, Argument[] paras, String returnType) throws RemoteException { Element root = null; for(int retry=1; retry<=5; retry++) { try { root = invoke(methodName, paras); // Success break; } catch (Exception e) { System.out.println((new Date()) + " WSClient.invoke()# SOAP Req Retrying(MAX=5)...#" + retry); if(retry == 5) { System.out.println((new Date()) + " WSClient.invoke()# SOAP Req Retry MAX attempts reached#" + e.getMessage()); e.printStackTrace(); throw new RemoteException(" WSClient.invoke()# SOAP Req Retry MAX attempts reached#" + e.getMessage()); } Object obj = new Object(); try { synchronized(obj){ obj.wait(retry * 1000); } } catch (Exception e1) { // ignore } } } Element body = (Element) root.elements().get(0); Element resp = (Element) body.elements().get(0); if(resp.getName().indexOf("Fault")!=-1) { SoapFaultException sfe = null; try { sfe = XmlGen.parseSoapFault(resp); } catch (Exception e) { throw new RemoteException("Exception in WSClient.invoke:", e); } if(sfe!=null && sfe.detail!=null) { throw (RemoteException) sfe.detail; } else { throw sfe; } } else { if(returnType!=null) { try { return XmlGen.fromXML(returnType, resp); } catch (Exception e) { throw new RemoteException("Exception in WSClient.invoke:", e); } } else { return null; } } } public Element invoke(String methodName, Argument[] paras) throws RemoteException { String soapMsg = createSoapMessage(methodName, paras); Element root = null; InputStream is = null; StringBuffer buff = new StringBuffer(); try { is = post(soapMsg); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; do { line = br.readLine(); if(line != null) buff.append(line); } while(line != null); SAXReader reader = new SAXReader(); // Parse the SOAP Response if(buff.length() != 0) { ByteArrayInputStream bin = new ByteArrayInputStream(buff.toString().getBytes()); Document doc = reader.read(bin); root = doc.getRootElement(); bin.close(); } else { throw new RemoteException("VI SDK invoke exception. Empty SOAP Response received for REQ\n" + soapMsg); } } catch (Exception e) { String msg = buff.toString(); throw new RemoteException("VI SDK invoke exception. ### Failed to Parse SOAP RES:\n" + (msg == null ? "<empty>" : msg) + "\n for REQ\n" + soapMsg); } finally { if(is!=null) try { is.close(); } catch(IOException ioe) {} } return root; } public StringBuffer invokeAsString(String methodName, Argument[] paras) throws RemoteException { String soapMsg = createSoapMessage(methodName, paras); try { InputStream is = post(soapMsg); return readStream(is); } catch (Exception e) { throw new RemoteException("VI SDK invoke exception:" + e); } } private String createSoapMessage(String methodName, Argument[] paras) { StringBuffer sb = new StringBuffer(); sb.append(SOAP_HEADER); sb.append("<" + methodName + vimNameSpace); for(int i=0; i<paras.length; i++) { String key = paras.getName(); String type = paras.getType(); Object obj = paras.getValue(); sb.append(XmlGen.toXML(key, type, obj)); //, null)); } sb.append("</" + methodName + ">"); sb.append(SOAP_END); return sb.toString(); } public InputStream post(String soapMsg) throws IOException { HttpURLConnection postCon = (HttpURLConnection) baseUrl.openConnection(); if(connectTimeout > 0) postCon.setConnectTimeout(connectTimeout); if(readTimeout > 0) postCon.setReadTimeout(readTimeout); try { postCon.setRequestMethod("POST"); } catch (ProtocolException e) { e.printStackTrace(); } postCon.setDoOutput(true); postCon.setDoInput(true); postCon.setRequestProperty(SOAP_ACTION_HEADER, soapAction); postCon.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); if(cookie!=null) { postCon.setRequestProperty("Cookie", cookie); } OutputStream os = postCon.getOutputStream(); OutputStreamWriter out = new OutputStreamWriter(os, "UTF8"); out.write(soapMsg); out.close(); InputStream is; try { is = postCon.getInputStream(); } catch(IOException ioe) { is = postCon.getErrorStream(); } if(cookie==null) { cookie = postCon.getHeaderField("Set-Cookie"); } return is; } public URL getBaseUrl() { return this.baseUrl; } public void setBaseUrl(URL baseUrl) { this.baseUrl = baseUrl; } public String getCookie() { return cookie; } public void setCookie(String cookie) { this.cookie = cookie; } public String getVimNameSpace() { return vimNameSpace; } public void setVimNameSpace(String vimNameSpace) { this.vimNameSpace = vimNameSpace; } public void setConnectTimeout(int timeoutMilliSec) { this.connectTimeout = timeoutMilliSec; } public int getConnectTimeout() { return this.connectTimeout; } public void setReadTimeout(int timeoutMilliSec) { this.readTimeout = timeoutMilliSec; } public int getReadTimeout() { return this.readTimeout; } /*=============================================== * API versions * "2.0.0" VI 3.0 "2.5.0" VI 3.5 (and u1) "2.5u2" VI 3.5u2 (and u3, u4) "4.0" vSphere 4.0 (and u1) "4.1" vSphere 4.1 "5.0" vSphere 5.0 ===============================================*/ public void setSoapActionOnApiVersion(String apiVersion) { //4.0 is set by default already, so skip it here if("4.1".equals(apiVersion)) { soapAction = SOAP_ACTION_V41; } else if("5.0".equals(apiVersion)) { soapAction = SOAP_ACTION_V50; } } private StringBuffer readStream(InputStream is) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String lineStr; while ((lineStr = in.readLine()) != null) { sb.append(lineStr); } in.close(); return sb; } private static void trustAllHttpsCertificates() throws NoSuchAlgorithmException, KeyManagementException { TrustManager[] trustAllCerts = new TrustManager[1]; trustAllCerts[0] = new TrustAllManager(); SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, null); HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory()); } private static class TrustAllManager implements X509TrustManager { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { } public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { } } }
  12. 2011-10-28 01:18:32 PDT
    Hi Steve, One more observation i have is, Some times VCenter is not responding to API calls on the ESX server configured as part of the Clusters. Please help me out to fix this issue.
  13. 2012-04-24 21:03:25 PDT
    hi steve, can we get the hardware information like bios, cpu, system information of server without connecting to VC(virtual center) using vijava api???? Thanks, Abhilash
  14. 2012-04-27 17:02:28 PDT
    Yes. Check out the HostHardwareInfo of HostSystem. Steve
Jump To:
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.