Search in sources :

Example 1 with InvokeOperationSyncResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse in project FAAAST-Service by FraunhoferIOSB.

the class InvokeOperationSyncRequestHandler method process.

@Override
public InvokeOperationSyncResponse process(InvokeOperationSyncRequest request) {
    Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
    InvokeOperationSyncResponse response = new InvokeOperationSyncResponse();
    try {
        // Check if submodelelement does exist
        Operation operation = (Operation) persistence.get(reference, new OutputModifier());
        publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
        OperationResult operationResult = executeOperationSync(reference, request);
        response.setPayload(operationResult);
        response.setStatusCode(StatusCode.Success);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    publishOperationFinishEventMessage(reference, toValues(response.getPayload().getOutputArguments()), toValues(response.getPayload().getInoutputArguments()));
    return response;
}
Also used : OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Reference(io.adminshell.aas.v3.model.Reference) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) TimeoutException(java.util.concurrent.TimeoutException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 2 with InvokeOperationSyncResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse 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 3 with InvokeOperationSyncResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse 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)3 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)2 InvokeOperationSyncRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest)2 Operation (io.adminshell.aas.v3.model.Operation)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 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)1 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)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 OperationVariable (io.adminshell.aas.v3.model.OperationVariable)1 Reference (io.adminshell.aas.v3.model.Reference)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 TimeoutException (java.util.concurrent.TimeoutException)1