Search in sources :

Example 1 with DiagnosticsContext

use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.

the class DefaultAttributeServiceSet method onRead.

@Override
public void onRead(ServiceRequest service) {
    ReadRequest request = (ReadRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<ReadValueId> nodesToRead = l(request.getNodesToRead());
    if (nodesToRead.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToRead.size() > server.getConfig().getLimits().getMaxNodesPerRead().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    if (request.getMaxAge() < 0d) {
        service.setServiceFault(StatusCodes.Bad_MaxAgeInvalid);
        return;
    }
    if (request.getTimestampsToReturn() == null) {
        service.setServiceFault(StatusCodes.Bad_TimestampsToReturnInvalid);
        return;
    }
    DiagnosticsContext<ReadValueId> diagnosticsContext = new DiagnosticsContext<>();
    ReadContext context = new ReadContext(server, session, diagnosticsContext);
    server.getAddressSpaceManager().read(context, request.getMaxAge(), request.getTimestampsToReturn(), nodesToRead);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToRead);
        ReadResponse response = new ReadResponse(header, values.toArray(new DataValue[0]), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 2 with DiagnosticsContext

use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.

the class DefaultAttributeServiceSet method onWrite.

@Override
public void onWrite(ServiceRequest service) {
    WriteRequest request = (WriteRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<WriteValue> nodesToWrite = l(request.getNodesToWrite());
    if (nodesToWrite.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToWrite.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<WriteValue> diagnosticsContext = new DiagnosticsContext<>();
    WriteContext context = new WriteContext(server, session, new DiagnosticsContext<>());
    server.getAddressSpaceManager().write(context, nodesToWrite);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToWrite);
        WriteResponse response = new WriteResponse(header, values.toArray(new StatusCode[0]), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) WriteRequest(org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) WriteContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 3 with DiagnosticsContext

use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.

the class DefaultAttributeHistoryServiceSet method onHistoryUpdate.

@Override
public void onHistoryUpdate(ServiceRequest service) {
    historyUpdateMetric.record(service);
    HistoryUpdateRequest request = (HistoryUpdateRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<HistoryUpdateDetails> historyUpdateDetailsList = l(request.getHistoryUpdateDetails()).stream().map(e -> (HistoryUpdateDetails) e.decode(server.getSerializationContext())).collect(Collectors.toList());
    if (historyUpdateDetailsList.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (historyUpdateDetailsList.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<HistoryUpdateDetails> diagnosticsContext = new DiagnosticsContext<>();
    HistoryUpdateContext context = new HistoryUpdateContext(server, session, diagnosticsContext);
    server.getAddressSpaceManager().historyUpdate(context, historyUpdateDetailsList);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(historyUpdateDetailsList);
        HistoryUpdateResponse response = new HistoryUpdateResponse(header, a(values, HistoryUpdateResult.class), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) HistoryReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest) HistoryUpdateResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResponse) HistoryUpdateDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateDetails) Collectors(java.util.stream.Collectors) Session(org.eclipse.milo.opcua.sdk.server.Session) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) HistoryReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) HistoryUpdateContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) List(java.util.List) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) HistoryReadResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) HistoryUpdateRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateRequest) HistoryUpdateResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResult) AttributeHistoryServiceSet(org.eclipse.milo.opcua.stack.server.services.AttributeHistoryServiceSet) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryReadDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse) HistoryReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryUpdateRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateRequest) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) HistoryUpdateResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResponse) HistoryUpdateResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResult) HistoryUpdateContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryUpdateDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateDetails) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 4 with DiagnosticsContext

use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.

the class DefaultAttributeHistoryServiceSet method onHistoryRead.

@Override
public void onHistoryRead(ServiceRequest service) {
    historyReadMetric.record(service);
    HistoryReadRequest request = (HistoryReadRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<HistoryReadValueId> nodesToRead = l(request.getNodesToRead());
    if (nodesToRead.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToRead.size() > server.getConfig().getLimits().getMaxNodesPerRead().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    if (request.getTimestampsToReturn() == null) {
        service.setServiceFault(StatusCodes.Bad_TimestampsToReturnInvalid);
        return;
    }
    DiagnosticsContext<HistoryReadValueId> diagnosticsContext = new DiagnosticsContext<>();
    HistoryReadContext context = new HistoryReadContext(server, session, diagnosticsContext);
    HistoryReadDetails details = (HistoryReadDetails) request.getHistoryReadDetails().decode(server.getSerializationContext());
    server.getAddressSpaceManager().historyRead(context, details, request.getTimestampsToReturn(), nodesToRead);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToRead);
        HistoryReadResponse response = new HistoryReadResponse(header, a(values, HistoryReadResult.class), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) HistoryReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) HistoryReadDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails) HistoryReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext) HistoryReadResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 5 with DiagnosticsContext

use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.

the class DefaultMethodServiceSet method onCall.

@Override
public void onCall(ServiceRequest service) {
    callCounter.record(service);
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    CallRequest request = (CallRequest) service.getRequest();
    List<CallMethodRequest> methodsToCall = l(request.getMethodsToCall());
    if (methodsToCall.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (methodsToCall.size() > server.getConfig().getLimits().getMaxNodesPerMethodCall().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<CallMethodRequest> diagnosticsContext = new DiagnosticsContext<>();
    CallContext context = new CallContext(server, session, diagnosticsContext);
    server.getAddressSpaceManager().call(context, methodsToCall);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        CallResponse response = new CallResponse(header, a(values, CallMethodResult.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) CallRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallRequest) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) CallContext(org.eclipse.milo.opcua.sdk.server.api.services.MethodServices.CallContext) CallResponse(org.eclipse.milo.opcua.stack.core.types.structured.CallResponse) Session(org.eclipse.milo.opcua.sdk.server.Session)

Aggregations

DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)6 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)6 Session (org.eclipse.milo.opcua.sdk.server.Session)6 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)6 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)5 HistoryReadContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext)2 HistoryReadDetails (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails)2 HistoryReadRequest (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest)2 HistoryReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse)2 HistoryReadResult (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult)2 HistoryReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId)2 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 HistoryUpdateContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext)1 ReadContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext)1 WriteContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext)1 CallContext (org.eclipse.milo.opcua.sdk.server.api.services.MethodServices.CallContext)1 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)1 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)1