Search in sources :

Example 1 with Session

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

the class DefaultNodeManagementServiceSet method onDeleteReferences.

@Override
public void onDeleteReferences(ServiceRequest service) {
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    DeleteReferencesRequest request = (DeleteReferencesRequest) service.getRequest();
    List<DeleteReferencesItem> referencesToDelete = l(request.getReferencesToDelete());
    if (referencesToDelete.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (referencesToDelete.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DeleteReferencesContext context = new DeleteReferencesContext(server, session, new DiagnosticsContext<>());
    server.getAddressSpaceManager().deleteReferences(context, referencesToDelete);
    context.getFuture().thenAccept(results -> {
        ResponseHeader header = service.createResponseHeader();
        DeleteReferencesResponse response = new DeleteReferencesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) DeleteReferencesRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteReferencesRequest) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) DeleteReferencesItem(org.eclipse.milo.opcua.stack.core.types.structured.DeleteReferencesItem) DeleteReferencesContext(org.eclipse.milo.opcua.sdk.server.api.services.NodeManagementServices.DeleteReferencesContext) DeleteReferencesResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteReferencesResponse) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 2 with Session

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

the class DefaultNodeManagementServiceSet method onAddReferences.

@Override
public void onAddReferences(ServiceRequest service) {
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    AddReferencesRequest request = (AddReferencesRequest) service.getRequest();
    List<AddReferencesItem> referencesToAdd = l(request.getReferencesToAdd());
    if (referencesToAdd.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (referencesToAdd.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    AddReferencesContext context = new AddReferencesContext(server, session, new DiagnosticsContext<>());
    server.getAddressSpaceManager().addReferences(context, referencesToAdd);
    context.getFuture().thenAccept(results -> {
        ResponseHeader header = service.createResponseHeader();
        AddReferencesResponse response = new AddReferencesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) AddReferencesItem(org.eclipse.milo.opcua.stack.core.types.structured.AddReferencesItem) AddReferencesContext(org.eclipse.milo.opcua.sdk.server.api.services.NodeManagementServices.AddReferencesContext) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) AddReferencesResponse(org.eclipse.milo.opcua.stack.core.types.structured.AddReferencesResponse) AddReferencesRequest(org.eclipse.milo.opcua.stack.core.types.structured.AddReferencesRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 3 with Session

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

the class DefaultSubscriptionServiceSet method onTransferSubscriptions.

@Override
public void onTransferSubscriptions(ServiceRequest service) throws UaException {
    TransferSubscriptionsRequest request = (TransferSubscriptionsRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<UInteger> subscriptionIds = l(request.getSubscriptionIds());
    if (subscriptionIds.isEmpty()) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }
    List<TransferResult> results = Lists.newArrayList();
    for (UInteger subscriptionId : subscriptionIds) {
        Subscription subscription = server.getSubscriptions().get(subscriptionId);
        if (subscription == null) {
            results.add(new TransferResult(new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid), new UInteger[0]));
        } else {
            Session otherSession = subscription.getSession();
            if (!sessionsHaveSameUser(session, otherSession)) {
                results.add(new TransferResult(new StatusCode(StatusCodes.Bad_UserAccessDenied), new UInteger[0]));
            } else {
                UInteger[] availableSequenceNumbers;
                synchronized (subscription) {
                    otherSession.getSubscriptionManager().sendStatusChangeNotification(subscription, new StatusCode(StatusCodes.Good_SubscriptionTransferred));
                    otherSession.getSubscriptionManager().removeSubscription(subscriptionId);
                    subscription.setSubscriptionManager(session.getSubscriptionManager());
                    subscriptionManager.addSubscription(subscription);
                    subscription.getMonitoredItems().values().forEach(item -> item.setSession(session));
                    availableSequenceNumbers = subscription.getAvailableSequenceNumbers();
                    if (request.getSendInitialValues()) {
                        subscription.getMonitoredItems().values().stream().filter(item -> item instanceof MonitoredDataItem).map(item -> (MonitoredDataItem) item).forEach(MonitoredDataItem::maybeSendLastValue);
                    }
                }
                subscription.getSubscriptionDiagnostics().getTransferRequestCount().increment();
                ApplicationDescription toClient = session.getClientDescription();
                ApplicationDescription fromClient = otherSession.getClientDescription();
                if (Objects.equals(toClient, fromClient)) {
                    subscription.getSubscriptionDiagnostics().getTransferredToSameClientCount().increment();
                } else {
                    subscription.getSubscriptionDiagnostics().getTransferredToAltClientCount().increment();
                }
                results.add(new TransferResult(StatusCode.GOOD, availableSequenceNumbers));
            }
        }
    }
    TransferSubscriptionsResponse response = new TransferSubscriptionsResponse(service.createResponseHeader(), a(results, TransferResult.class), new DiagnosticInfo[0]);
    service.setResponse(response);
}
Also used : StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) Subscription(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription) TransferResult(org.eclipse.milo.opcua.stack.core.types.structured.TransferResult) TransferSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsResponse) Session(org.eclipse.milo.opcua.sdk.server.Session) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) Objects(java.util.Objects) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) List(java.util.List) Lists(com.google.common.collect.Lists) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ApplicationDescription(org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription) UaException(org.eclipse.milo.opcua.stack.core.UaException) SubscriptionManager(org.eclipse.milo.opcua.sdk.server.subscriptions.SubscriptionManager) SubscriptionServiceSet(org.eclipse.milo.opcua.stack.server.services.SubscriptionServiceSet) TransferSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsRequest) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) TransferSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsRequest) UaException(org.eclipse.milo.opcua.stack.core.UaException) TransferResult(org.eclipse.milo.opcua.stack.core.types.structured.TransferResult) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ApplicationDescription(org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) TransferSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsResponse) Subscription(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 4 with Session

use of org.eclipse.milo.opcua.sdk.server.Session 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 5 with Session

use of org.eclipse.milo.opcua.sdk.server.Session 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)

Aggregations

Session (org.eclipse.milo.opcua.sdk.server.Session)17 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)16 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)13 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)8 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)7 DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)6 UaException (org.eclipse.milo.opcua.stack.core.UaException)5 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)4 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)4 List (java.util.List)3 Lists (com.google.common.collect.Lists)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)2 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)2 UaSerializationException (org.eclipse.milo.opcua.stack.core.UaSerializationException)2 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)2 CallMethodRequest (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest)2 CallMethodResult (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult)2 ConversionUtil.a (org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a)2 ConversionUtil.l (org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l)2