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