Search in sources :

Example 6 with ReferenceDescription

use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.

the class DataTypeDictionaryReader method readDataTypeDictionaries.

public CompletableFuture<List<DataTypeDictionary<?>>> readDataTypeDictionaries() {
    CompletableFuture<List<ReferenceDescription>> browseFuture = browseNode(new BrowseDescription(Identifiers.OPCBinarySchema_TypeSystem, BrowseDirection.Forward, Identifiers.HasComponent, false, uint(NodeClass.Variable.getValue()), uint(BrowseResultMask.All.getValue())));
    CompletableFuture<Stream<NodeId>> dictionaryNodeIds = browseFuture.thenApply(references -> references.stream().filter(r -> r.getTypeDefinition().equalTo(Identifiers.DataTypeDictionaryType)).flatMap(r -> opt2stream(r.getNodeId().toNodeId(stackClient.getNamespaceTable()))));
    return dictionaryNodeIds.thenApply(nodeIds -> nodeIds.map(this::readDataTypeDictionary).collect(Collectors.toList())).thenCompose(FutureUtils::sequence).thenApply(list -> list.stream().filter(Objects::nonNull).collect(Collectors.toList()));
}
Also used : BrowseNextRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseNextRequest) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) LoggerFactory(org.slf4j.LoggerFactory) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) DictionaryDescription(org.eclipse.milo.opcua.binaryschema.parser.DictionaryDescription) Unpooled(io.netty.buffer.Unpooled) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ByteArrayInputStream(java.io.ByteArrayInputStream) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) Map(java.util.Map) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) BsdParser(org.eclipse.milo.opcua.binaryschema.parser.BsdParser) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) CodecDescription(org.eclipse.milo.opcua.binaryschema.parser.CodecDescription) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) Objects(java.util.Objects) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) BrowseResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse) OpcUaSession(org.eclipse.milo.opcua.sdk.client.OpcUaSession) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest) DataTypeDictionary(org.eclipse.milo.opcua.stack.core.types.DataTypeDictionary) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaBinaryDataTypeDictionary(org.eclipse.milo.opcua.stack.core.types.OpcUaBinaryDataTypeDictionary) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) Lists(com.google.common.collect.Lists) ByteBuf(io.netty.buffer.ByteBuf) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) BrowseNextResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseNextResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) IOException(java.io.IOException) Ints(com.google.common.primitives.Ints) ViewDescription(org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) InputStream(java.io.InputStream) Namespaces(org.eclipse.milo.opcua.stack.core.util.Namespaces) Objects(java.util.Objects) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Example 7 with ReferenceDescription

use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.

the class UaNodeTest method browse.

