Search in sources :

Example 11 with Operation

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;
}
Also used : StatusException(com.prosysopc.ua.StatusException) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) Operation(io.adminshell.aas.v3.model.Operation) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 12 with Operation

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;
    }
}
Also used : AasServiceMethodManagerListener(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.listener.AasServiceMethodManagerListener) Operation(io.adminshell.aas.v3.model.Operation) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) AASIdentifierKeyValuePairType(opc.i4aas.AASIdentifierKeyValuePairType) ValueChangeEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) AASAssetInformationType(opc.i4aas.AASAssetInformationType) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) AASFileType(opc.i4aas.AASFileType) AASAssetType(opc.i4aas.AASAssetType) SubscriptionInfo(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo) Property(io.adminshell.aas.v3.model.Property) ServiceResultException(com.prosysopc.ua.stack.common.ServiceResultException) AssetKind(io.adminshell.aas.v3.model.AssetKind) Map(java.util.Map) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) RelationshipElement(io.adminshell.aas.v3.model.RelationshipElement) DecimalValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DecimalValue) AASIdentifiableType(opc.i4aas.AASIdentifiableType) AccessLevelType(com.prosysopc.ua.stack.core.AccessLevelType) UnsignedInteger(com.prosysopc.ua.stack.builtintypes.UnsignedInteger) Reference(io.adminshell.aas.v3.model.Reference) AASEventType(opc.i4aas.AASEventType) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) AASCapabilityType(opc.i4aas.AASCapabilityType) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) AASIriConceptDescriptionType(opc.i4aas.AASIriConceptDescriptionType) UaServer(com.prosysopc.ua.server.UaServer) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue) AASRelationshipElementType(opc.i4aas.AASRelationshipElementType) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) TypeDefinitionBasedNodeBuilderConfiguration(com.prosysopc.ua.server.instantiation.TypeDefinitionBasedNodeBuilderConfiguration) TypedValueFactory(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValueFactory) Range(io.adminshell.aas.v3.model.Range) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) BlobValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.BlobValue) AASOperationType(opc.i4aas.AASOperationType) AASRangeType(opc.i4aas.AASRangeType) ReferenceElement(io.adminshell.aas.v3.model.ReferenceElement) Qualifier(io.adminshell.aas.v3.model.Qualifier) AASPropertyType(opc.i4aas.AASPropertyType) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) StatusException(com.prosysopc.ua.StatusException) DictionaryEntryType(com.prosysopc.ua.types.opcua.DictionaryEntryType) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) AASReferenceType(opc.i4aas.AASReferenceType) AssetInformation(io.adminshell.aas.v3.model.AssetInformation) ArrayList(java.util.ArrayList) FolderTypeNode(com.prosysopc.ua.types.opcua.server.FolderTypeNode) AASValueTypeDataType(opc.i4aas.AASValueTypeDataType) PlainMethod(com.prosysopc.ua.server.nodes.PlainMethod) AASSubmodelType(opc.i4aas.AASSubmodelType) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) AASMultiLanguagePropertyType(opc.i4aas.AASMultiLanguagePropertyType) AASReferenceElementType(opc.i4aas.AASReferenceElementType) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) BasicEvent(io.adminshell.aas.v3.model.BasicEvent) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) UaNode(com.prosysopc.ua.nodes.UaNode) AASKeyDataType(opc.i4aas.AASKeyDataType) EmbeddedDataSpecification(io.adminshell.aas.v3.model.EmbeddedDataSpecification) PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) AASSubmodelElementList(opc.i4aas.AASSubmodelElementList) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Constraint(io.adminshell.aas.v3.model.Constraint) FileTypeNode(com.prosysopc.ua.types.opcua.server.FileTypeNode) Submodel(io.adminshell.aas.v3.model.Submodel) AASAssetAdministrationShellTypeNode(opc.i4aas.server.AASAssetAdministrationShellTypeNode) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) LoggerFactory(org.slf4j.LoggerFactory) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) AASBlobType(opc.i4aas.AASBlobType) CallableListener(com.prosysopc.ua.server.CallableListener) Locale(java.util.Locale) AASAssetAdministrationShellType(opc.i4aas.AASAssetAdministrationShellType) NodeManagerUaNode(com.prosysopc.ua.server.NodeManagerUaNode) AASReferenceTypeNode(opc.i4aas.server.AASReferenceTypeNode) FileValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.FileValue) Capability(io.adminshell.aas.v3.model.Capability) AASEnvironmentType(opc.i4aas.AASEnvironmentType) Collection(java.util.Collection) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DataElement(io.adminshell.aas.v3.model.DataElement) AasUtils(io.adminshell.aas.v3.dataformat.core.util.AasUtils) ServiceException(com.prosysopc.ua.ServiceException) AASQualifierType(opc.i4aas.AASQualifierType) Key(io.adminshell.aas.v3.model.Key) List(java.util.List) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) Entity(io.adminshell.aas.v3.model.Entity) AdministrativeInformation(io.adminshell.aas.v3.model.AdministrativeInformation) UaNodeFactoryException(com.prosysopc.ua.nodes.UaNodeFactoryException) AASSubmodelElementType(opc.i4aas.AASSubmodelElementType) BaseObjectType(com.prosysopc.ua.types.opcua.BaseObjectType) UaObject(com.prosysopc.ua.nodes.UaObject) ValueRanks(com.prosysopc.ua.ValueRanks) HashMap(java.util.HashMap) IntegerValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.IntegerValue) Identifier(io.adminshell.aas.v3.model.Identifier) AASQualifierList(opc.i4aas.AASQualifierList) AASIrdiConceptDescriptionType(opc.i4aas.AASIrdiConceptDescriptionType) RangeValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue) Referable(io.adminshell.aas.v3.model.Referable) File(io.adminshell.aas.v3.model.File) UaBrowsePath(com.prosysopc.ua.UaBrowsePath) LangString(io.adminshell.aas.v3.model.LangString) AASSubmodelElementCollectionType(opc.i4aas.AASSubmodelElementCollectionType) AASEntityType(opc.i4aas.AASEntityType) Identifiers(com.prosysopc.ua.stack.core.Identifiers) AASReferenceList(opc.i4aas.AASReferenceList) Logger(org.slf4j.Logger) AASOrderedSubmodelElementCollectionType(opc.i4aas.AASOrderedSubmodelElementCollectionType) Event(io.adminshell.aas.v3.model.Event) EntityValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue) AASCustomConceptDescriptionType(opc.i4aas.AASCustomConceptDescriptionType) MethodManagerUaNode(com.prosysopc.ua.server.MethodManagerUaNode) Asset(io.adminshell.aas.v3.model.Asset) Blob(io.adminshell.aas.v3.model.Blob) AddressSpaceException(com.prosysopc.ua.client.AddressSpaceException) AASAnnotatedRelationshipElementType(opc.i4aas.AASAnnotatedRelationshipElementType) AASIdentifierKeyValuePairList(opc.i4aas.AASIdentifierKeyValuePairList) AASAdministrativeInformationType(opc.i4aas.AASAdministrativeInformationType) Argument(com.prosysopc.ua.stack.core.Argument) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue) ArrayList(java.util.ArrayList) AASKeyDataType(opc.i4aas.AASKeyDataType)

