use of com.google.api.services.storagetransfer.v1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceMethodManagerListener method onCall.
/**
* Callback method when a method was called
*
* @param serviceContext the current service context
* @param objectId the ID of the node whose method is being called
* @param object the object node whose method is being called, if available
* @param methodId the ID of the method being called
* @param method the method node being called, if available
* @param inputArguments input argument values
* @param inputArgumentResults argument errors. If errors in the values are
* encountered.
* @param inputArgumentDiagnosticInfos diagnostic info, in case of errors.
* @param outputs output values. The array is pre-created, just fill in the
* values.
* @return true if you handle the call, which prevents any other handler
* being called.
* @throws StatusException if there are errors in the method handling. For
* example, if you set inputArgumentResults, you should throw a
* StatusException with StatusCodes.Bad_InvalidArgument
*/
@Override
public boolean onCall(ServiceContext serviceContext, NodeId objectId, UaNode object, NodeId methodId, UaMethod method, Variant[] inputArguments, StatusCode[] inputArgumentResults, DiagnosticInfo[] inputArgumentDiagnosticInfos, Variant[] outputs) throws StatusException {
boolean retval = false;
// Handle method calls
// Note that the outputs array is already allocated
logger.info("onCall: method " + methodId.toString() + ": called. InputArguments: " + Arrays.toString(inputArguments));
try {
if (endpoint == null) {
logger.warn("onCall: no Endpoint available");
} else {
SubmodelElementData data = nodeManager.getAasData(objectId);
Operation aasOper = (Operation) data.getSubmodelElement();
if (aasOper != null) {
List<OperationVariable> inputVariables = aasOper.getInputVariables();
ValueConverter.setOperationValues(inputVariables, inputArguments);
List<OperationVariable> outputVariables = endpoint.callOperation(aasOper, inputVariables, data.getSubmodel(), data.getReference());
ValueConverter.setOutputArguments(outputVariables, outputs);
retval = true;
} else {
logger.info("onCall: Property for " + objectId.toString() + " not found");
}
}
} catch (StatusException se) {
logger.error("onCall StatusException", se);
throw se;
} catch (Throwable ex) {
logger.error("onCall Exception", ex);
throw new StatusException(ex.getMessage(), StatusCodes.Bad_UnexpectedError);
}
return retval;
}
use of com.google.api.services.storagetransfer.v1.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.storagetransfer.v1.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.storagetransfer.v1.model.Operation in project terra-workspace-manager by DataBiosphere.
the class CompleteTransferOperationStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
// If cloning instructions don't say copy resource, bail
final CloningInstructions effectiveCloningInstructions = flightContext.getWorkingMap().get(ControlledResourceKeys.CLONING_INSTRUCTIONS, CloningInstructions.class);
// This step is only run for full resource clones
if (CloningInstructions.COPY_RESOURCE != effectiveCloningInstructions) {
return StepResult.getStepResultSuccess();
}
try {
final Storagetransfer storageTransferService = StorageTransferServiceUtils.createStorageTransferService();
final String transferJobName = flightContext.getWorkingMap().get(ControlledResourceKeys.STORAGE_TRANSFER_JOB_NAME, String.class);
final String controlPlaneProjectId = flightContext.getWorkingMap().get(ControlledResourceKeys.CONTROL_PLANE_PROJECT_ID, String.class);
// Job is now submitted with its schedule. We need to poll the transfer operations API
// for completion of the first transfer operation. The trick is going to be setting up a
// polling interval that's appropriate for a wide range of bucket sizes. Everything from
// millisecond
// to hours. The transfer operation won't exist until it starts.
final String operationName = getLatestOperationName(storageTransferService, transferJobName, controlPlaneProjectId);
final StepResult operationResult = getTransferOperationResult(storageTransferService, transferJobName, operationName);
if (StepStatus.STEP_RESULT_FAILURE_FATAL == operationResult.getStepStatus()) {
return operationResult;
}
} catch (IOException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
}
final ApiClonedControlledGcpGcsBucket apiBucketResult = flightContext.getWorkingMap().get(ControlledResourceKeys.CLONE_DEFINITION_RESULT, ApiClonedControlledGcpGcsBucket.class);
FlightUtils.setResponse(flightContext, apiBucketResult, HttpStatus.OK);
return StepResult.getStepResultSuccess();
}
use of com.google.api.services.storagetransfer.v1.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));
}
Aggregations