You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2022/08/03 07:10:13 UTC

[incubator-streampipes] branch dev updated: [hotfix] Relax filtering for OPC UA node types

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new b8f5b740e [hotfix] Relax filtering for OPC UA node types
b8f5b740e is described below

commit b8f5b740e180d62c30b60534d060d02b409c5ca7
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Wed Aug 3 09:10:01 2022 +0200

    [hotfix] Relax filtering for OPC UA node types
---
 .../connect/iiot/adapters/opcua/OpcUaAdapter.java  |  2 +-
 .../iiot/adapters/opcua/OpcUaNodeBrowser.java      | 28 ++++++++++++----------
 .../iiot/adapters/opcua/utils/OpcUaUtil.java       |  2 +-
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaAdapter.java
index 257abf860..0faffd00e 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaAdapter.java
@@ -94,7 +94,7 @@ public class OpcUaAdapter extends PullAdapter implements SupportsRuntimeConfig {
 
 
         } catch (Exception e) {
-            throw new AdapterException("The Connection to the OPC UA server could not be established.");
+            throw new AdapterException("The Connection to the OPC UA server could not be established.", e.getCause());
         }
     }
 
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaNodeBrowser.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaNodeBrowser.java
index 585c849a1..2e8e3dbc5 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaNodeBrowser.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcUaNodeBrowser.java
@@ -23,7 +23,6 @@ import org.apache.streampipes.connect.iiot.adapters.opcua.utils.OpcUaTypes;
 import org.apache.streampipes.model.staticproperty.TreeInputNode;
 import org.eclipse.milo.opcua.sdk.client.AddressSpace;
 import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
-import org.eclipse.milo.opcua.sdk.client.model.nodes.variables.BaseVariableTypeNode;
 import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
 import org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode;
 import org.eclipse.milo.opcua.stack.core.UaException;
@@ -31,12 +30,13 @@ import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
 import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
 import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
 import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
-import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 public class OpcUaNodeBrowser {
@@ -44,21 +44,21 @@ public class OpcUaNodeBrowser {
   private final OpcUaClient client;
   private final SpOpcUaConfig spOpcConfig;
 
+  private static final Logger LOG = LoggerFactory.getLogger(OpcUaNodeBrowser.class);
+
   public OpcUaNodeBrowser(OpcUaClient client,
                           SpOpcUaConfig spOpcUaClientConfig) {
     this.client = client;
     this.spOpcConfig = spOpcUaClientConfig;
   }
 
-  public List<OpcNode> findNodes() {
-    return this.spOpcConfig.getSelectedNodeNames().stream().map(n -> {
-      try {
-        return toOpcNode(n);
-      } catch (UaException e) {
-        e.printStackTrace();
-        return null;
-      }
-    }).collect(Collectors.toList());
+  public List<OpcNode> findNodes() throws UaException {
+    var opcNodes = new ArrayList<OpcNode>();
+    for(String selectedNodeName: this.spOpcConfig.getSelectedNodeNames()) {
+      opcNodes.add(toOpcNode(selectedNodeName));
+    }
+
+    return opcNodes;
   }
 
   public List<TreeInputNode> buildNodeTreeFromOrigin() throws UaException, ExecutionException, InterruptedException {
@@ -81,11 +81,15 @@ public class OpcUaNodeBrowser {
     NodeId nodeId = NodeId.parse(nodeName);
     UaNode node = addressSpace.getNode(nodeId);
 
-    if (node instanceof BaseVariableTypeNode) {
+    LOG.info("Using node of type {}", node.getNodeClass().toString() );
+
+    if (node instanceof UaVariableNode) {
       UInteger value = (UInteger) ((UaVariableNode) node).getDataType().getIdentifier();
       return new OpcNode(node.getDisplayName().getText(), OpcUaTypes.getType(value), node.getNodeId());
     }
 
+    LOG.warn("Node {} not of type UaVariableNode", node.getDisplayName());
+
     throw new UaException(StatusCode.BAD, "Node is not of type BaseDataVariableTypeNode");
   }
 
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java
index 38d4d4cb6..9e5ed16bf 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java
@@ -99,7 +99,7 @@ public class OpcUaUtil {
             spOpcUaClient.disconnect();
 
         } catch (Exception e) {
-            throw new AdapterException("Could not guess schema for opc node! " + e.getMessage());
+            throw new AdapterException("Could not guess schema for opc node:  " + e.getMessage(), e.getCause());
         }
 
         eventSchema.setEventProperties(allProperties);