Search in sources :

Example 31 with Operation

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

the class CreateStorageTransferServiceJobStep method doStep.

// See https://cloud.google.com/storage-transfer/docs/reference/rest/v1/transferJobs/create
// (somewhat dated) and
// https://cloud.google.com/storage-transfer/docs/create-manage-transfer-program
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
    final FlightMap workingMap = flightContext.getWorkingMap();
    FlightUtils.validateRequiredEntries(workingMap, ControlledResourceKeys.SOURCE_CLONE_INPUTS, ControlledResourceKeys.DESTINATION_CLONE_INPUTS, ControlledResourceKeys.CONTROL_PLANE_PROJECT_ID, ControlledResourceKeys.STORAGE_TRANSFER_SERVICE_SA_EMAIL);
    // Get source & destination bucket input values
    final BucketCloneInputs sourceInputs = workingMap.get(ControlledResourceKeys.SOURCE_CLONE_INPUTS, BucketCloneInputs.class);
    final BucketCloneInputs destinationInputs = workingMap.get(ControlledResourceKeys.DESTINATION_CLONE_INPUTS, BucketCloneInputs.class);
    logger.info("Starting data copy from source bucket \n\t{}\nto destination\n\t{}", sourceInputs, destinationInputs);
    final String transferJobName = StorageTransferServiceUtils.createTransferJobName(flightContext.getFlightId());
    workingMap.put(ControlledResourceKeys.STORAGE_TRANSFER_JOB_NAME, transferJobName);
    final String controlPlaneProjectId = workingMap.get(ControlledResourceKeys.CONTROL_PLANE_PROJECT_ID, String.class);
    logger.info("Creating transfer job named {} in project {}", transferJobName, controlPlaneProjectId);
    // the job either has an operation in progress or completed (possibly failed).
    try {
        final TransferJob existingTransferJob = storagetransfer.transferJobs().get(transferJobName, controlPlaneProjectId).execute();
        if (null != existingTransferJob) {
            logger.info("Transfer Job {} already exists. Nothing more for this step to do.", transferJobName);
            return StepResult.getStepResultSuccess();
        }
    } catch (GoogleJsonResponseException e) {
        logger.info("No pre-existing transfer job named {} found.", transferJobName);
    } catch (IOException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    // Get the service account in the control plane project used by the transfer service to
    // perform the actual data transfer. It's named for and scoped to the project.
    // Storage transfer service itself is free, so there should be no charges to the control
    // plane project. The usual egress charges will be made on the source bucket.
    // TODO(PF-888): understand what happens when the source bucket is requester pays. We don't
    // support requester pays right now for controlled gcs buckets, but it might be set on a
    // referenced bucket.
    final String transferServiceSAEmail = workingMap.get(ControlledResourceKeys.STORAGE_TRANSFER_SERVICE_SA_EMAIL, String.class);
    logger.debug("Storage Transfer Service SA: {}", transferServiceSAEmail);
    try {
        createTransferJob(sourceInputs, destinationInputs, transferJobName, controlPlaneProjectId);
    } catch (IOException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) FlightMap(bio.terra.stairway.FlightMap) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult) TransferJob(com.google.api.services.storagetransfer.v1.model.TransferJob)

Example 32 with Operation

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

the class CreateStorageTransferServiceJobStep method createScheduleRunOnceNow.

/**
 * Build a schedule to indicate that the job should run an operation immediately and not repeat
 * it.
 *
 * @return schedule object for the transfer job
 */
