use of com.google.api.services.healthcare.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.healthcare.v1.model.Operation in project terra-workspace-manager by DataBiosphere.
the class DeleteAiNotebookInstanceStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
final GcpCloudContext gcpCloudContext = flightContext.getWorkingMap().get(ControlledResourceKeys.GCP_CLOUD_CONTEXT, GcpCloudContext.class);
InstanceName instanceName = resource.toInstanceName(gcpCloudContext.getGcpProjectId());
AIPlatformNotebooksCow notebooks = crlService.getAIPlatformNotebooksCow();
try {
Optional<Operation> rawOperation = deleteIfFound(instanceName, notebooks);
if (rawOperation.isEmpty()) {
logger.info("Notebook instance {} already deleted", instanceName.formatName());
return StepResult.getStepResultSuccess();
}
GcpUtils.pollUntilSuccess(notebooks.operations().operationCow(rawOperation.get()), Duration.ofSeconds(20), Duration.ofMinutes(10));
} catch (IOException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.google.api.services.healthcare.v1.model.Operation in project terra-workspace-manager by DataBiosphere.
the class CreateAiNotebookInstanceStep method undoStep.
@Override
public StepResult undoStep(FlightContext flightContext) throws InterruptedException {
final GcpCloudContext gcpCloudContext = flightContext.getWorkingMap().get(ControlledResourceKeys.GCP_CLOUD_CONTEXT, GcpCloudContext.class);
InstanceName instanceName = resource.toInstanceName(gcpCloudContext.getGcpProjectId());
AIPlatformNotebooksCow notebooks = crlService.getAIPlatformNotebooksCow();
try {
OperationCow<Operation> deletionOperation;
try {
deletionOperation = notebooks.operations().operationCow(notebooks.instances().delete(instanceName).execute());
} catch (GoogleJsonResponseException e) {
// The AI notebook instance may never have been created or have already been deleted.
if (e.getStatusCode() == HttpStatus.NOT_FOUND.value()) {
logger.debug("No notebook instance {} to delete.", instanceName.formatName());
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
GcpUtils.pollUntilSuccess(deletionOperation, Duration.ofSeconds(20), Duration.ofMinutes(12));
} catch (IOException | RetryException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.google.api.services.healthcare.v1.model.Operation in project terra-workspace-manager by DataBiosphere.
the class CreateAiNotebookInstanceStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
final GcpCloudContext gcpCloudContext = flightContext.getWorkingMap().get(ControlledResourceKeys.GCP_CLOUD_CONTEXT, GcpCloudContext.class);
String projectId = gcpCloudContext.getGcpProjectId();
InstanceName instanceName = resource.toInstanceName(projectId);
Instance instance = createInstanceModel(flightContext, projectId, petEmail);
AIPlatformNotebooksCow notebooks = crlService.getAIPlatformNotebooksCow();
try {
OperationCow<Operation> creationOperation;
try {
creationOperation = notebooks.operations().operationCow(notebooks.instances().create(instanceName, instance).execute());
} catch (GoogleJsonResponseException e) {
// retry.
if (HttpStatus.CONFLICT.value() == e.getStatusCode()) {
logger.debug("Notebook instance {} already created.", instanceName.formatName());
return StepResult.getStepResultSuccess();
} else if (HttpStatus.BAD_REQUEST.value() == e.getStatusCode()) {
// Don't retry bad requests, which won't change. Instead fail faster.
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
GcpUtils.pollUntilSuccess(creationOperation, Duration.ofSeconds(20), Duration.ofMinutes(12));
} catch (IOException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.google.api.services.healthcare.v1.model.Operation in project terra-cli by DataBiosphere.
the class GoogleNotebooks method start.
public void start(InstanceName instanceName) {
try {
Operation startOperation = notebooks.instances().start(instanceName).execute();
pollForSuccess(startOperation, "Error starting notebook instance: ");
} catch (InterruptedException | IOException e) {
checkFor409BadState(e);
throw new SystemException("Error starting notebook instance", e);
}
}
Aggregations