Example 13 with Operation

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();
    }
}
Also used : Operation(com.google.api.services.storagetransfer.v1.model.Operation) StepResult(bio.terra.stairway.StepResult) StorageTransferServiceTimeoutException(bio.terra.workspace.service.resource.controlled.exception.StorageTransferServiceTimeoutException)

Example 14 with Operation

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();
}
Also used : CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) ApiClonedControlledGcpGcsBucket(bio.terra.workspace.generated.model.ApiClonedControlledGcpGcsBucket) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult) Storagetransfer(com.google.api.services.storagetransfer.v1.Storagetransfer)

Example 15 with Operation

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));
}
Also used : Operation(com.google.api.services.serviceusage.v1.model.Operation) BatchEnableServicesRequest(com.google.api.services.serviceusage.v1.model.BatchEnableServicesRequest)

Aggregations

IOException (java.io.IOException)15 Operation (io.adminshell.aas.v3.model.Operation)8 StepResult (bio.terra.stairway.StepResult)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)6 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 Operation (com.google.api.services.notebooks.v1.model.Operation)5 Reference (io.adminshell.aas.v3.model.Reference)5 Operation (com.google.api.services.appengine.v1.model.Operation)4 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)4 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)4 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)4 List (java.util.List)4 Test (org.junit.Test)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 Storagetransfer (com.google.api.services.storagetransfer.v1.Storagetransfer)3 SystemException (bio.terra.cli.exception.SystemException)2 RetryException (bio.terra.stairway.exception.RetryException)2