private Schedule createScheduleRunOnceNow() {
    final OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
    final Date runDate = new Date().setYear(now.getYear()).setMonth(now.getMonthValue()).setDay(now.getDayOfMonth());
    // Since our start and end days are the same, we get Run Once Now behavior.
    return new Schedule().setScheduleStartDate(runDate).setScheduleEndDate(runDate);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Schedule(com.google.api.services.storagetransfer.v1.model.Schedule) Date(com.google.api.services.storagetransfer.v1.model.Date)

Example 33 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.

the class CloudResourceManagerCowTest method createGetDeleteProject.

@Test
public void createGetDeleteProject() throws Exception {
    CloudResourceManagerCow managerCow = defaultManager();
    String projectId = ProjectUtils.randomProjectId();
    assertThrows(GoogleJsonResponseException.class, () -> managerCow.projects().get(projectId).execute());
    Operation operation = managerCow.projects().create(defaultProject(projectId)).execute();
    OperationTestUtils.pollAndAssertSuccess(managerCow.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(30));
    Project project = managerCow.projects().get(projectId).execute();
    assertEquals(projectId, project.getProjectId());
    assertEquals("ACTIVE", project.getState());
    Operation deleteOperation = managerCow.projects().delete(projectId).execute();
    OperationTestUtils.pollAndAssertSuccess(managerCow.operations().operationCow(deleteOperation), Duration.ofSeconds(5), Duration.ofSeconds(30));
    // After "deletion," the project still exists for up to 30 days where it can be recovered.
    project = managerCow.projects().get(projectId).execute();
    assertEquals("DELETE_REQUESTED", project.getState());
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Operation(com.google.api.services.cloudresourcemanager.v3.model.Operation) Test(org.junit.jupiter.api.Test)

Example 34 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.

the class AIPlatformNotebooksCowTest method createGetListDeleteNotebookInstance.

@Test
public void createGetListDeleteNotebookInstance() throws Exception {
    InstanceName instanceName = defaultInstanceName().build();
    createInstance(instanceName);
    Instance retrievedInstance = notebooks.instances().get(instanceName).execute();
    assertEquals(instanceName.formatName(), retrievedInstance.getName());
    ListInstancesResponse listResponse = notebooks.instances().list(instanceName.formatParent()).execute();
    // There may be other notebook instances from other tests.
    assertThat(listResponse.getInstances().size(), Matchers.greaterThan(0));
    assertThat(listResponse.getInstances().stream().map(Instance::getName).collect(Collectors.toList()), Matchers.hasItem(instanceName.formatName()));
    OperationCow<Operation> deleteOperation = notebooks.operations().operationCow(notebooks.instances().delete(instanceName).execute());
    OperationTestUtils.pollAndAssertSuccess(deleteOperation, Duration.ofSeconds(30), Duration.ofMinutes(5));
    GoogleJsonResponseException e = assertThrows(GoogleJsonResponseException.class, () -> notebooks.instances().get(instanceName).execute());
    assertEquals(404, e.getStatusCode());
}
Also used : ListInstancesResponse(com.google.api.services.notebooks.v1.model.ListInstancesResponse) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Instance(com.google.api.services.notebooks.v1.model.Instance) Operation(com.google.api.services.notebooks.v1.model.Operation) Test(org.junit.jupiter.api.Test)

Example 35 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.

the class ProjectUtils method executeCreateProject.

/**
 * Creates a new Google Project in GCP for testing.
 */
public static Project executeCreateProject() throws Exception {
    Project project = new Project().setProjectId(randomProjectId()).setParent(PARENT_RESOURCE);
    Operation operation = getManagerCow().projects().create(project).execute();
    OperationCow<Operation> operationCow = managerCow.operations().operationCow(operation);
    OperationTestUtils.pollAndAssertSuccess(operationCow, Duration.ofSeconds(5), Duration.ofSeconds(60));
    return managerCow.projects().get(project.getProjectId()).execute();
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Operation(com.google.api.services.cloudresourcemanager.v3.model.Operation)

Aggregations

IOException (java.io.IOException)15 Test (org.junit.Test)9 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)7 Operation (io.adminshell.aas.v3.model.Operation)7 StepResult (bio.terra.stairway.StepResult)6 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 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 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 StorageTransferServiceTimeoutException (bio.terra.workspace.service.resource.controlled.exception.StorageTransferServiceTimeoutException)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3 Create (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create)3 Get (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Get)3 Operation (com.google.api.services.serviceusage.v1beta1.model.Operation)3 TransferJob (com.google.api.services.storagetransfer.v1.model.TransferJob)3 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)3