Search in sources :

Example 21 with OpcUaServer

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

the class DefaultViewServiceSet method onBrowse.

@Override
public void onBrowse(ServiceRequest service) {
    browseCounter.record(service);
    BrowseRequest request = (BrowseRequest) service.getRequest();
    DiagnosticsContext<BrowseDescription> diagnosticsContext = new DiagnosticsContext<>();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<BrowseDescription> nodesToBrowse = l(request.getNodesToBrowse());
    if (nodesToBrowse.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToBrowse.size() > server.getConfig().getLimits().getMaxNodesPerBrowse().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    Stream<CompletableFuture<BrowseResult>> futures = nodesToBrowse.stream().map(browseDescription -> browseHelper.browse(() -> Optional.of(session), server, request.getView(), request.getRequestedMaxReferencesPerNode(), browseDescription));
    FutureUtils.sequence(futures).thenAccept(results -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToBrowse);
        BrowseResponse response = new BrowseResponse(header, a(results, BrowseResult.class), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : BrowseResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest) CompletableFuture(java.util.concurrent.CompletableFuture) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 22 with OpcUaServer

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

the class BrowsePathsHelper method onTranslateBrowsePaths.

public void onTranslateBrowsePaths(ServiceRequest service) {
    TranslateBrowsePathsToNodeIdsRequest request = (TranslateBrowsePathsToNodeIdsRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    List<BrowsePath> browsePaths = l(request.getBrowsePaths());
    if (browsePaths.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (browsePaths.size() > server.getConfig().getLimits().getMaxNodesPerTranslateBrowsePathsToNodeIds().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    List<CompletableFuture<BrowsePathResult>> futures = newArrayListWithCapacity(browsePaths.size());
    for (BrowsePath browsePath : browsePaths) {
        futures.add(translate(browsePath));
    }
    sequence(futures).thenAcceptAsync(results -> {
        ResponseHeader header = service.createResponseHeader();
        TranslateBrowsePathsToNodeIdsResponse response = new TranslateBrowsePathsToNodeIdsResponse(header, a(results, BrowsePathResult.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    }, server.getExecutorService());
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) CompletableFuture(java.util.concurrent.CompletableFuture) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) TranslateBrowsePathsToNodeIdsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsRequest) TranslateBrowsePathsToNodeIdsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath)

Example 23 with OpcUaServer

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

the class DefaultNodeManagementServiceSet method onAddNodes.

@Override
public void onAddNodes(ServiceRequest service) {
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    AddNodesRequest request = (AddNodesRequest) service.getRequest();
    List<AddNodesItem> nodesToAdd = l(request.getNodesToAdd());
    if (nodesToAdd.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToAdd.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    AddNodesContext context = new AddNodesContext(server, session, new DiagnosticsContext<>());
    server.getAddressSpaceManager().addNodes(context, nodesToAdd);
    context.getFuture().thenAccept(results -> {
        ResponseHeader header = service.createResponseHeader();
        AddNodesResponse response = new AddNodesResponse(header, a(results, AddNodesResult.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    });
}
Also used : AddNodesRequest(org.eclipse.milo.opcua.stack.core.types.structured.AddNodesRequest) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) AddNodesResponse(org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResponse) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) AddNodesResult(org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResult) AddNodesContext(org.eclipse.milo.opcua.sdk.server.api.services.NodeManagementServices.AddNodesContext) AddNodesItem(org.eclipse.milo.opcua.stack.core.types.structured.AddNodesItem) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 24 with OpcUaServer

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

the class DefaultNodeManagementServiceSet method onDeleteNodes.

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

Aggregations

OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)24 Session (org.eclipse.milo.opcua.sdk.server.Session)15 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)13 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)7 DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)6 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)6 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)6 UaException (org.eclipse.milo.opcua.stack.core.UaException)5 List (java.util.List)4 UaNodeManager (org.eclipse.milo.opcua.sdk.server.UaNodeManager)4 Optional (java.util.Optional)3 AddressSpaceManager (org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)3 NodeManager (org.eclipse.milo.opcua.sdk.server.api.NodeManager)3 NodeLoader (org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader)3 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)3 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)3 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)3 BeforeTest (org.testng.annotations.BeforeTest)3 Test (org.testng.annotations.Test)3 File (java.io.File)2