@Test
public void browse() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaNode serverNode = addressSpace.getNode(Identifiers.Server);
    BrowseOptions browseOptions = BrowseOptions.builder().setReferenceType(Identifiers.HasProperty).build();
    List<ReferenceDescription> references = serverNode.browse(browseOptions);
    assertEquals(5, references.size());
    assertTrue(references.stream().anyMatch(n -> n.getNodeId().equalTo(Identifiers.Server_ServerArray)));
    assertTrue(references.stream().anyMatch(n -> n.getNodeId().equalTo(Identifiers.Server_NamespaceArray)));
    assertTrue(references.stream().anyMatch(n -> n.getNodeId().equalTo(Identifiers.Server_ServiceLevel)));
    assertTrue(references.stream().anyMatch(n -> n.getNodeId().equalTo(Identifiers.Server_Auditing)));
    assertTrue(references.stream().anyMatch(n -> n.getNodeId().equalTo(Identifiers.Server_EstimatedReturnTime)));
}
Also used : BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) List(java.util.List) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaException(org.eclipse.milo.opcua.stack.core.UaException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EnumSet(java.util.EnumSet) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 8 with ReferenceDescription

use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.

the class BrowseHelper method browse.

public static CompletableFuture<List<ReferenceDescription>> browse(UaStackClient client, OpcUaSession session, BrowseDescription browseDescription, UInteger maxReferencesPerNode) {
    BrowseRequest browseRequest = new BrowseRequest(client.newRequestHeader(session.getAuthenticationToken(), client.getConfig().getRequestTimeout()), new ViewDescription(NodeId.NULL_VALUE, DateTime.MIN_VALUE, uint(0)), maxReferencesPerNode, new BrowseDescription[] { browseDescription });
    return client.sendRequest(browseRequest).thenApply(BrowseResponse.class::cast).thenCompose(response -> {
        BrowseResult result = response.getResults()[0];
        List<ReferenceDescription> references = Collections.synchronizedList(new ArrayList<>());
        return maybeBrowseNext(client, session, references, result);
    });
}
Also used : ViewDescription(org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)

Example 9 with ReferenceDescription

use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.

the class UaNode method getPropertyNodeAsync.

protected CompletableFuture<PropertyTypeNode> getPropertyNodeAsync(QualifiedName browseName) {
    UInteger nodeClassMask = uint(NodeClass.Variable.getValue());
    UInteger resultMask = uint(BrowseResultMask.BrowseName.getValue());
    CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasProperty, false, nodeClassMask, resultMask));
    return future.thenCompose(result -> {
        List<ReferenceDescription> references = l(result.getReferences());
        Optional<CompletableFuture<PropertyTypeNode>> node = references.stream().filter(r -> browseName.equals(r.getBrowseName())).flatMap(r -> {
            Optional<CompletableFuture<PropertyTypeNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id).thenApply(n -> (PropertyTypeNode) n));
            return opt2stream(opt);
        }).findFirst();
        return node.orElse(failedUaFuture(StatusCodes.Bad_NotFound));
    });
}
Also used : QualifiedProperty(org.eclipse.milo.opcua.sdk.core.QualifiedProperty) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Set(java.util.Set) UaEnumeration(org.eclipse.milo.opcua.stack.core.serialization.UaEnumeration) Collectors(java.util.stream.Collectors) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Optional(java.util.Optional) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) UaStructure(org.eclipse.milo.opcua.stack.core.serialization.UaStructure) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Iterator(java.util.Iterator) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) PropertyTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) UaException(org.eclipse.milo.opcua.stack.core.UaException) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) PropertyTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Example 10 with ReferenceDescription

use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.

the class UaObjectNode method getTypeDefinitionAsync.

public CompletableFuture<? extends UaObjectTypeNode> getTypeDefinitionAsync() {
    UInteger nodeClassMask = uint(NodeClass.ObjectType.getValue());
    UInteger resultMask = uint(BrowseResultMask.All.getValue());
    CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasTypeDefinition, false, nodeClassMask, resultMask));
    return future.thenCompose(result -> {
        List<ReferenceDescription> references = l(result.getReferences());
        Optional<CompletableFuture<UaObjectTypeNode>> node = references.stream().flatMap(r -> {
            Optional<CompletableFuture<UaObjectTypeNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id).thenApply(n -> (UaObjectTypeNode) n));
            return opt2stream(opt);
        }).findFirst();
        return node.orElse(FutureUtils.failedUaFuture(StatusCodes.Bad_NotFound));
    });
}
Also used : ObjectNode(org.eclipse.milo.opcua.sdk.core.nodes.ObjectNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) UaMethod(org.eclipse.milo.opcua.sdk.client.methods.UaMethod) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) CompletableFuture(java.util.concurrent.CompletableFuture) ObjectNodeProperties(org.eclipse.milo.opcua.sdk.core.nodes.ObjectNodeProperties) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) NamingRuleType(org.eclipse.milo.opcua.stack.core.types.enumerated.NamingRuleType) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Aggregations

ReferenceDescription (org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription)14 List (java.util.List)10 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)10 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)10 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)10 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)10 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)10 BrowseDescription (org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)10 BrowseResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 ExecutionException (java.util.concurrent.ExecutionException)9 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)9 UaException (org.eclipse.milo.opcua.stack.core.UaException)9 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)9 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)9 BrowseDirection (org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection)9 BrowseResultMask (org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask)9 NodeClass (org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass)9 Optional (java.util.Optional)8 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)8