use of com.google.api.services.container.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setAasReferenceData.
/**
* Sets the data in the given Reference node.
*
* @param ref The desired UA reference object
* @param refNode The AAS Reference object with the source data
* @param readOnly True if the value should be read-only
* @throws StatusException If the operation fails
*/
private void setAasReferenceData(Reference ref, AASReferenceType refNode, boolean readOnly) throws StatusException {
if (refNode == null) {
throw new IllegalArgumentException("refNode is null");
} else if (ref == null) {
throw new IllegalArgumentException("ref is null");
}
try {
List<AASKeyDataType> keyList = new ArrayList<>();
ref.getKeys().stream().map(k -> {
AASKeyDataType keyValue = new AASKeyDataType();
keyValue.setIdType(ValueConverter.getAasKeyType(k.getIdType()));
keyValue.setType(ValueConverter.getAasKeyElementsDataType(k.getType()));
keyValue.setValue(k.getValue());
return keyValue;
}).forEachOrdered(keyValue -> {
keyList.add(keyValue);
});
refNode.getKeysNode().setArrayDimensions(new UnsignedInteger[] { UnsignedInteger.valueOf(keyList.size()) });
if (readOnly) {
refNode.getKeysNode().setAccessLevel(AccessLevelType.CurrentRead);
}
refNode.setKeys(keyList.toArray(AASKeyDataType[]::new));
} catch (Throwable ex) {
logger.error("setAasReferenceData Exception", ex);
throw ex;
}
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-workspace-manager by DataBiosphere.
the class CompleteTransferOperationStep method getTransferOperationResult.
/**
* Poll for completion of the named transfer operation and return the result.
*
* @param storageTransferService - svc to perform the transfer
* @param transferJobName - name of job owning the transfer operation
* @param operationName - server-generated name of running operation
* @return StepResult indicating success or failure
* @throws IOException
* @throws InterruptedException
*/
private StepResult getTransferOperationResult(Storagetransfer storageTransferService, String transferJobName, String operationName) throws IOException, InterruptedException {
// Now that we have an operation name, we can poll the operations endpoint for completion
// information.
int attempts = 0;
Operation operation;
do {
operation = storageTransferService.transferOperations().get(operationName).execute();
if (operation == null) {
throw new RuntimeException(String.format("Failed to get transfer operation with name %s", operationName));
} else if (operation.getDone() != null && operation.getDone()) {
break;
} else {
// operation is not started or is in progress
TimeUnit.MILLISECONDS.sleep(OPERATIONS_POLL_INTERVAL.toMillis());
attempts++;
logger.debug("Attempted to get transfer operation {} {} times", operationName, attempts);
}
} while (attempts < MAX_ATTEMPTS);
if (MAX_ATTEMPTS <= attempts) {
final String message = "Timed out waiting for operation result.";
logger.info(message);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new StorageTransferServiceTimeoutException(message));
}
logger.info("Operation {} in transfer job {} has completed", operationName, transferJobName);
// Inspect the completed operation for success
if (operation.getError() != null) {
logger.warn("Error in transfer operation {}: {}", operationName, operation.getError());
final RuntimeException e = new RuntimeException("Failed transfer with error " + operation.getError().toString());
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
} else {
logger.debug("Completed operation metadata: {}", operation.getMetadata());
return StepResult.getStepResultSuccess();
}
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.
the class ServiceUsageUtils method enableServices.
/**
* Enables batch services for a project.
*
* @param projectId: The projectId to enable services on.
* @param services: Services to be enabled. See {@link BatchEnableServicesRequest}
*/
public static void enableServices(String projectId, List<String> services) throws Exception {
Operation operation = getServiceUsageCow().services().batchEnable(projectIdToName(projectId), new BatchEnableServicesRequest().setServiceIds(services)).execute();
OperationTestUtils.pollAndAssertSuccess(serviceUsageCow.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(100));
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.
the class ServiceUsageCowTest method listAndEnableServices.
@Test
public void listAndEnableServices() throws Exception {
ServiceUsageCow serviceUsage = defaultServiceUsage();
Project project = ProjectUtils.executeCreateProject();
String projectName = projectIdToName(project.getProjectId());
String storageServiceName = serviceName(project, STORAGE_SERVICE_ID);
ListServicesResponse response1 = serviceUsage.services().list(projectName).setFilter(ENABLED_FILTER).execute();
assertNull(response1.getServices());
Operation operation = serviceUsage.services().batchEnable(projectName, new BatchEnableServicesRequest().setServiceIds(ImmutableList.of(STORAGE_SERVICE_ID))).execute();
OperationTestUtils.pollAndAssertSuccess(serviceUsage.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(60));
ListServicesResponse response2 = serviceUsage.services().list(projectName).setFilter(ENABLED_FILTER).execute();
List<String> services2 = response2.getServices().stream().map(GoogleApiServiceusageV1Service::getName).collect(Collectors.toList());
assertThat(services2, Matchers.hasItem(storageServiceName));
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-cli by DataBiosphere.
the class GoogleNotebooks method stop.
public void stop(InstanceName instanceName) {
try {
Operation stopOperation = notebooks.instances().stop(instanceName).execute();
pollForSuccess(stopOperation, "Error stopping notebook instance: ");
} catch (InterruptedException | IOException e) {
checkFor409BadState(e);
throw new SystemException("Error stopping notebook instance", e);
}
}
Aggregations