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();
}
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);
}
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());
}
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());
}
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();
}
Aggregations