Search in sources :

Example 1 with TaskServiceState

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");
}
Also used : ArrayList(java.util.ArrayList) TaskServiceState(com.vmware.xenon.services.common.TaskService.TaskServiceState) URI(java.net.URI) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TaskServiceState (com.vmware.xenon.services.common.TaskService.TaskServiceState)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TimeoutException (java.util.concurrent.TimeoutException)1