Merge pull request #63 from Microsoft/users/subraman/threadhangissue
Thread is hang issue fix
This commit is contained in:
Коммит
e8585c5961
|
@ -32,6 +32,5 @@ public class Constants {
|
|||
|
||||
public static final String TASK_ID = "735d144e-55fe-44d6-b687-db9031b6e70b";
|
||||
public static final int OS_CUSTOMIZATION_MAX_WAIT_IN_MINUTES = 30;
|
||||
public static final int NETWORK_DISCOVERY_POLLING_INTERVAL_IN_SECONDS = 10;
|
||||
public static final int OS_CUSTOMIZATION_POLLING_INTERVAL_IN_SECONDS = 10;
|
||||
public static final int POLLING_INTERVAL_IN_SECONDS = 10;
|
||||
}
|
||||
|
|
|
@ -181,20 +181,23 @@ public class VMWareImpl implements IVMWare {
|
|||
ManagedObjectReference vmMor = getMorByName(targetDCMor, vmName, VIRTUAL_MACHINE, false);
|
||||
vimPort.shutdownGuest(vmMor);
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(1);
|
||||
ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
Runnable task = () -> {
|
||||
try {
|
||||
VMWareImpl.this.waitForPowerOffOperation(vmName, vmMor);
|
||||
} catch (Exception e) {
|
||||
new Exception("Failed to wait for vm [ " + vmName + " ] to be powered off");
|
||||
System.err.println("Failed to wait for vm [ " + vmName + " ] to be powered off. Failure reason: " + e.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
executorService.submit(task);
|
||||
executorService.shutdown();
|
||||
boolean isWaitSuccessful = executorService.awaitTermination(timeout, TimeUnit.SECONDS);
|
||||
if (!isWaitSuccessful) {
|
||||
threadPool.submit(task);
|
||||
threadPool.shutdown();
|
||||
if (!threadPool.awaitTermination(timeout, TimeUnit.SECONDS)) {
|
||||
System.out.println("Virtual machine [ " + vmName + " ] did not shutdown within given time, further deployment operation might fail.");
|
||||
threadPool.shutdownNow();
|
||||
if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -291,7 +294,7 @@ public class VMWareImpl implements IVMWare {
|
|||
|
||||
System.out.println(String.format("Waiting for virtual machine [ %s ] network discovery to complete. isGuestOSWindows = %s ", vmName, isGuestOSWindows));
|
||||
while (!(isDnsResolved && isNetBIOSResolved)) {
|
||||
sleep(Constants.NETWORK_DISCOVERY_POLLING_INTERVAL_IN_SECONDS * 1000);
|
||||
sleep(Constants.POLLING_INTERVAL_IN_SECONDS * 1000);
|
||||
|
||||
if (!isDnsResolved) {
|
||||
isDnsResolved = isDnsNameResolved(vmName);
|
||||
|
@ -365,22 +368,26 @@ public class VMWareImpl implements IVMWare {
|
|||
private void waitForVMToBeDeployReady(String vmName, ManagedObjectReference vmMor, int timeout) throws Exception {
|
||||
|
||||
System.out.println("Waiting for virtual machine [ " + vmName + " ] to be deployment ready.");
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(1);
|
||||
ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
Runnable task = () -> {
|
||||
try {
|
||||
VMWareImpl.this.waitForPowerOnOperation(vmName, vmMor);
|
||||
boolean isGuestOSWindows = isGuestOSWindows(vmMor);
|
||||
VMWareImpl.this.waitForNetworkDiscoveryOfVM(vmName, isGuestOSWindows);
|
||||
} catch (Exception e) {
|
||||
new Exception("Failed to wait for vm [ " + vmName + " ] to be deployment ready");
|
||||
System.err.println("Failed to wait for vm [ " + vmName + " ] to be deployment ready: Failure reason :" + e.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
executorService.submit(task);
|
||||
executorService.shutdown();
|
||||
boolean isWaitSuccessful = executorService.awaitTermination(timeout, TimeUnit.SECONDS);
|
||||
if (!isWaitSuccessful) {
|
||||
threadPool.submit(task);
|
||||
threadPool.shutdown();
|
||||
if (!threadPool.awaitTermination(timeout, TimeUnit.SECONDS)) {
|
||||
System.out.println("Virtual machine [ " + vmName + " ] deployment requirements not finished within given time, continuing further deployment operation might fail.");
|
||||
threadPool.shutdownNow();
|
||||
if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) {
|
||||
System.exit(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
System.out.println("Virtual machine [ " + vmName + " ] is now ready for deployment.");
|
||||
}
|
||||
|
@ -468,6 +475,7 @@ public class VMWareImpl implements IVMWare {
|
|||
reached = expectedVal.equals(endVals[chgi]);
|
||||
}
|
||||
}
|
||||
Thread.sleep(Constants.POLLING_INTERVAL_IN_SECONDS * 1000);
|
||||
}
|
||||
vimPort.destroyPropertyFilter(propertyFilter);
|
||||
return filterVals;
|
||||
|
@ -487,7 +495,7 @@ public class VMWareImpl implements IVMWare {
|
|||
long startTime = System.currentTimeMillis();
|
||||
|
||||
while ((new Date()).getTime() - startTime < maxWaitTimeInMinutes * 60 * 1000) {
|
||||
sleep(Constants.OS_CUSTOMIZATION_POLLING_INTERVAL_IN_SECONDS * 1000);
|
||||
sleep(Constants.POLLING_INTERVAL_IN_SECONDS * 1000);
|
||||
ArrayList<Event> eventList = (ArrayList<Event>) ((ArrayOfEvent) getMorProperties(vmEventHistoryCollector, new String[]{LATEST_PAGE}).get(LATEST_PAGE)).getEvent();
|
||||
for (Event anEvent : eventList) {
|
||||
String eventName = anEvent.getClass().getSimpleName();
|
||||
|
|
Загрузка…
Ссылка в новой задаче