Search in sources :

Example 1 with OpcUaServer

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

the class UaNodeTest method testCreateDeleteComplexInstance.

@Test
public void testCreateDeleteComplexInstance() throws UaException {
    NodeId nodeId = new NodeId(1, "TestAnalog");
    UaNodeManager nodeManager = new UaNodeManager();
    server.getAddressSpaceManager().register(nodeManager);
    assertFalse(nodeManager.containsNode(nodeId));
    assertEquals(0, nodeManager.getReferences(nodeId).size());
    NodeFactory nodeFactory = new NodeFactory(new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    });
    AnalogItemTypeNode analogItem = (AnalogItemTypeNode) nodeFactory.createNode(nodeId, Identifiers.AnalogItemType, new NodeFactory.InstantiationCallback() {

        @Override
        public boolean includeOptionalNode(NodeId typeDefinitionId, QualifiedName browseName) {
            return true;
        }
    });
    assertTrue(nodeManager.containsNode(nodeId));
    assertTrue(nodeManager.getReferences(nodeId).size() > 0);
    analogItem.delete();
    assertFalse(nodeManager.containsNode(nodeId));
    assertEquals(0, nodeManager.getReferences(nodeId).size());
}
Also used : NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) AnalogItemTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NodeFactory(org.eclipse.milo.opcua.sdk.server.nodes.factories.NodeFactory) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with OpcUaServer

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

the class InstanceDeclarationHierarchyTest method test.

@Test
public void test() throws Exception {
    NamespaceTable namespaceTable = new NamespaceTable();
    UaNodeManager nodeManager = new UaNodeManager();
    AddressSpaceManager addressSpaceManager = Mockito.mock(AddressSpaceManager.class);
    Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(NodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0)));
    Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(ExpandedNodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0), namespaceTable));
    Mockito.when(addressSpaceManager.getManagedReferences(Mockito.any(NodeId.class))).then((Answer<List<Reference>>) invocationOnMock -> nodeManager.getReferences(invocationOnMock.getArgument(0)));
    OpcUaServer server = Mockito.mock(OpcUaServer.class);
    Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
    Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
    UaNodeContext context = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    new NodeLoader(context, nodeManager).loadNodes();
    InstanceDeclarationHierarchy idh = InstanceDeclarationHierarchy.create(addressSpaceManager, namespaceTable, Identifiers.AnalogItemType);
    System.out.println(idh);
    assertNotNull(idh);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Optional(java.util.Optional) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) Reference(org.eclipse.milo.opcua.sdk.core.Reference) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Optional(java.util.Optional) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) List(java.util.List) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) Test(org.testng.annotations.Test)

Example 3 with OpcUaServer

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

the class UaNodeTest method setup.

@BeforeTest
public void setup() throws Exception {
    server = Mockito.mock(OpcUaServer.class);
    AddressSpaceManager addressSpaceManager = new AddressSpaceManager(server);
    NamespaceTable namespaceTable = new NamespaceTable();
    ObjectTypeManager objectTypeManager = new ObjectTypeManager();
    VariableTypeManager variableTypeManager = new VariableTypeManager();
    Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
    Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
    Mockito.when(server.getObjectTypeManager()).thenReturn(objectTypeManager);
    Mockito.when(server.getVariableTypeManager()).thenReturn(variableTypeManager);
    UaNodeManager nodeManager = new UaNodeManager();
    addressSpaceManager.register(nodeManager);
    UaNodeContext nodeContext = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    new NodeLoader(nodeContext, nodeManager).loadNodes();
    ObjectTypeInitializer.initialize(server.getNamespaceTable(), objectTypeManager);
    VariableTypeInitializer.initialize(server.getNamespaceTable(), variableTypeManager);
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with OpcUaServer

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

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

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