[hotfix] Add more logging to OPC-UA adapter
@@ -41,7 +41,10 @@ import org.apache.streampipes.sdk.utils.Assets;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
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.enumerated.TimestampsToReturn;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@@ -51,6 +54,7 @@ import java.util.concurrent.TimeUnit;
public class OpcUaAdapter extends PullAdapter implements SupportsRuntimeConfig {
public static final String ID = "org.apache.streampipes.connect.iiot.adapters.opcua";
+ private static final Logger LOG = LoggerFactory.getLogger(OpcUaAdapter.class);
private int pullingIntervalMilliSeconds;
private SpOpcUaClient spOpcUaClient;
@@ -123,20 +127,33 @@ public class OpcUaAdapter extends PullAdapter implements SupportsRuntimeConfig {
@Override
protected void pullData() {
CompletableFuture<List<DataValue>> response = this.spOpcUaClient.getClient().readValues(0, TimestampsToReturn.Both, this.allNodeIds);
+ boolean badStatusCodeReceived = false;
+ boolean emptyValueReceived = false;
try {
List<DataValue> returnValues = response.get();
+ if (returnValues.size() == 0) {
+ emptyValueReceived = true;
+ LOG.warn("Empty value object returned - event will not be sent");
+ } else {
for (int i = 0; i < returnValues.size(); i++) {
-
+ var status = returnValues.get(i).getStatusCode();
+ if (StatusCode.GOOD.equals(status)) {
Object value = returnValues.get(i).getValue().getValue();
this.event.put(this.allNodes.get(i).getLabel(), value);
-
+ } else {
+ badStatusCodeReceived = true;
+ LOG.warn("Received status code {} for node label: {} - event will not be sent",
+ status,
+ this.allNodes.get(i).getLabel());
}
- } catch (InterruptedException | ExecutionException ie) {
- ie.printStackTrace();
}
-
+ }
+ if (!badStatusCodeReceived && !emptyValueReceived) {
adapterPipeline.process(this.event);
-
+ }
+ } catch (InterruptedException | ExecutionException ie) {
+ LOG.error("Exception while reading data", ie);
+ }
}
public void onSubscriptionValue(UaMonitoredItem item, DataValue value) {
