Search in sources :

Example 26 with Operation

use of com.google.api.services.container.v1beta1.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 27 with Operation

use of com.google.api.services.container.v1beta1.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 28 with Operation

use of com.google.api.services.container.v1beta1.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();
}
Also used : InstanceName(bio.terra.cloudres.google.notebooks.InstanceName) AIPlatformNotebooksCow(bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow) Operation(com.google.api.services.notebooks.v1.model.Operation) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext)

Example 29 with Operation

use of com.google.api.services.container.v1beta1.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();
}
Also used : InstanceName(bio.terra.cloudres.google.notebooks.InstanceName) AIPlatformNotebooksCow(bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Operation(com.google.api.services.notebooks.v1.model.Operation) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult) RetryException(bio.terra.stairway.exception.RetryException) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext)

Example 30 with Operation

use of com.google.api.services.container.v1beta1.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();
}
Also used : InstanceName(bio.terra.cloudres.google.notebooks.InstanceName) AIPlatformNotebooksCow(bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow) 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) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext)

Aggregations

IOException (java.io.IOException)13 Operation (io.adminshell.aas.v3.model.Operation)8 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)5 Operation (com.google.api.services.notebooks.v1.model.Operation)5 Reference (io.adminshell.aas.v3.model.Reference)5 StepResult (bio.terra.stairway.StepResult)4 Operation (com.google.api.services.appengine.v1.model.Operation)4 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)4 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)4 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)4 List (java.util.List)4 Test (org.junit.Test)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 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)3 SystemException (bio.terra.cli.exception.SystemException)2