Search in sources :

Example 36 with Operation

use of com.google.api.services.notebooks.v1.model.Operation in project terra-workspace-manager by DataBiosphere.

the class CompleteTransferOperationStep method getTransferOperationResult.

/**
 * Poll for completion of the named transfer operation and return the result.
 *
 * @param transferJobName - name of job owning the transfer operation
 * @param operationName - server-generated name of running operation
 * @return StepResult indicating success or failure
 * @throws IOException
 * @throws InterruptedException
 */
private StepResult getTransferOperationResult(String transferJobName, String operationName) throws IOException, InterruptedException {
    // Now that we have an operation name, we can poll the operations endpoint for completion
    // information.
    int attempts = 0;
    Operation operation;
    do {
        operation = storagetransfer.transferOperations().get(operationName).execute();
        if (operation == null) {
            throw new RuntimeException(String.format("Failed to get transfer operation with name %s", operationName));
        } else if (operation.getDone() != null && operation.getDone()) {
            break;
        } else {
            // operation is not started or is in progress
            TimeUnit.MILLISECONDS.sleep(OPERATIONS_POLL_INTERVAL.toMillis());
            attempts++;
            logger.debug("Attempted to get transfer operation {} {} times", operationName, attempts);
        }
    } while (attempts < MAX_ATTEMPTS);
    if (MAX_ATTEMPTS <= attempts) {
        final String message = "Timed out waiting for operation result.";
        logger.info(message);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new StorageTransferServiceTimeoutException(message));
    }
    logger.info("Operation {} in transfer job {} has completed", operationName, transferJobName);
    // Inspect the completed operation for success
    if (operation.getError() != null) {
        logger.warn("Error in transfer operation {}: {}", operationName, operation.getError());
        final RuntimeException e = new RuntimeException("Failed transfer with error " + operation.getError().toString());
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
    } else {
        logger.debug("Completed operation metadata: {}", operation.getMetadata());
        return StepResult.getStepResultSuccess();
    }
}
Also used : Operation(com.google.api.services.storagetransfer.v1.model.Operation) StepResult(bio.terra.stairway.StepResult) StorageTransferServiceTimeoutException(bio.terra.workspace.service.resource.controlled.exception.StorageTransferServiceTimeoutException)

Aggregations

IOException (java.io.IOException)14 Test (org.junit.Test)9 Operation (io.adminshell.aas.v3.model.Operation)7 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)6 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 StepResult (bio.terra.stairway.StepResult)5 Operation (com.google.api.services.notebooks.v1.model.Operation)5 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)5 Operation (com.google.api.services.appengine.v1.model.Operation)4 Create (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create)4 Operation (com.google.api.services.container.v1beta1.model.Operation)4 AIPlatformNotebooksCow (bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow)3 InstanceName (bio.terra.cloudres.google.notebooks.InstanceName)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3 Status (com.google.api.services.appengine.v1.model.Status)3 Get (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Get)3 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)3 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)3 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)3