Search in sources :

Example 16 with OpcUaServer

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

the class AttributeWriterTest method testWriteConversion.

private void testWriteConversion(DataValue value, NodeId dataType, Consumer<UaVariableNode> nodeCustomizer) throws UaException {
    final UaVariableNode varNode = createMockNode("test", node -> {
        UByte accessLevel = AccessLevel.toValue(AccessLevel.READ_WRITE);
        node.setAccessLevel(accessLevel);
        node.setUserAccessLevel(accessLevel);
        if (nodeCustomizer != null) {
            nodeCustomizer.accept(node);
        }
    });
    if (dataType != null) {
        varNode.setDataType(dataType);
    }
    OpcUaServer server = Mockito.mock(OpcUaServer.class);
    AttributeWriter.writeAttribute(new AttributeContext(server, null), varNode, AttributeId.Value, value, null);
}
Also used : UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext)

Example 17 with OpcUaServer

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

Example 18 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 19 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)

Example 20 with OpcUaServer

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

the class DefaultViewServiceSet method onUnregisterNodes.

@Override
public void onUnregisterNodes(ServiceRequest service) throws UaException {
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    UnregisterNodesRequest request = (UnregisterNodesRequest) service.getRequest();
    List<NodeId> nodeIds = l(request.getNodesToUnregister());
    if (nodeIds.isEmpty()) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }
    if (nodeIds.size() > server.getConfig().getLimits().getMaxNodesPerRegisterNodes().intValue()) {
        throw new UaException(StatusCodes.Bad_TooManyOperations);
    }
    UnregisterNodesContext context = new UnregisterNodesContext(server, session);
    server.getAddressSpaceManager().unregisterNodes(context, nodeIds);
    context.getFuture().thenAccept(registeredNodeIds -> {
        ResponseHeader header = service.createResponseHeader();
        UnregisterNodesResponse response = new UnregisterNodesResponse(header);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) UnregisterNodesResponse(org.eclipse.milo.opcua.stack.core.types.structured.UnregisterNodesResponse) UaException(org.eclipse.milo.opcua.stack.core.UaException) UnregisterNodesRequest(org.eclipse.milo.opcua.stack.core.types.structured.UnregisterNodesRequest) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Session(org.eclipse.milo.opcua.sdk.server.Session) UnregisterNodesContext(org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.UnregisterNodesContext)

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