Search in sources :

Example 1 with InvokeOperationSyncRequest

use of de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpoint method callOperation.

/**
 * Calls the desired operation in the service.
 *
 * @param operation The desired operation
 * @param inputVariables The input arguments
 * @param submodel The corresponding submodel
 * @param refElement The reference to the SubmodelElement
 * @return The OutputArguments The output arguments returned from the operation call
 * @throws StatusException If the operation fails
 */
public List<OperationVariable> callOperation(Operation operation, List<OperationVariable> inputVariables, Submodel submodel, Reference refElement) throws StatusException {
    List<OperationVariable> outputArguments;
    try {
        InvokeOperationSyncRequest request = new InvokeOperationSyncRequest();
        List<Key> path = new ArrayList<>();
        path.addAll(refElement.getKeys());
        request.setId(submodel.getIdentification());
        request.setPath(path);
        request.setInputArguments(inputVariables);
        request.setContent(Content.Normal);
        requestCounter++;
        request.setRequestId(Integer.toString(requestCounter));
        // execute method
        InvokeOperationSyncResponse response = (InvokeOperationSyncResponse) service.execute(request);
        if (isSuccess(response.getStatusCode())) {
            logger.info("callOperation: Operation " + operation.getIdShort() + " executed successfully");
        } else if (response.getStatusCode() == StatusCode.ClientMethodNotAllowed) {
            logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
            throw new StatusException(StatusCodes.Bad_NotExecutable);
        } else {
            logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
            throw new StatusException(StatusCodes.Bad_UnexpectedError);
        }
        outputArguments = response.getPayload().getOutputArguments();
    } catch (Exception ex) {
        logger.error("callOperation error", ex);
        throw ex;
    }
    return outputArguments;
}
Also used : StatusException(com.prosysopc.ua.StatusException) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) InvokeOperationSyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest) ArrayList(java.util.ArrayList) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Key(io.adminshell.aas.v3.model.Key) StatusException(com.prosysopc.ua.StatusException)

Example 2 with InvokeOperationSyncRequest

use of de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest 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);
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) InvokeOperationSyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) DefaultOperation(io.adminshell.aas.v3.model.impl.DefaultOperation) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Test(org.junit.Test)

Aggregations

InvokeOperationSyncResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse)2 InvokeOperationSyncRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest)2 StatusException (com.prosysopc.ua.StatusException)1 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)1 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)1 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)1 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)1 Persistence (de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence)1 RequestHandlerManager (de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager)1 Key (io.adminshell.aas.v3.model.Key)1 Operation (io.adminshell.aas.v3.model.Operation)1 OperationVariable (io.adminshell.aas.v3.model.OperationVariable)1 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)1 DefaultOperation (io.adminshell.aas.v3.model.impl.DefaultOperation)1 DefaultOperationVariable (io.adminshell.aas.v3.model.impl.DefaultOperationVariable)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1