Search in sources :

Example 26 with Operation

use of com.google.api.services.healthcare.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DicomStoreExport method dicomStoreExport.

public static void dicomStoreExport(String dicomStoreName, String gcsUri) throws IOException {
    // String dicomStoreName =
    // String.format(
    // DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");
    // String gcsUri = "gs://your-bucket-id/path/to/destination/dir"
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure where the store will be exported too.
    GoogleCloudHealthcareV1DicomGcsDestination gcsDestination = new GoogleCloudHealthcareV1DicomGcsDestination().setUriPrefix(gcsUri);
    ExportDicomDataRequest exportRequest = new ExportDicomDataRequest().setGcsDestination(gcsDestination);
    // Create request and configure any parameters.
    DicomStores.Export request = client.projects().locations().datasets().dicomStores().export(dicomStoreName, exportRequest);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("DICOM store export complete." + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : DicomStores(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) GoogleCloudHealthcareV1DicomGcsDestination(com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1DicomGcsDestination) Operation(com.google.api.services.healthcare.v1.model.Operation) ExportDicomDataRequest(com.google.api.services.healthcare.v1.model.ExportDicomDataRequest) IOException(java.io.IOException)

Example 27 with Operation

use of com.google.api.services.healthcare.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class FhirStoreImport method fhirStoreImport.

public static void fhirStoreImport(String fhirStoreName, String gcsUri) throws IOException {
    // String fhirStoreName =
    // String.format(
    // FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");
    // String gcsUri = "gs://your-bucket-id/path/to/destination/dir"
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure where the store should be imported from.
    GoogleCloudHealthcareV1FhirGcsSource gcsSource = new GoogleCloudHealthcareV1FhirGcsSource().setUri(gcsUri);
    ImportResourcesRequest importRequest = new ImportResourcesRequest().setGcsSource(gcsSource);
    // Create request and configure any parameters.
    FhirStores.CloudHealthcareImport request = client.projects().locations().datasets().fhirStores().healthcareImport(fhirStoreName, importRequest);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("FHIR store import complete: " + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : FhirStores(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores) ImportResourcesRequest(com.google.api.services.healthcare.v1.model.ImportResourcesRequest) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) Operation(com.google.api.services.healthcare.v1.model.Operation) GoogleCloudHealthcareV1FhirGcsSource(com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1FhirGcsSource) IOException(java.io.IOException)

Example 28 with Operation

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, workspaceUserFacingId, cliConfiguration.getServerName());
    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)

Example 29 with Operation

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

Aggregations

IOException (java.io.IOException)14 Test (org.junit.Test)9 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)7 Operation (io.adminshell.aas.v3.model.Operation)7 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)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 Operation (com.google.api.services.serviceusage.v1beta1.model.Operation)3 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)3 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)3