use of com.vmware.xenon.services.common.TaskService.TaskServiceState in project photon-model by vmware.
the class ProvisioningUtils method waitForTaskCompletion.
public static void waitForTaskCompletion(VerificationHost host, List<URI> provisioningTasks, Class<? extends TaskServiceState> clazz) throws Throwable, InterruptedException, TimeoutException {
Date expiration = host.getTestExpiration();
List<String> pendingTasks = new ArrayList<String>();
do {
pendingTasks.clear();
// grab in parallel, all task state, from all running tasks
Map<URI, ? extends TaskServiceState> taskStates = host.getServiceState(null, clazz, provisioningTasks);
boolean isConverged = true;
for (Entry<URI, ? extends TaskServiceState> e : taskStates.entrySet()) {
TaskServiceState currentState = e.getValue();
if (currentState.taskInfo.stage == TaskState.TaskStage.FAILED) {
throw new IllegalStateException("Task failed:" + Utils.toJsonHtml(currentState));
}
if (currentState.taskInfo.stage != TaskState.TaskStage.FINISHED) {
pendingTasks.add(currentState.documentSelfLink);
isConverged = false;
}
}
if (isConverged) {
return;
}
Thread.sleep(1000);
} while (new Date().before(expiration));
for (String taskLink : pendingTasks) {
host.log("Pending task:\n%s", taskLink);
}
throw new TimeoutException("Some tasks never finished");
}
Aggregations