Search in sources :

Example 1 with Status

use of com.google.api.services.cloudresourcemanager.model.Status in project jade-data-repo by DataBiosphere.

the class GoogleResourceService method blockUntilResourceOperationComplete.

/**
 * Poll the resource manager api until an operation completes. It is possible to hit quota issues here, so the
 * timeout is set to 10 seconds.
 * @param resourceManager service instance
 * @param operation has an id for us to use in the check
 * @param timeoutSeconds how many seconds before we give up
 * @return a completed operation
 */
private static Operation blockUntilResourceOperationComplete(CloudResourceManager resourceManager, Operation operation, long timeoutSeconds) throws IOException, InterruptedException {
    long start = System.currentTimeMillis();
    // 10 seconds
    final long pollInterval = 10 * 1000;
    String opId = operation.getName();
    while (operation != null && (operation.getDone() == null || !operation.getDone())) {
        Status error = operation.getError();
        if (error != null) {
            throw new GoogleResourceException("Error while waiting for operation to complete" + error.getMessage());
        }
        Thread.sleep(pollInterval);
        long elapsed = System.currentTimeMillis() - start;
        if (elapsed >= timeoutSeconds * 1000) {
            throw new GoogleResourceException("Timed out waiting for operation to complete");
        }
        logger.info("checking operation: {}", opId);
        CloudResourceManager.Operations.Get request = resourceManager.operations().get(opId);
        operation = request.execute();
    }
    return operation;
}
Also used : Status(com.google.api.services.cloudresourcemanager.model.Status) GoogleResourceException(bio.terra.service.resourcemanagement.exception.GoogleResourceException)

Aggregations

GoogleResourceException (bio.terra.service.resourcemanagement.exception.GoogleResourceException)1 Status (com.google.api.services.cloudresourcemanager.model.Status)1