Search in sources :

Example 1 with UaNodeContext

use of org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext 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 2 with UaNodeContext

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

the class VendorServerInfoNodes method addVendorInfoJmx.

private static void addVendorInfoJmx(UaNodeContext context, UaObjectNode vendorServerInfo) {
    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    UaVariableNode usedMemory = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/UsedMemory")).setBrowseName(new QualifiedName(1, "UsedMemory")).setDisplayName(LocalizedText.english("UsedMemory")).setDataType(Identifiers.Int64).buildAndAdd();
    usedMemory.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(memoryBean.getHeapMemoryUsage().getUsed()))));
    UaVariableNode maxMemory = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/MaxMemory")).setBrowseName(new QualifiedName(1, "MaxMemory")).setDisplayName(LocalizedText.english("MaxMemory")).setDataType(Identifiers.Int64).buildAndAdd();
    maxMemory.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(memoryBean.getHeapMemoryUsage().getMax()))));
    UaVariableNode osName = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OsName")).setBrowseName(new QualifiedName(1, "OsName")).setDisplayName(LocalizedText.english("OsName")).setDataType(Identifiers.String).buildAndAdd();
    osName.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(osBean.getName()))));
    UaVariableNode osArch = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OsArch")).setBrowseName(new QualifiedName(1, "OsArch")).setDisplayName(LocalizedText.english("OsArch")).setDataType(Identifiers.String).buildAndAdd();
    osArch.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(osBean.getArch()))));
    UaVariableNode osVersion = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OsVersion")).setBrowseName(new QualifiedName(1, "OsVersion")).setDisplayName(LocalizedText.english("OsVersion")).setDataType(Identifiers.String).buildAndAdd();
    osVersion.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(osBean.getVersion()))));
    vendorServerInfo.addComponent(usedMemory);
    vendorServerInfo.addComponent(maxMemory);
    vendorServerInfo.addComponent(osName);
    vendorServerInfo.addComponent(osArch);
    vendorServerInfo.addComponent(osVersion);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) MemoryMXBean(java.lang.management.MemoryMXBean) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) Optional(java.util.Optional) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) MemoryMXBean(java.lang.management.MemoryMXBean) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean)

Example 3 with UaNodeContext

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

the class VendorServerInfoNodes method addVendorInfoPlainJava.

private static void addVendorInfoPlainJava(UaNodeContext context, UaObjectNode vendorServerInfo) {
    UaVariableNode availableProcessors = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/AvailableProcessors")).setBrowseName(new QualifiedName(1, "AvailableProcessors")).setDisplayName(LocalizedText.english("AvailableProcessors")).setDataType(Identifiers.Int32).buildAndAdd();
    availableProcessors.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(Runtime.getRuntime().availableProcessors()))));
    vendorServerInfo.addComponent(availableProcessors);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) MemoryMXBean(java.lang.management.MemoryMXBean) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) Optional(java.util.Optional) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)

Example 4 with UaNodeContext

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

the class VendorServerInfoNodes method addVendorInfoSunJmx.

private static void addVendorInfoSunJmx(UaNodeContext context, UaObjectNode vendorServerInfo) {
    OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
    if (osMxBean instanceof com.sun.management.OperatingSystemMXBean) {
        com.sun.management.OperatingSystemMXBean sunOsMxBean = (com.sun.management.OperatingSystemMXBean) osMxBean;
        UaVariableNode processCpuLoad = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/ProcessCpuLoad")).setBrowseName(new QualifiedName(1, "ProcessCpuLoad")).setDisplayName(LocalizedText.english("ProcessCpuLoad")).setDataType(Identifiers.Double).buildAndAdd();
        processCpuLoad.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(sunOsMxBean.getProcessCpuLoad() * 100d))));
        UaVariableNode systemCpuLoad = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/SystemCpuLoad")).setBrowseName(new QualifiedName(1, "SystemCpuLoad")).setDisplayName(LocalizedText.english("SystemCpuLoad")).setDataType(Identifiers.Double).buildAndAdd();
        systemCpuLoad.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(sunOsMxBean.getSystemCpuLoad() * 100d))));
        vendorServerInfo.addComponent(processCpuLoad);
        vendorServerInfo.addComponent(systemCpuLoad);
        if (sunOsMxBean instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) sunOsMxBean;
            UaVariableNode openFileDescriptors = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OpenFileDescriptors")).setBrowseName(new QualifiedName(1, "OpenFileDescriptors")).setDisplayName(LocalizedText.english("OpenFileDescriptors")).setDataType(Identifiers.Int64).buildAndAdd();
            openFileDescriptors.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(unixBean.getOpenFileDescriptorCount()))));
            UaVariableNode maxFileDescriptors = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/MaxFileDescriptors")).setBrowseName(new QualifiedName(1, "MaxFileDescriptors")).setDisplayName(LocalizedText.english("MaxFileDescriptors")).setDataType(Identifiers.Int64).buildAndAdd();
            maxFileDescriptors.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(unixBean.getMaxFileDescriptorCount()))));
            vendorServerInfo.addComponent(openFileDescriptors);
            vendorServerInfo.addComponent(maxFileDescriptors);
        }
    }
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) MemoryMXBean(java.lang.management.MemoryMXBean) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) Optional(java.util.Optional) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean)

Example 5 with UaNodeContext

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

the class AttributeDelegateChainTest method testCreate.

@Test
public void testCreate() throws Exception {
    List<String> list = new ArrayList<>();
    AttributeDelegate delegate = AttributeDelegateChain.create(new AttributeDelegate() {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("root");
            return node.getValue();
        }
    }, parent -> new DelegatingAttributeDelegate(parent) {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("child1");
            return super.getValue(context, node);
        }
    }, parent -> new DelegatingAttributeDelegate(parent) {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("child2");
            return super.getValue(context, node);
        }
    }, parent -> new DelegatingAttributeDelegate(parent) {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("child3");
            return super.getValue(context, node);
        }
    });
    UaNodeManager nodeManager = new UaNodeManager();
    UaNodeContext context = new UaNodeContext() {

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

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }

        @Override
        public NamespaceTable getNamespaceTable() {
            return new NamespaceTable();
        }
    };
    UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(context).setNodeId(NodeId.NULL_VALUE).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(QualifiedName.NULL_VALUE).setDisplayName(LocalizedText.NULL_VALUE).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    node.setValue(new DataValue(new Variant("foo")));
    DataValue value = delegate.getValue(new AttributeContext(null, null), node);
    assertEquals(value.getValue().getValue(), "foo");
    assertEquals(list.get(0), "child3");
    assertEquals(list.get(1), "child2");
    assertEquals(list.get(2), "child1");
    assertEquals(list.get(3), "root");
}
Also used : AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) ArrayList(java.util.ArrayList) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Test(org.testng.annotations.Test)

Aggregations

UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)6 UaNodeContext (org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext)6 Optional (java.util.Optional)5 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)5 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)5 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)5 UaObjectNode (org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode)4 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)4 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)4 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)4 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)3 ManagementFactory (java.lang.management.ManagementFactory)3 MemoryMXBean (java.lang.management.MemoryMXBean)3 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)3 UaNodeManager (org.eclipse.milo.opcua.sdk.server.UaNodeManager)3 AttributeFilters (org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters)3 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)3 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)3 Test (org.testng.annotations.Test)3 List (java.util.List)2