@Override public void run() { try { System.out.println( "---------------------- Thread for " + "Checking the HTTP NFCLEASE vmdkFlag: " + vmdkFlag + "----------------------"); while (!vmdkFlag) { System.out.println("#### TOTAL_BYTES_WRITTEN " + TOTAL_BYTES_WRITTEN); System.out.println("#### TOTAL_BYTES " + TOTAL_BYTES); try { vimPort.httpNfcLeaseProgress(httpNfcLease, 0); Thread.sleep(290000000); } catch (InterruptedException e) { System.out.println( "---------------------- Thread interrupted " + "----------------------"); } } } catch (Exception e) { e.printStackTrace(); } }
void exportVM() throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg { File file = new File(localPath); if (!file.exists()) { System.out.println("Wrong or invalid path " + localPath); return; } ManagedObjectReference srcMOR = getMOREFs.inFolderByType(serviceContent.getRootFolder(), "HostSystem").get(host); if (srcMOR == null) { throw new RuntimeException(" Source Host " + host + " Not Found."); } ManagedObjectReference vmMoRef = getMOREFs.inFolderByType(srcMOR, "VirtualMachine").get(vmname); if (vmMoRef == null) { throw new RuntimeException("Virtual Machine " + vmname + " Not Found."); } System.out.println("Getting the HTTP NFCLEASE for the VM: " + vmname); try { ManagedObjectReference httpNfcLease = vimPort.exportVm(vmMoRef); Object[] result = waitForValues.wait( httpNfcLease, new String[] {"state"}, new String[] {"state"}, new Object[][] {new Object[] {HttpNfcLeaseState.READY, HttpNfcLeaseState.ERROR}}); if (result[0].equals(HttpNfcLeaseState.READY)) { System.out.println("HttpNfcLeaseState: " + result[0]); HttpNfcLeaseInfo httpNfcLeaseInfo = (HttpNfcLeaseInfo) getMOREFs.entityProps(httpNfcLease, new String[] {"info"}).get("info"); httpNfcLeaseInfo.setLeaseTimeout(300000000); printHttpNfcLeaseInfo(httpNfcLeaseInfo, host); long diskCapacity = (httpNfcLeaseInfo.getTotalDiskCapacityInKB()) * 1024; TOTAL_BYTES = diskCapacity; leaseExtender = new OVFManagerExportVMDK().new HttpNfcLeaseExtender(httpNfcLease, vimPort); Thread t = new Thread(leaseExtender); t.start(); List<HttpNfcLeaseDeviceUrl> deviceUrlArr = httpNfcLeaseInfo.getDeviceUrl(); for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrlArr) { System.out.println("Downloading Files:"); String deviceUrlStr = deviceUrl.getUrl(); String absoluteFile = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1); System.out.println("Absolute File Name: " + absoluteFile); System.out.println("VMDK URL: " + deviceUrlStr.replace("*", host)); writeVMDKFile(absoluteFile, deviceUrlStr.replace("*", host), diskCapacity, vmname); } System.out.println("Completed Downloading the files"); vmdkFlag = true; t.interrupt(); vimPort.httpNfcLeaseProgress(httpNfcLease, 100); vimPort.httpNfcLeaseComplete(httpNfcLease); } else { System.out.println("HttpNfcLeaseState not ready"); for (Object o : result) { System.out.println("HttpNfcLeaseState: " + o); } } } catch (Exception e) { e.printStackTrace(); } }