use of com.google.api.services.container.v1beta1.model.Operation in project java-docs-samples by GoogleCloudPlatform.
the class DatasetDeIdentify method datasetDeIdentify.
public static void datasetDeIdentify(String srcDatasetName, String destDatasetName) throws IOException {
// String srcDatasetName =
// String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-src-dataset-id");
// String destDatasetName =
// String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dest-dataset-id");
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
// Configure what information needs to be De-Identified.
// For more information on de-identifying using tags, please see the following:
// https://cloud.google.com/healthcare/docs/how-tos/dicom-deidentify#de-identification_using_tags
TagFilterList tags = new TagFilterList().setTags(Arrays.asList("PatientID"));
DicomConfig dicomConfig = new DicomConfig().setKeepList(tags);
DeidentifyConfig config = new DeidentifyConfig().setDicom(dicomConfig);
// Create the de-identify request and configure any parameters.
DeidentifyDatasetRequest deidentifyRequest = new DeidentifyDatasetRequest().setDestinationDataset(destDatasetName).setConfig(config);
Datasets.Deidentify request = client.projects().locations().datasets().deidentify(srcDatasetName, deidentifyRequest);
// 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("De-identified Dataset created. Response content: " + 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.container.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class InvokeOperationAsyncRequestHandler method executeOperationAsync.
public OperationHandle executeOperationAsync(Reference reference, InvokeOperationAsyncRequest request) {
if (assetConnectionManager.hasOperationProvider(reference)) {
OperationHandle operationHandle = this.persistence.putOperationContext(null, request.getRequestId(), new OperationResult.Builder().requestId(request.getRequestId()).inoutputArguments(request.getInoutputArguments()).executionState(ExecutionState.Running).build());
BiConsumer<OperationVariable[], OperationVariable[]> callback = (x, y) -> {
OperationResult operationResult = persistence.getOperationResult(operationHandle.getHandleId());
operationResult.setExecutionState(ExecutionState.Completed);
operationResult.setOutputArguments(Arrays.asList(x));
operationResult.setInoutputArguments(Arrays.asList(y));
persistence.putOperationContext(operationHandle.getHandleId(), operationHandle.getRequestId(), operationResult);
publishOperationFinishEventMessage(reference, toValues(Arrays.asList(x)), toValues(Arrays.asList(y)));
};
AssetOperationProvider assetOperationProvider = assetConnectionManager.getOperationProvider(reference);
try {
assetOperationProvider.invokeAsync(request.getInputArguments().toArray(new OperationVariable[0]), request.getInoutputArguments().toArray(new OperationVariable[0]), callback);
} catch (AssetConnectionException ex) {
OperationResult operationResult = persistence.getOperationResult(operationHandle.getHandleId());
operationResult.setExecutionState(ExecutionState.Failed);
operationResult.setInoutputArguments(request.getInoutputArguments());
persistence.putOperationContext(operationHandle.getHandleId(), operationHandle.getRequestId(), operationResult);
publishOperationFinishEventMessage(reference, List.of(), toValues(operationResult.getInoutputArguments()));
}
return operationHandle;
} else {
throw new RuntimeException("No assetconnection available for running operation with request id" + request.getRequestId());
}
}
use of com.google.api.services.container.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class InvokeOperationAsyncRequestHandler method process.
@Override
public InvokeOperationAsyncResponse process(InvokeOperationAsyncRequest request) {
InvokeOperationAsyncResponse response = new InvokeOperationAsyncResponse();
try {
Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
// Check if submodelelement does exist
Operation operation = (Operation) persistence.get(reference, new OutputModifier());
OperationHandle operationHandle = executeOperationAsync(reference, request);
response.setPayload(operationHandle);
response.setStatusCode(StatusCode.Success);
publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
use of com.google.api.services.container.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testInvokeOperationSyncRequest.
@Test
public void testInvokeOperationSyncRequest() {
CoreConfig coreConfig = CoreConfig.builder().build();
Persistence persistence = mock(Persistence.class);
MessageBus messageBus = mock(MessageBus.class);
AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
when(assetConnectionManager.getOperationProvider(any())).thenReturn(new CustomAssetOperationProvider());
RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
Operation operation = getTestOperation();
InvokeOperationSyncRequest invokeOperationSyncRequest = new InvokeOperationSyncRequest.Builder().requestId("1").inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).build();
InvokeOperationSyncResponse actualResponse = manager.execute(invokeOperationSyncRequest);
InvokeOperationSyncResponse expectedResponse = new InvokeOperationSyncResponse.Builder().statusCode(StatusCode.Success).payload(new OperationResult.Builder().requestId("1").inoutputArguments(List.of(new DefaultOperationVariable.Builder().value(new DefaultProperty.Builder().idShort("TestProp").value("TestOutput").build()).build())).outputArguments(operation.getInputVariables()).executionState(ExecutionState.Completed).build()).build();
Assert.assertEquals(expectedResponse, actualResponse);
}
use of com.google.api.services.container.v1beta1.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