Search in sources :

Example 11 with Operation

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;
    }
}
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 12 with Operation

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();
    }
}
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 13 with Operation

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

Example 14 with Operation

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));
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ListServicesResponse(com.google.api.services.serviceusage.v1.model.ListServicesResponse) Operation(com.google.api.services.serviceusage.v1.model.Operation) BatchEnableServicesRequest(com.google.api.services.serviceusage.v1.model.BatchEnableServicesRequest) Test(org.junit.jupiter.api.Test)

Example 15 with Operation

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);
    }
}
Also used : SystemException(bio.terra.cli.exception.SystemException) Operation(com.google.api.services.notebooks.v1.model.Operation) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)13 Operation (io.adminshell.aas.v3.model.Operation)8 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)5 Operation (com.google.api.services.notebooks.v1.model.Operation)5 Reference (io.adminshell.aas.v3.model.Reference)5 StepResult (bio.terra.stairway.StepResult)4 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 Status (com.google.api.services.appengine.v1.model.Status)3 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)3 SystemException (bio.terra.cli.exception.SystemException)2