You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2022/12/07 17:02:47 UTC
[streampipes] 01/02: [#820] enable checkstyle for adapters in extensions
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 83a51757d46d2ae38a18789917a268c4a4bb4343
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Mon Dec 5 14:58:57 2022 +0100
[#820] enable checkstyle for adapters in extensions
---
.../streampipes-connect-adapters-iiot/pom.xml | 20 +-
.../connect/iiot/ConnectAdapterIiotInit.java | 63 +-
.../connect/iiot/adapters/PullAdapter.java | 120 ++--
.../connect/iiot/adapters/PullRestAdapter.java | 65 +-
.../iiot/adapters/influxdb/InfluxDbClient.java | 493 ++++++++--------
.../iiot/adapters/influxdb/InfluxDbSetAdapter.java | 256 ++++----
.../adapters/influxdb/InfluxDbStreamAdapter.java | 306 +++++-----
.../opcua/MiloOpcUaConfigurationProvider.java | 52 +-
.../connect/iiot/adapters/opcua/OpcNode.java | 195 +++---
.../connect/iiot/adapters/opcua/OpcUaAdapter.java | 412 ++++++-------
.../iiot/adapters/opcua/OpcUaNodeBrowser.java | 18 +-
.../connect/iiot/adapters/opcua/SpOpcUaClient.java | 228 +++----
.../opcua/configuration/SpOpcUaConfig.java | 51 +-
.../opcua/configuration/SpOpcUaConfigBuilder.java | 38 +-
.../adapters/opcua/utils/OpcUaNodeVariants.java | 39 +-
.../iiot/adapters/opcua/utils/OpcUaTypes.java | 57 +-
.../iiot/adapters/opcua/utils/OpcUaUtil.java | 35 +-
.../adapters/plc4x/modbus/ModbusConfigFile.java | 78 +--
.../adapters/plc4x/modbus/Plc4xModbusAdapter.java | 590 +++++++++---------
.../plc4x/passive/Plc4xPassiveAdapter.java | 157 ++---
.../iiot/adapters/plc4x/s7/Plc4xS7Adapter.java | 568 +++++++++---------
.../iiot/adapters/ros/RosBridgeAdapter.java | 326 +++++-----
.../simulator/machine/MachineDataSimulator.java | 235 ++++----
.../machine/MachineDataSimulatorUtils.java | 205 +++----
.../machine/MachineDataStreamAdapter.java | 99 ++--
.../connect/iiot/protocol/set/FileProtocol.java | 195 +++---
.../connect/iiot/protocol/set/HttpProtocol.java | 172 +++---
.../iiot/protocol/stream/BrokerEventProcessor.java | 3 +-
.../iiot/protocol/stream/FileStreamProtocol.java | 130 ++--
.../iiot/protocol/stream/HttpServerProtocol.java | 47 +-
.../iiot/protocol/stream/HttpStreamProtocol.java | 211 +++----
.../iiot/protocol/stream/KafkaProtocol.java | 353 +++++------
.../connect/iiot/protocol/stream/MqttProtocol.java | 19 +-
.../connect/iiot/protocol/stream/NatsProtocol.java | 19 +-
.../connect/iiot/protocol/stream/PullProtocol.java | 105 ++--
.../protocol/stream/pulsar/PulsarProtocol.java | 69 ++-
.../iiot/protocol/stream/pulsar/PulsarUtils.java | 4 +-
.../protocol/stream/rocketmq/RocketMQConsumer.java | 6 +-
.../protocol/stream/rocketmq/RocketMQProtocol.java | 229 +++----
.../protocol/stream/rocketmq/RocketMQUtils.java | 17 +-
.../connect/iiot/utils/FileProtocolUtils.java | 69 +--
.../streampipes-connect-adapters/pom.xml | 20 +-
.../streampipes/connect/ConnectAdapterInit.java | 38 +-
.../streampipes/connect/adapters/PullAdapter.java | 106 ++--
.../connect/adapters/PullRestAdapter.java | 66 ++-
.../adapters/coindesk/CoindeskBitcoinAdapter.java | 30 +-
.../connect/adapters/coindesk/model/Bpi.java | 60 +-
.../adapters/coindesk/model/CoindeskRawModel.java | 64 +-
.../connect/adapters/coindesk/model/EUR.java | 103 ++--
.../connect/adapters/coindesk/model/GBP.java | 100 ++--
.../connect/adapters/coindesk/model/Time.java | 60 +-
.../connect/adapters/coindesk/model/USD.java | 100 ++--
.../connect/adapters/flic/FlicMQTTAdapter.java | 214 +++----
.../connect/adapters/flic/FlicOutput.java | 41 +-
.../connect/adapters/flic/FlicUtils.java | 62 +-
.../connect/adapters/gdelt/GdeltAdapter.java | 327 +++++-----
.../connect/adapters/iex/IexCloudAdapter.java | 12 +-
.../connect/adapters/iex/IexCloudNewsAdapter.java | 60 +-
.../connect/adapters/iex/IexCloudStockAdapter.java | 34 +-
.../connect/adapters/iex/model/IexNewsData.java | 180 +++---
.../connect/adapters/iex/model/IexStockData.java | 656 ++++++++++-----------
.../connect/adapters/image/ImageZipAdapter.java | 113 ++--
.../connect/adapters/image/ImageZipUtils.java | 16 +-
.../adapters/image/ZipFileImageIterator.java | 117 ++--
.../adapters/image/set/ImageSetAdapter.java | 117 ++--
.../adapters/image/stream/ImageStreamAdapter.java | 119 ++--
.../connect/adapters/iss/IssAdapter.java | 211 +++----
.../connect/adapters/iss/model/IssModel.java | 60 +-
.../connect/adapters/iss/model/IssPosition.java | 40 +-
.../connect/adapters/netio/NetioMQTTAdapter.java | 239 ++++----
.../connect/adapters/netio/NetioRestAdapter.java | 334 ++++++-----
.../connect/adapters/netio/NetioUtils.java | 282 ++++-----
.../adapters/netio/model/NetioAllPowerOutputs.java | 32 +-
.../adapters/netio/model/NetioGlobalMeasure.java | 96 +--
.../adapters/netio/model/NetioPowerOutput.java | 144 ++---
.../adapters/sensemap/OpenSenseMapAdapter.java | 578 +++++++++---------
.../connect/adapters/sensemap/SensorNames.java | 213 ++++---
.../adapters/sensemap/model/CurrentLocation.java | 52 +-
.../connect/adapters/sensemap/model/Geometry.java | 52 +-
.../adapters/sensemap/model/LastMeasurement.java | 40 +-
.../connect/adapters/sensemap/model/Loc.java | 40 +-
.../connect/adapters/sensemap/model/SenseBox.java | 184 +++---
.../connect/adapters/sensemap/model/Sensor.java | 120 ++--
.../simulator/random/RandomDataSetAdapter.java | 19 +-
.../simulator/random/RandomDataSimulatorUtils.java | 22 +-
.../simulator/random/RandomDataStreamAdapter.java | 21 +-
.../connect/adapters/slack/SlackAdapter.java | 35 +-
.../connect/adapters/slack/SlackConsumer.java | 3 +-
.../connect/adapters/ti/TISensorTag.java | 325 +++++-----
.../adapters/wikipedia/WikipediaAdapter.java | 104 ++--
.../wikipedia/WikipediaEditedArticlesAdapter.java | 8 +-
.../wikipedia/WikipediaModelConverter.java | 17 +-
.../wikipedia/WikipediaNewArticlesAdapter.java | 8 +-
.../adapters/wikipedia/WikipediaSseConsumer.java | 2 +-
.../connect/adapters/wikipedia/model/Length.java | 40 +-
.../connect/adapters/wikipedia/model/Meta.java | 180 +++---
.../connect/adapters/wikipedia/model/Revision.java | 40 +-
.../adapters/wikipedia/model/WikipediaModel.java | 338 +++++------
.../streampipes/connect/config/ConfigKeys.java | 12 +-
.../connect/config/ConnectWorkerConfig.java | 6 +-
100 files changed, 6684 insertions(+), 6382 deletions(-)
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml b/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml
index 547b293bc..3c6ed5a30 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml
@@ -17,7 +17,8 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -263,6 +264,23 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>validate</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <logViolationsToConsole>true</logViolationsToConsole>
+ <failOnViolation>true</failOnViolation>
+ </configuration>
+ </plugin>
</plugins>
<finalName>streampipes-connect-adapters-iiot</finalName>
</build>
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java
index 449c7db6c..8599bc436 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java
@@ -27,7 +27,12 @@ import org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter;
import org.apache.streampipes.connect.iiot.adapters.simulator.machine.MachineDataStreamAdapter;
import org.apache.streampipes.connect.iiot.protocol.set.FileProtocol;
import org.apache.streampipes.connect.iiot.protocol.set.HttpProtocol;
-import org.apache.streampipes.connect.iiot.protocol.stream.*;
+import org.apache.streampipes.connect.iiot.protocol.stream.FileStreamProtocol;
+import org.apache.streampipes.connect.iiot.protocol.stream.HttpServerProtocol;
+import org.apache.streampipes.connect.iiot.protocol.stream.HttpStreamProtocol;
+import org.apache.streampipes.connect.iiot.protocol.stream.KafkaProtocol;
+import org.apache.streampipes.connect.iiot.protocol.stream.MqttProtocol;
+import org.apache.streampipes.connect.iiot.protocol.stream.NatsProtocol;
import org.apache.streampipes.connect.iiot.protocol.stream.pulsar.PulsarProtocol;
import org.apache.streampipes.connect.iiot.protocol.stream.rocketmq.RocketMQProtocol;
import org.apache.streampipes.container.extensions.ExtensionsModelSubmitter;
@@ -35,33 +40,33 @@ import org.apache.streampipes.container.model.SpServiceDefinition;
import org.apache.streampipes.container.model.SpServiceDefinitionBuilder;
public class ConnectAdapterIiotInit extends ExtensionsModelSubmitter {
- public static void main(String[] args) {
- new ConnectAdapterIiotInit().init();
- }
+ public static void main(String[] args) {
+ new ConnectAdapterIiotInit().init();
+ }
- @Override
- public SpServiceDefinition provideServiceDefinition() {
- return SpServiceDefinitionBuilder.create("connect-adapter-iiot",
- "StreamPipes connect worker containing adapters relevant for the IIoT",
- "",
- 8001)
- .registerAdapter(new MachineDataStreamAdapter())
- .registerAdapter(new RosBridgeAdapter())
- .registerAdapter(new OpcUaAdapter())
- .registerAdapter(new InfluxDbStreamAdapter())
- .registerAdapter(new InfluxDbSetAdapter())
- .registerAdapter(new Plc4xS7Adapter())
- .registerAdapter(new Plc4xModbusAdapter())
- .registerAdapter(new FileProtocol())
- .registerAdapter(new HttpProtocol())
- .registerAdapter(new FileStreamProtocol())
- .registerAdapter(new KafkaProtocol())
- .registerAdapter(new MqttProtocol())
- .registerAdapter(new NatsProtocol())
- .registerAdapter(new HttpStreamProtocol())
- .registerAdapter(new PulsarProtocol())
- .registerAdapter(new RocketMQProtocol())
- .registerAdapter(new HttpServerProtocol())
- .build();
- }
+ @Override
+ public SpServiceDefinition provideServiceDefinition() {
+ return SpServiceDefinitionBuilder.create("connect-adapter-iiot",
+ "StreamPipes connect worker containing adapters relevant for the IIoT",
+ "",
+ 8001)
+ .registerAdapter(new MachineDataStreamAdapter())
+ .registerAdapter(new RosBridgeAdapter())
+ .registerAdapter(new OpcUaAdapter())
+ .registerAdapter(new InfluxDbStreamAdapter())
+ .registerAdapter(new InfluxDbSetAdapter())
+ .registerAdapter(new Plc4xS7Adapter())
+ .registerAdapter(new Plc4xModbusAdapter())
+ .registerAdapter(new FileProtocol())
+ .registerAdapter(new HttpProtocol())
+ .registerAdapter(new FileStreamProtocol())
+ .registerAdapter(new KafkaProtocol())
+ .registerAdapter(new MqttProtocol())
+ .registerAdapter(new NatsProtocol())
+ .registerAdapter(new HttpStreamProtocol())
+ .registerAdapter(new PulsarProtocol())
+ .registerAdapter(new RocketMQProtocol())
+ .registerAdapter(new HttpServerProtocol())
+ .build();
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullAdapter.java
index 4e3a69353..770fd6ea2 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullAdapter.java
@@ -25,84 +25,90 @@ import org.apache.streampipes.container.monitoring.SpMonitoringManager;
import org.apache.streampipes.model.StreamPipesErrorMessage;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.monitoring.SpLogEntry;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.*;
-
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
public abstract class PullAdapter extends SpecificDataStreamAdapter {
- protected static final Logger logger = LoggerFactory.getLogger(PullAdapter.class);
+ protected static final Logger LOGGER = LoggerFactory.getLogger(PullAdapter.class);
- private ScheduledExecutorService scheduler;
- private ScheduledExecutorService errorThreadscheduler;
+ private ScheduledExecutorService scheduler;
+ private ScheduledExecutorService errorThreadscheduler;
- public PullAdapter() {
- super();
- }
+ public PullAdapter() {
+ super();
+ }
- public PullAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
+ public PullAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
- protected abstract void pullData() throws ExecutionException, RuntimeException, InterruptedException, TimeoutException;
+ protected abstract void pullData()
+ throws ExecutionException, RuntimeException, InterruptedException, TimeoutException;
- protected abstract PollingSettings getPollingInterval();
+ protected abstract PollingSettings getPollingInterval();
- @Override
- public void startAdapter() throws AdapterException {
- before();
+ @Override
+ public void startAdapter() throws AdapterException {
+ before();
- final Runnable errorThread = this::executeAdpaterLogic;
+ final Runnable errorThread = this::executeAdpaterLogic;
- scheduler = Executors.newScheduledThreadPool(1);
- scheduler.schedule(errorThread, 0, TimeUnit.MILLISECONDS);
+ scheduler = Executors.newScheduledThreadPool(1);
+ scheduler.schedule(errorThread, 0, TimeUnit.MILLISECONDS);
- }
+ }
- private void executeAdpaterLogic() {
- final Runnable task = () -> {
- try {
- pullData();
- } catch (ExecutionException | InterruptedException e) {
- SpMonitoringManager.INSTANCE.addErrorMessage(
- adapterDescription.getElementId(),
- SpLogEntry.from(System.currentTimeMillis(), StreamPipesErrorMessage.from(e)));
- } catch (TimeoutException e) {
- logger.warn("Timeout occurred", e);
- }
- };
-
- scheduler = Executors.newScheduledThreadPool(1);
- ScheduledFuture<?> handle = scheduler.scheduleAtFixedRate(task, 1,
- getPollingInterval().getValue(), getPollingInterval().getTimeUnit());
-
- try {
- handle.get();
- } catch (ExecutionException | InterruptedException e) {
- logger.error("Error", e);
- }
- }
+ private void executeAdpaterLogic() {
+ final Runnable task = () -> {
+ try {
+ pullData();
+ } catch (ExecutionException | InterruptedException e) {
+ SpMonitoringManager.INSTANCE.addErrorMessage(
+ adapterDescription.getElementId(),
+ SpLogEntry.from(System.currentTimeMillis(), StreamPipesErrorMessage.from(e)));
+ } catch (TimeoutException e) {
+ LOGGER.warn("Timeout occurred", e);
+ }
+ };
+
+ scheduler = Executors.newScheduledThreadPool(1);
+ ScheduledFuture<?> handle = scheduler.scheduleAtFixedRate(task, 1,
+ getPollingInterval().getValue(), getPollingInterval().getTimeUnit());
- @Override
- public void stopAdapter() throws AdapterException {
- after();
- scheduler.shutdownNow();
+ try {
+ handle.get();
+ } catch (ExecutionException | InterruptedException e) {
+ LOGGER.error("Error", e);
}
+ }
- /**
- * Called before adapter is started (e.g. initialize connections)
- */
- protected void before() throws AdapterException {
+ @Override
+ public void stopAdapter() throws AdapterException {
+ after();
+ scheduler.shutdownNow();
+ }
- }
+ /**
+ * Called before adapter is started (e.g. initialize connections)
+ */
+ protected void before() throws AdapterException {
- /**
- * Called before adapter is stopped (e.g. shutdown connections)
- */
- protected void after() throws AdapterException {
+ }
- }
+ /**
+ * Called before adapter is stopped (e.g. shutdown connections)
+ */
+ protected void after() throws AdapterException {
+
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullRestAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullRestAdapter.java
index 50a5612d9..6d4f10972 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullRestAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/PullRestAdapter.java
@@ -18,54 +18,55 @@
package org.apache.streampipes.connect.iiot.adapters;
-import com.google.gson.Gson;
-import org.apache.http.client.fluent.Request;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
-public abstract class PullRestAdapter extends PullAdapter {
+import com.google.gson.Gson;
+import org.apache.http.client.fluent.Request;
- public PullRestAdapter() {
- super();
- }
+public abstract class PullRestAdapter extends PullAdapter {
- public PullRestAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
+ public PullRestAdapter() {
+ super();
+ }
- protected static String getDataFromEndpointString(String url) throws AdapterException {
- String result = null;
+ public PullRestAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+ protected static String getDataFromEndpointString(String url) throws AdapterException {
+ String result = null;
- logger.info("Started Request to open sensemap endpoint: " + url);
- try {
- result = Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asString();
+ LOGGER.info("Started Request to open sensemap endpoint: " + url);
+ try {
+ result = Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asString();
- if (result.startsWith("ï")) {
- result = result.substring(3);
- }
- logger.info("Received data from request");
+ if (result.startsWith("ï")) {
+ result = result.substring(3);
+ }
- } catch (Exception e) {
- String errorMessage = "Error while connecting to the open sensemap api";
- logger.error(errorMessage, e);
- throw new AdapterException(errorMessage);
- }
+ LOGGER.info("Received data from request");
- return result;
+ } catch (Exception e) {
+ String errorMessage = "Error while connecting to the open sensemap api";
+ LOGGER.error(errorMessage, e);
+ throw new AdapterException(errorMessage);
}
- protected static <T> T getDataFromEndpoint(String url, Class<T> clazz) throws AdapterException {
+ return result;
+ }
- String rawJson = getDataFromEndpointString(url);
- T all = new Gson().fromJson(rawJson, clazz);
+ protected static <T> T getDataFromEndpoint(String url, Class<T> clazz) throws AdapterException {
- return all;
- }
+ String rawJson = getDataFromEndpointString(url);
+ T all = new Gson().fromJson(rawJson, clazz);
+
+ return all;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbClient.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbClient.java
index f3e861dd3..dbb48e847 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbClient.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbClient.java
@@ -18,12 +18,6 @@
package org.apache.streampipes.connect.iiot.adapters.influxdb;
-import org.influxdb.InfluxDB;
-import org.influxdb.InfluxDBFactory;
-import org.influxdb.InfluxDBIOException;
-import org.influxdb.dto.Pong;
-import org.influxdb.dto.Query;
-import org.influxdb.dto.QueryResult;
import org.apache.streampipes.commons.exceptions.SpRuntimeException;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -32,6 +26,13 @@ import org.apache.streampipes.model.schema.EventSchema;
import org.apache.streampipes.sdk.builder.PrimitivePropertyBuilder;
import org.apache.streampipes.sdk.utils.Datatypes;
+import org.influxdb.InfluxDB;
+import org.influxdb.InfluxDBFactory;
+import org.influxdb.InfluxDBIOException;
+import org.influxdb.dto.Pong;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
@@ -44,278 +45,278 @@ import static org.apache.streampipes.vocabulary.SO.DateTime;
public class InfluxDbClient {
- private InfluxDB influxDb;
-
- static final String HOST = "influxDbHost";
- static final String PORT = "influxDbPort";
- static final String DATABASE = "influxDbDatabase";
- static final String MEASUREMENT = "influxDbMeasurement";
- static final String USERNAME = "influxDbUsername";
- static final String PASSWORD = "influxDbPassword";
-
- static final String REPLACE_NULL_VALUES = "replaceNullValues";
- static final String DO_REPLACE = "doReplace";
- static final String DO_NOT_REPLACE = "doNotReplace";
+ private InfluxDB influxDb;
- private String host;
- private int port;
- private String database;
- private String measurement;
- private String username;
- private String password;
+ static final String HOST = "influxDbHost";
+ static final String PORT = "influxDbPort";
+ static final String DATABASE = "influxDbDatabase";
+ static final String MEASUREMENT = "influxDbMeasurement";
+ static final String USERNAME = "influxDbUsername";
+ static final String PASSWORD = "influxDbPassword";
- private boolean replaceNullValues;
+ static final String REPLACE_NULL_VALUES = "replaceNullValues";
+ static final String DO_REPLACE = "doReplace";
+ static final String DO_NOT_REPLACE = "doNotReplace";
- private List<Column> columns;
- private String columnsString;
+ private final String host;
+ private final int port;
+ private final String database;
+ private final String measurement;
+ private final String username;
+ private final String password;
- private boolean connected;
+ private final boolean replaceNullValues;
- public static class Column {
- private String name;
- private Datatypes datatypes;
+ private List<Column> columns;
+ private String columnsString;
- Column(String name, Datatypes datatypes) {
- this.name = name;
- this.datatypes = datatypes;
- }
+ private boolean connected;
- String getName() {
- return name;
- }
+ public static class Column {
+ private final String name;
+ private final Datatypes datatypes;
- Datatypes getDatatypes() {
- return datatypes;
- }
+ Column(String name, Datatypes datatypes) {
+ this.name = name;
+ this.datatypes = datatypes;
}
- InfluxDbClient(String host,
- int port,
- String database,
- String measurement,
- String username,
- String password,
- boolean replaceNullValues) {
- this.host = host;
- this.port = port;
- this.database = database;
- this.measurement = measurement;
- this.username = username;
- this.password = password;
- this.replaceNullValues = replaceNullValues;
-
- this.connected = false;
+ String getName() {
+ return name;
}
- public void connect() throws AdapterException {
- String urlAndPort = host + ":" + port;
- try {
- // Connect to the server and check if the server is available
- influxDb = InfluxDBFactory.connect(urlAndPort, username, password);
- Pong living = influxDb.ping();
- if (living.getVersion().equalsIgnoreCase("unknown")) {
- throw new AdapterException("Could not connect to InfluxDb Server: " + urlAndPort);
- }
-
- // Checking whether the database exists
- if (!databaseExists(database)) {
- throw new AdapterException("Database " + database + " could not be found.");
- }
-
- // Checking, whether the measurement exists
- if (!measurementExists(measurement)) {
- throw new AdapterException("Measurement " + measurement + " could not be found.");
- }
-
- connected = true;
- } catch (InfluxDBIOException e) {
- throw new AdapterException("Problem connecting with the server: " + e.getMessage());
- }
+ Datatypes getDatatypes() {
+ return datatypes;
}
-
- public void disconnect() {
- if (connected) {
- influxDb.close();
- connected = false;
- }
+ }
+
+ InfluxDbClient(String host,
+ int port,
+ String database,
+ String measurement,
+ String username,
+ String password,
+ boolean replaceNullValues) {
+ this.host = host;
+ this.port = port;
+ this.database = database;
+ this.measurement = measurement;
+ this.username = username;
+ this.password = password;
+ this.replaceNullValues = replaceNullValues;
+
+ this.connected = false;
+ }
+
+ public void connect() throws AdapterException {
+ String urlAndPort = host + ":" + port;
+ try {
+ // Connect to the server and check if the server is available
+ influxDb = InfluxDBFactory.connect(urlAndPort, username, password);
+ Pong living = influxDb.ping();
+ if (living.getVersion().equalsIgnoreCase("unknown")) {
+ throw new AdapterException("Could not connect to InfluxDb Server: " + urlAndPort);
+ }
+
+ // Checking whether the database exists
+ if (!databaseExists(database)) {
+ throw new AdapterException("Database " + database + " could not be found.");
+ }
+
+ // Checking, whether the measurement exists
+ if (!measurementExists(measurement)) {
+ throw new AdapterException("Measurement " + measurement + " could not be found.");
+ }
+
+ connected = true;
+ } catch (InfluxDBIOException e) {
+ throw new AdapterException("Problem connecting with the server: " + e.getMessage());
}
+ }
- private boolean databaseExists(String dbName) {
- QueryResult queryResult = influxDb.query(new Query("SHOW DATABASES", ""));
- for (List<Object> a : queryResult.getResults().get(0).getSeries().get(0).getValues()) {
- if (a.get(0).equals(dbName)) {
- return true;
- }
- }
- return false;
+ public void disconnect() {
+ if (connected) {
+ influxDb.close();
+ connected = false;
}
-
- private boolean measurementExists(String measurement) {
- // Database must exist
- QueryResult queryResult = influxDb.query(new Query("SHOW MEASUREMENTS", database));
- for (List<Object> a : queryResult.getResults().get(0).getSeries().get(0).getValues()) {
- if (a.get(0).equals(measurement)) {
- return true;
- }
- }
- return false;
+ }
+
+ private boolean databaseExists(String dbName) {
+ QueryResult queryResult = influxDb.query(new Query("SHOW DATABASES", ""));
+ for (List<Object> a : queryResult.getResults().get(0).getSeries().get(0).getValues()) {
+ if (a.get(0).equals(dbName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean measurementExists(String measurement) {
+ // Database must exist
+ QueryResult queryResult = influxDb.query(new Query("SHOW MEASUREMENTS", database));
+ for (List<Object> a : queryResult.getResults().get(0).getSeries().get(0).getValues()) {
+ if (a.get(0).equals(measurement)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public GuessSchema getSchema() throws AdapterException {
+ connect();
+ loadColumns();
+
+ EventSchema eventSchema = new EventSchema();
+ GuessSchema guessSchema = new GuessSchema();
+ List<EventProperty> allProperties = new ArrayList<>();
+
+ for (Column column : columns) {
+ PrimitivePropertyBuilder property = PrimitivePropertyBuilder
+ .create(column.getDatatypes(), column.getName())
+ .label(column.getName());
+ // Setting the timestamp field to the correct domainProperty
+ if (column.getName().equals("time")) {
+ property.domainProperty(DateTime);
+ }
+ allProperties.add(property.build());
}
- public GuessSchema getSchema() throws AdapterException {
- connect();
- loadColumns();
-
- EventSchema eventSchema = new EventSchema();
- GuessSchema guessSchema = new GuessSchema();
- List<EventProperty> allProperties = new ArrayList<>();
-
- for (Column column : columns) {
- PrimitivePropertyBuilder property = PrimitivePropertyBuilder
- .create(column.getDatatypes(), column.getName())
- .label(column.getName());
- // Setting the timestamp field to the correct domainProperty
- if (column.getName().equals("time")) {
- property.domainProperty(DateTime);
- }
- allProperties.add(property.build());
- }
+ eventSchema.setEventProperties(allProperties);
+ guessSchema.setEventSchema(eventSchema);
- eventSchema.setEventProperties(allProperties);
- guessSchema.setEventSchema(eventSchema);
+ disconnect();
+ return guessSchema;
+ }
- disconnect();
- return guessSchema;
+ // Client must be connected before calling this method
+ void loadColumns() throws AdapterException {
+ if (!connected) {
+ throw new AdapterException("Client must be connected to the server in order to load the columns.");
}
-
- // Client must be connected before calling this method
- void loadColumns() throws AdapterException {
- if (!connected) {
- throw new AdapterException("Client must be connected to the server in order to load the columns.");
- }
- List<List<Object>> fieldKeys = query("SHOW FIELD KEYS FROM " + measurement);
- List<List<Object>> tagKeys = query("SHOW TAG KEYS FROM " + measurement);
+ List<List<Object>> fieldKeys = query("SHOW FIELD KEYS FROM " + measurement);
+ List<List<Object>> tagKeys = query("SHOW TAG KEYS FROM " + measurement);
// if (fieldKeys.size() == 0 || tagKeys.size() == 0) {
- if (fieldKeys.size() == 0) {
- throw new AdapterException("Error while checking the Schema (does the measurement exist?)");
- }
-
- columns = new ArrayList<>();
- columns.add(new Column("time", Datatypes.Long));
-
- for (List o : fieldKeys) {
- // o.get(0): Name, o.get(1): Datatype
- // Data types: https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_reference/#data-types
- String name = o.get(0).toString();
- Datatypes datatype;
- switch (o.get(1).toString()) {
- case "float":
- datatype = Datatypes.Float;
- break;
- case "boolean":
- datatype = Datatypes.Boolean;
- break;
- case "integer":
- datatype = Datatypes.Integer;
- break;
- default:
- datatype = Datatypes.String;
- break;
- }
- columns.add(new Column(name, datatype));
- }
- for (List o : tagKeys) {
- // All tag keys are strings
- String name = o.get(0).toString();
- columns.add(new Column(name, Datatypes.String));
- }
+ if (fieldKeys.size() == 0) {
+ throw new AdapterException("Error while checking the Schema (does the measurement exist?)");
+ }
- // Update the column String
- // Do it only here, because it is needed every time for the query (performance)
- StringBuilder sb = new StringBuilder();
- for (Column column : columns) {
- sb.append(column.getName()).append(", ");
- }
- sb.setLength(sb.length() - 2);
- columnsString = sb.toString();
+ columns = new ArrayList<>();
+ columns.add(new Column("time", Datatypes.Long));
+
+ for (List o : fieldKeys) {
+ // o.get(0): Name, o.get(1): Datatype
+ // Data types: https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_reference/#data-types
+ String name = o.get(0).toString();
+ Datatypes datatype;
+ switch (o.get(1).toString()) {
+ case "float":
+ datatype = Datatypes.Float;
+ break;
+ case "boolean":
+ datatype = Datatypes.Boolean;
+ break;
+ case "integer":
+ datatype = Datatypes.Integer;
+ break;
+ default:
+ datatype = Datatypes.String;
+ break;
+ }
+ columns.add(new Column(name, datatype));
+ }
+ for (List o : tagKeys) {
+ // All tag keys are strings
+ String name = o.get(0).toString();
+ columns.add(new Column(name, Datatypes.String));
}
- // Returns a list with the entries of the query. If there are no entries, it returns an empty list
- List<List<Object>> query(String query) {
- if (!connected) {
- throw new RuntimeException("InfluxDbClient not connected");
- }
- QueryResult queryResult = influxDb.query(new Query(query, database));
- if (queryResult.getResults().get(0).getSeries() != null) {
- return queryResult.getResults().get(0).getSeries().get(0).getValues();
- } else {
- return new ArrayList<>();
- }
+ // Update the column String
+ // Do it only here, because it is needed every time for the query (performance)
+ StringBuilder sb = new StringBuilder();
+ for (Column column : columns) {
+ sb.append(column.getName()).append(", ");
}
+ sb.setLength(sb.length() - 2);
+ columnsString = sb.toString();
+ }
+
+ // Returns a list with the entries of the query. If there are no entries, it returns an empty list
+ List<List<Object>> query(String query) {
+ if (!connected) {
+ throw new RuntimeException("InfluxDbClient not connected");
+ }
+ QueryResult queryResult = influxDb.query(new Query(query, database));
+ if (queryResult.getResults().get(0).getSeries() != null) {
+ return queryResult.getResults().get(0).getSeries().get(0).getValues();
+ } else {
+ return new ArrayList<>();
+ }
+ }
- // Returns null, if replaceNullValues == false and if in items is a null value
- // Otherwise it returns a Map containing the runtimenames and the correctly parsed values
- Map<String, Object> extractEvent(List<Object> items) throws SpRuntimeException {
- if (items.size() != columns.size()) {
- throw new SpRuntimeException("Converter: Item list length is not the same as column list length");
- }
- Map<String, Object> out = new HashMap<>();
-
- // First element is the timestamp, which will be converted to milli seconds
- TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_INSTANT.parse((String)items.get(0));
- Instant time = Instant.from(temporalAccessor);
- out.put("time", time.toEpochMilli());
-
- for (int i = 1; i < items.size(); i++) {
- // The order of columns and items is the same, because the order in columnsString (which is used for the
- // query) is based on the order of columns
- if (items.get(i) != null) {
- out.put(columns.get(i).getName(), items.get(i));
- } else {
- if (replaceNullValues) {
- // Replace null values with defaults
- switch (columns.get(i).getDatatypes()) {
- case String:
- out.put(columns.get(i).getName(), "");
- break;
- case Integer:
- out.put(columns.get(i).getName(), 0);
- break;
- case Float:
- out.put(columns.get(i).getName(), 0.0f);
- break;
- case Boolean:
- out.put(columns.get(i).getName(), false);
- break;
- default:
- throw new SpRuntimeException("Unexpected value: " + columns.get(i).getDatatypes());
- }
- } else {
- // One field == null is enough to skip this event
- // Or maybe throw an exception instead?
- return null;
- }
- }
+ // Returns null, if replaceNullValues == false and if in items is a null value
+ // Otherwise it returns a Map containing the runtimenames and the correctly parsed values
+ Map<String, Object> extractEvent(List<Object> items) throws SpRuntimeException {
+ if (items.size() != columns.size()) {
+ throw new SpRuntimeException("Converter: Item list length is not the same as column list length");
+ }
+ Map<String, Object> out = new HashMap<>();
+
+ // First element is the timestamp, which will be converted to milli seconds
+ TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_INSTANT.parse((String) items.get(0));
+ Instant time = Instant.from(temporalAccessor);
+ out.put("time", time.toEpochMilli());
+
+ for (int i = 1; i < items.size(); i++) {
+ // The order of columns and items is the same, because the order in columnsString (which is used for the
+ // query) is based on the order of columns
+ if (items.get(i) != null) {
+ out.put(columns.get(i).getName(), items.get(i));
+ } else {
+ if (replaceNullValues) {
+ // Replace null values with defaults
+ switch (columns.get(i).getDatatypes()) {
+ case String:
+ out.put(columns.get(i).getName(), "");
+ break;
+ case Integer:
+ out.put(columns.get(i).getName(), 0);
+ break;
+ case Float:
+ out.put(columns.get(i).getName(), 0.0f);
+ break;
+ case Boolean:
+ out.put(columns.get(i).getName(), false);
+ break;
+ default:
+ throw new SpRuntimeException("Unexpected value: " + columns.get(i).getDatatypes());
+ }
+ } else {
+ // One field == null is enough to skip this event
+ // Or maybe throw an exception instead?
+ return null;
}
- return out;
+ }
}
+ return out;
+ }
- // Converts a string date from ISO_INSTANT format in a unix timestamp in nanoseconds
- static String getTimestamp(String date) {
- TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_INSTANT.parse(date);
+ // Converts a string date from ISO_INSTANT format in a unix timestamp in nanoseconds
+ static String getTimestamp(String date) {
+ TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_INSTANT.parse(date);
- Instant time = Instant.from(temporalAccessor);
- return time.getEpochSecond() + String.format("%09d", time.getNano());
- }
+ Instant time = Instant.from(temporalAccessor);
+ return time.getEpochSecond() + String.format("%09d", time.getNano());
+ }
- String getColumnsString() {
- return columnsString;
- }
+ String getColumnsString() {
+ return columnsString;
+ }
- String getMeasurement() {
- return measurement;
- }
+ String getMeasurement() {
+ return measurement;
+ }
- boolean isConnected() {
- return connected;
- }
+ boolean isConnected() {
+ return connected;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbSetAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbSetAdapter.java
index a31cb5ed6..ad554f950 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbSetAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbSetAdapter.java
@@ -20,10 +20,10 @@ package org.apache.streampipes.connect.iiot.adapters.influxdb;
import org.apache.streampipes.commons.exceptions.SpRuntimeException;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
-import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.connect.adapter.model.specific.SpecificDataSetAdapter;
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
+import org.apache.streampipes.connect.api.exception.AdapterException;
+import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterSetDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
import org.apache.streampipes.sdk.builder.adapter.SpecificDataSetAdapterBuilder;
@@ -38,141 +38,141 @@ import java.util.Map;
public class InfluxDbSetAdapter extends SpecificDataSetAdapter {
- public static final String ID = "org.apache.streampipes.connect.iiot.adapters.influxdb.set";
- public static final int BATCH_SIZE = 8192;
-
- private InfluxDbClient influxDbClient;
- private Thread fetchDataThread;
-
- public static class FetchDataThread implements Runnable {
-
- InfluxDbSetAdapter influxDbSetAdapter;
- InfluxDbClient influxDbClient;
-
- public FetchDataThread(InfluxDbSetAdapter influxDbSetAdapter) throws AdapterException {
- this.influxDbSetAdapter = influxDbSetAdapter;
- this.influxDbClient = influxDbSetAdapter.getInfluxDbClient();
-
- influxDbClient.connect();
- influxDbClient.loadColumns();
- }
+ public static final String ID = "org.apache.streampipes.connect.iiot.adapters.influxdb.set";
+ public static final int BATCH_SIZE = 8192;
- @Override
- public void run() {
- if (!influxDbClient.isConnected()) {
- System.out.println("Cannot start PollingThread, when the client is not connected");
- return;
- }
-
- String oldestTimestamp = "0";
- while (!Thread.interrupted()) {
- // Get the next n elements, where the time is > than the last timestamp and send them (if there are some)
- List<List<Object>> queryResult = influxDbClient.
- query("SELECT " + influxDbClient.getColumnsString() + " FROM " + influxDbClient.getMeasurement()
- + " WHERE time > " + oldestTimestamp + " ORDER BY time ASC LIMIT " + BATCH_SIZE);
-
- for (List<Object> event : queryResult) {
- try {
- influxDbSetAdapter.send(influxDbClient.extractEvent(event));
- } catch (SpRuntimeException e) {
- System.out.println(e.getMessage());
- }
- }
- if (queryResult.size() < BATCH_SIZE) {
- // The last events or no event at all => Stop
- break;
- } else {
- // Get the new timestamp for the new round
- oldestTimestamp = InfluxDbClient.getTimestamp((String) queryResult.get(queryResult.size() - 1).get(0));
- }
- }
- influxDbClient.disconnect();
- }
- }
+ private InfluxDbClient influxDbClient;
+ private Thread fetchDataThread;
- public InfluxDbSetAdapter() {
- }
+ public static class FetchDataThread implements Runnable {
- public InfluxDbSetAdapter(SpecificAdapterSetDescription specificAdapterSetDescription) {
- super(specificAdapterSetDescription);
+ InfluxDbSetAdapter influxDbSetAdapter;
+ InfluxDbClient influxDbClient;
- getConfigurations(specificAdapterSetDescription);
- }
+ public FetchDataThread(InfluxDbSetAdapter influxDbSetAdapter) throws AdapterException {
+ this.influxDbSetAdapter = influxDbSetAdapter;
+ this.influxDbClient = influxDbSetAdapter.getInfluxDbClient();
- @Override
- public SpecificAdapterSetDescription declareModel() {
- SpecificAdapterSetDescription description = SpecificDataSetAdapterBuilder.create(ID)
- .withAssets(Assets.ICON, Assets.DOCUMENTATION)
- .withLocales(Locales.EN)
- .requiredTextParameter(Labels.withId(InfluxDbClient.HOST))
- .requiredIntegerParameter(Labels.withId(InfluxDbClient.PORT))
- .requiredTextParameter(Labels.withId(InfluxDbClient.DATABASE))
- .requiredTextParameter(Labels.withId(InfluxDbClient.MEASUREMENT))
- .requiredTextParameter(Labels.withId(InfluxDbClient.USERNAME))
- .requiredSecret(Labels.withId(InfluxDbClient.PASSWORD))
- .requiredSingleValueSelection(Labels.withId(InfluxDbClient.REPLACE_NULL_VALUES),
- Options.from(
- new Tuple2<>("Yes", InfluxDbClient.DO_REPLACE),
- new Tuple2<>("No", InfluxDbClient.DO_NOT_REPLACE)))
- .build();
-
- description.setAppId(ID);
- return description;
- }
-
- @Override
- public void startAdapter() throws AdapterException {
- fetchDataThread = new Thread(new FetchDataThread(this));
- fetchDataThread.start();
+ influxDbClient.connect();
+ influxDbClient.loadColumns();
}
@Override
- public void stopAdapter() throws AdapterException {
- fetchDataThread.interrupt();
- try {
- fetchDataThread.join();
- } catch (InterruptedException e) {
- throw new AdapterException("Unexpected Error while joining polling thread: " + e.getMessage());
+ public void run() {
+ if (!influxDbClient.isConnected()) {
+ System.out.println("Cannot start PollingThread, when the client is not connected");
+ return;
+ }
+
+ String oldestTimestamp = "0";
+ while (!Thread.interrupted()) {
+ // Get the next n elements, where the time is > than the last timestamp and send them (if there are some)
+ List<List<Object>> queryResult = influxDbClient.
+ query("SELECT " + influxDbClient.getColumnsString() + " FROM " + influxDbClient.getMeasurement()
+ + " WHERE time > " + oldestTimestamp + " ORDER BY time ASC LIMIT " + BATCH_SIZE);
+
+ for (List<Object> event : queryResult) {
+ try {
+ influxDbSetAdapter.send(influxDbClient.extractEvent(event));
+ } catch (SpRuntimeException e) {
+ System.out.println(e.getMessage());
+ }
}
+ if (queryResult.size() < BATCH_SIZE) {
+ // The last events or no event at all => Stop
+ break;
+ } else {
+ // Get the new timestamp for the new round
+ oldestTimestamp = InfluxDbClient.getTimestamp((String) queryResult.get(queryResult.size() - 1).get(0));
+ }
+ }
+ influxDbClient.disconnect();
}
-
- @Override
- public Adapter getInstance(SpecificAdapterSetDescription adapterDescription) {
- return new InfluxDbSetAdapter(adapterDescription);
- }
-
- @Override
- public GuessSchema getSchema(SpecificAdapterSetDescription adapterDescription)
- throws AdapterException, ParseException {
- getConfigurations(adapterDescription);
- return influxDbClient.getSchema();
- }
-
- @Override
- public String getId() {
- return ID;
- }
-
- private void send(Map<String, Object> map) {
- adapterPipeline.process(map);
- }
-
- private void getConfigurations(SpecificAdapterSetDescription adapterDescription) {
- ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
-
- String replace = extractor.selectedSingleValueInternalName(InfluxDbClient.REPLACE_NULL_VALUES);
-
- influxDbClient = new InfluxDbClient(
- extractor.singleValue(InfluxDbClient.HOST, String.class),
- extractor.singleValue(InfluxDbClient.PORT, Integer.class),
- extractor.singleValue(InfluxDbClient.DATABASE, String.class),
- extractor.singleValue(InfluxDbClient.MEASUREMENT, String.class),
- extractor.singleValue(InfluxDbClient.USERNAME, String.class),
- extractor.secretValue(InfluxDbClient.PASSWORD),
- replace.equals(InfluxDbClient.DO_REPLACE));
- }
-
- public InfluxDbClient getInfluxDbClient() {
- return influxDbClient;
+ }
+
+ public InfluxDbSetAdapter() {
+ }
+
+ public InfluxDbSetAdapter(SpecificAdapterSetDescription specificAdapterSetDescription) {
+ super(specificAdapterSetDescription);
+
+ getConfigurations(specificAdapterSetDescription);
+ }
+
+ @Override
+ public SpecificAdapterSetDescription declareModel() {
+ SpecificAdapterSetDescription description = SpecificDataSetAdapterBuilder.create(ID)
+ .withAssets(Assets.ICON, Assets.DOCUMENTATION)
+ .withLocales(Locales.EN)
+ .requiredTextParameter(Labels.withId(InfluxDbClient.HOST))
+ .requiredIntegerParameter(Labels.withId(InfluxDbClient.PORT))
+ .requiredTextParameter(Labels.withId(InfluxDbClient.DATABASE))
+ .requiredTextParameter(Labels.withId(InfluxDbClient.MEASUREMENT))
+ .requiredTextParameter(Labels.withId(InfluxDbClient.USERNAME))
+ .requiredSecret(Labels.withId(InfluxDbClient.PASSWORD))
+ .requiredSingleValueSelection(Labels.withId(InfluxDbClient.REPLACE_NULL_VALUES),
+ Options.from(
+ new Tuple2<>("Yes", InfluxDbClient.DO_REPLACE),
+ new Tuple2<>("No", InfluxDbClient.DO_NOT_REPLACE)))
+ .build();
+
+ description.setAppId(ID);
+ return description;
+ }
+
+ @Override
+ public void startAdapter() throws AdapterException {
+ fetchDataThread = new Thread(new FetchDataThread(this));
+ fetchDataThread.start();
+ }
+
+ @Override
+ public void stopAdapter() throws AdapterException {
+ fetchDataThread.interrupt();
+ try {
+ fetchDataThread.join();
+ } catch (InterruptedException e) {
+ throw new AdapterException("Unexpected Error while joining polling thread: " + e.getMessage());
}
+ }
+
+ @Override
+ public Adapter getInstance(SpecificAdapterSetDescription adapterDescription) {
+ return new InfluxDbSetAdapter(adapterDescription);
+ }
+
+ @Override
+ public GuessSchema getSchema(SpecificAdapterSetDescription adapterDescription)
+ throws AdapterException, ParseException {
+ getConfigurations(adapterDescription);
+ return influxDbClient.getSchema();
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ private void send(Map<String, Object> map) {
+ adapterPipeline.process(map);
+ }
+
+ private void getConfigurations(SpecificAdapterSetDescription adapterDescription) {
+ ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
+
+ String replace = extractor.selectedSingleValueInternalName(InfluxDbClient.REPLACE_NULL_VALUES);
+
+ influxDbClient = new InfluxDbClient(
+ extractor.singleValue(InfluxDbClient.HOST, String.class),
+ extractor.singleValue(InfluxDbClient.PORT, Integer.class),
+ extractor.singleValue(InfluxDbClient.DATABASE, String.class),
+ extractor.singleValue(InfluxDbClient.MEASUREMENT, String.class),
+ extractor.singleValue(InfluxDbClient.USERNAME, String.class),
+ extractor.secretValue(InfluxDbClient.PASSWORD),
+ replace.equals(InfluxDbClient.DO_REPLACE));
+ }
+
+ public InfluxDbClient getInfluxDbClient() {
+ return influxDbClient;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbStreamAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbStreamAdapter.java
index dcea694ae..89a533b30 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbStreamAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/influxdb/InfluxDbStreamAdapter.java
@@ -20,10 +20,10 @@ package org.apache.streampipes.connect.iiot.adapters.influxdb;
import org.apache.streampipes.commons.exceptions.SpRuntimeException;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
-import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
+import org.apache.streampipes.connect.api.exception.AdapterException;
+import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
import org.apache.streampipes.sdk.builder.adapter.SpecificDataStreamAdapterBuilder;
@@ -38,173 +38,173 @@ import java.util.Map;
public class InfluxDbStreamAdapter extends SpecificDataStreamAdapter {
- public static final String ID = "org.apache.streampipes.connect.iiot.adapters.influxdb.stream";
+ public static final String ID = "org.apache.streampipes.connect.iiot.adapters.influxdb.stream";
- private static final String POLLING_INTERVAL = "pollingInterval";
+ private static final String POLLING_INTERVAL = "pollingInterval";
- private InfluxDbClient influxDbClient;
-
- private Thread pollingThread;
- private int pollingInterval;
+ private InfluxDbClient influxDbClient;
- public static class PollingThread implements Runnable {
- private int pollingInterval;
-
- private InfluxDbClient influxDbClient;
- private InfluxDbStreamAdapter influxDbStreamAdapter;
-
- PollingThread(InfluxDbStreamAdapter influxDbStreamAdapter, int pollingInterval) throws AdapterException {
- this.pollingInterval = pollingInterval;
- this.influxDbStreamAdapter = influxDbStreamAdapter;
- this.influxDbClient = influxDbStreamAdapter.getInfluxDbClient();
-
- influxDbClient.connect();
- influxDbClient.loadColumns();
- }
-
- @Override
- public void run() {
- if (!influxDbClient.isConnected()) {
- System.out.println("Cannot start PollingThread, when the client is not connected");
- return;
- }
- // Checking the most recent timestamp
- // Timestamp is a string, because a long might not be big enough (it includes nano seconds)
- String lastTimestamp;
- try {
- lastTimestamp = getNewestTimestamp();
- } catch (SpRuntimeException e) {
- System.out.println(e.getMessage());
- return;
- }
-
- while (!Thread.interrupted()) {
- try {
- Thread.sleep(pollingInterval);
- } catch (InterruptedException e) {
- break;
- }
- List<List<Object>> queryResult = influxDbClient.query("SELECT " + influxDbClient.getColumnsString()
- + " FROM " + influxDbClient.getMeasurement() + " WHERE time > " + lastTimestamp + " ORDER BY time ASC ");
- if (queryResult.size() > 0) {
- // The last element has the highest timestamp (ordered asc) -> Set the new latest timestamp
- lastTimestamp = InfluxDbClient.getTimestamp((String)queryResult.get(queryResult.size() - 1).get(0));
-
- for (List<Object> value : queryResult) {
- try {
- Map<String, Object> out = influxDbClient.extractEvent(value);
- if (out != null) {
- influxDbStreamAdapter.send(out);
- }
- } catch (SpRuntimeException e) {
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
- }
- influxDbClient.disconnect();
- }
-
- // Returns the newest timestamp in the measurement as unix timestamp in Nanoseconds.
- // If no entry is found, a SpRuntimeException is thrown
- String getNewestTimestamp() throws SpRuntimeException {
- List<List<Object>> queryResult = influxDbClient.query("SELECT * FROM " + influxDbClient.getMeasurement()
- + " ORDER BY time DESC LIMIT 1");
- if (queryResult.size() > 0) {
- return InfluxDbClient.getTimestamp((String)queryResult.get(0).get(0));
- } else {
- throw new SpRuntimeException("No entry found in query");
- }
- }
- }
-
- private InfluxDbClient getInfluxDbClient() {
- return influxDbClient;
- }
+ private Thread pollingThread;
+ private int pollingInterval;
- public InfluxDbStreamAdapter() {
- }
-
- public InfluxDbStreamAdapter(SpecificAdapterStreamDescription specificAdapterStreamDescription) {
- super(specificAdapterStreamDescription);
+ public static class PollingThread implements Runnable {
+ private int pollingInterval;
- getConfigurations(specificAdapterStreamDescription);
- }
+ private InfluxDbClient influxDbClient;
+ private InfluxDbStreamAdapter influxDbStreamAdapter;
- @Override
- public SpecificAdapterStreamDescription declareModel() {
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .requiredTextParameter(Labels.withId(InfluxDbClient.HOST))
- .requiredIntegerParameter(Labels.withId(InfluxDbClient.PORT))
- .requiredTextParameter(Labels.withId(InfluxDbClient.DATABASE))
- .requiredTextParameter(Labels.withId(InfluxDbClient.MEASUREMENT))
- .requiredTextParameter(Labels.withId(InfluxDbClient.USERNAME))
- .requiredSecret(Labels.withId(InfluxDbClient.PASSWORD))
- .requiredIntegerParameter(Labels.withId(POLLING_INTERVAL))
- .requiredSingleValueSelection(Labels.withId(InfluxDbClient.REPLACE_NULL_VALUES),
- Options.from(
- new Tuple2<>("Yes", InfluxDbClient.DO_REPLACE),
- new Tuple2<>("No", InfluxDbClient.DO_NOT_REPLACE)))
- .build();
-
- description.setAppId(ID);
- return description;
- }
+ PollingThread(InfluxDbStreamAdapter influxDbStreamAdapter, int pollingInterval) throws AdapterException {
+ this.pollingInterval = pollingInterval;
+ this.influxDbStreamAdapter = influxDbStreamAdapter;
+ this.influxDbClient = influxDbStreamAdapter.getInfluxDbClient();
- @Override
- public void startAdapter() throws AdapterException {
- pollingThread = new Thread(new PollingThread(this, pollingInterval));
- pollingThread.start();
+ influxDbClient.connect();
+ influxDbClient.loadColumns();
}
@Override
- public void stopAdapter() throws AdapterException {
- // Signaling the thread to stop and then disconnect from the server
- pollingThread.interrupt();
+ public void run() {
+ if (!influxDbClient.isConnected()) {
+ System.out.println("Cannot start PollingThread, when the client is not connected");
+ return;
+ }
+ // Checking the most recent timestamp
+ // Timestamp is a string, because a long might not be big enough (it includes nano seconds)
+ String lastTimestamp;
+ try {
+ lastTimestamp = getNewestTimestamp();
+ } catch (SpRuntimeException e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+
+ while (!Thread.interrupted()) {
try {
- pollingThread.join();
+ Thread.sleep(pollingInterval);
} catch (InterruptedException e) {
- throw new AdapterException("Unexpected Error while joining polling thread: " + e.getMessage());
+ break;
}
- }
-
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new InfluxDbStreamAdapter(adapterDescription);
- }
+ List<List<Object>> queryResult = influxDbClient.query("SELECT " + influxDbClient.getColumnsString()
+ + " FROM " + influxDbClient.getMeasurement() + " WHERE time > " + lastTimestamp + " ORDER BY time ASC ");
+ if (queryResult.size() > 0) {
+ // The last element has the highest timestamp (ordered asc) -> Set the new latest timestamp
+ lastTimestamp = InfluxDbClient.getTimestamp((String) queryResult.get(queryResult.size() - 1).get(0));
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
- throws AdapterException, ParseException {
- getConfigurations(adapterDescription);
- return influxDbClient.getSchema();
- }
-
- @Override
- public String getId() {
- return ID;
+ for (List<Object> value : queryResult) {
+ try {
+ Map<String, Object> out = influxDbClient.extractEvent(value);
+ if (out != null) {
+ influxDbStreamAdapter.send(out);
+ }
+ } catch (SpRuntimeException e) {
+ System.out.println("Error: " + e.getMessage());
+ }
+ }
+ }
+ }
+ influxDbClient.disconnect();
}
- private void send(Map<String, Object> map) {
- adapterPipeline.process(map);
+ // Returns the newest timestamp in the measurement as unix timestamp in Nanoseconds.
+ // If no entry is found, a SpRuntimeException is thrown
+ String getNewestTimestamp() throws SpRuntimeException {
+ List<List<Object>> queryResult = influxDbClient.query("SELECT * FROM " + influxDbClient.getMeasurement()
+ + " ORDER BY time DESC LIMIT 1");
+ if (queryResult.size() > 0) {
+ return InfluxDbClient.getTimestamp((String) queryResult.get(0).get(0));
+ } else {
+ throw new SpRuntimeException("No entry found in query");
+ }
}
-
- private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) {
- ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
-
- pollingInterval = extractor.singleValue(POLLING_INTERVAL, Integer.class);
- String replace = extractor.selectedSingleValueInternalName(InfluxDbClient.REPLACE_NULL_VALUES);
-
- influxDbClient = new InfluxDbClient(
- extractor.singleValue(InfluxDbClient.HOST, String.class),
- extractor.singleValue(InfluxDbClient.PORT, Integer.class),
- extractor.singleValue(InfluxDbClient.DATABASE, String.class),
- extractor.singleValue(InfluxDbClient.MEASUREMENT, String.class),
- extractor.singleValue(InfluxDbClient.USERNAME, String.class),
- extractor.secretValue(InfluxDbClient.PASSWORD),
- replace.equals(InfluxDbClient.DO_REPLACE));
-
+ }
+
+ private InfluxDbClient getInfluxDbClient() {
+ return influxDbClient;
+ }
+
+ public InfluxDbStreamAdapter() {
+ }
+
+ public InfluxDbStreamAdapter(SpecificAdapterStreamDescription specificAdapterStreamDescription) {
+ super(specificAdapterStreamDescription);
+
+ getConfigurations(specificAdapterStreamDescription);
+ }
+
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .requiredTextParameter(Labels.withId(InfluxDbClient.HOST))
+ .requiredIntegerParameter(Labels.withId(InfluxDbClient.PORT))
+ .requiredTextParameter(Labels.withId(InfluxDbClient.DATABASE))
+ .requiredTextParameter(Labels.withId(InfluxDbClient.MEASUREMENT))
+ .requiredTextParameter(Labels.withId(InfluxDbClient.USERNAME))
+ .requiredSecret(Labels.withId(InfluxDbClient.PASSWORD))
+ .requiredIntegerParameter(Labels.withId(POLLING_INTERVAL))
+ .requiredSingleValueSelection(Labels.withId(InfluxDbClient.REPLACE_NULL_VALUES),
+ Options.from(
+ new Tuple2<>("Yes", InfluxDbClient.DO_REPLACE),
+ new Tuple2<>("No", InfluxDbClient.DO_NOT_REPLACE)))
+ .build();
+
+ description.setAppId(ID);
+ return description;
+ }
+
+ @Override
+ public void startAdapter() throws AdapterException {
+ pollingThread = new Thread(new PollingThread(this, pollingInterval));
+ pollingThread.start();
+ }
+
+ @Override
+ public void stopAdapter() throws AdapterException {
+ // Signaling the thread to stop and then disconnect from the server
+ pollingThread.interrupt();
+ try {
+ pollingThread.join();
+ } catch (InterruptedException e) {
+ throw new AdapterException("Unexpected Error while joining polling thread: " + e.getMessage());
}
+ }
+
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new InfluxDbStreamAdapter(adapterDescription);
+ }
+
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
+ getConfigurations(adapterDescription);
+ return influxDbClient.getSchema();
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ private void send(Map<String, Object> map) {
+ adapterPipeline.process(map);
+ }
+
+ private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) {
+ ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
+
+ pollingInterval = extractor.singleValue(POLLING_INTERVAL, Integer.class);
+ String replace = extractor.selectedSingleValueInternalName(InfluxDbClient.REPLACE_NULL_VALUES);
+
+ influxDbClient = new InfluxDbClient(
+ extractor.singleValue(InfluxDbClient.HOST, String.class),
+ extractor.singleValue(InfluxDbClient.PORT, Integer.class),
+ extractor.singleValue(InfluxDbClient.DATABASE, String.class),
+ extractor.singleValue(InfluxDbClient.MEASUREMENT, String.class),
+ extractor.singleValue(InfluxDbClient.USERNAME, String.class),
+ extractor.secretValue(InfluxDbClient.PASSWORD),
+ replace.equals(InfluxDbClient.DO_REPLACE));
+
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/MiloOpcUaConfigurationProvider.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/MiloOpcUaConfigurationProvider.java
index 7145858ea..55ccc0907 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/MiloOpcUaConfigurationProvider.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/MiloOpcUaConfigurationProvider.java
@@ -20,6 +20,7 @@ package org.apache.streampipes.connect.iiot.adapters.opcua;
import org.apache.streampipes.commons.exceptions.SpConfigurationException;
import org.apache.streampipes.connect.iiot.adapters.opcua.configuration.SpOpcUaConfig;
+
import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfigBuilder;
import org.eclipse.milo.opcua.sdk.client.api.identity.UsernameProvider;
@@ -36,24 +37,25 @@ import java.util.concurrent.ExecutionException;
public class MiloOpcUaConfigurationProvider {
- public OpcUaClientConfig makeClientConfig(SpOpcUaConfig spOpcConfig) throws ExecutionException, InterruptedException, SpConfigurationException, URISyntaxException {
+ public OpcUaClientConfig makeClientConfig(SpOpcUaConfig spOpcConfig)
+ throws ExecutionException, InterruptedException, SpConfigurationException, URISyntaxException {
String opcServerUrl = spOpcConfig.getOpcServerURL();
List<EndpointDescription> endpoints = DiscoveryClient.getEndpoints(opcServerUrl).get();
String host = opcServerUrl.split("://")[1].split(":")[0];
EndpointDescription tmpEndpoint = endpoints
- .stream()
- .filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getUri()))
- .findFirst()
- .orElseThrow(() -> new SpConfigurationException("No endpoint with security policy none"));
+ .stream()
+ .filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getUri()))
+ .findFirst()
+ .orElseThrow(() -> new SpConfigurationException("No endpoint with security policy none"));
tmpEndpoint = updateEndpointUrl(tmpEndpoint, host);
endpoints = Collections.singletonList(tmpEndpoint);
EndpointDescription endpoint = endpoints
- .stream()
- .filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getUri()))
- .findFirst().orElseThrow(() -> new SpConfigurationException("no desired endpoints returned"));
+ .stream()
+ .filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getUri()))
+ .findFirst().orElseThrow(() -> new SpConfigurationException("no desired endpoints returned"));
return buildConfig(endpoint, spOpcConfig);
}
@@ -70,33 +72,33 @@ public class MiloOpcUaConfigurationProvider {
private OpcUaClientConfigBuilder defaultBuilder(EndpointDescription endpoint) {
return OpcUaClientConfig.builder()
- .setApplicationName(LocalizedText.english("eclipse milo opc-ua client"))
- .setApplicationUri("urn:eclipse:milo:examples:client")
- .setEndpoint(endpoint);
+ .setApplicationName(LocalizedText.english("eclipse milo opc-ua client"))
+ .setApplicationUri("urn:eclipse:milo:examples:client")
+ .setEndpoint(endpoint);
}
private EndpointDescription updateEndpointUrl(
- EndpointDescription original, String hostname) throws URISyntaxException {
+ EndpointDescription original, String hostname) throws URISyntaxException {
URI uri = new URI(original.getEndpointUrl()).parseServerAuthority();
String endpointUrl = String.format(
- "%s://%s:%s%s",
- uri.getScheme(),
- hostname,
- uri.getPort(),
- uri.getPath()
+ "%s://%s:%s%s",
+ uri.getScheme(),
+ hostname,
+ uri.getPort(),
+ uri.getPath()
);
return new EndpointDescription(
- endpointUrl,
- original.getServer(),
- original.getServerCertificate(),
- original.getSecurityMode(),
- original.getSecurityPolicyUri(),
- original.getUserIdentityTokens(),
- original.getTransportProfileUri(),
- original.getSecurityLevel()
+ endpointUrl,
+ original.getServer(),
+ original.getServerCertificate(),
+ original.getSecurityMode(),
+ original.getSecurityPolicyUri(),
+ original.getUserIdentityTokens(),
+ original.getTransportProfileUri(),
+ original.getSecurityLevel()
);
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcNode.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcNode.java
index 99c8da6d1..7bbe9e3e6 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcNode.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/OpcNode.java
@@ -18,109 +18,112 @@
package org.apache.streampipes.connect.iiot.adapters.opcua;
-import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.apache.streampipes.sdk.utils.Datatypes;
+import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
+
/**
* OpcNode is a StreamPipes internal model of an OPC UA node.
* It's main purpose is to ease the handling of nodes within StreamPipes.
*/
public class OpcNode {
- String label;
- Datatypes type;
- NodeId nodeId;
- int opcUnitId;
- private boolean readable;
-
- /**
- * Constructor for class OpcNode without an OPC UA unit identifier. <br>
- * Unit identifier is set to zero as default.
- *
- * @param label name of the OPC UA node
- * @param type datatype of the OPC UA node
- * @param nodeId identifier of the OPC UA node
- */
- public OpcNode(String label, Datatypes type, NodeId nodeId) {
- this.label = label;
- this.type = type;
- this.nodeId = nodeId;
- this.opcUnitId = 0;
- }
-
- /**
- * Constructor for class OpcNode with an OPC UA unit identifier. <br>
- * This identifier references to an OPC UA measurement unit, e.g. degree celsius. <br>
- * With {@link OpcNode#getQudtURI()} the OPC UA internal ID is mapped to the QUDT unit ontology <br>
- *
- * @param label name of the OPC UA node
- * @param type datatype of the OPC UA node
- * @param nodeId identifier of the OPC UA node
- * @param opcUnitId OPC UA internal unit identifier
- */
- public OpcNode(String label, Datatypes type, NodeId nodeId, Integer opcUnitId){
- this.label = label;
- this.type = type;
- this.nodeId = nodeId;
- this.opcUnitId = opcUnitId;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- public Datatypes getType() {
- return type;
- }
-
- public void setType(Datatypes type) {
- this.type = type;
- }
-
- public NodeId getNodeId() {
- return nodeId;
- }
-
- public void setNodeId(NodeId nodeId) {
- this.nodeId = nodeId;
- }
-
- public int getOpcUnitId() {return this.opcUnitId;}
-
- public boolean hasUnitId() {
- // zero is the default case when no unit id is present
- return this.opcUnitId !=0;
- }
-
- public boolean isReadable() {
- return readable;
- }
-
- public void setReadable(boolean readable) {
- this.readable = readable;
- }
-
- /**
- * Returns the corresponding QUDT URI if the {@code opcUnitId} is given,
- * otherwise it returns an empty string. <br>
- * Currently, there are only two examples added. <br>
- * Other units have to be added manually, please have a look at the <a href="http://opcfoundation.org/UA/EngineeringUnits/UNECE/UNECE_to_OPCUA.csv"> OPC UA unitID mapping table</a>. <br>
- *
- * @return QUDT URI as string of the given unit
- */
-
- public String getQudtURI(){
- switch (this.opcUnitId){
- case 17476:
- return "http://qudt.org/vocab/unit#DEG";
- case 4408652:
- return "http://qudt.org/vocab/unit#DegreeCelsius";
- default:
- return "";
- }
+ String label;
+ Datatypes type;
+ NodeId nodeId;
+ int opcUnitId;
+ private boolean readable;
+
+ /**
+ * Constructor for class OpcNode without an OPC UA unit identifier. <br>
+ * Unit identifier is set to zero as default.
+ *
+ * @param label name of the OPC UA node
+ * @param type datatype of the OPC UA node
+ * @param nodeId identifier of the OPC UA node
+ */
+ public OpcNode(String label, Datatypes type, NodeId nodeId) {
+ this.label = label;
+ this.type = type;
+ this.nodeId = nodeId;
+ this.opcUnitId = 0;
+ }
+
+ /**
+ * Constructor for class OpcNode with an OPC UA unit identifier. <br>
+ * This identifier references to an OPC UA measurement unit, e.g. degree celsius. <br>
+ * With {@link OpcNode#getQudtURI()} the OPC UA internal ID is mapped to the QUDT unit ontology <br>
+ *
+ * @param label name of the OPC UA node
+ * @param type datatype of the OPC UA node
+ * @param nodeId identifier of the OPC UA node
+ * @param opcUnitId OPC UA internal unit identifier
+ */
+ public OpcNode(String label, Datatypes type, NodeId nodeId, Integer opcUnitId) {
+ this.label = label;
+ this.type = type;
+ this.nodeId = nodeId;
+ this.opcUnitId = opcUnitId;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public Datatypes getType() {
+ return type;
+ }
+
+ public void setType(Datatypes type) {
+ this.type = type;
+ }
+
+ public NodeId getNodeId() {
+ return nodeId;
+ }
+
+ public void setNodeId(NodeId nodeId) {
+ this.nodeId = nodeId;
+ }
+
+ public int getOpcUnitId() {
+ return this.opcUnitId;
+ }
+
+ public boolean hasUnitId() {
+ // zero is the default case when no unit id is present
+ return this.opcUnitId != 0;
+ }
+
+ public boolean isReadable() {
+ return readable;
+ }
+
+ public void setReadable(boolean readable) {
+ this.readable = readable;
+ }
+
+ /**
+ * Returns the corresponding QUDT URI if the {@code opcUnitId} is given,
+ * otherwise it returns an empty string. <br>
+ * Currently, there are only two examples added. <br>
+ * Other units have to be added manually, please have a look at the <a href="http://opcfoundation.org/UA/EngineeringUnits/UNECE/UNECE_to_OPCUA.csv"> OPC UA unitID mapping table</a>. <br>
+ *
+ * @return QUDT URI as string of the given unit
+ */
+
+ public String getQudtURI() {
+ switch (this.opcUnitId) {
+ case 17476:
+ return "http://qudt.org/vocab/unit#DEG";
+ case 4408652:
+ return "http://qudt.org/vocab/unit#DegreeCelsius";
+ default:
+ return "";
}
+ }
}
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 293e2daf0..6ecc00456 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
@@ -40,6 +40,7 @@ import org.apache.streampipes.sdk.helpers.Alternatives;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
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;
@@ -48,7 +49,11 @@ import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -56,224 +61,225 @@ import java.util.stream.Collectors;
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;
- private List<OpcNode> allNodes;
- private List<NodeId> allNodeIds;
- private int numberProperties;
- private final Map<String, Object> event;
-
- /**
- * This variable is used to map the node ids during the subscription to the labels of the nodes
- */
- private final Map<String, String> nodeIdToLabelMapping;
-
- public OpcUaAdapter() {
- super();
- this.numberProperties = 0;
- this.event = new HashMap<>();
- this.nodeIdToLabelMapping = new HashMap<>();
- }
-
- public OpcUaAdapter(SpecificAdapterStreamDescription adapterStreamDescription) {
- super(adapterStreamDescription);
- this.numberProperties = 0;
- this.event = new HashMap<>();
- this.nodeIdToLabelMapping = new HashMap<>();
+ 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;
+ private List<OpcNode> allNodes;
+ private List<NodeId> allNodeIds;
+ private int numberProperties;
+ private final Map<String, Object> event;
+
+ /**
+ * This variable is used to map the node ids during the subscription to the labels of the nodes
+ */
+ private final Map<String, String> nodeIdToLabelMapping;
+
+ public OpcUaAdapter() {
+ super();
+ this.numberProperties = 0;
+ this.event = new HashMap<>();
+ this.nodeIdToLabelMapping = new HashMap<>();
+ }
+
+ public OpcUaAdapter(SpecificAdapterStreamDescription adapterStreamDescription) {
+ super(adapterStreamDescription);
+ this.numberProperties = 0;
+ this.event = new HashMap<>();
+ this.nodeIdToLabelMapping = new HashMap<>();
+ }
+
+ @Override
+ protected void before() throws AdapterException {
+
+ this.allNodeIds = new ArrayList<>();
+ List<String> deleteKeys = this.adapterDescription
+ .getSchemaRules()
+ .stream()
+ .filter(rule -> rule instanceof DeleteRuleDescription)
+ .map(rule -> ((DeleteRuleDescription) rule).getRuntimeKey())
+ .collect(Collectors.toList());
+
+ try {
+ this.spOpcUaClient.connect();
+ OpcUaNodeBrowser browserClient =
+ new OpcUaNodeBrowser(this.spOpcUaClient.getClient(), this.spOpcUaClient.getSpOpcConfig());
+ this.allNodes = browserClient.findNodes(deleteKeys);
+
+
+ for (OpcNode node : this.allNodes) {
+ this.allNodeIds.add(node.nodeId);
+ }
+
+ if (spOpcUaClient.inPullMode()) {
+ this.pullingIntervalMilliSeconds = spOpcUaClient.getPullIntervalMilliSeconds();
+ } else {
+ this.numberProperties = this.allNodeIds.size();
+ this.spOpcUaClient.createListSubscription(this.allNodeIds, this);
+ }
+
+ this.allNodes.forEach(node -> this.nodeIdToLabelMapping.put(node.getNodeId().toString(), node.getLabel()));
+
+
+ } catch (Exception e) {
+ throw new AdapterException("The Connection to the OPC UA server could not be established.", e.getCause());
}
+ }
- @Override
- protected void before() throws AdapterException {
-
- this.allNodeIds = new ArrayList<>();
- List<String> deleteKeys = this.adapterDescription
- .getSchemaRules()
- .stream()
- .filter(rule -> rule instanceof DeleteRuleDescription)
- .map(rule -> ((DeleteRuleDescription) rule).getRuntimeKey())
- .collect(Collectors.toList());
-
- try {
- this.spOpcUaClient.connect();
- OpcUaNodeBrowser browserClient =
- new OpcUaNodeBrowser(this.spOpcUaClient.getClient(), this.spOpcUaClient.getSpOpcConfig());
- this.allNodes = browserClient.findNodes(deleteKeys);
-
-
- for (OpcNode node : this.allNodes) {
- this.allNodeIds.add(node.nodeId);
- }
-
- if (spOpcUaClient.inPullMode()) {
- this.pullingIntervalMilliSeconds = spOpcUaClient.getPullIntervalMilliSeconds();
- } else {
- this.numberProperties = this.allNodeIds.size();
- this.spOpcUaClient.createListSubscription(this.allNodeIds, this);
- }
+ @Override
+ public void startAdapter() throws AdapterException {
- this.allNodes.forEach(node -> this.nodeIdToLabelMapping.put(node.getNodeId().toString(), node.getLabel()));
+ this.spOpcUaClient = new SpOpcUaClient(SpOpcUaConfigBuilder.from(this.adapterDescription));
-
- } catch (Exception e) {
- throw new AdapterException("The Connection to the OPC UA server could not be established.", e.getCause());
- }
- }
-
- @Override
- public void startAdapter() throws AdapterException {
-
- this.spOpcUaClient = new SpOpcUaClient(SpOpcUaConfigBuilder.from(this.adapterDescription));
-
- if (this.spOpcUaClient.inPullMode()) {
- super.startAdapter();
- } else {
- this.before();
- }
+ if (this.spOpcUaClient.inPullMode()) {
+ super.startAdapter();
+ } else {
+ this.before();
}
+ }
- @Override
- public void stopAdapter() throws AdapterException {
- // close connection
- this.spOpcUaClient.disconnect();
-
- if (this.spOpcUaClient.inPullMode()) {
- super.stopAdapter();
- }
- }
+ @Override
+ public void stopAdapter() throws AdapterException {
+ // close connection
+ this.spOpcUaClient.disconnect();
- @Override
- protected void pullData() throws ExecutionException, RuntimeException, InterruptedException, TimeoutException {
- var response =
- this.spOpcUaClient.getClient().readValues(0, TimestampsToReturn.Both, this.allNodeIds);
- boolean badStatusCodeReceived = false;
- boolean emptyValueReceived = false;
- List<DataValue> returnValues = response.get(this.getPollingInterval().getValue(), this.getPollingInterval().getTimeUnit());
- 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());
- }
- }
- }
- if (!badStatusCodeReceived && !emptyValueReceived) {
- adapterPipeline.process(this.event);
- }
+ if (this.spOpcUaClient.inPullMode()) {
+ super.stopAdapter();
}
-
- public void onSubscriptionValue(UaMonitoredItem item, DataValue value) {
-
- String key = this.nodeIdToLabelMapping.get(item.getReadValueId().getNodeId().toString());
-
- OpcNode currNode = this.allNodes.stream()
- .filter(node -> key.equals(node.getLabel()))
- .findFirst()
- .orElse(null);
-
- if (currNode != null) {
- event.put(currNode.getLabel(), value.getValue().getValue());
-
- // ensure that event is complete and all opc ua subscriptions transmitted at least one value
- if (event.keySet().size() >= this.numberProperties) {
- Map<String, Object> newEvent = new HashMap<>();
- // deep copy of event to prevent preprocessor error
- for (String k : event.keySet()) {
- newEvent.put(k, event.get(k));
- }
- adapterPipeline.process(newEvent);
- }
+ }
+
+ @Override
+ protected void pullData() throws ExecutionException, RuntimeException, InterruptedException, TimeoutException {
+ var response =
+ this.spOpcUaClient.getClient().readValues(0, TimestampsToReturn.Both, this.allNodeIds);
+ boolean badStatusCodeReceived = false;
+ boolean emptyValueReceived = false;
+ List<DataValue> returnValues =
+ response.get(this.getPollingInterval().getValue(), this.getPollingInterval().getTimeUnit());
+ 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 {
- LOG.error("No event is produced, because subscription item {} could not be found within all nodes", item);
+ badStatusCodeReceived = true;
+ LOG.warn("Received status code {} for node label: {} - event will not be sent",
+ status,
+ this.allNodes.get(i).getLabel());
}
+ }
}
-
- @Override
- protected PollingSettings getPollingInterval() {
- return PollingSettings.from(TimeUnit.MILLISECONDS, this.pullingIntervalMilliSeconds);
+ if (!badStatusCodeReceived && !emptyValueReceived) {
+ adapterPipeline.process(this.event);
}
+ }
- @Override
- public SpecificAdapterStreamDescription declareModel() {
-
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder
- .create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Generic, AdapterType.Manufacturing)
- .requiredAlternatives(Labels.withId(OpcUaLabels.ADAPTER_TYPE.name()),
- Alternatives.from(Labels.withId(OpcUaLabels.PULL_MODE.name()),
- StaticProperties.integerFreeTextProperty(
- Labels.withId(OpcUaLabels.PULLING_INTERVAL.name()))),
- Alternatives.from(Labels.withId(OpcUaLabels.SUBSCRIPTION_MODE.name())))
- .requiredAlternatives(Labels.withId(OpcUaLabels.ACCESS_MODE.name()),
- Alternatives.from(Labels.withId(OpcUaLabels.UNAUTHENTICATED.name())),
- Alternatives.from(Labels.withId(OpcUaLabels.USERNAME_GROUP.name()),
- StaticProperties.group(
- Labels.withId(OpcUaLabels.USERNAME_GROUP.name()),
- StaticProperties.stringFreeTextProperty(
- Labels.withId(OpcUaLabels.USERNAME.name())),
- StaticProperties.secretValue(Labels.withId(OpcUaLabels.PASSWORD.name()))
- ))
- )
- .requiredAlternatives(Labels.withId(OpcUaLabels.OPC_HOST_OR_URL.name()),
- Alternatives.from(
- Labels.withId(OpcUaLabels.OPC_URL.name()),
- StaticProperties.stringFreeTextProperty(
- Labels.withId(OpcUaLabels.OPC_SERVER_URL.name()), "opc.tcp://localhost:4840"))
- ,
- Alternatives.from(Labels.withId(OpcUaLabels.OPC_HOST.name()),
- StaticProperties.group(
- Labels.withId("host-port"),
- StaticProperties.stringFreeTextProperty(
- Labels.withId(OpcUaLabels.OPC_SERVER_HOST.name())),
- StaticProperties.stringFreeTextProperty(
- Labels.withId(OpcUaLabels.OPC_SERVER_PORT.name()))
- ))
- )
- .requiredTextParameter(Labels.withId(OpcUaLabels.NAMESPACE_INDEX.name()))
- .requiredTextParameter(Labels.withId(OpcUaLabels.NODE_ID.name()))
- .requiredRuntimeResolvableTreeInput(
- Labels.withId(OpcUaLabels.AVAILABLE_NODES.name()),
- Arrays.asList(OpcUaLabels.NAMESPACE_INDEX.name(), OpcUaLabels.NODE_ID.name())
- )
- .build();
-
- description.setAppId(ID);
-
- return description;
- }
+ public void onSubscriptionValue(UaMonitoredItem item, DataValue value) {
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new OpcUaAdapter(adapterDescription);
- }
+ String key = this.nodeIdToLabelMapping.get(item.getReadValueId().getNodeId().toString());
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
- throws AdapterException, ParseException {
- return OpcUaUtil.getSchema(adapterDescription);
- }
+ OpcNode currNode = this.allNodes.stream()
+ .filter(node -> key.equals(node.getLabel()))
+ .findFirst()
+ .orElse(null);
- @Override
- public String getId() {
- return ID;
- }
+ if (currNode != null) {
+ event.put(currNode.getLabel(), value.getValue().getValue());
- @Override
- public StaticProperty resolveConfiguration(String staticPropertyInternalName,
- StaticPropertyExtractor extractor) throws SpConfigurationException {
- return OpcUaUtil.resolveConfiguration(staticPropertyInternalName, extractor);
+ // ensure that event is complete and all opc ua subscriptions transmitted at least one value
+ if (event.keySet().size() >= this.numberProperties) {
+ Map<String, Object> newEvent = new HashMap<>();
+ // deep copy of event to prevent preprocessor error
+ for (String k : event.keySet()) {
+ newEvent.put(k, event.get(k));
+ }
+ adapterPipeline.process(newEvent);
+ }
+ } else {
+ LOG.error("No event is produced, because subscription item {} could not be found within all nodes", item);
}
+ }
+
+ @Override
+ protected PollingSettings getPollingInterval() {
+ return PollingSettings.from(TimeUnit.MILLISECONDS, this.pullingIntervalMilliSeconds);
+ }
+
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder
+ .create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Generic, AdapterType.Manufacturing)
+ .requiredAlternatives(Labels.withId(OpcUaLabels.ADAPTER_TYPE.name()),
+ Alternatives.from(Labels.withId(OpcUaLabels.PULL_MODE.name()),
+ StaticProperties.integerFreeTextProperty(
+ Labels.withId(OpcUaLabels.PULLING_INTERVAL.name()))),
+ Alternatives.from(Labels.withId(OpcUaLabels.SUBSCRIPTION_MODE.name())))
+ .requiredAlternatives(Labels.withId(OpcUaLabels.ACCESS_MODE.name()),
+ Alternatives.from(Labels.withId(OpcUaLabels.UNAUTHENTICATED.name())),
+ Alternatives.from(Labels.withId(OpcUaLabels.USERNAME_GROUP.name()),
+ StaticProperties.group(
+ Labels.withId(OpcUaLabels.USERNAME_GROUP.name()),
+ StaticProperties.stringFreeTextProperty(
+ Labels.withId(OpcUaLabels.USERNAME.name())),
+ StaticProperties.secretValue(Labels.withId(OpcUaLabels.PASSWORD.name()))
+ ))
+ )
+ .requiredAlternatives(Labels.withId(OpcUaLabels.OPC_HOST_OR_URL.name()),
+ Alternatives.from(
+ Labels.withId(OpcUaLabels.OPC_URL.name()),
+ StaticProperties.stringFreeTextProperty(
+ Labels.withId(OpcUaLabels.OPC_SERVER_URL.name()), "opc.tcp://localhost:4840"))
+ ,
+ Alternatives.from(Labels.withId(OpcUaLabels.OPC_HOST.name()),
+ StaticProperties.group(
+ Labels.withId("host-port"),
+ StaticProperties.stringFreeTextProperty(
+ Labels.withId(OpcUaLabels.OPC_SERVER_HOST.name())),
+ StaticProperties.stringFreeTextProperty(
+ Labels.withId(OpcUaLabels.OPC_SERVER_PORT.name()))
+ ))
+ )
+ .requiredTextParameter(Labels.withId(OpcUaLabels.NAMESPACE_INDEX.name()))
+ .requiredTextParameter(Labels.withId(OpcUaLabels.NODE_ID.name()))
+ .requiredRuntimeResolvableTreeInput(
+ Labels.withId(OpcUaLabels.AVAILABLE_NODES.name()),
+ Arrays.asList(OpcUaLabels.NAMESPACE_INDEX.name(), OpcUaLabels.NODE_ID.name())
+ )
+ .build();
+
+ description.setAppId(ID);
+
+ return description;
+ }
+
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new OpcUaAdapter(adapterDescription);
+ }
+
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
+ return OpcUaUtil.getSchema(adapterDescription);
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ @Override
+ public StaticProperty resolveConfiguration(String staticPropertyInternalName,
+ StaticPropertyExtractor extractor) throws SpConfigurationException {
+ return OpcUaUtil.resolveConfiguration(staticPropertyInternalName, extractor);
+ }
}
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 c1cbc202e..16be0f149 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
@@ -21,6 +21,7 @@ package org.apache.streampipes.connect.iiot.adapters.opcua;
import org.apache.streampipes.connect.iiot.adapters.opcua.configuration.SpOpcUaConfig;
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.nodes.UaNode;
@@ -55,7 +56,7 @@ public class OpcUaNodeBrowser {
public List<OpcNode> findNodes() throws UaException {
var opcNodes = new ArrayList<OpcNode>();
- for(String selectedNodeName: this.spOpcConfig.getSelectedNodeNames()) {
+ for (String selectedNodeName : this.spOpcConfig.getSelectedNodeNames()) {
opcNodes.add(toOpcNode(selectedNodeName));
}
@@ -64,11 +65,11 @@ public class OpcUaNodeBrowser {
public List<OpcNode> findNodes(List<String> runtimeNameFilters) throws UaException {
return findNodes()
- .stream()
- .filter(node -> runtimeNameFilters
.stream()
- .noneMatch(f -> f.equals(node.getLabel())))
- .collect(Collectors.toList());
+ .filter(node -> runtimeNameFilters
+ .stream()
+ .noneMatch(f -> f.equals(node.getLabel())))
+ .collect(Collectors.toList());
}
public List<TreeInputNode> buildNodeTreeFromOrigin() throws UaException, ExecutionException, InterruptedException {
@@ -91,7 +92,7 @@ public class OpcUaNodeBrowser {
NodeId nodeId = NodeId.parse(nodeName);
UaNode node = addressSpace.getNode(nodeId);
- LOG.info("Using node of type {}", node.getNodeClass().toString() );
+ LOG.info("Using node of type {}", node.getNodeClass().toString());
if (node instanceof UaVariableNode) {
UInteger value = (UInteger) ((UaVariableNode) node).getDataType().getIdentifier();
@@ -116,7 +117,7 @@ public class OpcUaNodeBrowser {
});
Stream<CompletableFuture<Void>> futures =
- tree.getChildren().stream().map(child -> buildTreeAsync(client, child));
+ tree.getChildren().stream().map(child -> buildTreeAsync(client, child));
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
});
@@ -127,6 +128,7 @@ public class OpcUaNodeBrowser {
}
private boolean isDataNode(UaNode node) {
- return (node.getNodeClass().equals(NodeClass.Variable) || (node.getNodeClass().equals(NodeClass.VariableType))) && node instanceof UaVariableNode;
+ return (node.getNodeClass().equals(NodeClass.Variable) || (node.getNodeClass().equals(NodeClass.VariableType)))
+ && node instanceof UaVariableNode;
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/SpOpcUaClient.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/SpOpcUaClient.java
index 299c4f04f..dd81ecde7 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/SpOpcUaClient.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/SpOpcUaClient.java
@@ -21,6 +21,7 @@ package org.apache.streampipes.connect.iiot.adapters.opcua;
import org.apache.streampipes.commons.exceptions.SpConfigurationException;
import org.apache.streampipes.connect.iiot.adapters.opcua.configuration.SpOpcUaConfig;
+
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
@@ -55,137 +56,138 @@ import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.
*/
public class SpOpcUaClient {
- private static final Logger LOG = LoggerFactory.getLogger(SpOpcUaClient.class);
-
- private OpcUaClient client;
- private final SpOpcUaConfig spOpcConfig;
+ private static final Logger LOG = LoggerFactory.getLogger(SpOpcUaClient.class);
+
+ private OpcUaClient client;
+ private final SpOpcUaConfig spOpcConfig;
+
+ private static final AtomicLong clientHandles = new AtomicLong(1L);
+
+ public SpOpcUaClient(SpOpcUaConfig config) {
+ this.spOpcConfig = config;
+ }
+
+ /***
+ *
+ * @return current {@link org.eclipse.milo.opcua.sdk.client.OpcUaClient}
+ */
+ public OpcUaClient getClient() {
+ return this.client;
+ }
+
+ /***
+ * Establishes appropriate connection to OPC UA endpoint depending on the {@link SpOpcUaClient} instance
+ *
+ * @throws UaException An exception occurring during OPC connection
+ */
+ public void connect()
+ throws UaException, ExecutionException, InterruptedException, SpConfigurationException, URISyntaxException {
+ OpcUaClientConfig clientConfig = new MiloOpcUaConfigurationProvider().makeClientConfig(spOpcConfig);
+ this.client = OpcUaClient.create(clientConfig);
+ client.connect().get();
+ }
+
+ public void disconnect() {
+ client.disconnect();
+ }
+
+ /***
+ * Register subscriptions for given OPC UA nodes
+ * @param nodes List of {@link org.eclipse.milo.opcua.stack.core.types.builtin.NodeId}
+ * @param opcUaAdapter current instance of {@link OpcUaAdapter}
+ * @throws Exception
+ */
+ public void createListSubscription(List<NodeId> nodes,
+ OpcUaAdapter opcUaAdapter) throws Exception {
+ client.getSubscriptionManager().addSubscriptionListener(new UaSubscriptionManager.SubscriptionListener() {
+ @Override
+ public void onSubscriptionTransferFailed(UaSubscription subscription, StatusCode statusCode) {
+ LOG.warn("Transfer for subscriptionId={} failed: {}", subscription.getSubscriptionId(), statusCode);
+ try {
+ initSubscription(nodes, opcUaAdapter);
+ } catch (Exception e) {
+ LOG.error("Re-creating the subscription failed", e);
+ }
+ }
+ });
- private static final AtomicLong clientHandles = new AtomicLong(1L);
+ initSubscription(nodes, opcUaAdapter);
+ }
- public SpOpcUaClient(SpOpcUaConfig config) {
- this.spOpcConfig = config;
- }
- /***
- *
- * @return current {@link org.eclipse.milo.opcua.sdk.client.OpcUaClient}
+ public void initSubscription(List<NodeId> nodes, OpcUaAdapter opcUaAdapter) throws Exception {
+ /*
+ * create a subscription @ 1000ms
*/
- public OpcUaClient getClient() {
- return this.client;
- }
+ UaSubscription subscription = this.client.getSubscriptionManager().createSubscription(1000.0).get();
- /***
- * Establishes appropriate connection to OPC UA endpoint depending on the {@link SpOpcUaClient} instance
- *
- * @throws UaException An exception occurring during OPC connection
- */
- public void connect() throws UaException, ExecutionException, InterruptedException, SpConfigurationException, URISyntaxException {
- OpcUaClientConfig clientConfig = new MiloOpcUaConfigurationProvider().makeClientConfig(spOpcConfig);
- this.client = OpcUaClient.create(clientConfig);
- client.connect().get();
- }
+ List<CompletableFuture<DataValue>> values = new ArrayList<>();
- public void disconnect() {
- client.disconnect();
+ for (NodeId node : nodes) {
+ values.add(this.client.readValue(0, TimestampsToReturn.Both, node));
}
- /***
- * Register subscriptions for given OPC UA nodes
- * @param nodes List of {@link org.eclipse.milo.opcua.stack.core.types.builtin.NodeId}
- * @param opcUaAdapter current instance of {@link OpcUaAdapter}
- * @throws Exception
- */
- public void createListSubscription(List<NodeId> nodes,
- OpcUaAdapter opcUaAdapter) throws Exception {
- client.getSubscriptionManager().addSubscriptionListener(new UaSubscriptionManager.SubscriptionListener() {
- @Override
- public void onSubscriptionTransferFailed(UaSubscription subscription, StatusCode statusCode) {
- LOG.warn("Transfer for subscriptionId={} failed: {}", subscription.getSubscriptionId(), statusCode);
- try {
- initSubscription(nodes, opcUaAdapter);
- } catch (Exception e) {
- LOG.error("Re-creating the subscription failed", e);
- }
- }
- });
-
- initSubscription(nodes, opcUaAdapter);
+ for (CompletableFuture<DataValue> value : values) {
+ if (value.get().getValue().toString().contains("null")) {
+ LOG.error("Node has no value");
+ }
}
- public void initSubscription(List<NodeId> nodes, OpcUaAdapter opcUaAdapter) throws Exception {
- /*
- * create a subscription @ 1000ms
- */
- UaSubscription subscription = this.client.getSubscriptionManager().createSubscription(1000.0).get();
-
- List<CompletableFuture<DataValue>> values = new ArrayList<>();
-
- for (NodeId node : nodes) {
- values.add(this.client.readValue(0, TimestampsToReturn.Both, node));
- }
-
- for (CompletableFuture<DataValue> value : values) {
- if (value.get().getValue().toString().contains("null")) {
- LOG.error("Node has no value");
- }
- }
-
-
- List<ReadValueId> readValues = new ArrayList<>();
- // Read a specific value attribute
- for (NodeId node : nodes) {
- readValues.add(new ReadValueId(node, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE));
- }
+ List<ReadValueId> readValues = new ArrayList<>();
+ // Read a specific value attribute
+ for (NodeId node : nodes) {
+ readValues.add(new ReadValueId(node, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE));
+ }
- List<MonitoredItemCreateRequest> requests = new ArrayList<>();
+ List<MonitoredItemCreateRequest> requests = new ArrayList<>();
- for (ReadValueId readValue : readValues) {
- // important: client handle must be unique per item
- UInteger clientHandle = uint(clientHandles.getAndIncrement());
+ for (ReadValueId readValue : readValues) {
+ // important: client handle must be unique per item
+ UInteger clientHandle = uint(clientHandles.getAndIncrement());
- MonitoringParameters parameters = new MonitoringParameters(
- clientHandle,
- 1000.0, // sampling interval
- null, // filter, null means use default
- uint(10), // queue size
- true // discard oldest
- );
+ MonitoringParameters parameters = new MonitoringParameters(
+ clientHandle,
+ 1000.0, // sampling interval
+ null, // filter, null means use default
+ uint(10), // queue size
+ true // discard oldest
+ );
- requests.add(new MonitoredItemCreateRequest(readValue, MonitoringMode.Reporting, parameters));
- }
-
- UaSubscription.ItemCreationCallback onItemCreated = new UaSubscription.ItemCreationCallback() {
- @Override
- public void onItemCreated(UaMonitoredItem item, int i) {
- item.setValueConsumer(opcUaAdapter::onSubscriptionValue);
- }
- };
- List<UaMonitoredItem> items = subscription.createMonitoredItems(
- TimestampsToReturn.Both,
- requests,
- onItemCreated
- ).get();
-
- for (UaMonitoredItem item : items) {
- NodeId tagId = item.getReadValueId().getNodeId();
- if (item.getStatusCode().isGood()) {
- LOG.info("item created for nodeId="+ tagId);
- } else {
- LOG.error("failed to create item for " + item.getReadValueId().getNodeId() + item.getStatusCode());
- }
- }
+ requests.add(new MonitoredItemCreateRequest(readValue, MonitoringMode.Reporting, parameters));
}
- public boolean inPullMode() {
- return !(spOpcConfig.getPullIntervalMilliSeconds() == null);
+ UaSubscription.ItemCreationCallback onItemCreated = new UaSubscription.ItemCreationCallback() {
+ @Override
+ public void onItemCreated(UaMonitoredItem item, int i) {
+ item.setValueConsumer(opcUaAdapter::onSubscriptionValue);
+ }
+ };
+ List<UaMonitoredItem> items = subscription.createMonitoredItems(
+ TimestampsToReturn.Both,
+ requests,
+ onItemCreated
+ ).get();
+
+ for (UaMonitoredItem item : items) {
+ NodeId tagId = item.getReadValueId().getNodeId();
+ if (item.getStatusCode().isGood()) {
+ LOG.info("item created for nodeId=" + tagId);
+ } else {
+ LOG.error("failed to create item for " + item.getReadValueId().getNodeId() + item.getStatusCode());
+ }
}
+ }
- public int getPullIntervalMilliSeconds() {
- return spOpcConfig.getPullIntervalMilliSeconds();
- }
+ public boolean inPullMode() {
+ return !(spOpcConfig.getPullIntervalMilliSeconds() == null);
+ }
- public SpOpcUaConfig getSpOpcConfig() {
- return spOpcConfig;
- }
+ public int getPullIntervalMilliSeconds() {
+ return spOpcConfig.getPullIntervalMilliSeconds();
+ }
+
+ public SpOpcUaConfig getSpOpcConfig() {
+ return spOpcConfig;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfig.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfig.java
index a17548e5d..dcd65a1c8 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfig.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfig.java
@@ -20,6 +20,7 @@ package org.apache.streampipes.connect.iiot.adapters.opcua.configuration;
import org.apache.streampipes.connect.iiot.adapters.opcua.utils.OpcUaUtil;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
+
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import java.util.List;
@@ -44,11 +45,11 @@ public class SpOpcUaConfig {
/**
* Constructor for security level {@code None}, OPC server given by url and subscription-based
*
- * @param opcServerURL complete OPC UA server url
- * @param namespaceIndex namespace index of the given node
- * @param nodeId node identifier
+ * @param opcServerURL complete OPC UA server url
+ * @param namespaceIndex namespace index of the given node
+ * @param nodeId node identifier
* @param pullIntervalMilliSeconds duration of pull interval in milliseconds, {@code null} if in subscription mode
- * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)} (String, StaticPropertyExtractor)}
+ * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)} (String, StaticPropertyExtractor)}
*/
public SpOpcUaConfig(String opcServerURL,
int namespaceIndex,
@@ -73,12 +74,12 @@ public class SpOpcUaConfig {
/**
* Constructor for security level {@code None} and OPC server given by hostname and port number
*
- * @param opcServer OPC UA hostname
- * @param opcServerPort OPC UA port number
- * @param namespaceIndex namespace index of the given node
- * @param nodeId node identifier
+ * @param opcServer OPC UA hostname
+ * @param opcServerPort OPC UA port number
+ * @param namespaceIndex namespace index of the given node
+ * @param nodeId node identifier
* @param pullIntervalMilliSeconds duration of pull interval in milliseconds, {@code null} if in subscription mode
- * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)}
+ * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)}
*/
public SpOpcUaConfig(String opcServer,
int opcServerPort,
@@ -86,19 +87,19 @@ public class SpOpcUaConfig {
String nodeId,
Integer pullIntervalMilliSeconds,
List<String> selectedNodeNames) {
- this( opcServer + ":" + opcServerPort, namespaceIndex, nodeId, pullIntervalMilliSeconds, selectedNodeNames);
+ this(opcServer + ":" + opcServerPort, namespaceIndex, nodeId, pullIntervalMilliSeconds, selectedNodeNames);
}
/**
* Constructor for security level {@code Sign} and OPC server given by url
*
- * @param opcServerURL complete OPC UA server url
- * @param namespaceIndex namespace index of the given node
- * @param nodeId node identifier
- * @param username username to authenticate at the OPC UA server
- * @param password corresponding password to given user name
+ * @param opcServerURL complete OPC UA server url
+ * @param namespaceIndex namespace index of the given node
+ * @param nodeId node identifier
+ * @param username username to authenticate at the OPC UA server
+ * @param password corresponding password to given user name
* @param pullIntervalMilliSeconds duration of pull interval in milliseconds, {@code null} if in subscription mode
- * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)}
+ * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)}
*/
public SpOpcUaConfig(String opcServerURL,
int namespaceIndex,
@@ -116,14 +117,14 @@ public class SpOpcUaConfig {
/**
* Constructor for OPC UA security level {@code Sign} and OPC server given by hostname and port number
*
- * @param opcServer OPC UA hostname
- * @param opcServerPort OPC UA port number
- * @param namespaceIndex namespace index of the given node
- * @param nodeId node identifier
- * @param username username to authenticate at the OPC UA server
- * @param password corresponding password to given user name
+ * @param opcServer OPC UA hostname
+ * @param opcServerPort OPC UA port number
+ * @param namespaceIndex namespace index of the given node
+ * @param nodeId node identifier
+ * @param username username to authenticate at the OPC UA server
+ * @param password corresponding password to given user name
* @param pullIntervalMilliSeconds duration of pull interval in milliseconds, {@code null} if in subscription mode
- * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)}
+ * @param selectedNodeNames list of node names provided from {@link OpcUaUtil#resolveConfiguration(String, StaticPropertyExtractor)}
*/
public SpOpcUaConfig(String opcServer,
int opcServerPort,
@@ -133,7 +134,7 @@ public class SpOpcUaConfig {
String password,
int pullIntervalMilliSeconds,
List<String> selectedNodeNames) {
- this (opcServer, opcServerPort, namespaceIndex, nodeId, pullIntervalMilliSeconds, selectedNodeNames);
+ this(opcServer, opcServerPort, namespaceIndex, nodeId, pullIntervalMilliSeconds, selectedNodeNames);
this.unauthenticated = false;
this.username = username;
this.password = password;
@@ -206,7 +207,7 @@ public class SpOpcUaConfig {
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
- } catch(NumberFormatException | NullPointerException e) {
+ } catch (NumberFormatException | NullPointerException e) {
return false;
}
// only got here if we didn't return false
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfigBuilder.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfigBuilder.java
index f37d5a117..e0faeba0f 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfigBuilder.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/configuration/SpOpcUaConfigBuilder.java
@@ -29,36 +29,42 @@ public class SpOpcUaConfigBuilder {
/**
* Creates {@link SpOpcUaConfig} instance in accordance with the given {@link org.apache.streampipes.sdk.extractor.StaticPropertyExtractor}.
+ *
* @param extractor extractor for user inputs
* @return {@link SpOpcUaConfig} instance based on information from {@code extractor}
*/
public static SpOpcUaConfig from(StaticPropertyExtractor extractor) {
- String selectedAlternativeConnection = extractor.selectedAlternativeInternalId(OpcUaUtil.OpcUaLabels.OPC_HOST_OR_URL.name());
- String selectedAlternativeAuthentication = extractor.selectedAlternativeInternalId(OpcUaUtil.OpcUaLabels.ACCESS_MODE.name());
+ String selectedAlternativeConnection =
+ extractor.selectedAlternativeInternalId(OpcUaUtil.OpcUaLabels.OPC_HOST_OR_URL.name());
+ String selectedAlternativeAuthentication =
+ extractor.selectedAlternativeInternalId(OpcUaUtil.OpcUaLabels.ACCESS_MODE.name());
int namespaceIndex = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.NAMESPACE_INDEX.name(), int.class);
String nodeId = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.NODE_ID.name(), String.class);
- boolean usePullMode = extractor.selectedAlternativeInternalId(OpcUaUtil.OpcUaLabels.ADAPTER_TYPE.name()).equals(OpcUaUtil.OpcUaLabels.PULL_MODE.name());
+ boolean usePullMode = extractor.selectedAlternativeInternalId(OpcUaUtil.OpcUaLabels.ADAPTER_TYPE.name())
+ .equals(OpcUaUtil.OpcUaLabels.PULL_MODE.name());
boolean useURL = selectedAlternativeConnection.equals(OpcUaUtil.OpcUaLabels.OPC_URL.name());
- boolean unauthenticated = selectedAlternativeAuthentication.equals(OpcUaUtil.OpcUaLabels.UNAUTHENTICATED.name());
+ boolean unauthenticated = selectedAlternativeAuthentication.equals(OpcUaUtil.OpcUaLabels.UNAUTHENTICATED.name());
Integer pullIntervalSeconds = null;
if (usePullMode) {
- pullIntervalSeconds = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.PULLING_INTERVAL.name(), Integer.class);
+ pullIntervalSeconds =
+ extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.PULLING_INTERVAL.name(), Integer.class);
}
- List<String> selectedNodeNames = extractor.selectedTreeNodesInternalNames(OpcUaUtil.OpcUaLabels.AVAILABLE_NODES.name(), String.class, true);
+ List<String> selectedNodeNames =
+ extractor.selectedTreeNodesInternalNames(OpcUaUtil.OpcUaLabels.AVAILABLE_NODES.name(), String.class, true);
- if (useURL && unauthenticated){
+ if (useURL && unauthenticated) {
String serverAddress = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_URL.name(), String.class);
serverAddress = OpcUaUtil.formatServerAddress(serverAddress);
return new SpOpcUaConfig(serverAddress, namespaceIndex, nodeId, pullIntervalSeconds, selectedNodeNames);
- } else if(!useURL && unauthenticated){
+ } else if (!useURL && unauthenticated) {
String serverAddress = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_HOST.name(), String.class);
serverAddress = OpcUaUtil.formatServerAddress(serverAddress);
int port = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_PORT.name(), int.class);
@@ -70,16 +76,20 @@ public class SpOpcUaConfigBuilder {
String password = extractor.secretValue(OpcUaUtil.OpcUaLabels.PASSWORD.name());
if (useURL) {
- String serverAddress = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_URL.name(), String.class);
+ String serverAddress =
+ extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_URL.name(), String.class);
serverAddress = OpcUaUtil.formatServerAddress(serverAddress);
- return new SpOpcUaConfig(serverAddress, namespaceIndex, nodeId, username, password, pullIntervalSeconds, selectedNodeNames);
+ return new SpOpcUaConfig(serverAddress, namespaceIndex, nodeId, username, password, pullIntervalSeconds,
+ selectedNodeNames);
} else {
- String serverAddress = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_HOST.name(), String.class);
+ String serverAddress =
+ extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_HOST.name(), String.class);
serverAddress = OpcUaUtil.formatServerAddress(serverAddress);
int port = extractor.singleValueParameter(OpcUaUtil.OpcUaLabels.OPC_SERVER_PORT.name(), int.class);
- return new SpOpcUaConfig(serverAddress, port, namespaceIndex, nodeId, username, password, pullIntervalSeconds, selectedNodeNames);
+ return new SpOpcUaConfig(serverAddress, port, namespaceIndex, nodeId, username, password, pullIntervalSeconds,
+ selectedNodeNames);
}
}
}
@@ -89,10 +99,10 @@ public class SpOpcUaConfigBuilder {
* @param adapterDescription description of current adapter
* @return {@link SpOpcUaConfig} instance based on information from {@code adapterDescription}
*/
- public static SpOpcUaConfig from(AdapterDescription adapterDescription){
+ public static SpOpcUaConfig from(AdapterDescription adapterDescription) {
StaticPropertyExtractor extractor =
- StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+ StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
return from(extractor);
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaNodeVariants.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaNodeVariants.java
index 51700c489..b75c5ef3b 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaNodeVariants.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaNodeVariants.java
@@ -23,30 +23,31 @@ import javax.annotation.Nullable;
/**
* Enum that maintains different variants of OPC UA nodes. <br>
* Not yet completed. <br>
- *
*/
public enum OpcUaNodeVariants {
- Property(68),
- EUInformation(887);
+ Property(68),
+ EUInformation(887);
- // ID as specified in OPC UA standard
- private final int id;
+ // ID as specified in OPC UA standard
+ private final int id;
- private OpcUaNodeVariants(int id){
- this.id = id;
- }
+ private OpcUaNodeVariants(int id) {
+ this.id = id;
+ }
- public int getId() { return this.id;}
+ public int getId() {
+ return this.id;
+ }
- @Nullable
- public static OpcUaNodeVariants from(int id){
- switch (id){
- case 68:
- return Property;
- case 887:
- return EUInformation;
- default:
- return null;
- }
+ @Nullable
+ public static OpcUaNodeVariants from(int id) {
+ switch (id) {
+ case 68:
+ return Property;
+ case 887:
+ return EUInformation;
+ default:
+ return null;
}
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaTypes.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaTypes.java
index 0dc1efc39..388de51d0 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaTypes.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaTypes.java
@@ -18,40 +18,41 @@
package org.apache.streampipes.connect.iiot.adapters.opcua.utils;
+import org.apache.streampipes.sdk.utils.Datatypes;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
-import org.apache.streampipes.sdk.utils.Datatypes;
public class OpcUaTypes {
- /**
- * Maps OPC UA data types to internal StreamPipes data types
- * @param o data type id as UInteger
- * @return StreamPipes internal data type
- */
- public static Datatypes getType(UInteger o) {
- if (UInteger.valueOf(4).equals(o) |
- UInteger.valueOf(5).equals(o) |
- UInteger.valueOf(6).equals(o) |
- UInteger.valueOf(7).equals(o) |
- UInteger.valueOf(8).equals(o) |
- UInteger.valueOf(9).equals(o) |
- UInteger.valueOf(27).equals(o)) {
- return Datatypes.Integer;
- } else if (UInteger.valueOf(8).equals(o) ) {
- return Datatypes.Long;
- } else if (UInteger.valueOf(11).equals(o)) {
- return Datatypes.Double;
- } else if (UInteger.valueOf(10).equals(o) | UInteger.valueOf(26).equals(o) | UInteger.valueOf(50).equals(o)) {
- return Datatypes.Float;
- } else if (UInteger.valueOf(1).equals(o)) {
- return Datatypes.Boolean;
- } else if (UInteger.valueOf(12).equals(o)) {
- return Datatypes.String;
- }
-
- return Datatypes.String;
+ /**
+ * Maps OPC UA data types to internal StreamPipes data types
+ *
+ * @param o data type id as UInteger
+ * @return StreamPipes internal data type
+ */
+ public static Datatypes getType(UInteger o) {
+ if (UInteger.valueOf(4).equals(o)
+ | UInteger.valueOf(5).equals(o)
+ | UInteger.valueOf(6).equals(o)
+ | UInteger.valueOf(7).equals(o)
+ | UInteger.valueOf(8).equals(o)
+ | UInteger.valueOf(9).equals(o)
+ | UInteger.valueOf(27).equals(o)) {
+ return Datatypes.Integer;
+ } else if (UInteger.valueOf(8).equals(o)) {
+ return Datatypes.Long;
+ } else if (UInteger.valueOf(11).equals(o)) {
+ return Datatypes.Double;
+ } else if (UInteger.valueOf(10).equals(o) | UInteger.valueOf(26).equals(o) | UInteger.valueOf(50).equals(o)) {
+ return Datatypes.Float;
+ } else if (UInteger.valueOf(1).equals(o)) {
+ return Datatypes.Boolean;
+ } else if (UInteger.valueOf(12).equals(o)) {
+ return Datatypes.String;
}
+ return Datatypes.String;
+ }
+
}
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 739dc1928..080d1692a 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
@@ -34,6 +34,7 @@ import org.apache.streampipes.model.schema.EventSchema;
import org.apache.streampipes.model.staticproperty.RuntimeResolvableTreeInputStaticProperty;
import org.apache.streampipes.sdk.builder.PrimitivePropertyBuilder;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
+
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.stack.core.UaException;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
@@ -78,7 +79,7 @@ public class OpcUaUtil {
* @throws ParseException
*/
public static GuessSchema getSchema(SpecificAdapterStreamDescription adapterStreamDescription)
- throws AdapterException, ParseException {
+ throws AdapterException, ParseException {
GuessSchema guessSchema = new GuessSchema();
EventSchema eventSchema = new EventSchema();
List<Map<String, GuessTypeInfo>> eventPreview = new ArrayList<>();
@@ -90,22 +91,22 @@ public class OpcUaUtil {
try {
spOpcUaClient.connect();
OpcUaNodeBrowser nodeBrowser =
- new OpcUaNodeBrowser(spOpcUaClient.getClient(), spOpcUaClient.getSpOpcConfig());
+ new OpcUaNodeBrowser(spOpcUaClient.getClient(), spOpcUaClient.getSpOpcConfig());
List<OpcNode> selectedNodes = nodeBrowser.findNodes();
if (!selectedNodes.isEmpty()) {
for (OpcNode opcNode : selectedNodes) {
if (opcNode.hasUnitId()) {
allProperties.add(PrimitivePropertyBuilder
- .create(opcNode.getType(), opcNode.getLabel())
- .label(opcNode.getLabel())
- .measurementUnit(new URI(opcNode.getQudtURI()))
- .build());
+ .create(opcNode.getType(), opcNode.getLabel())
+ .label(opcNode.getLabel())
+ .measurementUnit(new URI(opcNode.getQudtURI()))
+ .build());
} else {
allProperties.add(PrimitivePropertyBuilder
- .create(opcNode.getType(), opcNode.getLabel())
- .label(opcNode.getLabel())
- .build());
+ .create(opcNode.getType(), opcNode.getLabel())
+ .label(opcNode.getLabel())
+ .build());
}
}
}
@@ -157,17 +158,19 @@ public class OpcUaUtil {
/***
* OPC UA specific implementation of {@link
- * org.apache.streampipes.container.api.ResolvesContainerProvidedOptions#
+ * org.apache.streampipes.container.api.ResolvesContainerProvidedOptions
* resolveOptions(String, StaticPropertyExtractor)}.
* @param internalName The internal name of the Static Property
* @param parameterExtractor to extract parameters from the OPC UA config
* @return {@code List<Option>} with available node names for the given OPC UA configuration
*/
- public static RuntimeResolvableTreeInputStaticProperty resolveConfiguration(String internalName,
- StaticPropertyExtractor parameterExtractor) throws SpConfigurationException {
+ public static RuntimeResolvableTreeInputStaticProperty
+ resolveConfiguration(String internalName,
+ StaticPropertyExtractor parameterExtractor)
+ throws SpConfigurationException {
RuntimeResolvableTreeInputStaticProperty config = parameterExtractor
- .getStaticPropertyByName(internalName, RuntimeResolvableTreeInputStaticProperty.class);
+ .getStaticPropertyByName(internalName, RuntimeResolvableTreeInputStaticProperty.class);
// access mode and host/url have to be selected
try {
parameterExtractor.selectedAlternativeInternalId(OpcUaLabels.OPC_HOST_OR_URL.name());
@@ -181,7 +184,7 @@ public class OpcUaUtil {
try {
spOpcUaClient.connect();
OpcUaNodeBrowser nodeBrowser =
- new OpcUaNodeBrowser(spOpcUaClient.getClient(), spOpcUaClient.getSpOpcConfig());
+ new OpcUaNodeBrowser(spOpcUaClient.getClient(), spOpcUaClient.getSpOpcConfig());
config.setNodes(nodeBrowser.buildNodeTreeFromOrigin());
return config;
@@ -219,8 +222,8 @@ public class OpcUaUtil {
for (OpcNode opcNode : opcNodes) {
try {
UInteger dataTypeId =
- (UInteger) client.getAddressSpace().getVariableNode(opcNode.getNodeId()).getDataType()
- .getIdentifier();
+ (UInteger) client.getAddressSpace().getVariableNode(opcNode.getNodeId()).getDataType()
+ .getIdentifier();
OpcUaTypes.getType(dataTypeId);
opcNode.setType(OpcUaTypes.getType(dataTypeId));
} catch (UaException e) {
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java
index 349bf7033..fbda391ec 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java
@@ -19,43 +19,43 @@
package org.apache.streampipes.connect.iiot.adapters.plc4x.modbus;
public class ModbusConfigFile {
-
- private String name;
-
- private String dataType;
-
- private String logicalAddress;
-
- public ModbusConfigFile() {
- }
-
- public ModbusConfigFile(String name, String dataType, String logicalAddress) {
- this.name = name;
- this.setDataType(dataType);
- this.setLogicalAddress(logicalAddress);
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDataType() {
- return dataType;
- }
-
- public void setDataType(String dataType) {
- this.dataType = dataType;
- }
-
- public String getLogicalAddress() {
- return logicalAddress;
- }
-
- public void setLogicalAddress(String logicalAddress) {
- this.logicalAddress = logicalAddress;
- }
+
+ private String name;
+
+ private String dataType;
+
+ private String logicalAddress;
+
+ public ModbusConfigFile() {
+ }
+
+ public ModbusConfigFile(String name, String dataType, String logicalAddress) {
+ this.name = name;
+ this.setDataType(dataType);
+ this.setLogicalAddress(logicalAddress);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDataType() {
+ return dataType;
+ }
+
+ public void setDataType(String dataType) {
+ this.dataType = dataType;
+ }
+
+ public String getLogicalAddress() {
+ return logicalAddress;
+ }
+
+ public void setLogicalAddress(String logicalAddress) {
+ this.logicalAddress = logicalAddress;
+ }
}
\ No newline at end of file
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java
index 3b0a4a6d7..176fd49fb 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java
@@ -18,16 +18,11 @@
package org.apache.streampipes.connect.iiot.adapters.plc4x.modbus;
-import org.apache.plc4x.java.PlcDriverManager;
-import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.api.messages.PlcReadRequest;
-import org.apache.plc4x.java.api.messages.PlcReadResponse;
-import org.apache.plc4x.java.api.types.PlcResponseCode;
+
import org.apache.streampipes.connect.adapter.Adapter;
+import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.api.exception.ParseException;
-import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.iiot.adapters.PullAdapter;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
@@ -47,296 +42,301 @@ import org.apache.streampipes.sdk.helpers.Options;
import org.apache.streampipes.sdk.utils.Assets;
import org.apache.streampipes.sdk.utils.Datatypes;
-import java.util.*;
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-public class Plc4xModbusAdapter extends PullAdapter{
-
- /**
- * A unique id to identify the Plc4xModbusAdapter
- */
- public static final String ID = "org.apache.streampipes.connect.iiot.adapters.plc4x.modbus";
-
- /**
- * Keys of user configuration parameters
- */
- private static final String PLC_IP = "plc_ip";
- private static final String PLC_PORT = "plc_port";
-
- private static final String PLC_NODES = "plc_nodes";
- private static final String PLC_NODE_ID = "plc_node_id";
- private static final String PLC_NODE_RUNTIME_NAME = "plc_node_runtime_name";
- private static final String PLC_NODE_ADDRESS = "plc_node_address";
- private static final String PLC_NODE_TYPE = "plc_node_type";
- private static final String CONFIGURE = "configure";
-
- /**
- * Values of user configuration parameters
- */
- private String ip;
- private int port;
- private int slaveID;
- private List<Map<String, String>> nodes;
-
- /**
- * Connection to the PLC
- */
- private PlcConnection plcConnection;
-
- /**
- * Empty constructor and a constructor with SpecificAdapterStreamDescription are mandatory
- */
- public Plc4xModbusAdapter() {
- }
-
- public Plc4xModbusAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
-
- /**
- * Describe the adapter adapter and define what user inputs are required. Currently users can just select one node,
- * this will be extended in the future
- * @return description of adapter
- */
- @Override
- public SpecificAdapterStreamDescription declareModel() {
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
- .withLocales(Locales.EN)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .category(AdapterType.Manufacturing)
- .requiredTextParameter(Labels.withId(PLC_IP))
- .requiredTextParameter(Labels.withId(PLC_PORT))
- .requiredTextParameter(Labels.withId(PLC_NODE_ID))
- .requiredCollection(Labels.withId(PLC_NODES),
-// StaticProperties.collection(Labels.withId(PLC_NODES),
- StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_RUNTIME_NAME)),
- StaticProperties.integerFreeTextProperty(Labels.withId(PLC_NODE_ADDRESS)),
- StaticProperties.singleValueSelection(Labels.withId(PLC_NODE_TYPE),
- Options.from("DiscreteInput", "Coil", "InputRegister", "HoldingRegister")))
-// )
- .build();
- description.setAppId(ID);
-
- return description;
- }
-
- /**
- * Extracts the user configuration from the SpecificAdapterStreamDescription and sets the local variables
- * @param adapterDescription description of the adapter
- * @throws AdapterException
- */
- private void getConfigurations(SpecificAdapterStreamDescription adapterDescription)
- throws AdapterException{
-
- StaticPropertyExtractor extractor = StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
-
- this.ip = extractor.singleValueParameter(PLC_IP, String.class);
- this.port = extractor.singleValueParameter(PLC_PORT, Integer.class);
- this.slaveID = extractor.singleValueParameter(PLC_NODE_ID, Integer.class);
-
- this.nodes = new ArrayList<>();
- CollectionStaticProperty sp = (CollectionStaticProperty) extractor.getStaticPropertyByName(PLC_NODES);
- Set<Integer> ids = new HashSet<>();
- Set<String> names = new HashSet<>();
- for (StaticProperty member : sp.getMembers()) {
- StaticPropertyExtractor memberExtractor =
- StaticPropertyExtractor.from(((StaticPropertyGroup) member).getStaticProperties(), new ArrayList<>());
-
- // ensure that NODE_ADDRESS and NODE_RUNTIME_TIME appear only once to prevent duplicates
- if (ids.add(memberExtractor.singleValueParameter(PLC_NODE_ADDRESS, Integer.class)) == false ||
- names.add(memberExtractor.textParameter(PLC_NODE_RUNTIME_NAME)) == false) {
-
- throw new AdapterException("NodeID or RuntimeName is specified twice." +
- "Please prevent duplicate names.");
- }
-
- Map map = new HashMap();
- map.put(PLC_NODE_RUNTIME_NAME, memberExtractor.textParameter(PLC_NODE_RUNTIME_NAME));
- map.put(PLC_NODE_ADDRESS, memberExtractor.singleValueParameter(PLC_NODE_ADDRESS, Integer.class));
- map.put(PLC_NODE_TYPE, memberExtractor.selectedSingleValue(PLC_NODE_TYPE, String.class));
-
- this.nodes.add(map);
- }
-
- }
-
-
- /**
- * Transforms chosen data type to StreamPipes supported data type
- * @param plcType
- * @return
- * @throws AdapterException *
- */
- private Datatypes getStreamPipesDataType(String plcType)
- throws AdapterException{
-
- String type = plcType.substring(plcType.lastIndexOf(":") + 1);
-
- switch (type) {
- case "DISCRETEINPUT":
- case "COIL": return Datatypes.Boolean;
- case "INPUTREGISTER":
- case "HOLDINGREGISTER": return Datatypes.Integer;
- default:
- throw new AdapterException("Datatype " + plcType + " is not supported");
- }
- }
-
- /**
- * Takes the user input and creates the event schema. The event schema describes the properties of the event stream.
- * @param
- * @return
- * @throws AdapterException, ParseException
- */
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
- throws AdapterException, ParseException {
-
- // Extract user input
- getConfigurations(adapterDescription);
-
- GuessSchema guessSchema = new GuessSchema();
-
- EventSchema eventSchema = new EventSchema();
- List<EventProperty> allProperties = new ArrayList<>();
-
- for (Map<String, String> node: this.nodes) {
- Datatypes datatype = getStreamPipesDataType(node.get(PLC_NODE_TYPE).toUpperCase());
-
- allProperties.add(
- PrimitivePropertyBuilder
- .create(datatype, node.get(PLC_NODE_RUNTIME_NAME))
- .label(node.get(PLC_NODE_RUNTIME_NAME))
- .description("FieldAddress: " + node.get(PLC_NODE_TYPE) + " " + String.valueOf(node.get(PLC_NODE_ADDRESS)))
- .build());
- }
-
- eventSchema.setEventProperties(allProperties);
- guessSchema.setEventSchema(eventSchema);
- return guessSchema;
- }
-
- /**
- * This method is executed when the adapter is started. A connection to the PLC is initialized
- * @throws AdapterException
- */
- @Override
- protected void before()
- throws AdapterException{
-
- // Extract user input
- getConfigurations(adapterDescription);
-
- try {
- this.plcConnection = new PlcDriverManager().getConnection("modbus:tcp://" + this.ip + ":" + this.port
- + "?unit-identifier=" + this.slaveID);
-
- if (!this.plcConnection.getMetadata().canRead()) {
- throw new AdapterException("The Modbus device on IP: " + this.ip + " does not support reading data");
- }
- }
- catch (PlcConnectionException pce){
- throw new AdapterException("Could not establish a connection to Modbus device on IP: " + this.ip);
- }
- }
-
- /**
- * is called iteratively according to the polling interval defined in getPollInterval.
- */
- @Override
- protected void pullData() {
-
- // create PLC read request
- PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
- for (Map<String, String> node : this.nodes) {
-
- switch (node.get(PLC_NODE_TYPE)){
- case "Coil":
- builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
- "coil:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));break;
- case "HoldingRegister":
- builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
- "holding-register:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));break;
- case "DiscreteInput":
- builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
- "discrete-input:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));break;
- case "InputRegister":
- builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
- "input-register:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));break;
- }
- }
- PlcReadRequest readRequest = builder.build();
-
-
- // Execute the request
- PlcReadResponse response = null;
-
- try {
- response = readRequest.execute().get();
- }
- catch (InterruptedException ie) {
- ie.printStackTrace();
- }
- catch (ExecutionException ee) {
- ee.printStackTrace();
- }
-
- // Create an event containing the value of the PLC
- Map<String, Object> event = new HashMap<>();
- for (Map<String, String> node : this.nodes) {
-
- if (response.getResponseCode(node.get(PLC_NODE_RUNTIME_NAME)) == PlcResponseCode.OK) {
-
- switch (node.get(PLC_NODE_TYPE)) {
- case "Coil":
- event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getBoolean(node.get(PLC_NODE_RUNTIME_NAME)));
- break;
- case "DiscreteInput":
- event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getBoolean(node.get(PLC_NODE_RUNTIME_NAME)));
- break;
- case "InputRegister":
- event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getInteger(node.get(PLC_NODE_RUNTIME_NAME)));
- break;
- case "HoldingRegister":
- event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getInteger(node.get(PLC_NODE_RUNTIME_NAME)));
- break;
- }
- } else {
- logger.error("Error[" + node.get(PLC_NODE_RUNTIME_NAME) + "]: " +
- response.getResponseCode(node.get(PLC_NODE_RUNTIME_NAME)));
- }
- }
-
- // publish the final event
- adapterPipeline.process(event);
- }
-
- /**
- * return polling interval for this adapter, default is set to one second
- * @return
- */
- @Override
- protected PollingSettings getPollingInterval() {
- return PollingSettings.from(TimeUnit.SECONDS, 1);
- }
-
- /**
- * Required by StreamPipes to return a new adapter instance by calling the constructor with SpecificAdapterStreamDescription
- * @param adapterDescription
- * @return
- */
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new Plc4xModbusAdapter(adapterDescription);
- }
-
- /**
- * Required by StreamPipes, return the ID of the adapter
- */
- @Override
- public String getId() {
- return ID;
- }
+public class Plc4xModbusAdapter extends PullAdapter {
+
+ /**
+ * A unique id to identify the Plc4xModbusAdapter
+ */
+ public static final String ID = "org.apache.streampipes.connect.iiot.adapters.plc4x.modbus";
+
+ /**
+ * Keys of user configuration parameters
+ */
+ private static final String PLC_IP = "plc_ip";
+ private static final String PLC_PORT = "plc_port";
+
+ private static final String PLC_NODES = "plc_nodes";
+ private static final String PLC_NODE_ID = "plc_node_id";
+ private static final String PLC_NODE_RUNTIME_NAME = "plc_node_runtime_name";
+ private static final String PLC_NODE_ADDRESS = "plc_node_address";
+ private static final String PLC_NODE_TYPE = "plc_node_type";
+ private static final String CONFIGURE = "configure";
+
+ /**
+ * Values of user configuration parameters
+ */
+ private String ip;
+ private int port;
+ private int slaveID;
+ private List<Map<String, String>> nodes;
+
+ /**
+ * Connection to the PLC
+ */
+ private PlcConnection plcConnection;
+
+ /**
+ * Empty constructor and a constructor with SpecificAdapterStreamDescription are mandatory
+ */
+ public Plc4xModbusAdapter() {
+ }
+
+ public Plc4xModbusAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+
+ /**
+ * Describe the adapter adapter and define what user inputs are required. Currently users can just select one node,
+ * this will be extended in the future
+ *
+ * @return description of adapter
+ */
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID).withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON).category(AdapterType.Manufacturing)
+ .requiredTextParameter(Labels.withId(PLC_IP)).requiredTextParameter(Labels.withId(PLC_PORT))
+ .requiredTextParameter(Labels.withId(PLC_NODE_ID)).requiredCollection(Labels.withId(PLC_NODES),
+ StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_RUNTIME_NAME)),
+ StaticProperties.integerFreeTextProperty(Labels.withId(PLC_NODE_ADDRESS)),
+ StaticProperties.singleValueSelection(Labels.withId(PLC_NODE_TYPE),
+ Options.from("DiscreteInput", "Coil", "InputRegister", "HoldingRegister")))
+ .build();
+ description.setAppId(ID);
+
+ return description;
+ }
+
+ /**
+ * Extracts the user configuration from the SpecificAdapterStreamDescription and sets the local variables
+ *
+ * @param adapterDescription description of the adapter
+ * @throws AdapterException
+ */
+ private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
+
+ StaticPropertyExtractor extractor = StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+
+ this.ip = extractor.singleValueParameter(PLC_IP, String.class);
+ this.port = extractor.singleValueParameter(PLC_PORT, Integer.class);
+ this.slaveID = extractor.singleValueParameter(PLC_NODE_ID, Integer.class);
+
+ this.nodes = new ArrayList<>();
+ CollectionStaticProperty sp = (CollectionStaticProperty) extractor.getStaticPropertyByName(PLC_NODES);
+ Set<Integer> ids = new HashSet<>();
+ Set<String> names = new HashSet<>();
+ for (StaticProperty member : sp.getMembers()) {
+ StaticPropertyExtractor memberExtractor =
+ StaticPropertyExtractor.from(((StaticPropertyGroup) member).getStaticProperties(), new ArrayList<>());
+
+ // ensure that NODE_ADDRESS and NODE_RUNTIME_TIME appear only once to prevent duplicates
+ if (!ids.add(memberExtractor.singleValueParameter(PLC_NODE_ADDRESS, Integer.class))
+ || !names.add(memberExtractor.textParameter(PLC_NODE_RUNTIME_NAME))) {
+
+ throw new AdapterException("NodeID or RuntimeName is specified twice." + "Please prevent duplicate names.");
+ }
+
+ Map map = new HashMap();
+ map.put(PLC_NODE_RUNTIME_NAME, memberExtractor.textParameter(PLC_NODE_RUNTIME_NAME));
+ map.put(PLC_NODE_ADDRESS, memberExtractor.singleValueParameter(PLC_NODE_ADDRESS, Integer.class));
+ map.put(PLC_NODE_TYPE, memberExtractor.selectedSingleValue(PLC_NODE_TYPE, String.class));
+
+ this.nodes.add(map);
+ }
+
+ }
+
+
+ /**
+ * Transforms chosen data type to StreamPipes supported data type
+ *
+ * @param plcType
+ * @return
+ */
+ private Datatypes getStreamPipesDataType(String plcType) throws AdapterException {
+
+ String type = plcType.substring(plcType.lastIndexOf(":") + 1);
+
+ switch (type) {
+ case "DISCRETEINPUT":
+ case "COIL":
+ return Datatypes.Boolean;
+ case "INPUTREGISTER":
+ case "HOLDINGREGISTER":
+ return Datatypes.Integer;
+ default:
+ throw new AdapterException("Datatype " + plcType + " is not supported");
+ }
+ }
+
+ /**
+ * Takes the user input and creates the event schema. The event schema describes the properties of the event stream.
+ */
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
+
+ // Extract user input
+ getConfigurations(adapterDescription);
+
+ GuessSchema guessSchema = new GuessSchema();
+
+ EventSchema eventSchema = new EventSchema();
+ List<EventProperty> allProperties = new ArrayList<>();
+
+ for (Map<String, String> node : this.nodes) {
+ Datatypes datatype = getStreamPipesDataType(node.get(PLC_NODE_TYPE).toUpperCase());
+
+ allProperties.add(PrimitivePropertyBuilder.create(datatype, node.get(PLC_NODE_RUNTIME_NAME))
+ .label(node.get(PLC_NODE_RUNTIME_NAME))
+ .description("FieldAddress: " + node.get(PLC_NODE_TYPE) + " " + String.valueOf(node.get(PLC_NODE_ADDRESS)))
+ .build());
+ }
+
+ eventSchema.setEventProperties(allProperties);
+ guessSchema.setEventSchema(eventSchema);
+ return guessSchema;
+ }
+
+ /**
+ * This method is executed when the adapter is started. A connection to the PLC is initialized
+ *
+ * @throws AdapterException
+ */
+ @Override
+ protected void before() throws AdapterException {
+
+ // Extract user input
+ getConfigurations(adapterDescription);
+
+ try {
+ this.plcConnection = new PlcDriverManager().getConnection(
+ "modbus:tcp://" + this.ip + ":" + this.port + "?unit-identifier=" + this.slaveID);
+
+ if (!this.plcConnection.getMetadata().canRead()) {
+ throw new AdapterException("The Modbus device on IP: " + this.ip + " does not support reading data");
+ }
+ } catch (PlcConnectionException pce) {
+ throw new AdapterException("Could not establish a connection to Modbus device on IP: " + this.ip);
+ }
+ }
+
+ /**
+ * is called iteratively according to the polling interval defined in getPollInterval.
+ */
+ @Override
+ protected void pullData() {
+
+ // create PLC read request
+ PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
+ for (Map<String, String> node : this.nodes) {
+
+ switch (node.get(PLC_NODE_TYPE)) {
+ case "Coil":
+ builder.addItem(node.get(PLC_NODE_RUNTIME_NAME), "coil:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));
+ break;
+ case "HoldingRegister":
+ builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
+ "holding-register:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));
+ break;
+ case "DiscreteInput":
+ builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
+ "discrete-input:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));
+ break;
+ case "InputRegister":
+ builder.addItem(node.get(PLC_NODE_RUNTIME_NAME),
+ "input-register:" + String.valueOf(node.get(PLC_NODE_ADDRESS)));
+ break;
+ }
+ }
+ PlcReadRequest readRequest = builder.build();
+
+
+ // Execute the request
+ PlcReadResponse response = null;
+
+ try {
+ response = readRequest.execute().get();
+ } catch (InterruptedException ie) {
+ ie.printStackTrace();
+ } catch (ExecutionException ee) {
+ ee.printStackTrace();
+ }
+
+ // Create an event containing the value of the PLC
+ Map<String, Object> event = new HashMap<>();
+ for (Map<String, String> node : this.nodes) {
+
+ if (response.getResponseCode(node.get(PLC_NODE_RUNTIME_NAME)) == PlcResponseCode.OK) {
+
+ switch (node.get(PLC_NODE_TYPE)) {
+ case "Coil":
+ event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getBoolean(node.get(PLC_NODE_RUNTIME_NAME)));
+ break;
+ case "DiscreteInput":
+ event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getBoolean(node.get(PLC_NODE_RUNTIME_NAME)));
+ break;
+ case "InputRegister":
+ event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getInteger(node.get(PLC_NODE_RUNTIME_NAME)));
+ break;
+ case "HoldingRegister":
+ event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getInteger(node.get(PLC_NODE_RUNTIME_NAME)));
+ break;
+ }
+ } else {
+ LOGGER.error("Error[" + node.get(PLC_NODE_RUNTIME_NAME) + "]: "
+ + response.getResponseCode(node.get(PLC_NODE_RUNTIME_NAME)));
+ }
+ }
+
+ // publish the final event
+ adapterPipeline.process(event);
+ }
+
+ /**
+ * return polling interval for this adapter, default is set to one second
+ *
+ * @return
+ */
+ @Override
+ protected PollingSettings getPollingInterval() {
+ return PollingSettings.from(TimeUnit.SECONDS, 1);
+ }
+
+ /**
+ * Required by StreamPipes to return a new adapter instance by calling the constructor with
+ * SpecificAdapterStreamDescription
+ *
+ * @param adapterDescription
+ * @return
+ */
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new Plc4xModbusAdapter(adapterDescription);
+ }
+
+ /**
+ * Required by StreamPipes, return the ID of the adapter
+ */
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/passive/Plc4xPassiveAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/passive/Plc4xPassiveAdapter.java
index d4e916f88..28880c959 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/passive/Plc4xPassiveAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/passive/Plc4xPassiveAdapter.java
@@ -19,9 +19,9 @@
package org.apache.streampipes.connect.iiot.adapters.plc4x.passive;
import org.apache.streampipes.connect.adapter.Adapter;
+import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.api.exception.ParseException;
-import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -36,81 +36,82 @@ import java.util.List;
public class Plc4xPassiveAdapter extends SpecificDataStreamAdapter {
- /**
- * A unique id to identify the adapter
- */
- public static final String ID = " org.apache.streampipes.connect.iiot.adapters.plc4x.passive";
-
- public Plc4xPassiveAdapter() {
- }
-
- public Plc4xPassiveAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
-
- @Override
- public SpecificAdapterStreamDescription declareModel() {
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID, "PLC4X Passive", "")
- .iconUrl("plc4x.png")
- .category(AdapterType.Manufacturing)
- .build();
- description.setAppId(ID);
-
- return description;
- }
-
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException, ParseException {
- GuessSchema guessSchema = new GuessSchema();
-
- EventSchema eventSchema = new EventSchema();
- List<EventProperty> allProperties = new ArrayList<>();
-
- allProperties.add(
- PrimitivePropertyBuilder
- .create(Datatypes.String, "sourceId")
- .label("Source Id")
- .description("")
- .build());
-
- allProperties.add(
- PrimitivePropertyBuilder
- .create(Datatypes.String, "propertyId")
- .label("Property Id")
- .description("")
- .build());
-
- // We need to define the type of the value, I choose a numerical value
- allProperties.add(
- PrimitivePropertyBuilder
- .create(Datatypes.Float, "value")
- .label("Value")
- .description("")
- .build());
-
-
- eventSchema.setEventProperties(allProperties);
- guessSchema.setEventSchema(eventSchema);
- return guessSchema;
- }
-
- @Override
- public void startAdapter() throws AdapterException {
- // TODO
- }
-
- @Override
- public void stopAdapter() throws AdapterException {
- // TODO
- }
-
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new Plc4xPassiveAdapter(adapterDescription);
- }
-
- @Override
- public String getId() {
- return ID;
- }
+ /**
+ * A unique id to identify the adapter
+ */
+ public static final String ID = " org.apache.streampipes.connect.iiot.adapters.plc4x.passive";
+
+ public Plc4xPassiveAdapter() {
+ }
+
+ public Plc4xPassiveAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID, "PLC4X Passive", "")
+ .iconUrl("plc4x.png")
+ .category(AdapterType.Manufacturing)
+ .build();
+ description.setAppId(ID);
+
+ return description;
+ }
+
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
+ GuessSchema guessSchema = new GuessSchema();
+
+ EventSchema eventSchema = new EventSchema();
+ List<EventProperty> allProperties = new ArrayList<>();
+
+ allProperties.add(
+ PrimitivePropertyBuilder
+ .create(Datatypes.String, "sourceId")
+ .label("Source Id")
+ .description("")
+ .build());
+
+ allProperties.add(
+ PrimitivePropertyBuilder
+ .create(Datatypes.String, "propertyId")
+ .label("Property Id")
+ .description("")
+ .build());
+
+ // We need to define the type of the value, I choose a numerical value
+ allProperties.add(
+ PrimitivePropertyBuilder
+ .create(Datatypes.Float, "value")
+ .label("Value")
+ .description("")
+ .build());
+
+
+ eventSchema.setEventProperties(allProperties);
+ guessSchema.setEventSchema(eventSchema);
+ return guessSchema;
+ }
+
+ @Override
+ public void startAdapter() throws AdapterException {
+ // TODO
+ }
+
+ @Override
+ public void stopAdapter() throws AdapterException {
+ // TODO
+ }
+
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new Plc4xPassiveAdapter(adapterDescription);
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java
index 227054b81..77a30142a 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java
@@ -18,13 +18,7 @@
package org.apache.streampipes.connect.iiot.adapters.plc4x.s7;
-import org.apache.plc4x.java.PlcDriverManager;
-import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.api.messages.PlcReadRequest;
-import org.apache.plc4x.java.api.messages.PlcReadResponse;
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-import org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager;
+
import org.apache.streampipes.connect.adapter.Adapter;
import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.api.exception.AdapterException;
@@ -47,6 +41,14 @@ import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.helpers.Options;
import org.apache.streampipes.sdk.utils.Assets;
import org.apache.streampipes.sdk.utils.Datatypes;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,286 +62,296 @@ import java.util.stream.Collectors;
public class Plc4xS7Adapter extends PullAdapter implements PlcReadResponseHandler {
- /**
- * A unique id to identify the Plc4xS7Adapter
- */
- public static final String ID = "org.apache.streampipes.connect.iiot.adapters.plc4x.s7";
-
- Logger LOG = LoggerFactory.getLogger(Plc4xS7Adapter.class);
-
- /**
- * Keys of user configuration parameters
- */
- private static final String PLC_IP = "plc_ip";
- private static final String PLC_POLLING_INTERVAL = "plc_polling_interval";
- private static final String PLC_NODES = "plc_nodes";
- private static final String PLC_NODE_NAME = "plc_node_name";
- private static final String PLC_NODE_RUNTIME_NAME = "plc_node_runtime_name";
- private static final String PLC_NODE_TYPE = "plc_node_type";
-
- /**
- * Values of user configuration parameters
- */
- private String ip;
- private int pollingInterval;
- private List<Map<String, String>> nodes;
-
- /**
- * Connection to the PLC
- */
+ /**
+ * A unique id to identify the Plc4xS7Adapter
+ */
+ public static final String ID = "org.apache.streampipes.connect.iiot.adapters.plc4x.s7";
+
+ private static final Logger LOG = LoggerFactory.getLogger(Plc4xS7Adapter.class);
+
+ /**
+ * Keys of user configuration parameters
+ */
+ private static final String PLC_IP = "plc_ip";
+ private static final String PLC_POLLING_INTERVAL = "plc_polling_interval";
+ private static final String PLC_NODES = "plc_nodes";
+ private static final String PLC_NODE_NAME = "plc_node_name";
+ private static final String PLC_NODE_RUNTIME_NAME = "plc_node_runtime_name";
+ private static final String PLC_NODE_TYPE = "plc_node_type";
+
+ /**
+ * Values of user configuration parameters
+ */
+ private String ip;
+ private int pollingInterval;
+ private List<Map<String, String>> nodes;
+
+ /**
+ * Connection to the PLC
+ */
// private PlcConnection plcConnection;
- private PlcDriverManager driverManager;
-
- /**
- * Empty constructor and a constructor with SpecificAdapterStreamDescription are mandatory
- */
- public Plc4xS7Adapter() {
- }
-
- public Plc4xS7Adapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
-
- /**
- * Describe the adapter adapter and define what user inputs are required. Currently users can just select one node, this will be extended in the future
- * @return
- */
- @Override
- public SpecificAdapterStreamDescription declareModel() {
-
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
- .withLocales(Locales.EN)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .category(AdapterType.Manufacturing)
- .requiredTextParameter(Labels.withId(PLC_IP))
- .requiredIntegerParameter(Labels.withId(PLC_POLLING_INTERVAL), 1000)
- .requiredCollection(Labels.withId(PLC_NODES),
- StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_RUNTIME_NAME)),
- StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_NAME)),
- StaticProperties.singleValueSelection(Labels.withId(PLC_NODE_TYPE),
- Options.from("Bool", "Byte", "Int", "Word", "Real", "Char", "String", "Date", "Time of day", "Date and Time")))
- .build();
- description.setAppId(ID);
-
- return description;
- }
-
- /**
- * Takes the user input and creates the event schema. The event schema describes the properties of the event stream.
- * @param adapterDescription
- * @return
- * @throws AdapterException
- */
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
-
- // Extract user input
- try {
- getConfigurations(adapterDescription);
-
- if (this.pollingInterval < 10) {
- throw new AdapterException("Polling interval must be higher than 10. Current value: " + this.pollingInterval);
- }
-
- GuessSchema guessSchema = new GuessSchema();
-
- EventSchema eventSchema = new EventSchema();
- List<EventProperty> allProperties = new ArrayList<>();
-
- for (Map<String, String> node : this.nodes) {
- Datatypes datatype = getStreamPipesDataType(node.get(PLC_NODE_TYPE).toUpperCase().replaceAll(" ", "_"));
-
- allProperties.add(
- PrimitivePropertyBuilder
- .create(datatype, node.get(PLC_NODE_RUNTIME_NAME))
- .label(node.get(PLC_NODE_RUNTIME_NAME))
- .description("")
- .build());
- }
-
- this.before();
- var event = readPlcDataSynchronized();
- var preview = event
- .entrySet()
- .stream()
- .collect(Collectors.toMap(Map.Entry::getKey, e ->
- new GuessTypeInfo(e.getValue().getClass().getCanonicalName(), e.getValue())));
-
- eventSchema.setEventProperties(allProperties);
- guessSchema.setEventSchema(eventSchema);
- guessSchema.setEventPreview(List.of(preview));
-
- return guessSchema;
- } catch (Exception e) {
- throw new AdapterException(e.getMessage(), e);
- }
- }
-
- /**
- * This method is executed when the adapter is started. A connection to the PLC is initialized
- * @throws AdapterException
- */
- @Override
- protected void before() throws AdapterException {
- // Extract user input
- getConfigurations(adapterDescription);
-
- this.driverManager = new PooledPlcDriverManager();
- try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
- if (!plcConnection.getMetadata().canRead()) {
- this.LOG.error("The S7 on IP: " + this.ip + " does not support reading data");
- }
- } catch (PlcConnectionException e) {
- this.LOG.error("Could not establish connection to S7 with ip " + this.ip, e);
- } catch (Exception e) {
- this.LOG.error("Could not close connection to S7 with ip " + this.ip, e);
- }
- }
-
-
- /**
- * pullData is called iteratively according to the polling interval defined in getPollInterval.
- */
- @Override
- protected void pullData() {
- // Create PLC read request
- try(PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
- readPlcData(plcConnection, this);
- } catch (Exception e) {
- LOG.error("Error while reading from PLC with IP {} ", this.ip, e);
- }
- }
-
- private PlcReadRequest makeReadRequest(PlcConnection plcConnection) throws PlcConnectionException {
- PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
- for (Map<String, String> node : this.nodes) {
- builder.addItem(node.get(PLC_NODE_NAME), node.get(PLC_NODE_NAME) + ":" + node.get(PLC_NODE_TYPE).toUpperCase().replaceAll(" ", "_"));
- }
- return builder.build();
+ private PlcDriverManager driverManager;
+
+ /**
+ * Empty constructor and a constructor with SpecificAdapterStreamDescription are mandatory
+ */
+ public Plc4xS7Adapter() {
+ }
+
+ public Plc4xS7Adapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+
+ /**
+ * Describe the adapter adapter and define what user inputs are required.
+ * Currently, users can just select one node, this will be extended in the future
+ *
+ * @return
+ */
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
+ .withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .category(AdapterType.Manufacturing)
+ .requiredTextParameter(Labels.withId(PLC_IP))
+ .requiredIntegerParameter(Labels.withId(PLC_POLLING_INTERVAL), 1000)
+ .requiredCollection(Labels.withId(PLC_NODES),
+ StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_RUNTIME_NAME)),
+ StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_NAME)),
+ StaticProperties.singleValueSelection(Labels.withId(PLC_NODE_TYPE),
+ Options.from("Bool", "Byte", "Int", "Word", "Real", "Char", "String", "Date", "Time of day",
+ "Date and Time")))
+ .build();
+ description.setAppId(ID);
+
+ return description;
+ }
+
+ /**
+ * Takes the user input and creates the event schema. The event schema describes the properties of the event stream.
+ *
+ * @param adapterDescription
+ * @return
+ */
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
+
+ // Extract user input
+ try {
+ getConfigurations(adapterDescription);
+
+ if (this.pollingInterval < 10) {
+ throw new AdapterException("Polling interval must be higher than 10. Current value: " + this.pollingInterval);
+ }
+
+ GuessSchema guessSchema = new GuessSchema();
+
+ EventSchema eventSchema = new EventSchema();
+ List<EventProperty> allProperties = new ArrayList<>();
+
+ for (Map<String, String> node : this.nodes) {
+ Datatypes datatype = getStreamPipesDataType(node.get(PLC_NODE_TYPE).toUpperCase().replaceAll(" ", "_"));
+
+ allProperties.add(
+ PrimitivePropertyBuilder
+ .create(datatype, node.get(PLC_NODE_RUNTIME_NAME))
+ .label(node.get(PLC_NODE_RUNTIME_NAME))
+ .description("")
+ .build());
+ }
+
+ this.before();
+ var event = readPlcDataSynchronized();
+ var preview = event
+ .entrySet()
+ .stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e ->
+ new GuessTypeInfo(e.getValue().getClass().getCanonicalName(), e.getValue())));
+
+ eventSchema.setEventProperties(allProperties);
+ guessSchema.setEventSchema(eventSchema);
+ guessSchema.setEventPreview(List.of(preview));
+
+ return guessSchema;
+ } catch (Exception e) {
+ throw new AdapterException(e.getMessage(), e);
}
-
- private void readPlcData(PlcConnection plcConnection, PlcReadResponseHandler handler) throws PlcConnectionException {
- var readRequest = makeReadRequest(plcConnection);
- // Execute the request
- CompletableFuture<? extends PlcReadResponse> asyncResponse = readRequest.execute();
- asyncResponse.whenComplete(handler::onReadResult);
+ }
+
+ /**
+ * This method is executed when the adapter is started. A connection to the PLC is initialized
+ *
+ * @throws AdapterException
+ */
+ @Override
+ protected void before() throws AdapterException {
+ // Extract user input
+ getConfigurations(adapterDescription);
+
+ this.driverManager = new PooledPlcDriverManager();
+ try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
+ if (!plcConnection.getMetadata().canRead()) {
+ this.LOG.error("The S7 on IP: " + this.ip + " does not support reading data");
+ }
+ } catch (PlcConnectionException e) {
+ this.LOG.error("Could not establish connection to S7 with ip " + this.ip, e);
+ } catch (Exception e) {
+ this.LOG.error("Could not close connection to S7 with ip " + this.ip, e);
}
-
- private Map<String, Object> readPlcDataSynchronized() throws Exception {
- try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
- var readRequest = makeReadRequest(plcConnection);
- // Execute the request
- var readResponse = readRequest.execute().get(5000, TimeUnit.MILLISECONDS);
- return makeEvent(readResponse);
- }
+ }
+
+
+ /**
+ * pullData is called iteratively according to the polling interval defined in getPollInterval.
+ */
+ @Override
+ protected void pullData() {
+ // Create PLC read request
+ try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
+ readPlcData(plcConnection, this);
+ } catch (Exception e) {
+ LOG.error("Error while reading from PLC with IP {} ", this.ip, e);
}
+ }
- /**
- * Define the polling interval of this adapter. Default is to poll every second
- * @return
- */
- @Override
- protected PollingSettings getPollingInterval() {
- return PollingSettings.from(TimeUnit.MILLISECONDS, this.pollingInterval);
+ private PlcReadRequest makeReadRequest(PlcConnection plcConnection) throws PlcConnectionException {
+ PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
+ for (Map<String, String> node : this.nodes) {
+ builder.addItem(node.get(PLC_NODE_NAME),
+ node.get(PLC_NODE_NAME) + ":" + node.get(PLC_NODE_TYPE).toUpperCase().replaceAll(" ", "_"));
}
-
- /**
- * Required by StreamPipes return a new adapter instance by calling the constructor with SpecificAdapterStreamDescription
- * @param adapterDescription
- * @return
- */
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new Plc4xS7Adapter(adapterDescription);
- }
-
-
- /**
- * Required by StreamPipes. Return the id of the adapter
- * @return
- */
- @Override
- public String getId() {
- return ID;
+ return builder.build();
+ }
+
+ private void readPlcData(PlcConnection plcConnection, PlcReadResponseHandler handler) throws PlcConnectionException {
+ var readRequest = makeReadRequest(plcConnection);
+ // Execute the request
+ CompletableFuture<? extends PlcReadResponse> asyncResponse = readRequest.execute();
+ asyncResponse.whenComplete(handler::onReadResult);
+ }
+
+ private Map<String, Object> readPlcDataSynchronized() throws Exception {
+ try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
+ var readRequest = makeReadRequest(plcConnection);
+ // Execute the request
+ var readResponse = readRequest.execute().get(5000, TimeUnit.MILLISECONDS);
+ return makeEvent(readResponse);
}
-
- /**
- * Extracts the user configuration from the SpecificAdapterStreamDescription and sets the local variales
- * @param adapterDescription
- */
- private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
- StaticPropertyExtractor extractor =
- StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
-
- this.ip = extractor.singleValueParameter(PLC_IP, String.class);
- this.pollingInterval = extractor.singleValueParameter(PLC_POLLING_INTERVAL, Integer.class);
-
- this.nodes = new ArrayList<>();
- CollectionStaticProperty sp = (CollectionStaticProperty) extractor.getStaticPropertyByName(PLC_NODES);
-
- for (StaticProperty member : sp.getMembers()) {
- StaticPropertyExtractor memberExtractor =
- StaticPropertyExtractor.from(((StaticPropertyGroup) member).getStaticProperties(), new ArrayList<>());
- Map<String, String> map = new HashMap<>();
- map.put(PLC_NODE_RUNTIME_NAME, memberExtractor.textParameter(PLC_NODE_RUNTIME_NAME));
- map.put(PLC_NODE_NAME, memberExtractor.textParameter(PLC_NODE_NAME));
- map.put(PLC_NODE_TYPE, memberExtractor.selectedSingleValue(PLC_NODE_TYPE, String.class));
- this.nodes.add(map);
- }
+ }
+
+ /**
+ * Define the polling interval of this adapter. Default is to poll every second
+ *
+ * @return
+ */
+ @Override
+ protected PollingSettings getPollingInterval() {
+ return PollingSettings.from(TimeUnit.MILLISECONDS, this.pollingInterval);
+ }
+
+ /**
+ * Required by StreamPipes return a new adapter instance by calling the constructor with
+ * SpecificAdapterStreamDescription
+ *
+ * @param adapterDescription
+ * @return
+ */
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new Plc4xS7Adapter(adapterDescription);
+ }
+
+
+ /**
+ * Required by StreamPipes. Return the id of the adapter
+ *
+ * @return
+ */
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ /**
+ * Extracts the user configuration from the SpecificAdapterStreamDescription and sets the local variales
+ *
+ * @param adapterDescription
+ */
+ private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
+ StaticPropertyExtractor extractor =
+ StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+
+ this.ip = extractor.singleValueParameter(PLC_IP, String.class);
+ this.pollingInterval = extractor.singleValueParameter(PLC_POLLING_INTERVAL, Integer.class);
+
+ this.nodes = new ArrayList<>();
+ CollectionStaticProperty sp = (CollectionStaticProperty) extractor.getStaticPropertyByName(PLC_NODES);
+
+ for (StaticProperty member : sp.getMembers()) {
+ StaticPropertyExtractor memberExtractor =
+ StaticPropertyExtractor.from(((StaticPropertyGroup) member).getStaticProperties(), new ArrayList<>());
+ Map<String, String> map = new HashMap<>();
+ map.put(PLC_NODE_RUNTIME_NAME, memberExtractor.textParameter(PLC_NODE_RUNTIME_NAME));
+ map.put(PLC_NODE_NAME, memberExtractor.textParameter(PLC_NODE_NAME));
+ map.put(PLC_NODE_TYPE, memberExtractor.selectedSingleValue(PLC_NODE_TYPE, String.class));
+ this.nodes.add(map);
}
-
- /**
- * Transforms PLC4X data types to datatypes supported in StreamPipes
- * @param plcType
- * @return
- * @throws AdapterException
- */
- private Datatypes getStreamPipesDataType(String plcType) throws AdapterException {
-
- String type = plcType.substring(plcType.lastIndexOf(":")+1);
-
- switch (type) {
- case "BOOL":
- return Datatypes.Boolean;
- case "BYTE":
- case "REAL":
- return Datatypes.Float;
- case "INT":
- return Datatypes.Integer;
- case "WORD":
- case "TIME_OF_DAY":
- case "DATE":
- case "DATE_AND_TIME":
- case "STRING":
- case "CHAR":
- return Datatypes.String;
- default:
- throw new AdapterException("Datatype " + plcType + " is not supported");
- }
+ }
+
+ /**
+ * Transforms PLC4X data types to datatypes supported in StreamPipes
+ *
+ * @param plcType
+ * @return
+ */
+ private Datatypes getStreamPipesDataType(String plcType) throws AdapterException {
+
+ String type = plcType.substring(plcType.lastIndexOf(":") + 1);
+
+ switch (type) {
+ case "BOOL":
+ return Datatypes.Boolean;
+ case "BYTE":
+ case "REAL":
+ return Datatypes.Float;
+ case "INT":
+ return Datatypes.Integer;
+ case "WORD":
+ case "TIME_OF_DAY":
+ case "DATE":
+ case "DATE_AND_TIME":
+ case "STRING":
+ case "CHAR":
+ return Datatypes.String;
+ default:
+ throw new AdapterException("Datatype " + plcType + " is not supported");
}
-
- @Override
- public void onReadResult(PlcReadResponse response, Throwable throwable) {
- if (throwable != null) {
- throwable.printStackTrace();
- this.LOG.error(throwable.getMessage());
- } else {
- var event = makeEvent(response);
- // publish the final event
- adapterPipeline.process(event);
- }
+ }
+
+ @Override
+ public void onReadResult(PlcReadResponse response, Throwable throwable) {
+ if (throwable != null) {
+ throwable.printStackTrace();
+ this.LOG.error(throwable.getMessage());
+ } else {
+ var event = makeEvent(response);
+ // publish the final event
+ adapterPipeline.process(event);
}
-
- private Map<String, Object> makeEvent(PlcReadResponse response) {
- Map<String, Object> event = new HashMap<>();
- for (Map<String, String> node : this.nodes) {
- if (response.getResponseCode(node.get(PLC_NODE_NAME)) == PlcResponseCode.OK) {
- event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getObject(node.get(PLC_NODE_NAME)));
- } else {
- this.LOG.error("Error[" + node.get(PLC_NODE_NAME) + "]: " +
- response.getResponseCode(node.get(PLC_NODE_NAME)).name());
- }
- }
- return event;
+ }
+
+ private Map<String, Object> makeEvent(PlcReadResponse response) {
+ Map<String, Object> event = new HashMap<>();
+ for (Map<String, String> node : this.nodes) {
+ if (response.getResponseCode(node.get(PLC_NODE_NAME)) == PlcResponseCode.OK) {
+ event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getObject(node.get(PLC_NODE_NAME)));
+ } else {
+ this.LOG.error("Error[" + node.get(PLC_NODE_NAME) + "]: "
+ + response.getResponseCode(node.get(PLC_NODE_NAME)).name());
+ }
}
+ return event;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/ros/RosBridgeAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/ros/RosBridgeAdapter.java
index 161b8f4fc..704e568db 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/ros/RosBridgeAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/ros/RosBridgeAdapter.java
@@ -18,23 +18,12 @@
package org.apache.streampipes.connect.iiot.adapters.ros;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import edu.wpi.rail.jrosbridge.Ros;
-import edu.wpi.rail.jrosbridge.Service;
-import edu.wpi.rail.jrosbridge.Topic;
-import edu.wpi.rail.jrosbridge.callback.TopicCallback;
-import edu.wpi.rail.jrosbridge.messages.Message;
-import edu.wpi.rail.jrosbridge.services.ServiceRequest;
-import edu.wpi.rail.jrosbridge.services.ServiceResponse;
+
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.adapter.format.json.object.JsonObjectParser;
import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
+import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.container.api.ResolvesContainerProvidedOptions;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
@@ -47,207 +36,224 @@ import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
-import java.util.*;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import edu.wpi.rail.jrosbridge.Ros;
+import edu.wpi.rail.jrosbridge.Service;
+import edu.wpi.rail.jrosbridge.Topic;
+import edu.wpi.rail.jrosbridge.callback.TopicCallback;
+import edu.wpi.rail.jrosbridge.messages.Message;
+import edu.wpi.rail.jrosbridge.services.ServiceRequest;
+import edu.wpi.rail.jrosbridge.services.ServiceResponse;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
public class RosBridgeAdapter extends SpecificDataStreamAdapter implements ResolvesContainerProvidedOptions {
- public static final String ID = "org.apache.streampipes.connect.iiot.adapters.ros";
+ public static final String ID = "org.apache.streampipes.connect.iiot.adapters.ros";
- private static final String ROS_HOST_KEY = "ROS_HOST_KEY";
- private static final String ROS_PORT_KEY = "ROS_PORT_KEY";
- private static final String TOPIC_KEY = "TOPIC_KEY";
+ private static final String ROS_HOST_KEY = "ROS_HOST_KEY";
+ private static final String ROS_PORT_KEY = "ROS_PORT_KEY";
+ private static final String TOPIC_KEY = "TOPIC_KEY";
- private String topic;
- private String host;
- private int port;
-
- private Ros ros;
+ private String topic;
+ private String host;
+ private int port;
- private JsonObjectParser jsonObjectParser;
+ private Ros ros;
- public RosBridgeAdapter() {
- }
+ private JsonObjectParser jsonObjectParser;
- public RosBridgeAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
+ public RosBridgeAdapter() {
+ }
- getConfigurations(adapterDescription);
+ public RosBridgeAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
- this.jsonObjectParser = new JsonObjectParser();
- }
+ getConfigurations(adapterDescription);
- @Override
- public SpecificAdapterStreamDescription declareModel() {
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
- .withLocales(Locales.EN)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .category(AdapterType.Manufacturing)
- .requiredTextParameter(Labels.withId(ROS_HOST_KEY))
- .requiredTextParameter(Labels.withId(ROS_PORT_KEY))
- .requiredSingleValueSelectionFromContainer(Labels.withId(TOPIC_KEY), Arrays.asList(ROS_HOST_KEY, ROS_PORT_KEY))
- .build();
-
- return description;
- }
+ this.jsonObjectParser = new JsonObjectParser();
+ }
- @Override
- public void startAdapter() throws AdapterException {
- this.ros = new Ros(this.host, this.port);
- this.ros.connect();
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
+ .withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .category(AdapterType.Manufacturing)
+ .requiredTextParameter(Labels.withId(ROS_HOST_KEY))
+ .requiredTextParameter(Labels.withId(ROS_PORT_KEY))
+ .requiredSingleValueSelectionFromContainer(Labels.withId(TOPIC_KEY), Arrays.asList(ROS_HOST_KEY, ROS_PORT_KEY))
+ .build();
- String topicType = getMethodType(this.ros, this.topic);
+ return description;
+ }
- ObjectMapper mapper = new ObjectMapper();
- Topic echoBack = new Topic(ros, this.topic, topicType);
- echoBack.subscribe(new TopicCallback() {
- @Override
- public void handleMessage(Message message) {
+ @Override
+ public void startAdapter() throws AdapterException {
+ this.ros = new Ros(this.host, this.port);
+ this.ros.connect();
+ String topicType = getMethodType(this.ros, this.topic);
- try {
- Map<String, Object> result = mapper.readValue(message.toString(), HashMap.class);
- adapterPipeline.process(result);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- }
- }
- });
+ ObjectMapper mapper = new ObjectMapper();
+ Topic echoBack = new Topic(ros, this.topic, topicType);
+ echoBack.subscribe(new TopicCallback() {
+ @Override
+ public void handleMessage(Message message) {
- }
+ try {
+ Map<String, Object> result = mapper.readValue(message.toString(), HashMap.class);
+ adapterPipeline.process(result);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ }
+ });
- @Override
- public List<Option> resolveOptions(String requestId, StaticPropertyExtractor extractor) {
- String rosBridgeHost = extractor.singleValueParameter(ROS_HOST_KEY, String.class);
- Integer rosBridgePort = extractor.singleValueParameter(ROS_PORT_KEY, Integer.class);
- Ros ros = new Ros(rosBridgeHost, rosBridgePort);
+ }
- ros.connect();
- List<String> topics = getListOfAllTopics(ros);
- ros.disconnect();
- return topics.stream().map(Option::new).collect(Collectors.toList());
- }
+ @Override
+ public List<Option> resolveOptions(String requestId, StaticPropertyExtractor extractor) {
+ String rosBridgeHost = extractor.singleValueParameter(ROS_HOST_KEY, String.class);
+ Integer rosBridgePort = extractor.singleValueParameter(ROS_PORT_KEY, Integer.class);
- private class GetNEvents implements Runnable {
+ Ros ros = new Ros(rosBridgeHost, rosBridgePort);
- private String topic;
- private String topicType;
- private Ros ros;
+ ros.connect();
+ List<String> topics = getListOfAllTopics(ros);
+ ros.disconnect();
+ return topics.stream().map(Option::new).collect(Collectors.toList());
+ }
- private List<byte[]> events;
+ private class GetNEvents implements Runnable {
- public GetNEvents(String topic, String topicType, Ros ros) {
- this.topic = topic;
- this.topicType = topicType;
- this.ros = ros;
- this.events = new ArrayList<>();
- }
+ private String topic;
+ private String topicType;
+ private Ros ros;
- @Override
- public void run() {
- Topic echoBack = new Topic(ros, this.topic, topicType);
- echoBack.subscribe(new TopicCallback() {
- @Override
- public void handleMessage(Message message) {
- events.add(message.toString().getBytes());
- }
- });
- }
+ private List<byte[]> events;
- public List<byte[]> getEvents() {
- return this.events;
- }
+ public GetNEvents(String topic, String topicType, Ros ros) {
+ this.topic = topic;
+ this.topicType = topicType;
+ this.ros = ros;
+ this.events = new ArrayList<>();
}
@Override
- public void stopAdapter() throws AdapterException {
- this.ros.disconnect();
+ public void run() {
+ Topic echoBack = new Topic(ros, this.topic, topicType);
+ echoBack.subscribe(new TopicCallback() {
+ @Override
+ public void handleMessage(Message message) {
+ events.add(message.toString().getBytes());
+ }
+ });
}
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
- getConfigurations(adapterDescription);
+ public List<byte[]> getEvents() {
+ return this.events;
+ }
+ }
+ @Override
+ public void stopAdapter() throws AdapterException {
+ this.ros.disconnect();
+ }
- Ros ros = new Ros(host, port);
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
+ getConfigurations(adapterDescription);
- boolean connect = ros.connect();
- if (!connect) {
- throw new AdapterException("Could not connect to ROS bridge Endpoint: " + host + " with port: " + port);
- }
+ Ros ros = new Ros(host, port);
- String topicType = getMethodType(ros, topic);
+ boolean connect = ros.connect();
- GetNEvents getNEvents = new GetNEvents(topic, topicType, ros);
- Thread t = new Thread(getNEvents);
- t.start();
+ if (!connect) {
+ throw new AdapterException("Could not connect to ROS bridge Endpoint: " + host + " with port: " + port);
+ }
- while (getNEvents.getEvents().size() < 1) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
+ String topicType = getMethodType(ros, topic);
- t.interrupt();
+ GetNEvents getNEvents = new GetNEvents(topic, topicType, ros);
+ Thread t = new Thread(getNEvents);
+ t.start();
- ros.disconnect();
+ while (getNEvents.getEvents().size() < 1) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
- EventSchema eventSchema = this.jsonObjectParser.getEventSchema(getNEvents.getEvents());
+ t.interrupt();
- GuessSchema guessSchema = new GuessSchema();
+ ros.disconnect();
- guessSchema.setEventSchema(eventSchema);
- return guessSchema;
- }
+ EventSchema eventSchema = this.jsonObjectParser.getEventSchema(getNEvents.getEvents());
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new RosBridgeAdapter(adapterDescription);
- }
+ GuessSchema guessSchema = new GuessSchema();
- @Override
- public String getId() {
- return ID;
- }
+ guessSchema.setEventSchema(eventSchema);
+ return guessSchema;
+ }
- private String getMethodType(Ros ros, String topic) {
- Service addTwoInts = new Service(ros, "/rosapi/topic_type", "rosapi/TopicType");
- ServiceRequest request = new ServiceRequest("{\"topic\": \""+ topic +"\"}");
- ServiceResponse response = addTwoInts.callServiceAndWait(request);
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new RosBridgeAdapter(adapterDescription);
+ }
- JsonObject ob = new JsonParser().parse(response.toString()).getAsJsonObject();
- return ob.get("type").getAsString();
- }
+ @Override
+ public String getId() {
+ return ID;
+ }
- private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) {
- ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
- this.host = extractor.singleValue(ROS_HOST_KEY, String.class);
- this.topic = extractor.selectedSingleValueOption(TOPIC_KEY);
- this.port = extractor.singleValue(ROS_PORT_KEY, Integer.class);
- }
+ private String getMethodType(Ros ros, String topic) {
+ Service addTwoInts = new Service(ros, "/rosapi/topic_type", "rosapi/TopicType");
+ ServiceRequest request = new ServiceRequest("{\"topic\": \"" + topic + "\"}");
+ ServiceResponse response = addTwoInts.callServiceAndWait(request);
- // Ignore for now, but is interesting for future implementations
- private List<String> getListOfAllTopics(Ros ros) {
- List<String> result = new ArrayList<>();
- Service service = new Service(ros, "/rosapi/topics", "rosapi/Topics");
- ServiceRequest request = new ServiceRequest();
- ServiceResponse response = service.callServiceAndWait(request);
- JsonObject ob = new JsonParser().parse(response.toString()).getAsJsonObject();
+ JsonObject ob = new JsonParser().parse(response.toString()).getAsJsonObject();
+ return ob.get("type").getAsString();
+ }
- if (ob.has("topics")) {
- JsonArray topics = ob.get("topics").getAsJsonArray();
- for (int i = 0; i < topics.size(); i++) {
- result.add(topics.get(i).getAsString());
- }
+ private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) {
+ ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
+ this.host = extractor.singleValue(ROS_HOST_KEY, String.class);
+ this.topic = extractor.selectedSingleValueOption(TOPIC_KEY);
+ this.port = extractor.singleValue(ROS_PORT_KEY, Integer.class);
+ }
- }
+ // Ignore for now, but is interesting for future implementations
+ private List<String> getListOfAllTopics(Ros ros) {
+ List<String> result = new ArrayList<>();
+ Service service = new Service(ros, "/rosapi/topics", "rosapi/Topics");
+ ServiceRequest request = new ServiceRequest();
+ ServiceResponse response = service.callServiceAndWait(request);
+ JsonObject ob = new JsonParser().parse(response.toString()).getAsJsonObject();
- return result;
+ if (ob.has("topics")) {
+ JsonArray topics = ob.get("topics").getAsJsonArray();
+ for (int i = 0; i < topics.size(); i++) {
+ result.add(topics.get(i).getAsString());
+ }
}
+
+ return result;
+
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java
index ee3b18be7..f0d668a42 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulator.java
@@ -1,4 +1,4 @@
-package org.apache.streampipes.connect.iiot.adapters.simulator.machine;/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -15,6 +15,7 @@ package org.apache.streampipes.connect.iiot.adapters.simulator.machine;/*
* limitations under the License.
*
*/
+package org.apache.streampipes.connect.iiot.adapters.simulator.machine;
import org.apache.streampipes.connect.adapter.model.pipeline.AdapterPipeline;
import org.apache.streampipes.connect.api.exception.AdapterException;
@@ -24,135 +25,129 @@ import java.util.Map;
public class MachineDataSimulator implements Runnable {
- private final AdapterPipeline adapterPipeline;
- private final Integer waitTimeMs;
- private final String selectedSimulatorOption;
-
- private Boolean running;
-
- public MachineDataSimulator(AdapterPipeline adapterPipeline, Integer waitTimeMs, String selectedSimulatorOption) {
- this.adapterPipeline = adapterPipeline;
- this.waitTimeMs = waitTimeMs;
- this.selectedSimulatorOption = selectedSimulatorOption;
- this.running = true;
+ private final AdapterPipeline adapterPipeline;
+ private final Integer waitTimeMs;
+ private final String selectedSimulatorOption;
+
+ private Boolean running;
+
+ public MachineDataSimulator(AdapterPipeline adapterPipeline, Integer waitTimeMs, String selectedSimulatorOption) {
+ this.adapterPipeline = adapterPipeline;
+ this.waitTimeMs = waitTimeMs;
+ this.selectedSimulatorOption = selectedSimulatorOption;
+ this.running = true;
+ }
+
+ @Override
+ public void run() {
+ this.running = true;
+ Map<String, Object> event = new HashMap<>();
+ long startTimeMs = System.currentTimeMillis();
+
+ while (running) {
+ long currentTimeMs = System.currentTimeMillis();
+ long timeDeltaMs = currentTimeMs - startTimeMs;
+
+ switch (this.selectedSimulatorOption) {
+ case "flowrate":
+ // 0 - 30s
+ if (timeDeltaMs > 0 && timeDeltaMs <= 30000) {
+ event = buildFlowrateEvent(0);
+ } else if (timeDeltaMs > 30000 && timeDeltaMs <= 60000) {
+ // 30s - 60s
+ event = buildFlowrateEvent(1);
+ } else {
+ // > 60s
+ // reset start time to start over again
+ startTimeMs = currentTimeMs;
+ }
+ break;
+ case "pressure":
+ // 0 - 30s
+ if (timeDeltaMs > 0 && timeDeltaMs <= 30000) {
+ event = buildPressureEvent(0);
+ } else if (timeDeltaMs > 30000 && timeDeltaMs <= 60000) {
+ // 30s - 60s
+ event = buildPressureEvent(1);
+ } else {
+ // > 60s
+ // reset start time to start over again
+ startTimeMs = currentTimeMs;
+ }
+ break;
+ case "waterlevel":
+ if (timeDeltaMs > 0 && timeDeltaMs <= 30000) {
+ // 0 - 30s
+ event = buildWaterlevelEvent(0);
+ } else if (timeDeltaMs > 30000 && timeDeltaMs <= 60000) {
+ // 30s - 60s
+ event = buildWaterlevelEvent(1);
+ } else {
+ // > 60s
+ // reset start time to start over again
+ startTimeMs = currentTimeMs;
+ }
+ break;
+ default:
+ try {
+ throw new AdapterException("resource not found");
+ } catch (AdapterException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (event.keySet().size() > 0) {
+ adapterPipeline.process(event);
+ }
+
+ try {
+ Thread.sleep(waitTimeMs);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
+ }
- @Override
- public void run() {
- this.running = true;
- Map<String, Object> event = new HashMap<>();
- long startTimeMs = System.currentTimeMillis();
-
- while (running) {
- long currentTimeMs = System.currentTimeMillis();
- long timeDeltaMs = currentTimeMs - startTimeMs;
-
- switch(this.selectedSimulatorOption) {
- case "flowrate":
- // 0 - 30s
- if (timeDeltaMs > 0 && timeDeltaMs <= 30000) {
- event = buildFlowrateEvent(0);
- }
- // 30s - 60s
- else if (timeDeltaMs > 30000 && timeDeltaMs <= 60000) {
- event = buildFlowrateEvent(1);
- }
- // > 60s
- else {
- // reset start time to start over again
- startTimeMs = currentTimeMs;
- }
- break;
- case "pressure":
- // 0 - 30s
- if (timeDeltaMs > 0 && timeDeltaMs <= 30000) {
- event = buildPressureEvent(0);
- }
- // 30s - 60s
- else if (timeDeltaMs > 30000 && timeDeltaMs <= 60000) {
- event = buildPressureEvent(1);
- }
- // > 60s
- else {
- // reset start time to start over again
- startTimeMs = currentTimeMs;
- }
- break;
- case "waterlevel":
- // 0 - 30s
- if (timeDeltaMs > 0 && timeDeltaMs <= 30000) {
- event = buildWaterlevelEvent(0);
- }
- // 30s - 60s
- else if (timeDeltaMs > 30000 && timeDeltaMs <= 60000) {
- event = buildWaterlevelEvent(1);
- }
- // > 60s
- else {
- // reset start time to start over again
- startTimeMs = currentTimeMs;
- }
- break;
- default:
- try {
- throw new AdapterException("resource not found");
- } catch (AdapterException e) {
- e.printStackTrace();
- }
- }
-
- if (event.keySet().size() > 0) {
- adapterPipeline.process(event);
- }
-
- try {
- Thread.sleep(waitTimeMs);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
+ private Map<String, Object> buildFlowrateEvent(int simulationPhase) {
+ Map<String, Object> event = new HashMap<>();
- private Map<String, Object> buildFlowrateEvent(int simulationPhase) {
- Map<String, Object> event = new HashMap<>();
+ event.put("timestamp", System.currentTimeMillis());
+ event.put("sensorId", "flowrate02");
+ event.put("mass_flow", randomDoubleBetween(0, 10));
+ event.put("volume_flow", randomDoubleBetween(0, 10));
+ event.put("temperature", simulationPhase == 0 ? randomDoubleBetween(40, 50) : randomDoubleBetween(80, 100));
+ event.put("density", randomDoubleBetween(40, 50));
+ event.put("sensor_fault_flags", simulationPhase != 0);
- event.put("timestamp", System.currentTimeMillis());
- event.put("sensorId", "flowrate02");
- event.put("mass_flow", randomDoubleBetween(0,10));
- event.put("volume_flow", randomDoubleBetween(0,10));
- event.put("temperature", simulationPhase == 0 ? randomDoubleBetween(40,50) : randomDoubleBetween(80,100));
- event.put("density", randomDoubleBetween(40,50));
- event.put("sensor_fault_flags", simulationPhase != 0);
+ return event;
+ }
- return event;
- }
+ private Map<String, Object> buildPressureEvent(int simulationPhase) {
+ Map<String, Object> event = new HashMap<>();
- private Map<String, Object> buildPressureEvent(int simulationPhase) {
- Map<String, Object> event = new HashMap<>();
+ event.put("timestamp", System.currentTimeMillis());
+ event.put("sensorId", "pressure01");
+ event.put("pressure", simulationPhase == 0 ? randomDoubleBetween(10, 40) : randomDoubleBetween(40, 70));
- event.put("timestamp", System.currentTimeMillis());
- event.put("sensorId", "pressure01");
- event.put("pressure", simulationPhase == 0 ? randomDoubleBetween(10,40) : randomDoubleBetween(40,70));
+ return event;
+ }
- return event;
- }
+ private Map<String, Object> buildWaterlevelEvent(int simulationPhase) {
+ Map<String, Object> event = new HashMap<>();
- private Map<String, Object> buildWaterlevelEvent(int simulationPhase) {
- Map<String, Object> event = new HashMap<>();
+ event.put("timestamp", System.currentTimeMillis());
+ event.put("sensorId", "level01");
+ event.put("level", simulationPhase == 0 ? randomDoubleBetween(20, 30) : randomDoubleBetween(60, 80));
+ event.put("overflow", simulationPhase != 0);
- event.put("timestamp", System.currentTimeMillis());
- event.put("sensorId", "level01");
- event.put("level", simulationPhase == 0 ? randomDoubleBetween(20,30) : randomDoubleBetween(60,80));
- event.put("overflow", simulationPhase != 0);
+ return event;
+ }
- return event;
- }
-
- private double randomDoubleBetween(int min, int max) {
- return Math.random() * (max - min + 1) + min;
- }
+ private double randomDoubleBetween(int min, int max) {
+ return Math.random() * (max - min + 1) + min;
+ }
- public void setRunning(Boolean running) {
- this.running = running;
- }
+ public void setRunning(Boolean running) {
+ this.running = running;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulatorUtils.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulatorUtils.java
index f157babca..b38f6ab12 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulatorUtils.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataSimulatorUtils.java
@@ -1,4 +1,4 @@
-package org.apache.streampipes.connect.iiot.adapters.simulator.machine;/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -15,6 +15,7 @@ package org.apache.streampipes.connect.iiot.adapters.simulator.machine;/*
* limitations under the License.
*
*/
+package org.apache.streampipes.connect.iiot.adapters.simulator.machine;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -26,7 +27,7 @@ import org.apache.streampipes.vocabulary.SO;
import java.net.URI;
-import static org.apache.streampipes.sdk.helpers.EpProperties.*;
+import static org.apache.streampipes.sdk.helpers.EpProperties.timestampProperty;
public class MachineDataSimulatorUtils {
@@ -54,113 +55,113 @@ public class MachineDataSimulatorUtils {
private static GuessSchema getWaterlevelSchema() {
return GuessSchemaBuilder.create()
- .property(timestampProperty(TIMESTAMP))
- .sample(TIMESTAMP, System.currentTimeMillis())
- .property(PrimitivePropertyBuilder
- .create(Datatypes.String, "sensorId")
- .label("Sensor ID")
- .description("The ID of the sensor")
- .domainProperty(HAS_SENSOR_ID)
- .scope(PropertyScope.DIMENSION_PROPERTY)
- .build())
- .sample("sensorId", "sensor01")
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Float, "level")
- .label("Water Level")
- .description("Denotes the current water level in the container")
- .domainProperty(SO.Number)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample("level", 5.25f)
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Boolean, "overflow")
- .label("Overflow")
- .description("Indicates whether the tank overflows")
- .domainProperty(SO.Number)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample("overflow", true)
- .build();
+ .property(timestampProperty(TIMESTAMP))
+ .sample(TIMESTAMP, System.currentTimeMillis())
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.String, "sensorId")
+ .label("Sensor ID")
+ .description("The ID of the sensor")
+ .domainProperty(HAS_SENSOR_ID)
+ .scope(PropertyScope.DIMENSION_PROPERTY)
+ .build())
+ .sample("sensorId", "sensor01")
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Float, "level")
+ .label("Water Level")
+ .description("Denotes the current water level in the container")
+ .domainProperty(SO.Number)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample("level", 5.25f)
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Boolean, "overflow")
+ .label("Overflow")
+ .description("Indicates whether the tank overflows")
+ .domainProperty(SO.Number)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample("overflow", true)
+ .build();
}
private static GuessSchema getPressureSchema() {
return GuessSchemaBuilder.create()
- .property(timestampProperty(TIMESTAMP))
- .sample(TIMESTAMP, System.currentTimeMillis())
- .property(PrimitivePropertyBuilder
- .create(Datatypes.String, "sensorId")
- .label("Sensor ID")
- .description("The ID of the sensor")
- .domainProperty(HAS_SENSOR_ID)
- .scope(PropertyScope.DIMENSION_PROPERTY)
- .build())
- .sample("sensorId", "sensor01")
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Float, "pressure")
- .label("Pressure")
- .description("Denotes the current pressure in the pressure tank")
- .domainProperty(SO.Number)
- .valueSpecification(0.0f, 100.0f, 0.5f)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample("pressure", 85.22f)
- .build();
+ .property(timestampProperty(TIMESTAMP))
+ .sample(TIMESTAMP, System.currentTimeMillis())
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.String, "sensorId")
+ .label("Sensor ID")
+ .description("The ID of the sensor")
+ .domainProperty(HAS_SENSOR_ID)
+ .scope(PropertyScope.DIMENSION_PROPERTY)
+ .build())
+ .sample("sensorId", "sensor01")
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Float, "pressure")
+ .label("Pressure")
+ .description("Denotes the current pressure in the pressure tank")
+ .domainProperty(SO.Number)
+ .valueSpecification(0.0f, 100.0f, 0.5f)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample("pressure", 85.22f)
+ .build();
}
public static GuessSchema getFlowrateSchema() {
return GuessSchemaBuilder.create()
- .property(timestampProperty(TIMESTAMP))
- .sample(TIMESTAMP, System.currentTimeMillis())
- .property(PrimitivePropertyBuilder
- .create(Datatypes.String, SENSOR_ID)
- .label("Sensor ID")
- .description("The ID of the sensor")
- .domainProperty(HAS_SENSOR_ID)
- .scope(PropertyScope.DIMENSION_PROPERTY)
- .build())
- .sample("sensorId", "sensor01")
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Float, MASS_FLOW)
- .label("Mass Flow")
- .description("Denotes the current mass flow in the sensor")
- .domainProperty(SO.Number)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample(MASS_FLOW, 5.76f)
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Float, "volume_flow")
- .label("Volume Flow")
- .description("Denotes the current volume flow")
- .domainProperty(SO.Number)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample("volume_flow", 3.34f)
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Float, TEMPERATURE)
- .label("Temperature")
- .description("Denotes the current temperature in degrees celsius")
- .domainProperty(SO.Number)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .measurementUnit(URI.create("http://codes.wmo.int/common/unit/degC"))
- .valueSpecification(0.0f, 100.0f, 0.1f)
- .build())
- .sample(TEMPERATURE, 33.221f)
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Float, "density")
- .label("Density")
- .description("Denotes the current density of the fluid")
- .domainProperty(SO.Number)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample("density", 5.0f)
- .property(PrimitivePropertyBuilder
- .create(Datatypes.Boolean, "sensor_fault_flags")
- .label("Sensor Fault Flags")
- .description("Any fault flags of the sensors")
- .domainProperty(SO.Boolean)
- .scope(PropertyScope.MEASUREMENT_PROPERTY)
- .build())
- .sample("sensor_fault_flags", true)
- .build();
+ .property(timestampProperty(TIMESTAMP))
+ .sample(TIMESTAMP, System.currentTimeMillis())
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.String, SENSOR_ID)
+ .label("Sensor ID")
+ .description("The ID of the sensor")
+ .domainProperty(HAS_SENSOR_ID)
+ .scope(PropertyScope.DIMENSION_PROPERTY)
+ .build())
+ .sample("sensorId", "sensor01")
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Float, MASS_FLOW)
+ .label("Mass Flow")
+ .description("Denotes the current mass flow in the sensor")
+ .domainProperty(SO.Number)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample(MASS_FLOW, 5.76f)
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Float, "volume_flow")
+ .label("Volume Flow")
+ .description("Denotes the current volume flow")
+ .domainProperty(SO.Number)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample("volume_flow", 3.34f)
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Float, TEMPERATURE)
+ .label("Temperature")
+ .description("Denotes the current temperature in degrees celsius")
+ .domainProperty(SO.Number)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .measurementUnit(URI.create("http://codes.wmo.int/common/unit/degC"))
+ .valueSpecification(0.0f, 100.0f, 0.1f)
+ .build())
+ .sample(TEMPERATURE, 33.221f)
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Float, "density")
+ .label("Density")
+ .description("Denotes the current density of the fluid")
+ .domainProperty(SO.Number)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample("density", 5.0f)
+ .property(PrimitivePropertyBuilder
+ .create(Datatypes.Boolean, "sensor_fault_flags")
+ .label("Sensor Fault Flags")
+ .description("Any fault flags of the sensors")
+ .domainProperty(SO.Boolean)
+ .scope(PropertyScope.MEASUREMENT_PROPERTY)
+ .build())
+ .sample("sensor_fault_flags", true)
+ .build();
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataStreamAdapter.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataStreamAdapter.java
index aaf7a90ee..b5d4717e9 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataStreamAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/simulator/machine/MachineDataStreamAdapter.java
@@ -1,4 +1,4 @@
-package org.apache.streampipes.connect.iiot.adapters.simulator.machine;/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -15,11 +15,12 @@ package org.apache.streampipes.connect.iiot.adapters.simulator.machine;/*
* limitations under the License.
*
*/
+package org.apache.streampipes.connect.iiot.adapters.simulator.machine;
import org.apache.streampipes.connect.adapter.Adapter;
+import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.api.exception.ParseException;
-import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -34,60 +35,62 @@ import java.util.ArrayList;
public class MachineDataStreamAdapter extends SpecificDataStreamAdapter {
- public static final String ID = "org.apache.streampipes.connect.iiot.adapters.simulator.machine";
- private static final String WAIT_TIME_MS = "wait-time-ms";
- private static final String SELECTED_SIMULATOR_OPTION = "selected-simulator-option";
+ public static final String ID = "org.apache.streampipes.connect.iiot.adapters.simulator.machine";
+ private static final String WAIT_TIME_MS = "wait-time-ms";
+ private static final String SELECTED_SIMULATOR_OPTION = "selected-simulator-option";
- private String selectedSimulatorOption = "";
+ private String selectedSimulatorOption = "";
- private MachineDataSimulator machineDataSimulator;
+ private MachineDataSimulator machineDataSimulator;
- public MachineDataStreamAdapter() {
- }
+ public MachineDataStreamAdapter() {
+ }
- public MachineDataStreamAdapter(SpecificAdapterStreamDescription adapterStreamDescription) {
- super(adapterStreamDescription);
- StaticPropertyExtractor extractor = StaticPropertyExtractor.from(adapterStreamDescription.getConfig(), new ArrayList<>());
- Integer waitTimeMs = extractor.singleValueParameter(WAIT_TIME_MS, Integer.class);
- this.selectedSimulatorOption = extractor.selectedSingleValue(SELECTED_SIMULATOR_OPTION, String.class);
- this.machineDataSimulator = new MachineDataSimulator(adapterPipeline, waitTimeMs, selectedSimulatorOption);
- }
+ public MachineDataStreamAdapter(SpecificAdapterStreamDescription adapterStreamDescription) {
+ super(adapterStreamDescription);
+ StaticPropertyExtractor extractor =
+ StaticPropertyExtractor.from(adapterStreamDescription.getConfig(), new ArrayList<>());
+ Integer waitTimeMs = extractor.singleValueParameter(WAIT_TIME_MS, Integer.class);
+ this.selectedSimulatorOption = extractor.selectedSingleValue(SELECTED_SIMULATOR_OPTION, String.class);
+ this.machineDataSimulator = new MachineDataSimulator(adapterPipeline, waitTimeMs, selectedSimulatorOption);
+ }
- @Override
- public SpecificAdapterStreamDescription declareModel() {
- return SpecificDataStreamAdapterBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Debugging)
- .requiredIntegerParameter(Labels.withId(WAIT_TIME_MS), 1000)
- .requiredSingleValueSelection(Labels.withId(SELECTED_SIMULATOR_OPTION), Options.from(
- "flowrate", "pressure", "waterlevel"))
- .build();
- }
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ return SpecificDataStreamAdapterBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Debugging)
+ .requiredIntegerParameter(Labels.withId(WAIT_TIME_MS), 1000)
+ .requiredSingleValueSelection(Labels.withId(SELECTED_SIMULATOR_OPTION), Options.from(
+ "flowrate", "pressure", "waterlevel"))
+ .build();
+ }
- @Override
- public void startAdapter() throws AdapterException {
- Thread thread = new Thread(this.machineDataSimulator);
- thread.start();
- }
+ @Override
+ public void startAdapter() throws AdapterException {
+ Thread thread = new Thread(this.machineDataSimulator);
+ thread.start();
+ }
- @Override
- public void stopAdapter() throws AdapterException {
- this.machineDataSimulator.setRunning(false);
- }
+ @Override
+ public void stopAdapter() throws AdapterException {
+ this.machineDataSimulator.setRunning(false);
+ }
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterStreamDescription) {
- return new MachineDataStreamAdapter(adapterStreamDescription);
- }
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterStreamDescription) {
+ return new MachineDataStreamAdapter(adapterStreamDescription);
+ }
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterStreamDescription) throws AdapterException, ParseException {
- return MachineDataSimulatorUtils.getSchema(this.selectedSimulatorOption);
- }
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterStreamDescription)
+ throws AdapterException, ParseException {
+ return MachineDataSimulatorUtils.getSchema(this.selectedSimulatorOption);
+ }
- @Override
- public String getId() {
- return ID;
- }
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/FileProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/FileProtocol.java
index 8dcb342c4..636cbd2da 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/FileProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/FileProtocol.java
@@ -38,6 +38,7 @@ import org.apache.streampipes.sdk.helpers.Filetypes;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,118 +51,118 @@ import java.util.Map;
public class FileProtocol extends Protocol {
- private static Logger logger = LoggerFactory.getLogger(FileProtocol.class);
-
- public static final String ID = "org.apache.streampipes.connect.iiot.protocol.set.file";
-
- private String selectedFilename;
-
- public FileProtocol() {
+ private static Logger logger = LoggerFactory.getLogger(FileProtocol.class);
+
+ public static final String ID = "org.apache.streampipes.connect.iiot.protocol.set.file";
+
+ private String selectedFilename;
+
+ public FileProtocol() {
+ }
+
+ public FileProtocol(IParser parser,
+ IFormat format,
+ String selectedFilename) {
+ super(parser, format);
+ this.selectedFilename = selectedFilename;
+ }
+
+ @Override
+ public ProtocolDescription declareModel() {
+ return ProtocolDescriptionBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .sourceType(AdapterSourceType.SET)
+ .category(AdapterType.Generic)
+ .requiredFile(Labels.withId("filePath"), Filetypes.XML, Filetypes.JSON, Filetypes.CSV)
+ .build();
+ }
+
+ @Override
+ public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
+ StaticPropertyExtractor extractor = StaticPropertyExtractor.from(protocolDescription.getConfig());
+ String selectedFilename = extractor.selectedFilename("filePath");
+ return new FileProtocol(parser, format, selectedFilename);
+ }
+
+ @Override
+ public void run(IAdapterPipeline adapterPipeline) {
+ FileReader fr = null;
+
+ // TODO fix this. Currently needed because it must be wait till the whole pipeline is up and running
+ try {
+ Thread.sleep(7000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
-
- public FileProtocol(IParser parser,
- IFormat format,
- String selectedFilename) {
- super(parser, format);
- this.selectedFilename = selectedFilename;
+ SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
+ try {
+ InputStream dataInputStream = FileProtocolUtils.getFileInputStream(this.selectedFilename);
+ if (dataInputStream != null) {
+ parser.parse(dataInputStream, stk);
+ } else {
+ logger.warn("Could not read data from file.");
+ }
+ } catch (ParseException e) {
+ logger.error("Error while parsing: " + e.getMessage());
+ } catch (FileNotFoundException e) {
+ logger.error("Error reading file: " + e.getMessage());
}
+ }
- @Override
- public ProtocolDescription declareModel() {
- return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .sourceType(AdapterSourceType.SET)
- .category(AdapterType.Generic)
- .requiredFile(Labels.withId("filePath"), Filetypes.XML, Filetypes.JSON, Filetypes.CSV)
- .build();
- }
+ @Override
+ public void stop() {
- @Override
- public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
- StaticPropertyExtractor extractor = StaticPropertyExtractor.from(protocolDescription.getConfig());
- String selectedFilename = extractor.selectedFilename("filePath");
- return new FileProtocol(parser, format, selectedFilename);
- }
+ }
- @Override
- public void run(IAdapterPipeline adapterPipeline) {
- FileReader fr = null;
-
- // TODO fix this. Currently needed because it must be wait till the whole pipeline is up and running
- try {
- Thread.sleep(7000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
- try {
- InputStream dataInputStream = FileProtocolUtils.getFileInputStream(this.selectedFilename);
- if(dataInputStream != null) {
- parser.parse(dataInputStream, stk);
- } else {
- logger.warn("Could not read data from file.");
- }
- } catch (ParseException e) {
- logger.error("Error while parsing: " + e.getMessage());
- } catch (FileNotFoundException e) {
- logger.error("Error reading file: " + e.getMessage());
- }
- }
+ @Override
+ public GuessSchema getGuessSchema() throws ParseException {
- @Override
- public void stop() {
+ try {
+ InputStream targetStream = FileProtocolUtils.getFileInputStream(this.selectedFilename);
+ List<byte[]> dataByte = parser.parseNEvents(targetStream, 20);
+ if (parser.supportsPreview()) {
+ return SchemaGuesser.guessSchema(parser.getSchemaAndSample(dataByte));
+ } else {
+ EventSchema eventSchema = parser.getEventSchema(dataByte);
+ return SchemaGuesser.guessSchema(eventSchema);
+ }
+ } catch (FileNotFoundException e) {
+ throw new ParseException("Could not read local file");
}
-
- @Override
- public GuessSchema getGuessSchema() throws ParseException {
-
- try {
- InputStream targetStream = FileProtocolUtils.getFileInputStream(this.selectedFilename);
- List<byte[]> dataByte = parser.parseNEvents(targetStream, 20);
-
- if (parser.supportsPreview()) {
- return SchemaGuesser.guessSchema(parser.getSchemaAndSample(dataByte));
- } else {
- EventSchema eventSchema = parser.getEventSchema(dataByte);
- return SchemaGuesser.guessSchema(eventSchema);
- }
- } catch (FileNotFoundException e) {
- throw new ParseException("Could not read local file");
- }
- }
+ }
- @Override
- public List<Map<String, Object>> getNElements(int n) throws ParseException {
- List<Map<String, Object>> result = new ArrayList<>();
+ @Override
+ public List<Map<String, Object>> getNElements(int n) throws ParseException {
+ List<Map<String, Object>> result = new ArrayList<>();
- List<byte[]> dataByteArray = new ArrayList<>();
- try {
- InputStream dataInputStream = FileProtocolUtils.getFileInputStream(this.selectedFilename);
- dataByteArray = parser.parseNEvents(dataInputStream, n);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
-
- // Check that result size is n. Currently just an error is logged. Maybe change to an exception
- if (dataByteArray.size() < n) {
- logger.error("Error in File Protocol! User required: " + n + " elements but the resource just had: " +
- dataByteArray.size());
- }
+ List<byte[]> dataByteArray = new ArrayList<>();
+ try {
+ InputStream dataInputStream = FileProtocolUtils.getFileInputStream(this.selectedFilename);
+ dataByteArray = parser.parseNEvents(dataInputStream, n);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
- for (byte[] b : dataByteArray) {
- result.add(format.parse(b));
- }
+ // Check that result size is n. Currently just an error is logged. Maybe change to an exception
+ if (dataByteArray.size() < n) {
+ logger.error("Error in File Protocol! User required: " + n + " elements but the resource just had: "
+ + dataByteArray.size());
+ }
- return result;
+ for (byte[] b : dataByteArray) {
+ result.add(format.parse(b));
}
+ return result;
+ }
- @Override
- public String getId() {
- return ID;
- }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/HttpProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/HttpProtocol.java
index eca0f25f7..a3753c20e 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/HttpProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/set/HttpProtocol.java
@@ -18,7 +18,6 @@
package org.apache.streampipes.connect.iiot.protocol.set;
-import org.apache.http.client.fluent.Request;
import org.apache.streampipes.connect.SendToPipeline;
import org.apache.streampipes.connect.adapter.guess.SchemaGuesser;
import org.apache.streampipes.connect.adapter.model.generic.Protocol;
@@ -36,6 +35,8 @@ import org.apache.streampipes.sdk.helpers.AdapterSourceType;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
+
+import org.apache.http.client.fluent.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,110 +48,110 @@ import java.util.Map;
public class HttpProtocol extends Protocol {
- Logger logger = LoggerFactory.getLogger(Protocol.class);
+ Logger logger = LoggerFactory.getLogger(Protocol.class);
- public static final String ID = "org.apache.streampipes.connect.iiot.protocol.set.http";
+ public static final String ID = "org.apache.streampipes.connect.iiot.protocol.set.http";
- private String url;
+ private String url;
- public HttpProtocol() {
- }
+ public HttpProtocol() {
+ }
- public HttpProtocol(IParser parser, IFormat format, String url) {
- super(parser, format);
- this.url = url;
- }
+ public HttpProtocol(IParser parser, IFormat format, String url) {
+ super(parser, format);
+ this.url = url;
+ }
- @Override
- public ProtocolDescription declareModel() {
- return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Generic)
- .sourceType(AdapterSourceType.SET)
- .requiredTextParameter(Labels.withId("url"))
- .build();
- }
+ @Override
+ public ProtocolDescription declareModel() {
+ return ProtocolDescriptionBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Generic)
+ .sourceType(AdapterSourceType.SET)
+ .requiredTextParameter(Labels.withId("url"))
+ .build();
+ }
- @Override
- public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
- ParameterExtractor extractor = new ParameterExtractor(protocolDescription.getConfig());
- String url = extractor.singleValue("url");
+ @Override
+ public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
+ ParameterExtractor extractor = new ParameterExtractor(protocolDescription.getConfig());
+ String url = extractor.singleValue("url");
- return new HttpProtocol(parser, format, url);
- }
+ return new HttpProtocol(parser, format, url);
+ }
- @Override
- public void run(IAdapterPipeline adapterPipeline) {
+ @Override
+ public void run(IAdapterPipeline adapterPipeline) {
- // TODO fix this. Currently needed because it must be wait till the whole pipeline is up and running
- try {
- Thread.sleep(7000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ // TODO fix this. Currently needed because it must be wait till the whole pipeline is up and running
+ try {
+ Thread.sleep(7000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
- SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
+ SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
- InputStream data = getDataFromEndpoint();
- try {
- parser.parse(data, stk);
+ InputStream data = getDataFromEndpoint();
+ try {
+ parser.parse(data, stk);
- } catch (ParseException e) {
- logger.error("Error while parsing: " + e.getMessage());
- }
+ } catch (ParseException e) {
+ logger.error("Error while parsing: " + e.getMessage());
}
+ }
- @Override
- public void stop() {
-
- }
+ @Override
+ public void stop() {
+ }
- @Override
- public GuessSchema getGuessSchema() throws ParseException {
- InputStream dataInputStream = getDataFromEndpoint();
+ @Override
+ public GuessSchema getGuessSchema() throws ParseException {
- List<byte[]> dataByte = parser.parseNEvents(dataInputStream, 2);
+ InputStream dataInputStream = getDataFromEndpoint();
- EventSchema eventSchema= parser.getEventSchema(dataByte);
+ List<byte[]> dataByte = parser.parseNEvents(dataInputStream, 2);
- GuessSchema result = SchemaGuesser.guessSchema(eventSchema);
+ EventSchema eventSchema = parser.getEventSchema(dataByte);
- return result;
- }
+ GuessSchema result = SchemaGuesser.guessSchema(eventSchema);
- @Override
- public List<Map<String, Object>> getNElements(int n) throws ParseException {
+ return result;
+ }
- List<Map<String, Object>> result = new ArrayList<>();
+ @Override
+ public List<Map<String, Object>> getNElements(int n) throws ParseException {
- InputStream dataInputStream = getDataFromEndpoint();
+ List<Map<String, Object>> result = new ArrayList<>();
- List<byte[]> dataByteArray = parser.parseNEvents(dataInputStream, n);
+ InputStream dataInputStream = getDataFromEndpoint();
- // Check that result size is n. Currently just an error is logged. Maybe change to an exception
- if (dataByteArray.size() < n) {
- logger.error("Error in HttpProtocol! User required: " + n + " elements but the resource just had: " +
- dataByteArray.size());
- }
+ List<byte[]> dataByteArray = parser.parseNEvents(dataInputStream, n);
- for (byte[] b : dataByteArray) {
- result.add(format.parse(b));
- }
+ // Check that result size is n. Currently just an error is logged. Maybe change to an exception
+ if (dataByteArray.size() < n) {
+ logger.error("Error in HttpProtocol! User required: " + n + " elements but the resource just had: " +
+ dataByteArray.size());
+ }
- return result;
+ for (byte[] b : dataByteArray) {
+ result.add(format.parse(b));
}
- public InputStream getDataFromEndpoint() throws ParseException {
- InputStream result = null;
+ return result;
+ }
- try {
- result = Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asStream();
+ public InputStream getDataFromEndpoint() throws ParseException {
+ InputStream result = null;
+
+ try {
+ result = Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asStream();
// if (s.startsWith("ï")) {
// s = s.substring(3);
@@ -158,18 +159,19 @@ public class HttpProtocol extends Protocol {
// result = IOUtils.toInputStream(s, "UTF-8");
- } catch (IOException e) {
- throw new ParseException("Could not receive Data from: " + url);
- }
+ } catch (IOException e) {
+ throw new ParseException("Could not receive Data from: " + url);
+ }
- if (result == null)
- throw new ParseException("Could not receive Data from: " + url);
+ if (result == null) {
+ throw new ParseException("Could not receive Data from: " + url);
+ }
- return result;
- }
+ return result;
+ }
- @Override
- public String getId() {
- return ID;
- }
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/BrokerEventProcessor.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/BrokerEventProcessor.java
index 7130d809e..e32d5d1bc 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/BrokerEventProcessor.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/BrokerEventProcessor.java
@@ -18,12 +18,13 @@
package org.apache.streampipes.connect.iiot.protocol.stream;
-import org.apache.commons.io.IOUtils;
import org.apache.streampipes.connect.SendToPipeline;
import org.apache.streampipes.connect.api.IParser;
import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.messaging.InternalEventProcessor;
+import org.apache.commons.io.IOUtils;
+
public class BrokerEventProcessor implements InternalEventProcessor<byte[]> {
private SendToPipeline stk;
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/FileStreamProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/FileStreamProtocol.java
index f88f5c538..97e3fc53f 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/FileStreamProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/FileStreamProtocol.java
@@ -33,11 +33,20 @@ import org.apache.streampipes.connect.iiot.utils.FileProtocolUtils;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.grounding.ProtocolDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
-import org.apache.streampipes.model.schema.*;
+import org.apache.streampipes.model.schema.EventProperty;
+import org.apache.streampipes.model.schema.EventPropertyList;
+import org.apache.streampipes.model.schema.EventPropertyNested;
+import org.apache.streampipes.model.schema.EventPropertyPrimitive;
+import org.apache.streampipes.model.schema.EventSchema;
import org.apache.streampipes.sdk.builder.adapter.ProtocolDescriptionBuilder;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
-import org.apache.streampipes.sdk.helpers.*;
+import org.apache.streampipes.sdk.helpers.AdapterSourceType;
+import org.apache.streampipes.sdk.helpers.Filetypes;
+import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.helpers.Options;
import org.apache.streampipes.sdk.utils.Assets;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,7 +65,7 @@ public class FileStreamProtocol extends Protocol {
//private String filePath;
private String selectedFileName;
- // private String timestampKey;
+ // private String timestampKey;
private boolean replaceTimestamp;
private float speedUp;
private int timeBetweenReplay;
@@ -83,53 +92,53 @@ public class FileStreamProtocol extends Protocol {
// exchange adapter pipeline sink with special purpose replay sink for file replay
if (adapterPipeline.getPipelineSink() instanceof SendToKafkaAdapterSink) {
- adapterPipeline.changePipelineSink(new SendToBrokerReplayAdapterSink(
- (SendToKafkaAdapterSink) adapterPipeline.getPipelineSink(),
- timestampKey,
- replaceTimestamp,
- speedUp));
+ adapterPipeline.changePipelineSink(new SendToBrokerReplayAdapterSink(
+ (SendToKafkaAdapterSink) adapterPipeline.getPipelineSink(),
+ timestampKey,
+ replaceTimestamp,
+ speedUp));
} else if (adapterPipeline.getPipelineSink() instanceof SendToMqttAdapterSink) {
- adapterPipeline.changePipelineSink(new SendToBrokerReplayAdapterSink(
- (SendToMqttAdapterSink) adapterPipeline.getPipelineSink(),
- timestampKey,
- replaceTimestamp,
- speedUp));
+ adapterPipeline.changePipelineSink(new SendToBrokerReplayAdapterSink(
+ (SendToMqttAdapterSink) adapterPipeline.getPipelineSink(),
+ timestampKey,
+ replaceTimestamp,
+ speedUp));
} else if (adapterPipeline.getPipelineSink() instanceof SendToJmsAdapterSink) {
- adapterPipeline.changePipelineSink(new SendToBrokerReplayAdapterSink(
- (SendToJmsAdapterSink) adapterPipeline.getPipelineSink(),
- timestampKey,
- replaceTimestamp,
- speedUp));
+ adapterPipeline.changePipelineSink(new SendToBrokerReplayAdapterSink(
+ (SendToJmsAdapterSink) adapterPipeline.getPipelineSink(),
+ timestampKey,
+ replaceTimestamp,
+ speedUp));
}
running = true;
task = new Thread() {
- @Override
- public void run() {
- while (running) {
-
- format.reset();
- SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
- InputStream dataInputStream = getDataFromEndpoint();
- try {
- if(dataInputStream != null) {
- parser.parse(dataInputStream, stk);
- } else {
- logger.warn("Could not read data from file.");
- }
- } catch (ParseException e) {
- logger.error("Error while parsing: " + e.getMessage());
+ @Override
+ public void run() {
+ while (running) {
+
+ format.reset();
+ SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
+ InputStream dataInputStream = getDataFromEndpoint();
+ try {
+ if (dataInputStream != null) {
+ parser.parse(dataInputStream, stk);
+ } else {
+ logger.warn("Could not read data from file.");
}
+ } catch (ParseException e) {
+ logger.error("Error while parsing: " + e.getMessage());
+ }
- try {
- Thread.sleep(timeBetweenReplay * 1000);
- } catch (InterruptedException e) {
- logger.error("Error while waiting for next replay round" + e.getMessage());
- }
+ try {
+ Thread.sleep(timeBetweenReplay * 1000);
+ } catch (InterruptedException e) {
+ logger.error("Error while waiting for next replay round" + e.getMessage());
}
}
+ }
};
task.start();
}
@@ -143,8 +152,8 @@ public class FileStreamProtocol extends Protocol {
private InputStream getDataFromEndpoint() throws ParseException {
- try {
- return FileProtocolUtils.getFileInputStream(this.selectedFileName);
+ try {
+ return FileProtocolUtils.getFileInputStream(this.selectedFileName);
} catch (IOException e) {
throw new ParseException("Could not find file: " + selectedFileName);
}
@@ -152,11 +161,12 @@ public class FileStreamProtocol extends Protocol {
@Override
public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
- StaticPropertyExtractor extractor = StaticPropertyExtractor.from(protocolDescription.getConfig(), new ArrayList<>());
+ StaticPropertyExtractor extractor =
+ StaticPropertyExtractor.from(protocolDescription.getConfig(), new ArrayList<>());
List<String> replaceTimestampStringList = extractor.selectedMultiValues("replaceTimestamp", String.class);
// String replaceTimestampString = extractor.selectedSingleValueOption("replaceTimestamp");
- boolean replaceTimestamp = replaceTimestampStringList.size() == 0 ? false : true;
+ boolean replaceTimestamp = replaceTimestampStringList.size() != 0;
float speedUp = extractor.singleValueParameter("speed", Float.class);
@@ -175,12 +185,14 @@ public class FileStreamProtocol extends Protocol {
result = prefixKey + eventProperty.getRuntimeName();
}
}
- } else if (eventProperty instanceof EventPropertyNested && ((EventPropertyNested) eventProperty).getEventProperties() != null) {
+ } else if (eventProperty instanceof EventPropertyNested
+ && ((EventPropertyNested) eventProperty).getEventProperties() != null) {
result = getTimestampKey(((EventPropertyNested) eventProperty).getEventProperties(),
- prefixKey + eventProperty.getRuntimeName() + ".");
- } else if (eventProperty instanceof EventPropertyList && ((EventPropertyList) eventProperty).getEventProperty() != null) {
+ prefixKey + eventProperty.getRuntimeName() + ".");
+ } else if (eventProperty instanceof EventPropertyList
+ && ((EventPropertyList) eventProperty).getEventProperty() != null) {
result = getTimestampKey(Arrays.asList(((EventPropertyList) eventProperty).getEventProperty()),
- prefixKey + eventProperty.getRuntimeName() + ".");
+ prefixKey + eventProperty.getRuntimeName() + ".");
}
if (result != null) {
return result;
@@ -192,22 +204,22 @@ public class FileStreamProtocol extends Protocol {
@Override
public ProtocolDescription declareModel() {
return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .sourceType(AdapterSourceType.STREAM)
- .category(AdapterType.Generic)
- .requiredFile(Labels.withId("filePath"), Filetypes.CSV, Filetypes.JSON, Filetypes.XML)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .sourceType(AdapterSourceType.STREAM)
+ .category(AdapterType.Generic)
+ .requiredFile(Labels.withId("filePath"), Filetypes.CSV, Filetypes.JSON, Filetypes.XML)
// .requiredSingleValueSelection(Labels.withId("replaceTimestamp"),
// Options.from("True", "False"))
- .requiredMultiValueSelection(Labels.withId("replaceTimestamp"),
- Options.from(""))
- .requiredFloatParameter(Labels.withId("speed"))
- .build();
+ .requiredMultiValueSelection(Labels.withId("replaceTimestamp"),
+ Options.from(""))
+ .requiredFloatParameter(Labels.withId("speed"))
+ .build();
}
@Override
public GuessSchema getGuessSchema() throws ParseException {
- InputStream dataInputStream = getDataFromEndpoint();
+ InputStream dataInputStream = getDataFromEndpoint();
List<byte[]> dataByte = parser.parseNEvents(dataInputStream, 2);
@@ -227,10 +239,10 @@ public class FileStreamProtocol extends Protocol {
List<byte[]> dataByteArray = parser.parseNEvents(dataInputStream, n);
- // Check that result size is n. Currently just an error is logged. Maybe change to an exception
+ // Check that result size is n. Currently, just an error is logged. Maybe change to an exception
if (dataByteArray.size() < n) {
- logger.error("Error in File Protocol! User required: " + n + " elements but the resource just had: " +
- dataByteArray.size());
+ logger.error("Error in File Protocol! User required: " + n + " elements but the resource just had: "
+ + dataByteArray.size());
}
for (byte[] b : dataByteArray) {
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpServerProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpServerProtocol.java
index 6b6f21b6f..7fed6bcad 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpServerProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpServerProtocol.java
@@ -37,7 +37,12 @@ import org.apache.streampipes.sdk.StaticProperties;
import org.apache.streampipes.sdk.builder.adapter.GuessSchemaBuilder;
import org.apache.streampipes.sdk.builder.adapter.ProtocolDescriptionBuilder;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
-import org.apache.streampipes.sdk.helpers.*;
+import org.apache.streampipes.sdk.helpers.AdapterSourceType;
+import org.apache.streampipes.sdk.helpers.Alternatives;
+import org.apache.streampipes.sdk.helpers.Filetypes;
+import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.helpers.Options;
import org.apache.streampipes.sdk.utils.Assets;
import org.apache.streampipes.sdk.utils.Datatypes;
@@ -74,7 +79,7 @@ public class HttpServerProtocol extends Protocol {
public HttpServerProtocol(ProtocolDescription adapterDescription, IParser parser, IFormat format) {
super(parser, format);
StaticPropertyExtractor extractor =
- StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+ StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
this.adapterDescription = adapterDescription;
this.endpointId = extractor.singleValueParameter(ENDPOINT_NAME, String.class);
}
@@ -87,27 +92,27 @@ public class HttpServerProtocol extends Protocol {
@Override
public ProtocolDescription declareModel() {
return ProtocolDescriptionBuilder.create(ID)
- .withLocales(Locales.EN)
- .sourceType(AdapterSourceType.STREAM)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .category(AdapterType.Generic)
- .requiredTextParameter(Labels.withId(ENDPOINT_NAME))
- .requiredAlternatives(Labels.withId(CONFIGURE),
- Alternatives.from(Labels.withId(MANUALLY),
- StaticProperties.collection(Labels.withId(EP_CONFIG),
- StaticProperties.stringFreeTextProperty(Labels.withId(EP_RUNTIME_NAME)),
- StaticProperties.singleValueSelection(Labels.withId(EP_RUNTIME_TYPE),
- Options.from("String", "Integer", "Double", "Boolean")),
- StaticProperties.stringFreeTextProperty(Labels.withId(EP_DOMAIN_PROPERTY)))),
- Alternatives.from(Labels.withId(FILE_IMPORT),
- StaticProperties.fileProperty(Labels.withId(FILE), Filetypes.CSV, Filetypes.JSON, Filetypes.XML)))
- .build();
+ .withLocales(Locales.EN)
+ .sourceType(AdapterSourceType.STREAM)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .category(AdapterType.Generic)
+ .requiredTextParameter(Labels.withId(ENDPOINT_NAME))
+ .requiredAlternatives(Labels.withId(CONFIGURE),
+ Alternatives.from(Labels.withId(MANUALLY),
+ StaticProperties.collection(Labels.withId(EP_CONFIG),
+ StaticProperties.stringFreeTextProperty(Labels.withId(EP_RUNTIME_NAME)),
+ StaticProperties.singleValueSelection(Labels.withId(EP_RUNTIME_TYPE),
+ Options.from("String", "Integer", "Double", "Boolean")),
+ StaticProperties.stringFreeTextProperty(Labels.withId(EP_DOMAIN_PROPERTY)))),
+ Alternatives.from(Labels.withId(FILE_IMPORT),
+ StaticProperties.fileProperty(Labels.withId(FILE), Filetypes.CSV, Filetypes.JSON, Filetypes.XML)))
+ .build();
}
@Override
public GuessSchema getGuessSchema() throws ParseException {
StaticPropertyExtractor extractor =
- StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+ StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
GuessSchemaBuilder schemaBuilder = GuessSchemaBuilder.create();
String selectedImportMode = extractor.selectedAlternativeInternalId(CONFIGURE);
@@ -117,7 +122,7 @@ public class HttpServerProtocol extends Protocol {
for (StaticProperty member : sp.getMembers()) {
StaticPropertyExtractor memberExtractor =
- StaticPropertyExtractor.from(((StaticPropertyGroup) member).getStaticProperties(), new ArrayList<>());
+ StaticPropertyExtractor.from(((StaticPropertyGroup) member).getStaticProperties(), new ArrayList<>());
schemaBuilder.property(makeProperty(memberExtractor));
}
}
@@ -130,8 +135,8 @@ public class HttpServerProtocol extends Protocol {
primitive.setRuntimeName(memberExtractor.singleValueParameter(EP_RUNTIME_NAME, String.class));
primitive.setRuntimeType(extractRuntimeType(memberExtractor.selectedSingleValue(EP_RUNTIME_TYPE, String.class)));
primitive
- .setDomainProperties(Collections
- .singletonList(URI.create(memberExtractor.singleValueParameter(EP_DOMAIN_PROPERTY, String.class))));
+ .setDomainProperties(Collections
+ .singletonList(URI.create(memberExtractor.singleValueParameter(EP_DOMAIN_PROPERTY, String.class))));
return primitive;
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
index be6882957..1a674f7cd 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
@@ -18,17 +18,12 @@
package org.apache.streampipes.connect.iiot.protocol.stream;
-import org.apache.http.client.fluent.Request;
-import org.apache.streampipes.connect.api.IParser;
-import org.apache.streampipes.sdk.helpers.Locales;
-import org.apache.streampipes.sdk.utils.Assets;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.connect.adapter.guess.SchemaGuesser;
-import org.apache.streampipes.connect.api.IFormat;
import org.apache.streampipes.connect.adapter.model.generic.Protocol;
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
+import org.apache.streampipes.connect.api.IFormat;
+import org.apache.streampipes.connect.api.IParser;
+import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.grounding.ProtocolDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -36,6 +31,12 @@ import org.apache.streampipes.model.schema.EventSchema;
import org.apache.streampipes.sdk.builder.adapter.ProtocolDescriptionBuilder;
import org.apache.streampipes.sdk.helpers.AdapterSourceType;
import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.utils.Assets;
+
+import org.apache.http.client.fluent.Request;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.util.ArrayList;
@@ -44,121 +45,120 @@ import java.util.Map;
public class HttpStreamProtocol extends PullProtocol {
- Logger logger = LoggerFactory.getLogger(HttpStreamProtocol.class);
-
- public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.http";
+ Logger logger = LoggerFactory.getLogger(HttpStreamProtocol.class);
- private static String URL_PROPERTY ="url";
- private static String INTERVAL_PROPERTY ="interval";
- private static String ACCESS_TOKEN_PROPERTY ="access_token";
+ public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.http";
- private String url;
- private String accessToken;
+ private static final String URL_PROPERTY = "url";
+ private static final String INTERVAL_PROPERTY = "interval";
+ private static final String ACCESS_TOKEN_PROPERTY = "access_token";
- public HttpStreamProtocol() {
- }
+ private String url;
+ private String accessToken;
+ public HttpStreamProtocol() {
+ }
- public HttpStreamProtocol(IParser parser, IFormat format, String url, long interval, String accessToken) {
- super(parser, format, interval);
- this.url = url;
- this.accessToken = accessToken;
- }
+ public HttpStreamProtocol(IParser parser, IFormat format, String url, long interval, String accessToken) {
+ super(parser, format, interval);
+ this.url = url;
+ this.accessToken = accessToken;
+ }
- @Override
- public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
- ParameterExtractor extractor = new ParameterExtractor(protocolDescription.getConfig());
+ @Override
+ public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
+ ParameterExtractor extractor = new ParameterExtractor(protocolDescription.getConfig());
- String urlProperty = extractor.singleValue(URL_PROPERTY);
- try {
- long intervalProperty = Long.parseLong(extractor.singleValue(INTERVAL_PROPERTY));
- // TODO change access token to an optional parameter
+ String urlProperty = extractor.singleValue(URL_PROPERTY);
+ try {
+ long intervalProperty = Long.parseLong(extractor.singleValue(INTERVAL_PROPERTY));
+ // TODO change access token to an optional parameter
// String accessToken = extractor.singleValue(ACCESS_TOKEN_PROPERTY);
- String accessToken = "";
- return new HttpStreamProtocol(parser, format, urlProperty, intervalProperty, accessToken);
- } catch (NumberFormatException e) {
- logger.error("Could not parse" + extractor.singleValue(INTERVAL_PROPERTY) + "to int");
- return null;
- }
-
+ String accessToken = "";
+ return new HttpStreamProtocol(parser, format, urlProperty, intervalProperty, accessToken);
+ } catch (NumberFormatException e) {
+ logger.error("Could not parse" + extractor.singleValue(INTERVAL_PROPERTY) + "to int");
+ return null;
}
- @Override
- public ProtocolDescription declareModel() {
- return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .sourceType(AdapterSourceType.STREAM)
- .category(AdapterType.Generic)
- .requiredTextParameter(Labels.withId(URL_PROPERTY))
- .requiredIntegerParameter(Labels.withId(INTERVAL_PROPERTY))
- //.requiredTextParameter(Labels.from(ACCESS_TOKEN_PROPERTY, "Access Token", "Http
- // Access Token"))
- .build();
+ }
+
+ @Override
+ public ProtocolDescription declareModel() {
+ return ProtocolDescriptionBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .sourceType(AdapterSourceType.STREAM)
+ .category(AdapterType.Generic)
+ .requiredTextParameter(Labels.withId(URL_PROPERTY))
+ .requiredIntegerParameter(Labels.withId(INTERVAL_PROPERTY))
+ //.requiredTextParameter(Labels.from(ACCESS_TOKEN_PROPERTY, "Access Token", "Http
+ // Access Token"))
+ .build();
+ }
+
+ @Override
+ public GuessSchema getGuessSchema() throws ParseException {
+ int n = 2;
+
+ InputStream dataInputStream = getDataFromEndpoint();
+
+ List<byte[]> dataByte = parser.parseNEvents(dataInputStream, n);
+ if (dataByte.size() < n) {
+ logger.error("Error in HttpStreamProtocol! Required: " + n + " elements but the resource just had: "
+ + dataByte.size());
+
+ dataByte.addAll(dataByte);
}
+ EventSchema eventSchema = parser.getEventSchema(dataByte);
+ GuessSchema result = SchemaGuesser.guessSchema(eventSchema);
- @Override
- public GuessSchema getGuessSchema() throws ParseException {
- int n = 2;
+ return result;
+ }
- InputStream dataInputStream = getDataFromEndpoint();
+ @Override
+ public List<Map<String, Object>> getNElements(int n) throws ParseException {
+ List<Map<String, Object>> result = new ArrayList<>();
- List<byte[]> dataByte = parser.parseNEvents(dataInputStream, n);
- if (dataByte.size() < n) {
- logger.error("Error in HttpStreamProtocol! Required: " + n + " elements but the resource just had: " +
- dataByte.size());
+ InputStream dataInputStream = getDataFromEndpoint();
- dataByte.addAll(dataByte);
- }
- EventSchema eventSchema= parser.getEventSchema(dataByte);
- GuessSchema result = SchemaGuesser.guessSchema(eventSchema);
+ List<byte[]> dataByte = parser.parseNEvents(dataInputStream, n);
- return result;
+ // Check that result size is n. Currently just an error is logged. Maybe change to an exception
+ if (dataByte.size() < n) {
+ logger.error("Error in HttpStreamProtocol! User required: " + n + " elements but the resource just had: "
+ + dataByte.size());
}
- @Override
- public List<Map<String, Object>> getNElements(int n) throws ParseException {
- List<Map<String, Object>> result = new ArrayList<>();
-
- InputStream dataInputStream = getDataFromEndpoint();
-
- List<byte[]> dataByte = parser.parseNEvents(dataInputStream, n);
-
- // Check that result size is n. Currently just an error is logged. Maybe change to an exception
- if (dataByte.size() < n) {
- logger.error("Error in HttpStreamProtocol! User required: " + n + " elements but the resource just had: " +
- dataByte.size());
- }
-
- for (byte[] b : dataByte) {
- result.add(format.parse(b));
- }
-
- return result;
+ for (byte[] b : dataByte) {
+ result.add(format.parse(b));
}
+ return result;
+ }
- @Override
- public String getId() {
- return ID;
- }
- @Override
- public InputStream getDataFromEndpoint() throws ParseException {
- InputStream result = null;
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ @Override
+ public InputStream getDataFromEndpoint() throws ParseException {
+ InputStream result = null;
- try {
- Request request = Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000);
+ try {
+ Request request = Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000);
- if (this.accessToken != null && !this.accessToken.equals("")) {
- request.setHeader("Authorization", "Bearer " + this.accessToken);
- }
+ if (this.accessToken != null && !this.accessToken.equals("")) {
+ request.setHeader("Authorization", "Bearer " + this.accessToken);
+ }
- result = request
- .execute().returnContent().asStream();
+ result = request
+ .execute().returnContent().asStream();
// if (s.startsWith("ï")) {
// s = s.substring(3);
@@ -166,14 +166,15 @@ public class HttpStreamProtocol extends PullProtocol {
// result = IOUtils.toInputStream(s, "UTF-8");
- } catch (Exception e) {
- logger.error("Error while fetching data from URL: " + url, e);
- throw new ParseException("Error while fetching data from URL: " + url);
+ } catch (Exception e) {
+ logger.error("Error while fetching data from URL: " + url, e);
+ throw new ParseException("Error while fetching data from URL: " + url);
// throw new AdapterException();
- }
- if (result == null)
- throw new ParseException("Could not receive Data from file: " + url);
-
- return result;
}
+ if (result == null) {
+ throw new ParseException("Could not receive Data from file: " + url);
+ }
+
+ return result;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/KafkaProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/KafkaProtocol.java
index cdc8cb492..18aed7d12 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/KafkaProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/KafkaProtocol.java
@@ -18,11 +18,7 @@
package org.apache.streampipes.connect.iiot.protocol.stream;
-import org.apache.commons.io.IOUtils;
-import org.apache.kafka.clients.consumer.*;
-import org.apache.kafka.common.KafkaException;
-import org.apache.kafka.common.TopicPartition;
-import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+
import org.apache.streampipes.commons.constants.GlobalStreamPipesConstants;
import org.apache.streampipes.commons.exceptions.SpConfigurationException;
import org.apache.streampipes.commons.exceptions.SpRuntimeException;
@@ -50,220 +46,237 @@ import org.apache.streampipes.sdk.helpers.AdapterSourceType;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.kafka.clients.consumer.Consumer;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.common.KafkaException;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
import java.util.stream.Collectors;
public class KafkaProtocol extends BrokerProtocol implements SupportsRuntimeConfig {
- Logger logger = LoggerFactory.getLogger(KafkaProtocol.class);
- KafkaConfig config;
+ Logger logger = LoggerFactory.getLogger(KafkaProtocol.class);
+ KafkaConfig config;
- public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.kafka";
+ public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.kafka";
- private Thread thread;
- private SpKafkaConsumer kafkaConsumer;
+ private Thread thread;
+ private SpKafkaConsumer kafkaConsumer;
- public KafkaProtocol() {
- }
+ public KafkaProtocol() {
+ }
- public KafkaProtocol(IParser parser, IFormat format, KafkaConfig config) {
- super(parser, format, config.getKafkaHost() + ":" + config.getKafkaPort(), config.getTopic());
- this.config = config;
- }
+ public KafkaProtocol(IParser parser, IFormat format, KafkaConfig config) {
+ super(parser, format, config.getKafkaHost() + ":" + config.getKafkaPort(), config.getTopic());
+ this.config = config;
+ }
- @Override
- public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
- StaticPropertyExtractor extractor = StaticPropertyExtractor
- .from(protocolDescription.getConfig(), new ArrayList<>());
- this.config = KafkaConnectUtils.getConfig(extractor, true);
+ @Override
+ public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
+ StaticPropertyExtractor extractor = StaticPropertyExtractor
+ .from(protocolDescription.getConfig(), new ArrayList<>());
+ this.config = KafkaConnectUtils.getConfig(extractor, true);
- return new KafkaProtocol(parser, format, config);
- }
+ return new KafkaProtocol(parser, format, config);
+ }
- @Override
- public ProtocolDescription declareModel() {
- return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Generic, AdapterType.Manufacturing)
- .sourceType(AdapterSourceType.STREAM)
-
- .requiredAlternatives(Labels.withId(KafkaConnectUtils.ACCESS_MODE),
- KafkaConnectUtils.getAlternativeUnauthenticatedPlain(),
- KafkaConnectUtils.getAlternativeUnauthenticatedSSL(),
- KafkaConnectUtils.getAlternativesSaslPlain(),
- KafkaConnectUtils.getAlternativesSaslSSL())
-
- .requiredTextParameter(KafkaConnectUtils.getHostLabel())
- .requiredIntegerParameter(KafkaConnectUtils.getPortLabel())
-
- .requiredSlideToggle(KafkaConnectUtils.getHideInternalTopicsLabel(), true)
-
- .requiredSingleValueSelectionFromContainer(KafkaConnectUtils.getTopicLabel(), Arrays.asList(
- KafkaConnectUtils.HOST_KEY,
- KafkaConnectUtils.PORT_KEY))
- .build();
- }
+ @Override
+ public ProtocolDescription declareModel() {
+ return ProtocolDescriptionBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Generic, AdapterType.Manufacturing)
+ .sourceType(AdapterSourceType.STREAM)
- @Override
- protected List<byte[]> getNByteElements(int n) throws ParseException {
- final Consumer<byte[], byte[]> consumer;
+ .requiredAlternatives(Labels.withId(KafkaConnectUtils.ACCESS_MODE),
+ KafkaConnectUtils.getAlternativeUnauthenticatedPlain(),
+ KafkaConnectUtils.getAlternativeUnauthenticatedSSL(),
+ KafkaConnectUtils.getAlternativesSaslPlain(),
+ KafkaConnectUtils.getAlternativesSaslSSL())
+
+ .requiredTextParameter(KafkaConnectUtils.getHostLabel())
+ .requiredIntegerParameter(KafkaConnectUtils.getPortLabel())
+
+ .requiredSlideToggle(KafkaConnectUtils.getHideInternalTopicsLabel(), true)
- consumer = createConsumer(this.config);
- consumer.subscribe(Arrays.asList(this.topic), new ConsumerRebalanceListener() {
- @Override
- public void onPartitionsRevoked(Collection<TopicPartition> collection) {
+ .requiredSingleValueSelectionFromContainer(KafkaConnectUtils.getTopicLabel(), Arrays.asList(
+ KafkaConnectUtils.HOST_KEY,
+ KafkaConnectUtils.PORT_KEY))
+ .build();
+ }
- }
+ @Override
+ protected List<byte[]> getNByteElements(int n) throws ParseException {
+ final Consumer<byte[], byte[]> consumer;
- @Override
- public void onPartitionsAssigned(Collection<TopicPartition> collection) {
- consumer.seekToBeginning(collection);
- }
- });
+ consumer = createConsumer(this.config);
+ consumer.subscribe(Arrays.asList(this.topic), new ConsumerRebalanceListener() {
+ @Override
+ public void onPartitionsRevoked(Collection<TopicPartition> collection) {
- List<byte[]> nEventsByte = new ArrayList<>();
- List<byte[]> resultEventsByte;
+ }
+ @Override
+ public void onPartitionsAssigned(Collection<TopicPartition> collection) {
+ consumer.seekToBeginning(collection);
+ }
+ });
- while (true) {
- final ConsumerRecords<byte[], byte[]> consumerRecords =
- consumer.poll(1000);
+ List<byte[]> nEventsByte = new ArrayList<>();
+ List<byte[]> resultEventsByte;
- consumerRecords.forEach(record -> {
- InputStream inputStream = new ByteArrayInputStream(record.value());
- nEventsByte.addAll(parser.parseNEvents(inputStream, n));
- });
+ while (true) {
+ final ConsumerRecords<byte[], byte[]> consumerRecords =
+ consumer.poll(1000);
- if (nEventsByte.size() > n) {
- resultEventsByte = nEventsByte.subList(0, n);
- break;
- } else if (nEventsByte.size() == n) {
- resultEventsByte = nEventsByte;
- break;
- }
+ consumerRecords.forEach(record -> {
+ InputStream inputStream = new ByteArrayInputStream(record.value());
- consumer.commitAsync();
- }
+ nEventsByte.addAll(parser.parseNEvents(inputStream, n));
+ });
- consumer.close();
+ if (nEventsByte.size() > n) {
+ resultEventsByte = nEventsByte.subList(0, n);
+ break;
+ } else if (nEventsByte.size() == n) {
+ resultEventsByte = nEventsByte;
+ break;
+ }
- return resultEventsByte;
+ consumer.commitAsync();
}
- private Consumer<byte[], byte[]> createConsumer(KafkaConfig kafkaConfig) throws KafkaException {
- final Properties props = new Properties();
+ consumer.close();
- kafkaConfig.getSecurityConfig().appendConfig(props);
+ return resultEventsByte;
+ }
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
- kafkaConfig.getKafkaHost() + ":" + kafkaConfig.getKafkaPort());
+ private Consumer<byte[], byte[]> createConsumer(KafkaConfig kafkaConfig) throws KafkaException {
+ final Properties props = new Properties();
- props.put(ConsumerConfig.GROUP_ID_CONFIG,
- "KafkaExampleConsumer" + System.currentTimeMillis());
+ kafkaConfig.getSecurityConfig().appendConfig(props);
- props.put(ConsumerConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, 6000);
+ props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
+ kafkaConfig.getKafkaHost() + ":" + kafkaConfig.getKafkaPort());
- props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
- ByteArrayDeserializer.class.getName());
- props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
- ByteArrayDeserializer.class.getName());
+ props.put(ConsumerConfig.GROUP_ID_CONFIG,
+ "KafkaExampleConsumer" + System.currentTimeMillis());
- // Create the consumer using props.
- final Consumer<byte[], byte[]> consumer =
- new KafkaConsumer<>(props);
+ props.put(ConsumerConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, 6000);
- return consumer;
- }
+ props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
+ ByteArrayDeserializer.class.getName());
+ props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
+ ByteArrayDeserializer.class.getName());
+ // Create the consumer using props.
+ final Consumer<byte[], byte[]> consumer =
+ new KafkaConsumer<>(props);
- @Override
- public void run(IAdapterPipeline adapterPipeline) {
- SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
- KafkaTransportProtocol protocol = new KafkaTransportProtocol();
- protocol.setKafkaPort(config.getKafkaPort());
- protocol.setBrokerHostname(config.getKafkaHost());
- protocol.setTopicDefinition(new SimpleTopicDefinition(topic));
-
- this.kafkaConsumer = new SpKafkaConsumer(protocol,
- config.getTopic(),
- new EventProcessor(stk),
- Arrays.asList(this.config.getSecurityConfig()));
-
- thread = new Thread(this.kafkaConsumer);
- thread.start();
+ return consumer;
+ }
+
+
+ @Override
+ public void run(IAdapterPipeline adapterPipeline) {
+ SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
+ KafkaTransportProtocol protocol = new KafkaTransportProtocol();
+ protocol.setKafkaPort(config.getKafkaPort());
+ protocol.setBrokerHostname(config.getKafkaHost());
+ protocol.setTopicDefinition(new SimpleTopicDefinition(topic));
+
+ this.kafkaConsumer = new SpKafkaConsumer(protocol,
+ config.getTopic(),
+ new EventProcessor(stk),
+ Arrays.asList(this.config.getSecurityConfig()));
+
+ thread = new Thread(this.kafkaConsumer);
+ thread.start();
+ }
+
+ @Override
+ public void stop() {
+ try {
+ kafkaConsumer.disconnect();
+ } catch (SpRuntimeException e) {
+ e.printStackTrace();
}
- @Override
- public void stop() {
- try {
- kafkaConsumer.disconnect();
- } catch (SpRuntimeException e) {
- e.printStackTrace();
- }
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- logger.info("Kafka Adapter was sucessfully stopped");
- thread.interrupt();
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- @Override
- public StaticProperty resolveConfiguration(String staticPropertyInternalName, StaticPropertyExtractor extractor) throws SpConfigurationException {
- RuntimeResolvableOneOfStaticProperty config = extractor
- .getStaticPropertyByName(KafkaConnectUtils.TOPIC_KEY, RuntimeResolvableOneOfStaticProperty.class);
- KafkaConfig kafkaConfig = KafkaConnectUtils.getConfig(extractor, false);
- boolean hideInternalTopics = extractor.slideToggleValue(KafkaConnectUtils.getHideInternalTopicsKey());
-
- try {
- Consumer<byte[], byte[]> consumer = createConsumer(kafkaConfig);
- Set<String> topics = consumer.listTopics().keySet();
- consumer.close();
-
- if (hideInternalTopics) {
- topics = topics
- .stream()
- .filter(t -> !t.startsWith(GlobalStreamPipesConstants.INTERNAL_TOPIC_PREFIX))
- .collect(Collectors.toSet());
- }
-
- config.setOptions(topics.stream().map(Option::new).collect(Collectors.toList()));
-
- return config;
- } catch (KafkaException e) {
- throw new SpConfigurationException(e.getMessage(), e);
- }
+ logger.info("Kafka Adapter was sucessfully stopped");
+ thread.interrupt();
+ }
+
+ @Override
+ public StaticProperty resolveConfiguration(String staticPropertyInternalName, StaticPropertyExtractor extractor)
+ throws SpConfigurationException {
+ RuntimeResolvableOneOfStaticProperty config = extractor
+ .getStaticPropertyByName(KafkaConnectUtils.TOPIC_KEY, RuntimeResolvableOneOfStaticProperty.class);
+ KafkaConfig kafkaConfig = KafkaConnectUtils.getConfig(extractor, false);
+ boolean hideInternalTopics = extractor.slideToggleValue(KafkaConnectUtils.getHideInternalTopicsKey());
+
+ try {
+ Consumer<byte[], byte[]> consumer = createConsumer(kafkaConfig);
+ Set<String> topics = consumer.listTopics().keySet();
+ consumer.close();
+
+ if (hideInternalTopics) {
+ topics = topics
+ .stream()
+ .filter(t -> !t.startsWith(GlobalStreamPipesConstants.INTERNAL_TOPIC_PREFIX))
+ .collect(Collectors.toSet());
+ }
+
+ config.setOptions(topics.stream().map(Option::new).collect(Collectors.toList()));
+
+ return config;
+ } catch (KafkaException e) {
+ throw new SpConfigurationException(e.getMessage(), e);
}
+ }
+
+ private class EventProcessor implements InternalEventProcessor<byte[]> {
+ private SendToPipeline stk;
- private class EventProcessor implements InternalEventProcessor<byte[]> {
- private SendToPipeline stk;
- public EventProcessor(SendToPipeline stk) {
- this.stk = stk;
- }
-
- @Override
- public void onEvent(byte[] payload) {
- try {
- parser.parse(IOUtils.toInputStream(new String(payload), "UTF-8"), stk);
- } catch (ParseException e) {
- logger.error("Error while parsing: " + e.getMessage());
- }
- }
+ public EventProcessor(SendToPipeline stk) {
+ this.stk = stk;
}
@Override
- public String getId() {
- return ID;
+ public void onEvent(byte[] payload) {
+ try {
+ parser.parse(IOUtils.toInputStream(new String(payload), "UTF-8"), stk);
+ } catch (ParseException e) {
+ logger.error("Error while parsing: " + e.getMessage());
+ }
}
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/MqttProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/MqttProtocol.java
index 2f1804dd9..3014d13f0 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/MqttProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/MqttProtocol.java
@@ -58,7 +58,7 @@ public class MqttProtocol extends BrokerProtocol {
public Protocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
MqttConfig mqttConfig;
StaticPropertyExtractor extractor =
- StaticPropertyExtractor.from(protocolDescription.getConfig(), new ArrayList<>());
+ StaticPropertyExtractor.from(protocolDescription.getConfig(), new ArrayList<>());
mqttConfig = MqttConnectUtils.getMqttConfig(extractor);
@@ -68,14 +68,15 @@ public class MqttProtocol extends BrokerProtocol {
@Override
public ProtocolDescription declareModel() {
return ProtocolDescriptionBuilder.create(ID)
- .withLocales(Locales.EN)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .category(AdapterType.Generic, AdapterType.Manufacturing)
- .sourceType(AdapterSourceType.STREAM)
- .requiredTextParameter(MqttConnectUtils.getBrokerUrlLabel())
- .requiredAlternatives(MqttConnectUtils.getAccessModeLabel(), MqttConnectUtils.getAlternativesOne(), MqttConnectUtils.getAlternativesTwo())
- .requiredTextParameter(MqttConnectUtils.getTopicLabel())
- .build();
+ .withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .category(AdapterType.Generic, AdapterType.Manufacturing)
+ .sourceType(AdapterSourceType.STREAM)
+ .requiredTextParameter(MqttConnectUtils.getBrokerUrlLabel())
+ .requiredAlternatives(MqttConnectUtils.getAccessModeLabel(), MqttConnectUtils.getAlternativesOne(),
+ MqttConnectUtils.getAlternativesTwo())
+ .requiredTextParameter(MqttConnectUtils.getTopicLabel())
+ .build();
}
@Override
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/NatsProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/NatsProtocol.java
index 2e27b007c..8df068189 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/NatsProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/NatsProtocol.java
@@ -46,7 +46,19 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.*;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.ACCESS_MODE;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.ANONYMOUS_ACCESS;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.CONNECTION_PROPERTIES;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.CONNECTION_PROPERTIES_GROUP;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.CUSTOM_PROPERTIES;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.NONE_PROPERTIES;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.PASSWORD_KEY;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.PROPERTIES_KEY;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.SUBJECT_KEY;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.URLS_KEY;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.USERNAME_ACCESS;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.USERNAME_GROUP;
+import static org.apache.streampipes.pe.shared.config.nats.NatsConfigUtils.USERNAME_KEY;
public class NatsProtocol extends BrokerProtocol {
@@ -161,7 +173,7 @@ public class NatsProtocol extends BrokerProtocol {
}
int totalTimeout = 0;
- while(!completed[0] && totalTimeout < MAX_TIMEOUT) {
+ while (!completed[0] && totalTimeout < MAX_TIMEOUT) {
try {
TimeUnit.MILLISECONDS.sleep(TIMEOUT);
totalTimeout += TIMEOUT;
@@ -172,7 +184,8 @@ public class NatsProtocol extends BrokerProtocol {
if (elements.size() > 0) {
return elements;
} else {
- throw new ParseException("Did not receive any data within " + MAX_TIMEOUT / 1000 + " seconds, is this subjects currently providing data?");
+ throw new ParseException("Did not receive any data within " + MAX_TIMEOUT / 1000 +
+ " seconds, is this subjects currently providing data?");
}
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/PullProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/PullProtocol.java
index ad931ef75..2f765cb35 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/PullProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/PullProtocol.java
@@ -23,76 +23,81 @@ import org.apache.streampipes.connect.api.IAdapterPipeline;
import org.apache.streampipes.connect.api.IFormat;
import org.apache.streampipes.connect.api.IParser;
import org.apache.streampipes.connect.api.exception.ParseException;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
public abstract class PullProtocol extends Protocol {
- private ScheduledExecutorService scheduler;
+ private ScheduledExecutorService scheduler;
- private Logger logger = LoggerFactory.getLogger(PullProtocol.class);
+ private Logger logger = LoggerFactory.getLogger(PullProtocol.class);
- private long interval;
+ private long interval;
- public PullProtocol() {
- }
+ public PullProtocol() {
+ }
- public PullProtocol(IParser parser, IFormat format, long interval) {
- super(parser, format);
- this.interval = interval;
- }
+ public PullProtocol(IParser parser, IFormat format, long interval) {
+ super(parser, format);
+ this.interval = interval;
+ }
- @Override
- public void run(IAdapterPipeline adapterPipeline) {
- final Runnable errorThread = () -> {
- executeProtocolLogic(adapterPipeline);
- };
+ @Override
+ public void run(IAdapterPipeline adapterPipeline) {
+ final Runnable errorThread = () -> {
+ executeProtocolLogic(adapterPipeline);
+ };
- scheduler = Executors.newScheduledThreadPool(1);
- scheduler.schedule(errorThread, 0, TimeUnit.MILLISECONDS);
+ scheduler = Executors.newScheduledThreadPool(1);
+ scheduler.schedule(errorThread, 0, TimeUnit.MILLISECONDS);
+
+ }
- }
+ private void executeProtocolLogic(IAdapterPipeline adapterPipeline) {
+ final Runnable task = () -> {
- private void executeProtocolLogic(IAdapterPipeline adapterPipeline) {
- final Runnable task = () -> {
-
- format.reset();
- SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
- try {
- InputStream data = getDataFromEndpoint();
- if(data != null) {
- parser.parse(data, stk);
- } else {
- logger.warn("Could not receive data from Endpoint. Try again in " + interval + " seconds.");
- }
- } catch (ParseException e) {
- logger.error("Error while parsing: " + e.getMessage());
- }
-
-
- };
-
- scheduler = Executors.newScheduledThreadPool(1);
- ScheduledFuture<?> handle = scheduler.scheduleAtFixedRate(task, 1, interval, TimeUnit.SECONDS);
- try {
- handle.get();
- } catch (ExecutionException e ) {
- logger.error("Error", e);
- } catch (InterruptedException e) {
- logger.error("Error", e);
+ format.reset();
+ SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
+ try {
+ InputStream data = getDataFromEndpoint();
+ if (data != null) {
+ parser.parse(data, stk);
+ } else {
+ logger.warn("Could not receive data from Endpoint. Try again in " + interval + " seconds.");
}
- }
+ } catch (ParseException e) {
+ logger.error("Error while parsing: " + e.getMessage());
+ }
+
- @Override
- public void stop() {
- scheduler.shutdownNow();
+ };
+
+ scheduler = Executors.newScheduledThreadPool(1);
+ ScheduledFuture<?> handle = scheduler.scheduleAtFixedRate(task, 1, interval, TimeUnit.SECONDS);
+ try {
+ handle.get();
+ } catch (ExecutionException e) {
+ logger.error("Error", e);
+ } catch (InterruptedException e) {
+ logger.error("Error", e);
}
+ }
+
+ @Override
+ public void stop() {
+ scheduler.shutdownNow();
+ }
- abstract InputStream getDataFromEndpoint() throws ParseException;
+ abstract InputStream getDataFromEndpoint() throws ParseException;
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarProtocol.java
index 9e24d5bde..cd5bf1674 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarProtocol.java
@@ -17,17 +17,6 @@
*/
package org.apache.streampipes.connect.iiot.protocol.stream.pulsar;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.pulsar.client.api.Consumer;
-import org.apache.pulsar.client.api.Message;
-import org.apache.pulsar.client.api.MessageId;
-import org.apache.pulsar.client.api.MessageListener;
-import org.apache.pulsar.client.api.PulsarClient;
-import org.apache.pulsar.client.api.PulsarClientException;
-import org.apache.pulsar.client.api.Reader;
-
import org.apache.streampipes.commons.exceptions.SpConfigurationException;
import org.apache.streampipes.connect.SendToPipeline;
import org.apache.streampipes.connect.adapter.model.generic.Protocol;
@@ -48,11 +37,20 @@ import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.MessageListener;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Reader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
public class PulsarProtocol extends BrokerProtocol implements SupportsRuntimeConfig {
@@ -82,9 +80,9 @@ public class PulsarProtocol extends BrokerProtocol implements SupportsRuntimeCon
List<byte[]> elements = new ArrayList<>();
try (PulsarClient pulsarClient = PulsarUtils.makePulsarClient(brokerUrl);
Reader<byte[]> reader = pulsarClient.newReader()
- .topic(topic)
- .startMessageId(MessageId.earliest)
- .create()) {
+ .topic(topic)
+ .startMessageId(MessageId.earliest)
+ .create()) {
int readCount = 0;
while (readCount < n) {
Message<byte[]> message = reader.readNext(1, TimeUnit.SECONDS);
@@ -115,15 +113,15 @@ public class PulsarProtocol extends BrokerProtocol implements SupportsRuntimeCon
@Override
public ProtocolDescription declareModel() {
return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Generic)
- .sourceType(AdapterSourceType.STREAM)
- .requiredTextParameter(Labels.withId(PULSAR_BROKER_HOST))
- .requiredIntegerParameter(Labels.withId(PULSAR_BROKER_PORT), 6650)
- .requiredTextParameter(Labels.withId(PULSAR_TOPIC))
- .requiredTextParameter(Labels.withId(PULSAR_SUBSCRIPTION_NAME))
- .build();
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Generic)
+ .sourceType(AdapterSourceType.STREAM)
+ .requiredTextParameter(Labels.withId(PULSAR_BROKER_HOST))
+ .requiredIntegerParameter(Labels.withId(PULSAR_BROKER_PORT), 6650)
+ .requiredTextParameter(Labels.withId(PULSAR_TOPIC))
+ .requiredTextParameter(Labels.withId(PULSAR_SUBSCRIPTION_NAME))
+ .build();
}
@Override
@@ -136,15 +134,15 @@ public class PulsarProtocol extends BrokerProtocol implements SupportsRuntimeCon
}
PulsarClient client = PulsarUtils.makePulsarClient(brokerUrl);
consumer = client.newConsumer()
- .topic(topic)
- .subscriptionName(subscriptionName)
- .messageListener((MessageListener<byte[]>) (consumer, msg) -> {
- try {
- stk.emit(msg.getValue());
- } catch (ParseException e) {
- LOG.error("Failed to parse message.", e);
- }
- }).subscribe();
+ .topic(topic)
+ .subscriptionName(subscriptionName)
+ .messageListener((MessageListener<byte[]>) (consumer, msg) -> {
+ try {
+ stk.emit(msg.getValue());
+ } catch (ParseException e) {
+ LOG.error("Failed to parse message.", e);
+ }
+ }).subscribe();
} catch (PulsarClientException e) {
throw new RuntimeException(e);
}
@@ -152,7 +150,7 @@ public class PulsarProtocol extends BrokerProtocol implements SupportsRuntimeCon
@Override
public void stop() {
- if(consumer != null) {
+ if (consumer != null) {
try {
consumer.close();
} catch (PulsarClientException e) {
@@ -168,8 +166,9 @@ public class PulsarProtocol extends BrokerProtocol implements SupportsRuntimeCon
}
@Override
- public StaticProperty resolveConfiguration(String staticPropertyInternalName, StaticPropertyExtractor extractor) throws
- SpConfigurationException {
+ public StaticProperty resolveConfiguration(String staticPropertyInternalName, StaticPropertyExtractor extractor)
+ throws
+ SpConfigurationException {
String brokerHost = extractor.singleValueParameter(PULSAR_BROKER_HOST, String.class);
Integer brokerPort = extractor.singleValueParameter(PULSAR_BROKER_PORT, Integer.class);
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarUtils.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarUtils.java
index 6bf062db5..9df4e494e 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarUtils.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/pulsar/PulsarUtils.java
@@ -27,7 +27,7 @@ public class PulsarUtils {
public static PulsarClient makePulsarClient(String brokerHostname) throws PulsarClientException {
String serviceUrl = PULSAR_SCHEME + brokerHostname;
return PulsarClient.builder()
- .serviceUrl(serviceUrl)
- .build();
+ .serviceUrl(serviceUrl)
+ .build();
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQConsumer.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQConsumer.java
index dbb6ab57a..43115ffcc 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQConsumer.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQConsumer.java
@@ -17,10 +17,11 @@
*/
package org.apache.streampipes.connect.iiot.protocol.stream.rocketmq;
+import org.apache.streampipes.messaging.InternalEventProcessor;
+
import org.apache.rocketmq.client.apis.ClientException;
import org.apache.rocketmq.client.apis.consumer.ConsumeResult;
import org.apache.rocketmq.client.apis.consumer.PushConsumer;
-import org.apache.streampipes.messaging.InternalEventProcessor;
import java.io.IOException;
@@ -35,7 +36,8 @@ public class RocketMQConsumer implements Runnable {
private PushConsumer consumer;
- public RocketMQConsumer(String brokerUrl, String topic, String consumerGroup, InternalEventProcessor<byte[]> eventProcessor) {
+ public RocketMQConsumer(String brokerUrl, String topic, String consumerGroup,
+ InternalEventProcessor<byte[]> eventProcessor) {
this.brokerUrl = brokerUrl;
this.topic = topic;
this.consumerGroup = consumerGroup;
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQProtocol.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQProtocol.java
index 33d6cd6c8..6a280653d 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQProtocol.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQProtocol.java
@@ -17,10 +17,7 @@
*/
package org.apache.streampipes.connect.iiot.protocol.stream.rocketmq;
-import org.apache.commons.io.IOUtils;
-import org.apache.rocketmq.client.apis.ClientException;
-import org.apache.rocketmq.client.apis.consumer.ConsumeResult;
-import org.apache.rocketmq.client.apis.consumer.PushConsumer;
+
import org.apache.streampipes.connect.SendToPipeline;
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
import org.apache.streampipes.connect.api.IAdapterPipeline;
@@ -38,6 +35,11 @@ import org.apache.streampipes.sdk.helpers.AdapterSourceType;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.rocketmq.client.apis.ClientException;
+import org.apache.rocketmq.client.apis.consumer.ConsumeResult;
+import org.apache.rocketmq.client.apis.consumer.PushConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,125 +52,126 @@ import java.util.concurrent.CountDownLatch;
public class RocketMQProtocol extends BrokerProtocol {
- public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.rocketmq";
-
- public static final String TOPIC_KEY = "rocketmq-topic";
- public static final String ENDPOINT_KEY = "rocketmq-endpoint";
- public static final String CONSUMER_GROUP_KEY = "rocketmq-consumer-group";
-
- private Logger logger = LoggerFactory.getLogger(RocketMQProtocol.class);
-
- private String consumerGroup;
-
- private Thread thread;
- private RocketMQConsumer rocketMQConsumer;
-
- public RocketMQProtocol() {
+ public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.rocketmq";
+
+ public static final String TOPIC_KEY = "rocketmq-topic";
+ public static final String ENDPOINT_KEY = "rocketmq-endpoint";
+ public static final String CONSUMER_GROUP_KEY = "rocketmq-consumer-group";
+
+ private Logger logger = LoggerFactory.getLogger(RocketMQProtocol.class);
+
+ private String consumerGroup;
+
+ private Thread thread;
+ private RocketMQConsumer rocketMQConsumer;
+
+ public RocketMQProtocol() {
+ }
+
+ public RocketMQProtocol(IParser parser, IFormat format, String brokerUrl, String topic, String consumerGroup) {
+ super(parser, format, brokerUrl, topic);
+ this.consumerGroup = consumerGroup;
+ }
+
+ @Override
+ public IProtocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
+ ParameterExtractor extractor = new ParameterExtractor(protocolDescription.getConfig());
+ String endpoint = extractor.singleValue(ENDPOINT_KEY, String.class);
+ String topic = extractor.singleValue(TOPIC_KEY, String.class);
+ String consumerGroup = extractor.singleValue(CONSUMER_GROUP_KEY, String.class);
+
+ return new RocketMQProtocol(parser, format, endpoint, topic, consumerGroup);
+ }
+
+ @Override
+ public ProtocolDescription declareModel() {
+ return ProtocolDescriptionBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Generic)
+ .sourceType(AdapterSourceType.STREAM)
+ .requiredTextParameter(Labels.withId(ENDPOINT_KEY))
+ .requiredTextParameter(Labels.withId(TOPIC_KEY))
+ .requiredTextParameter(Labels.withId(CONSUMER_GROUP_KEY))
+ .build();
+ }
+
+ @Override
+ public void run(IAdapterPipeline adapterPipeline) throws AdapterException {
+ SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
+ this.rocketMQConsumer = new RocketMQConsumer(brokerUrl, topic, consumerGroup, new EventProcessor(stk));
+
+ thread = new Thread(this.rocketMQConsumer);
+ thread.start();
+ }
+
+ @Override
+ public void stop() {
+ try {
+ rocketMQConsumer.stop();
+ } catch (IOException e) {
+ e.printStackTrace();
}
-
- public RocketMQProtocol(IParser parser, IFormat format, String brokerUrl, String topic, String consumerGroup) {
- super(parser, format, brokerUrl, topic);
- this.consumerGroup = consumerGroup;
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ @Override
+ protected List<byte[]> getNByteElements(int n) throws ParseException {
+ List<byte[]> nEventsByte = new ArrayList<>(n);
+ CountDownLatch latch = new CountDownLatch(n);
+
+ PushConsumer consumer = null;
+ try {
+ consumer = RocketMQUtils.createConsumer(brokerUrl, topic, consumerGroup, messageView -> {
+ InputStream inputStream = new ByteArrayInputStream(messageView.getBody().array());
+ nEventsByte.addAll(parser.parseNEvents(inputStream, n));
+
+ latch.countDown();
+ return ConsumeResult.SUCCESS;
+ });
+ } catch (ClientException e) {
+ e.printStackTrace();
+ try {
+ if (consumer != null) {
+ consumer.close();
+ }
+ } catch (IOException ex) {
+ }
+ throw new ParseException("Failed to fetch messages.", e);
}
- @Override
- public IProtocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) {
- ParameterExtractor extractor = new ParameterExtractor(protocolDescription.getConfig());
- String endpoint = extractor.singleValue(ENDPOINT_KEY, String.class);
- String topic = extractor.singleValue(TOPIC_KEY, String.class);
- String consumerGroup = extractor.singleValue(CONSUMER_GROUP_KEY, String.class);
-
- return new RocketMQProtocol(parser, format, endpoint, topic, consumerGroup);
+ try {
+ latch.await();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
-
- @Override
- public ProtocolDescription declareModel() {
- return ProtocolDescriptionBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Generic)
- .sourceType(AdapterSourceType.STREAM)
- .requiredTextParameter(Labels.withId(ENDPOINT_KEY))
- .requiredTextParameter(Labels.withId(TOPIC_KEY))
- .requiredTextParameter(Labels.withId(CONSUMER_GROUP_KEY))
- .build();
+ try {
+ consumer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
}
- @Override
- public void run(IAdapterPipeline adapterPipeline) throws AdapterException {
- SendToPipeline stk = new SendToPipeline(format, adapterPipeline);
- this.rocketMQConsumer = new RocketMQConsumer(brokerUrl, topic, consumerGroup, new EventProcessor(stk));
-
- thread = new Thread(this.rocketMQConsumer);
- thread.start();
- }
+ return nEventsByte;
+ }
- @Override
- public void stop() {
- try {
- rocketMQConsumer.stop();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ private class EventProcessor implements InternalEventProcessor<byte[]> {
+ private SendToPipeline stk;
- @Override
- public String getId() {
- return ID;
+ public EventProcessor(SendToPipeline stk) {
+ this.stk = stk;
}
@Override
- protected List<byte[]> getNByteElements(int n) throws ParseException {
- List<byte[]> nEventsByte = new ArrayList<>(n);
- CountDownLatch latch = new CountDownLatch(n);
-
- PushConsumer consumer = null;
- try {
- consumer = RocketMQUtils.createConsumer(brokerUrl, topic, consumerGroup, messageView -> {
- InputStream inputStream = new ByteArrayInputStream(messageView.getBody().array());
- nEventsByte.addAll(parser.parseNEvents(inputStream, n));
-
- latch.countDown();
- return ConsumeResult.SUCCESS;
- });
- } catch (ClientException e) {
- e.printStackTrace();
- try {
- if (consumer != null) {
- consumer.close();
- }
- } catch (IOException ex) {
- }
- throw new ParseException("Failed to fetch messages.", e);
- }
-
- try {
- latch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- try {
- consumer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return nEventsByte;
- }
-
- private class EventProcessor implements InternalEventProcessor<byte[]> {
- private SendToPipeline stk;
- public EventProcessor(SendToPipeline stk) {
- this.stk = stk;
- }
-
- @Override
- public void onEvent(byte[] payload) {
- try {
- parser.parse(IOUtils.toInputStream(new String(payload), "UTF-8"), stk);
- } catch (ParseException e) {
- logger.error("Error while parsing: " + e.getMessage());
- }
- }
+ public void onEvent(byte[] payload) {
+ try {
+ parser.parse(IOUtils.toInputStream(new String(payload), "UTF-8"), stk);
+ } catch (ParseException e) {
+ logger.error("Error while parsing: " + e.getMessage());
+ }
}
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQUtils.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQUtils.java
index d21c6a29c..38426ae69 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQUtils.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQUtils.java
@@ -29,19 +29,20 @@ import java.util.Collections;
public class RocketMQUtils {
- public static PushConsumer createConsumer(String endpoint, String topic, String consumerGroup, MessageListener listener) throws ClientException {
+ public static PushConsumer createConsumer(String endpoint, String topic, String consumerGroup,
+ MessageListener listener) throws ClientException {
ClientServiceProvider provider = ClientServiceProvider.loadService();
ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder()
- .setEndpoints(endpoint)
- .build();
+ .setEndpoints(endpoint)
+ .build();
FilterExpression filterExpression = new FilterExpression("*", FilterExpressionType.TAG);
PushConsumer consumer = provider.newPushConsumerBuilder()
- .setClientConfiguration(clientConfiguration)
- .setConsumerGroup(consumerGroup)
- .setSubscriptionExpressions(Collections.singletonMap(topic, filterExpression))
- .setMessageListener(listener)
- .build();
+ .setClientConfiguration(clientConfiguration)
+ .setConsumerGroup(consumerGroup)
+ .setSubscriptionExpressions(Collections.singletonMap(topic, filterExpression))
+ .setMessageListener(listener)
+ .build();
return consumer;
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java
index e7e89c311..8b80d8d9e 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java
@@ -18,52 +18,55 @@
package org.apache.streampipes.connect.iiot.utils;
-import org.apache.commons.io.FileUtils;
import org.apache.streampipes.client.StreamPipesClient;
import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.service.extensions.base.client.StreamPipesClientResolver;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
public class FileProtocolUtils {
- public static InputStream getFileInputStream(String selectedFilename) throws FileNotFoundException {
- if (!isFilePresent(selectedFilename)) {
- try {
- storeFileLocally(selectedFilename);
- } catch (IOException e) {
- throw new ParseException("Could not receive file");
- }
- }
-
- return new FileInputStream(makeFileLoc(selectedFilename));
+ public static InputStream getFileInputStream(String selectedFilename) throws FileNotFoundException {
+ if (!isFilePresent(selectedFilename)) {
+ try {
+ storeFileLocally(selectedFilename);
+ } catch (IOException e) {
+ throw new ParseException("Could not receive file");
+ }
}
- private static boolean isFilePresent(String selectedFilename) {
- File file = new File(makeFileLoc(selectedFilename));
- return file.exists();
- }
+ return new FileInputStream(makeFileLoc(selectedFilename));
+ }
- private static void storeFileLocally(String selectedFilename) throws IOException {
- File storageDir = new File(makeServiceStorageDir());
- if (!storageDir.exists()) {
- storageDir.mkdirs();
- }
- StreamPipesClient client = new StreamPipesClientResolver().makeStreamPipesClientInstance();
+ private static boolean isFilePresent(String selectedFilename) {
+ File file = new File(makeFileLoc(selectedFilename));
+ return file.exists();
+ }
- client.fileApi().writeToFile(selectedFilename, makeFileLoc(selectedFilename));
+ private static void storeFileLocally(String selectedFilename) throws IOException {
+ File storageDir = new File(makeServiceStorageDir());
+ if (!storageDir.exists()) {
+ storageDir.mkdirs();
}
+ StreamPipesClient client = new StreamPipesClientResolver().makeStreamPipesClientInstance();
- private static String makeServiceStorageDir() {
- return System.getProperty("user.home")
- + File.separator
- + ".streampipes"
- + File.separator
- + "service";
- }
+ client.fileApi().writeToFile(selectedFilename, makeFileLoc(selectedFilename));
+ }
- private static String makeFileLoc(String filename) {
- return makeServiceStorageDir() + File.separator + filename;
- }
+ private static String makeServiceStorageDir() {
+ return System.getProperty("user.home")
+ + File.separator
+ + ".streampipes"
+ + File.separator
+ + "service";
+ }
+
+ private static String makeFileLoc(String filename) {
+ return makeServiceStorageDir() + File.separator + filename;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/pom.xml b/streampipes-extensions/streampipes-connect-adapters/pom.xml
index 40c2f3f43..140000153 100644
--- a/streampipes-extensions/streampipes-connect-adapters/pom.xml
+++ b/streampipes-extensions/streampipes-connect-adapters/pom.xml
@@ -17,7 +17,8 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -212,6 +213,23 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>validate</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <logViolationsToConsole>true</logViolationsToConsole>
+ <failOnViolation>true</failOnViolation>
+ </configuration>
+ </plugin>
</plugins>
<finalName>streampipes-connect-adapters</finalName>
</build>
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/ConnectAdapterInit.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/ConnectAdapterInit.java
index 624b9e2bb..dd4a6d481 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/ConnectAdapterInit.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/ConnectAdapterInit.java
@@ -47,25 +47,25 @@ public class ConnectAdapterInit extends ExtensionsModelSubmitter {
@Override
public SpServiceDefinition provideServiceDefinition() {
return SpServiceDefinitionBuilder.create("connect-adapter",
- "StreamPipes Connect Worker Main",
- "", 8001)
- .registerAdapter(new GdeltAdapter())
- .registerAdapter(new CoindeskBitcoinAdapter())
- .registerAdapter(new NetioRestAdapter())
- .registerAdapter(new NetioMQTTAdapter())
- .registerAdapter(new IexCloudNewsAdapter())
- .registerAdapter(new IexCloudStockAdapter())
- .registerAdapter(new RandomDataSetAdapter())
- .registerAdapter(new RandomDataStreamAdapter())
- .registerAdapter(new SlackAdapter())
- .registerAdapter(new WikipediaEditedArticlesAdapter())
- .registerAdapter(new WikipediaNewArticlesAdapter())
- .registerAdapter(new ImageStreamAdapter())
- .registerAdapter(new ImageSetAdapter())
- .registerAdapter(new IssAdapter())
- .registerAdapter(new FlicMQTTAdapter())
- .registerAdapter(new TISensorTag())
- .build();
+ "StreamPipes Connect Worker Main",
+ "", 8001)
+ .registerAdapter(new GdeltAdapter())
+ .registerAdapter(new CoindeskBitcoinAdapter())
+ .registerAdapter(new NetioRestAdapter())
+ .registerAdapter(new NetioMQTTAdapter())
+ .registerAdapter(new IexCloudNewsAdapter())
+ .registerAdapter(new IexCloudStockAdapter())
+ .registerAdapter(new RandomDataSetAdapter())
+ .registerAdapter(new RandomDataStreamAdapter())
+ .registerAdapter(new SlackAdapter())
+ .registerAdapter(new WikipediaEditedArticlesAdapter())
+ .registerAdapter(new WikipediaNewArticlesAdapter())
+ .registerAdapter(new ImageStreamAdapter())
+ .registerAdapter(new ImageSetAdapter())
+ .registerAdapter(new IssAdapter())
+ .registerAdapter(new FlicMQTTAdapter())
+ .registerAdapter(new TISensorTag())
+ .build();
}
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullAdapter.java
index 157dac3eb..11c113eac 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullAdapter.java
@@ -18,83 +18,87 @@
package org.apache.streampipes.connect.adapters;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
import org.apache.streampipes.connect.adapter.util.PollingSettings;
+import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
public abstract class PullAdapter extends SpecificDataStreamAdapter {
- protected static Logger logger = LoggerFactory.getLogger(PullAdapter.class);
- private ScheduledExecutorService scheduler;
- private ScheduledExecutorService errorThreadscheduler;
+ protected static Logger logger = LoggerFactory.getLogger(PullAdapter.class);
+ private ScheduledExecutorService scheduler;
+ private ScheduledExecutorService errorThreadscheduler;
- public PullAdapter() {
- super();
- }
+ public PullAdapter() {
+ super();
+ }
- public PullAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
+ public PullAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
- protected abstract void pullData();
+ protected abstract void pullData();
- protected abstract PollingSettings getPollingInterval();
+ protected abstract PollingSettings getPollingInterval();
- @Override
- public void startAdapter() throws AdapterException {
- before();
+ @Override
+ public void startAdapter() throws AdapterException {
+ before();
- final Runnable errorThread = () -> {
- executeAdpaterLogic();
- };
+ final Runnable errorThread = () -> {
+ executeAdpaterLogic();
+ };
- scheduler = Executors.newScheduledThreadPool(1);
- scheduler.schedule(errorThread, 0, TimeUnit.MILLISECONDS);
+ scheduler = Executors.newScheduledThreadPool(1);
+ scheduler.schedule(errorThread, 0, TimeUnit.MILLISECONDS);
- }
+ }
- private void executeAdpaterLogic() {
- final Runnable task = () -> {
+ private void executeAdpaterLogic() {
+ final Runnable task = () -> {
- pullData();
+ pullData();
- };
+ };
- scheduler = Executors.newScheduledThreadPool(1);
- ScheduledFuture<?> handle = scheduler.scheduleAtFixedRate(task, 1,
- getPollingInterval().getValue(), getPollingInterval().getTimeUnit());
+ scheduler = Executors.newScheduledThreadPool(1);
+ ScheduledFuture<?> handle = scheduler.scheduleAtFixedRate(task, 1,
+ getPollingInterval().getValue(), getPollingInterval().getTimeUnit());
- try {
- handle.get();
- } catch (ExecutionException | InterruptedException e) {
- logger.error("Error", e);
- }
+ try {
+ handle.get();
+ } catch (ExecutionException | InterruptedException e) {
+ logger.error("Error", e);
}
+ }
- @Override
- public void stopAdapter() throws AdapterException {
- after();
- scheduler.shutdownNow();
- }
+ @Override
+ public void stopAdapter() throws AdapterException {
+ after();
+ scheduler.shutdownNow();
+ }
- /**
- * Called before adapter is started (e.g. initialize connections)
- */
- protected void before() throws AdapterException {
+ /**
+ * Called before adapter is started (e.g. initialize connections)
+ */
+ protected void before() throws AdapterException {
- }
+ }
- /**
- * Called before adapter is stopped (e.g. shutdown connections)
- */
- protected void after() throws AdapterException {
+ /**
+ * Called before adapter is stopped (e.g. shutdown connections)
+ */
+ protected void after() throws AdapterException {
- }
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullRestAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullRestAdapter.java
index 626259968..ab8d7b153 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullRestAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/PullRestAdapter.java
@@ -18,54 +18,56 @@
package org.apache.streampipes.connect.adapters;
-import com.google.gson.Gson;
-import org.apache.http.client.fluent.Request;
+
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
-public abstract class PullRestAdapter extends PullAdapter {
+import com.google.gson.Gson;
+import org.apache.http.client.fluent.Request;
- public PullRestAdapter() {
- super();
- }
+public abstract class PullRestAdapter extends PullAdapter {
- public PullRestAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
+ public PullRestAdapter() {
+ super();
+ }
- protected static String getDataFromEndpointString(String url) throws AdapterException {
- String result = null;
+ public PullRestAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+ protected static String getDataFromEndpointString(String url) throws AdapterException {
+ String result = null;
- logger.info("Started Request to open sensemap endpoint: " + url);
- try {
- result = Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asString();
+ logger.info("Started Request to open sensemap endpoint: " + url);
+ try {
+ result = Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asString();
- if (result.startsWith("ï")) {
- result = result.substring(3);
- }
- logger.info("Received data from request");
+ if (result.startsWith("ï")) {
+ result = result.substring(3);
+ }
- } catch (Exception e) {
- String errorMessage = "Error while connecting to the open sensemap api";
- logger.error(errorMessage, e);
- throw new AdapterException(errorMessage);
- }
+ logger.info("Received data from request");
- return result;
+ } catch (Exception e) {
+ String errorMessage = "Error while connecting to the open sensemap api";
+ logger.error(errorMessage, e);
+ throw new AdapterException(errorMessage);
}
- protected static <T> T getDataFromEndpoint(String url, Class<T> clazz) throws AdapterException {
+ return result;
+ }
- String rawJson = getDataFromEndpointString(url);
- T all = new Gson().fromJson(rawJson, clazz);
+ protected static <T> T getDataFromEndpoint(String url, Class<T> clazz) throws AdapterException {
- return all;
- }
+ String rawJson = getDataFromEndpointString(url);
+ T all = new Gson().fromJson(rawJson, clazz);
+
+ return all;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/CoindeskBitcoinAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/CoindeskBitcoinAdapter.java
index 3c8f5902a..a89dae404 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/CoindeskBitcoinAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/CoindeskBitcoinAdapter.java
@@ -17,15 +17,13 @@
*/
package org.apache.streampipes.connect.adapters.coindesk;
-import com.google.gson.Gson;
-import org.apache.http.client.fluent.Request;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
-import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.adapters.PullAdapter;
import org.apache.streampipes.connect.adapters.coindesk.model.CoindeskRawModel;
+import org.apache.streampipes.connect.api.exception.AdapterException;
+import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -38,6 +36,9 @@ import org.apache.streampipes.sdk.helpers.Options;
import org.apache.streampipes.sdk.utils.Assets;
import org.apache.streampipes.vocabulary.SO;
+import com.google.gson.Gson;
+import org.apache.http.client.fluent.Request;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -97,11 +98,11 @@ public class CoindeskBitcoinAdapter extends PullAdapter {
@Override
public SpecificAdapterStreamDescription declareModel() {
return SpecificDataStreamAdapterBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Finance)
- .requiredSingleValueSelection(Labels.withId(CURRENCY_KEY), Options.from("USD", "EUR", "GBP"))
- .build();
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Finance)
+ .requiredSingleValueSelection(Labels.withId(CURRENCY_KEY), Options.from("USD", "EUR", "GBP"))
+ .build();
}
@Override
@@ -110,12 +111,13 @@ public class CoindeskBitcoinAdapter extends PullAdapter {
}
@Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException, ParseException {
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
return GuessSchemaBuilder.create()
- .property(EpProperties.timestampProperty("timestamp"))
- .property(EpProperties.doubleEp(Labels.from("rate-field", "Rate", "The current " +
- "bitcoin rate"), "rate", SO.Price))
- .build();
+ .property(EpProperties.timestampProperty("timestamp"))
+ .property(EpProperties.doubleEp(Labels.from("rate-field", "Rate", "The current "
+ + "bitcoin rate"), "rate", SO.Price))
+ .build();
}
@Override
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Bpi.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Bpi.java
index 5ec9fa37b..87c25993b 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Bpi.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Bpi.java
@@ -26,35 +26,35 @@ import javax.annotation.Generated;
@SuppressWarnings("unused")
public class Bpi {
- @SerializedName("EUR")
- private EUR mEUR;
- @SerializedName("GBP")
- private GBP mGBP;
- @SerializedName("USD")
- private USD mUSD;
-
- public EUR getEUR() {
- return mEUR;
- }
-
- public void setEUR(EUR eUR) {
- mEUR = eUR;
- }
-
- public GBP getGBP() {
- return mGBP;
- }
-
- public void setGBP(GBP gBP) {
- mGBP = gBP;
- }
-
- public USD getUSD() {
- return mUSD;
- }
-
- public void setUSD(USD uSD) {
- mUSD = uSD;
- }
+ @SerializedName("EUR")
+ private EUR mEUR;
+ @SerializedName("GBP")
+ private GBP mGBP;
+ @SerializedName("USD")
+ private USD mUSD;
+
+ public EUR getEUR() {
+ return mEUR;
+ }
+
+ public void setEUR(EUR eUR) {
+ mEUR = eUR;
+ }
+
+ public GBP getGBP() {
+ return mGBP;
+ }
+
+ public void setGBP(GBP gBP) {
+ mGBP = gBP;
+ }
+
+ public USD getUSD() {
+ return mUSD;
+ }
+
+ public void setUSD(USD uSD) {
+ mUSD = uSD;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/CoindeskRawModel.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/CoindeskRawModel.java
index ad68f3663..13de0b8b0 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/CoindeskRawModel.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/CoindeskRawModel.java
@@ -26,45 +26,45 @@ import javax.annotation.Generated;
@SuppressWarnings("unused")
public class CoindeskRawModel {
- @SerializedName("bpi")
- private Bpi mBpi;
- @SerializedName("chartName")
- private String mChartName;
- @SerializedName("disclaimer")
- private String mDisclaimer;
- @SerializedName("time")
- private Time mTime;
+ @SerializedName("bpi")
+ private Bpi mBpi;
+ @SerializedName("chartName")
+ private String mChartName;
+ @SerializedName("disclaimer")
+ private String mDisclaimer;
+ @SerializedName("time")
+ private Time mTime;
- public Bpi getBpi() {
- return mBpi;
- }
+ public Bpi getBpi() {
+ return mBpi;
+ }
- public void setBpi(Bpi bpi) {
- mBpi = bpi;
- }
+ public void setBpi(Bpi bpi) {
+ mBpi = bpi;
+ }
- public String getChartName() {
- return mChartName;
- }
+ public String getChartName() {
+ return mChartName;
+ }
- public void setChartName(String chartName) {
- mChartName = chartName;
- }
+ public void setChartName(String chartName) {
+ mChartName = chartName;
+ }
- public String getDisclaimer() {
- return mDisclaimer;
- }
+ public String getDisclaimer() {
+ return mDisclaimer;
+ }
- public void setDisclaimer(String disclaimer) {
- mDisclaimer = disclaimer;
- }
+ public void setDisclaimer(String disclaimer) {
+ mDisclaimer = disclaimer;
+ }
- public Time getTime() {
- return mTime;
- }
+ public Time getTime() {
+ return mTime;
+ }
- public void setTime(Time time) {
- mTime = time;
- }
+ public void setTime(Time time) {
+ mTime = time;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/EUR.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/EUR.java
index 6d4c54e39..a481b2220 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/EUR.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/EUR.java
@@ -19,62 +19,63 @@
package org.apache.streampipes.connect.adapters.coindesk.model;
-import javax.annotation.Generated;
import com.google.gson.annotations.SerializedName;
+import javax.annotation.Generated;
+
@Generated("net.hexar.json2pojo")
@SuppressWarnings("unused")
public class EUR {
- @SerializedName("code")
- private String mCode;
- @SerializedName("description")
- private String mDescription;
- @SerializedName("rate")
- private String mRate;
- @SerializedName("rate_float")
- private Double mRateFloat;
- @SerializedName("symbol")
- private String mSymbol;
-
- public String getCode() {
- return mCode;
- }
-
- public void setCode(String code) {
- mCode = code;
- }
-
- public String getDescription() {
- return mDescription;
- }
-
- public void setDescription(String description) {
- mDescription = description;
- }
-
- public String getRate() {
- return mRate;
- }
-
- public void setRate(String rate) {
- mRate = rate;
- }
-
- public Double getRateFloat() {
- return mRateFloat;
- }
-
- public void setRateFloat(Double rateFloat) {
- mRateFloat = rateFloat;
- }
-
- public String getSymbol() {
- return mSymbol;
- }
-
- public void setSymbol(String symbol) {
- mSymbol = symbol;
- }
+ @SerializedName("code")
+ private String mCode;
+ @SerializedName("description")
+ private String mDescription;
+ @SerializedName("rate")
+ private String mRate;
+ @SerializedName("rate_float")
+ private Double mRateFloat;
+ @SerializedName("symbol")
+ private String mSymbol;
+
+ public String getCode() {
+ return mCode;
+ }
+
+ public void setCode(String code) {
+ mCode = code;
+ }
+
+ public String getDescription() {
+ return mDescription;
+ }
+
+ public void setDescription(String description) {
+ mDescription = description;
+ }
+
+ public String getRate() {
+ return mRate;
+ }
+
+ public void setRate(String rate) {
+ mRate = rate;
+ }
+
+ public Double getRateFloat() {
+ return mRateFloat;
+ }
+
+ public void setRateFloat(Double rateFloat) {
+ mRateFloat = rateFloat;
+ }
+
+ public String getSymbol() {
+ return mSymbol;
+ }
+
+ public void setSymbol(String symbol) {
+ mSymbol = symbol;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/GBP.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/GBP.java
index 9b6f0e658..1d4ddfe25 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/GBP.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/GBP.java
@@ -26,55 +26,55 @@ import javax.annotation.Generated;
@SuppressWarnings("unused")
public class GBP {
- @SerializedName("code")
- private String mCode;
- @SerializedName("description")
- private String mDescription;
- @SerializedName("rate")
- private String mRate;
- @SerializedName("rate_float")
- private Double mRateFloat;
- @SerializedName("symbol")
- private String mSymbol;
-
- public String getCode() {
- return mCode;
- }
-
- public void setCode(String code) {
- mCode = code;
- }
-
- public String getDescription() {
- return mDescription;
- }
-
- public void setDescription(String description) {
- mDescription = description;
- }
-
- public String getRate() {
- return mRate;
- }
-
- public void setRate(String rate) {
- mRate = rate;
- }
-
- public Double getRateFloat() {
- return mRateFloat;
- }
-
- public void setRateFloat(Double rateFloat) {
- mRateFloat = rateFloat;
- }
-
- public String getSymbol() {
- return mSymbol;
- }
-
- public void setSymbol(String symbol) {
- mSymbol = symbol;
- }
+ @SerializedName("code")
+ private String mCode;
+ @SerializedName("description")
+ private String mDescription;
+ @SerializedName("rate")
+ private String mRate;
+ @SerializedName("rate_float")
+ private Double mRateFloat;
+ @SerializedName("symbol")
+ private String mSymbol;
+
+ public String getCode() {
+ return mCode;
+ }
+
+ public void setCode(String code) {
+ mCode = code;
+ }
+
+ public String getDescription() {
+ return mDescription;
+ }
+
+ public void setDescription(String description) {
+ mDescription = description;
+ }
+
+ public String getRate() {
+ return mRate;
+ }
+
+ public void setRate(String rate) {
+ mRate = rate;
+ }
+
+ public Double getRateFloat() {
+ return mRateFloat;
+ }
+
+ public void setRateFloat(Double rateFloat) {
+ mRateFloat = rateFloat;
+ }
+
+ public String getSymbol() {
+ return mSymbol;
+ }
+
+ public void setSymbol(String symbol) {
+ mSymbol = symbol;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Time.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Time.java
index ecf6a4862..5125c38e9 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Time.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/Time.java
@@ -26,35 +26,35 @@ import javax.annotation.Generated;
@SuppressWarnings("unused")
public class Time {
- @SerializedName("updated")
- private String mUpdated;
- @SerializedName("updatedISO")
- private String mUpdatedISO;
- @SerializedName("updateduk")
- private String mUpdateduk;
-
- public String getUpdated() {
- return mUpdated;
- }
-
- public void setUpdated(String updated) {
- mUpdated = updated;
- }
-
- public String getUpdatedISO() {
- return mUpdatedISO;
- }
-
- public void setUpdatedISO(String updatedISO) {
- mUpdatedISO = updatedISO;
- }
-
- public String getUpdateduk() {
- return mUpdateduk;
- }
-
- public void setUpdateduk(String updateduk) {
- mUpdateduk = updateduk;
- }
+ @SerializedName("updated")
+ private String mUpdated;
+ @SerializedName("updatedISO")
+ private String mUpdatedISO;
+ @SerializedName("updateduk")
+ private String mUpdateduk;
+
+ public String getUpdated() {
+ return mUpdated;
+ }
+
+ public void setUpdated(String updated) {
+ mUpdated = updated;
+ }
+
+ public String getUpdatedISO() {
+ return mUpdatedISO;
+ }
+
+ public void setUpdatedISO(String updatedISO) {
+ mUpdatedISO = updatedISO;
+ }
+
+ public String getUpdateduk() {
+ return mUpdateduk;
+ }
+
+ public void setUpdateduk(String updateduk) {
+ mUpdateduk = updateduk;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/USD.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/USD.java
index 3f8c92fd8..22013055c 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/USD.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/coindesk/model/USD.java
@@ -26,55 +26,55 @@ import javax.annotation.Generated;
@SuppressWarnings("unused")
public class USD {
- @SerializedName("code")
- private String mCode;
- @SerializedName("description")
- private String mDescription;
- @SerializedName("rate")
- private String mRate;
- @SerializedName("rate_float")
- private Double mRateFloat;
- @SerializedName("symbol")
- private String mSymbol;
-
- public String getCode() {
- return mCode;
- }
-
- public void setCode(String code) {
- mCode = code;
- }
-
- public String getDescription() {
- return mDescription;
- }
-
- public void setDescription(String description) {
- mDescription = description;
- }
-
- public String getRate() {
- return mRate;
- }
-
- public void setRate(String rate) {
- mRate = rate;
- }
-
- public Double getRateFloat() {
- return mRateFloat;
- }
-
- public void setRateFloat(Double rateFloat) {
- mRateFloat = rateFloat;
- }
-
- public String getSymbol() {
- return mSymbol;
- }
-
- public void setSymbol(String symbol) {
- mSymbol = symbol;
- }
+ @SerializedName("code")
+ private String mCode;
+ @SerializedName("description")
+ private String mDescription;
+ @SerializedName("rate")
+ private String mRate;
+ @SerializedName("rate_float")
+ private Double mRateFloat;
+ @SerializedName("symbol")
+ private String mSymbol;
+
+ public String getCode() {
+ return mCode;
+ }
+
+ public void setCode(String code) {
+ mCode = code;
+ }
+
+ public String getDescription() {
+ return mDescription;
+ }
+
+ public void setDescription(String description) {
+ mDescription = description;
+ }
+
+ public String getRate() {
+ return mRate;
+ }
+
+ public void setRate(String rate) {
+ mRate = rate;
+ }
+
+ public Double getRateFloat() {
+ return mRateFloat;
+ }
+
+ public void setRateFloat(Double rateFloat) {
+ mRateFloat = rateFloat;
+ }
+
+ public String getSymbol() {
+ return mSymbol;
+ }
+
+ public void setSymbol(String symbol) {
+ mSymbol = symbol;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicMQTTAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicMQTTAdapter.java
index efca72326..c568c4495 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicMQTTAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicMQTTAdapter.java
@@ -18,125 +18,135 @@
package org.apache.streampipes.connect.adapters.flic;
-import com.google.gson.Gson;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.adapter.model.pipeline.AdapterPipeline;
import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
-import org.apache.streampipes.pe.shared.config.mqtt.*;
+import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.messaging.InternalEventProcessor;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
+import org.apache.streampipes.pe.shared.config.mqtt.MqttConfig;
+import org.apache.streampipes.pe.shared.config.mqtt.MqttConnectUtils;
+import org.apache.streampipes.pe.shared.config.mqtt.MqttConsumer;
import org.apache.streampipes.sdk.builder.adapter.SpecificDataStreamAdapterBuilder;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
-import java.util.*;
-
-public class FlicMQTTAdapter extends SpecificDataStreamAdapter {
-
- private MqttConsumer mqttConsumer;
- private MqttConfig mqttConfig;
- private Thread thread;
-
- /**
- * A unique id to identify the adapter type
- */
- public static final String ID = "org.apache.streampipes.connect.adapters.flic.mqtt";
-
- /**
- * Empty constructor and a constructor with SpecificAdapterStreamDescription are mandatory
- */
- public FlicMQTTAdapter() {
- }
-
- public FlicMQTTAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
-
-
- /**
- * Describe the adapter adapter and define what user inputs are required.
- * @return
- */
- @Override
- public SpecificAdapterStreamDescription declareModel() {
-
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
- .withLocales(Locales.EN)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .category(AdapterType.Energy)
- .requiredTextParameter(MqttConnectUtils.getBrokerUrlLabel())
- .requiredAlternatives(MqttConnectUtils.getAccessModeLabel(), MqttConnectUtils.getAlternativesOne(), MqttConnectUtils.getAlternativesTwo())
- .requiredTextParameter(MqttConnectUtils.getTopicLabel())
- .build();
- description.setAppId(ID);
-
- return description;
- }
-
- /**
- * Takes the user input and creates the event schema. The event schema describes the properties of the event stream.
- * @param adapterDescription
- * @return
- * @throws AdapterException
- */
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
- return FlicUtils.getFlicSchema();
- }
- @Override
- public void startAdapter() throws AdapterException {
- StaticPropertyExtractor extractor =
- StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
-
- this.mqttConfig = MqttConnectUtils.getMqttConfig(extractor);
- this.mqttConsumer = new MqttConsumer(this.mqttConfig, new EventProcessor(adapterPipeline));
+import com.google.gson.Gson;
- thread = new Thread(this.mqttConsumer);
- thread.start();
- }
+import java.util.ArrayList;
+import java.util.Map;
- @Override
- public void stopAdapter() throws AdapterException {
- this.mqttConsumer.close();
- }
+public class FlicMQTTAdapter extends SpecificDataStreamAdapter {
- /**
- * Required by StreamPipes return a new adapter instance by calling the constructor with SpecificAdapterStreamDescription
- * @param adapterDescription
- * @return
- */
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new FlicMQTTAdapter(adapterDescription);
+ private MqttConsumer mqttConsumer;
+ private MqttConfig mqttConfig;
+ private Thread thread;
+
+ /**
+ * A unique id to identify the adapter type
+ */
+ public static final String ID = "org.apache.streampipes.connect.adapters.flic.mqtt";
+
+ /**
+ * Empty constructor and a constructor with SpecificAdapterStreamDescription are mandatory
+ */
+ public FlicMQTTAdapter() {
+ }
+
+ public FlicMQTTAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+
+
+ /**
+ * Describe the adapter adapter and define what user inputs are required.
+ *
+ * @return
+ */
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
+ .withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .category(AdapterType.Energy)
+ .requiredTextParameter(MqttConnectUtils.getBrokerUrlLabel())
+ .requiredAlternatives(MqttConnectUtils.getAccessModeLabel(), MqttConnectUtils.getAlternativesOne(),
+ MqttConnectUtils.getAlternativesTwo())
+ .requiredTextParameter(MqttConnectUtils.getTopicLabel())
+ .build();
+ description.setAppId(ID);
+
+ return description;
+ }
+
+ /**
+ * Takes the user input and creates the event schema. The event schema describes the properties of the event stream.
+ *
+ * @param adapterDescription
+ * @return
+ */
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
+ return FlicUtils.getFlicSchema();
+ }
+
+ @Override
+ public void startAdapter() throws AdapterException {
+ StaticPropertyExtractor extractor =
+ StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+
+ this.mqttConfig = MqttConnectUtils.getMqttConfig(extractor);
+ this.mqttConsumer = new MqttConsumer(this.mqttConfig, new EventProcessor(adapterPipeline));
+
+ thread = new Thread(this.mqttConsumer);
+ thread.start();
+ }
+
+ @Override
+ public void stopAdapter() throws AdapterException {
+ this.mqttConsumer.close();
+ }
+
+ /**
+ * Required by StreamPipes return a new adapter instance by calling the constructor
+ * with SpecificAdapterStreamDescription
+ *
+ * @param adapterDescription
+ * @return
+ */
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new FlicMQTTAdapter(adapterDescription);
+ }
+
+
+ /**
+ * Required by StreamPipes. Return the id of the adapter
+ *
+ * @return
+ */
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ private class EventProcessor implements InternalEventProcessor<byte[]> {
+ private AdapterPipeline adapterPipeline;
+
+ public EventProcessor(AdapterPipeline adapterpipeline) {
+ this.adapterPipeline = adapterpipeline;
}
-
- /**
- * Required by StreamPipes. Return the id of the adapter
- * @return
- */
@Override
- public String getId() {
- return ID;
- }
-
- private class EventProcessor implements InternalEventProcessor<byte[]> {
- private AdapterPipeline adapterPipeline;
-
- public EventProcessor(AdapterPipeline adapterpipeline) {
- this.adapterPipeline = adapterpipeline;
- }
-
- @Override
- public void onEvent(byte[] payload) {
- String s = new String(payload);
- FlicOutput output = new Gson().fromJson(s, FlicOutput.class);
- Map<String, Object> event = FlicUtils.getEvent(output);
- adapterPipeline.process(event);
- }
+ public void onEvent(byte[] payload) {
+ String s = new String(payload);
+ FlicOutput output = new Gson().fromJson(s, FlicOutput.class);
+ Map<String, Object> event = FlicUtils.getEvent(output);
+ adapterPipeline.process(event);
}
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicOutput.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicOutput.java
index aa372cc52..51075410c 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicOutput.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicOutput.java
@@ -19,34 +19,43 @@
package org.apache.streampipes.connect.adapters.flic;
import com.google.gson.annotations.SerializedName;
+
import javax.annotation.Generated;
@Generated("net.hexar.json2pojo")
public class FlicOutput {
- @SerializedName("timestamp")
- private Long timestamp;
+ @SerializedName("timestamp")
+ private Long timestamp;
- @SerializedName("button_id")
- private String buttonID;
+ @SerializedName("button_id")
+ private String buttonID;
- @SerializedName("click_type")
- private String clickType;
+ @SerializedName("click_type")
+ private String clickType;
- public Long getTimestamp() { return timestamp; }
+ public Long getTimestamp() {
+ return timestamp;
+ }
- public void setTimestamp(Long timestamp) { this.timestamp = timestamp; }
+ public void setTimestamp(Long timestamp) {
+ this.timestamp = timestamp;
+ }
- public String getButtonID() { return buttonID; }
+ public String getButtonID() {
+ return buttonID;
+ }
- public void setButtonID(String buttonID) { this.buttonID = buttonID; }
+ public void setButtonID(String buttonID) {
+ this.buttonID = buttonID;
+ }
- public String getClickType() {
- return clickType;
- }
+ public String getClickType() {
+ return clickType;
+ }
- public void setClickType(float voltage) {
- this.clickType = clickType;
- }
+ public void setClickType(float voltage) {
+ this.clickType = clickType;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicUtils.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicUtils.java
index 7b0b6b903..118a68ed4 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicUtils.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/flic/FlicUtils.java
@@ -31,43 +31,43 @@ import java.util.List;
import java.util.Map;
public class FlicUtils {
- public static final String TIMESTAMP_KEY = "timestamp";
- public static final String BUTTON_ID_KEY = "button_id";
- public static final String CLICK_TYPE_KEY = "click_type";
+ public static final String TIMESTAMP_KEY = "timestamp";
+ public static final String BUTTON_ID_KEY = "button_id";
+ public static final String CLICK_TYPE_KEY = "click_type";
- public static GuessSchema getFlicSchema() {
+ public static GuessSchema getFlicSchema() {
- GuessSchema guessSchema = new GuessSchema();
+ GuessSchema guessSchema = new GuessSchema();
- EventSchema eventSchema = new EventSchema();
- List<EventProperty> allProperties = new ArrayList<>();
+ EventSchema eventSchema = new EventSchema();
+ List<EventProperty> allProperties = new ArrayList<>();
- allProperties.add(EpProperties.timestampProperty(TIMESTAMP_KEY));
- allProperties.add(
- PrimitivePropertyBuilder
- .create(Datatypes.String, BUTTON_ID_KEY)
- .label("Button ID")
- .description("The ID of the button")
- .build());
- allProperties.add(
- PrimitivePropertyBuilder
- .create(Datatypes.String, CLICK_TYPE_KEY)
- .label("Click Type")
- .description("Type of the click")
- .build());
+ allProperties.add(EpProperties.timestampProperty(TIMESTAMP_KEY));
+ allProperties.add(
+ PrimitivePropertyBuilder
+ .create(Datatypes.String, BUTTON_ID_KEY)
+ .label("Button ID")
+ .description("The ID of the button")
+ .build());
+ allProperties.add(
+ PrimitivePropertyBuilder
+ .create(Datatypes.String, CLICK_TYPE_KEY)
+ .label("Click Type")
+ .description("Type of the click")
+ .build());
- eventSchema.setEventProperties(allProperties);
- guessSchema.setEventSchema(eventSchema);
- return guessSchema;
- }
+ eventSchema.setEventProperties(allProperties);
+ guessSchema.setEventSchema(eventSchema);
+ return guessSchema;
+ }
- public static Map<String, Object> getEvent(FlicOutput output) {
- Map<String, Object> event = new HashMap<>();
+ public static Map<String, Object> getEvent(FlicOutput output) {
+ Map<String, Object> event = new HashMap<>();
- event.put(TIMESTAMP_KEY, output.getTimestamp());
- event.put(BUTTON_ID_KEY, output.getButtonID());
- event.put(CLICK_TYPE_KEY, output.getClickType());
- return event;
- }
+ event.put(TIMESTAMP_KEY, output.getTimestamp());
+ event.put(BUTTON_ID_KEY, output.getButtonID());
+ event.put(CLICK_TYPE_KEY, output.getClickType());
+ return event;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/gdelt/GdeltAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/gdelt/GdeltAdapter.java
index e2d593185..86319232e 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/gdelt/GdeltAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/gdelt/GdeltAdapter.java
@@ -18,11 +18,10 @@
package org.apache.streampipes.connect.adapters.gdelt;
-import com.opencsv.CSVReader;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.adapters.PullAdapter;
+import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
import org.apache.streampipes.model.schema.EventProperty;
@@ -33,6 +32,8 @@ import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;
import org.apache.streampipes.sdk.utils.Datatypes;
+import com.opencsv.CSVReader;
+
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
@@ -45,147 +46,187 @@ import java.util.zip.ZipInputStream;
public class GdeltAdapter extends PullAdapter {
- public static final String ID = "org.apache.streampipes.connect.adapters.gdelt";
-
-
- private String url = "http://data.gdeltproject.org/gdeltv2/lastupdate.txt";
-
- public GdeltAdapter() {
- super();
- }
-
- public GdeltAdapter(SpecificAdapterStreamDescription adapterDescription) {
- super(adapterDescription);
- }
-
- @Override
- protected PollingSettings getPollingInterval() {
- return PollingSettings.from(TimeUnit.MINUTES, 15);
- }
-
- @Override
- public SpecificAdapterStreamDescription declareModel() {
- SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .build();
- return description;
+ public static final String ID = "org.apache.streampipes.connect.adapters.gdelt";
+
+
+ private String url = "http://data.gdeltproject.org/gdeltv2/lastupdate.txt";
+
+ public GdeltAdapter() {
+ super();
+ }
+
+ public GdeltAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+
+ @Override
+ protected PollingSettings getPollingInterval() {
+ return PollingSettings.from(TimeUnit.MINUTES, 15);
+ }
+
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .build();
+ return description;
+ }
+
+ public List<Map<String, Object>> getEvents() {
+
+ List<Map<String, Object>> eventResults = new ArrayList<>();
+ return eventResults;
+ }
+
+ @Override
+ protected void pullData() {
+ try {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
+ String firstLine = bufferedReader.readLine();
+ String[] parts = firstLine.split(" ");
+ URL zipFileUrl = new URL(parts[2]);
+ bufferedReader.close();
+ ZipInputStream zipInputStream = new ZipInputStream(zipFileUrl.openStream());
+ BufferedReader zipBufferedReader = new BufferedReader(new InputStreamReader(zipInputStream));
+ zipInputStream.getNextEntry();
+ CSVReader csvReader = new CSVReader(zipBufferedReader);
+ String[] nextRecord;
+ while ((nextRecord = csvReader.readNext()) != null) {
+
+ Map<String, Object> event = new HashMap<>();
+
+ event.put("global_event_id", nextRecord[0]);
+ event.put("day", nextRecord[1]);
+ event.put("month_year", nextRecord[2]);
+ event.put("year", nextRecord[3]);
+ event.put("fraction_date", nextRecord[4]);
+
+ event.put("actor_1_code", nextRecord[5]);
+ event.put("actor_1_name", nextRecord[6]);
+ event.put("actor_1_country_code", nextRecord[7]);
+ event.put("actor_1_known_group_code", nextRecord[8]);
+ event.put("actor_1_ethnic_code", nextRecord[9]);
+ event.put("actor_1_religion_1_code", nextRecord[10]);
+ event.put("actor_1_religion_2_code", nextRecord[11]);
+ event.put("actor_1_type_1_code", nextRecord[12]);
+ event.put("actor_1_type_2_code", nextRecord[13]);
+ event.put("actor_1_type_3_code", nextRecord[14]);
+
+ event.put("actor_2_code", nextRecord[15]);
+ event.put("actor_2_name", nextRecord[16]);
+ event.put("actor_2_country_code", nextRecord[17]);
+ event.put("actor_2_known_group_code", nextRecord[18]);
+ event.put("actor_2_ethnic_code", nextRecord[19]);
+ event.put("actor_2_religion_1_code", nextRecord[20]);
+ event.put("actor_2_religion_2_code", nextRecord[21]);
+ event.put("actor_2_type_1_code", nextRecord[22]);
+ event.put("actor_2_type_2_code", nextRecord[23]);
+ event.put("actor_2_type_3_code", nextRecord[24]);
+
+ event.put("source_url", nextRecord[60]);
+ adapterPipeline.process(event);
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
}
- public List<Map<String, Object>> getEvents() {
-
- List<Map<String, Object>> eventResults = new ArrayList<>();
- return eventResults;
- }
-
- @Override
- protected void pullData() {
- try {
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
- String firstLine = bufferedReader.readLine();
- String[] parts = firstLine.split(" ");
- URL zipFileUrl = new URL(parts[2]);
- bufferedReader.close();
- ZipInputStream zipInputStream = new ZipInputStream(zipFileUrl.openStream());
- BufferedReader zipBufferedReader = new BufferedReader(new InputStreamReader(zipInputStream));
- zipInputStream.getNextEntry();
- CSVReader csvReader = new CSVReader(zipBufferedReader);
- String[] nextRecord;
- while ((nextRecord = csvReader.readNext()) != null) {
-
- Map<String, Object> event = new HashMap<>();
-
- event.put("global_event_id", nextRecord[0]);
- event.put("day", nextRecord[1]);
- event.put("month_year", nextRecord[2]);
- event.put("year", nextRecord[3]);
- event.put("fraction_date", nextRecord[4]);
-
- event.put("actor_1_code", nextRecord[5]);
- event.put("actor_1_name", nextRecord[6]);
- event.put("actor_1_country_code", nextRecord[7]);
- event.put("actor_1_known_group_code", nextRecord[8]);
- event.put("actor_1_ethnic_code", nextRecord[9]);
- event.put("actor_1_religion_1_code", nextRecord[10]);
- event.put("actor_1_religion_2_code", nextRecord[11]);
- event.put("actor_1_type_1_code", nextRecord[12]);
- event.put("actor_1_type_2_code", nextRecord[13]);
- event.put("actor_1_type_3_code", nextRecord[14]);
-
- event.put("actor_2_code", nextRecord[15]);
- event.put("actor_2_name", nextRecord[16]);
- event.put("actor_2_country_code", nextRecord[17]);
- event.put("actor_2_known_group_code", nextRecord[18]);
- event.put("actor_2_ethnic_code", nextRecord[19]);
- event.put("actor_2_religion_1_code", nextRecord[20]);
- event.put("actor_2_religion_2_code", nextRecord[21]);
- event.put("actor_2_type_1_code", nextRecord[22]);
- event.put("actor_2_type_2_code", nextRecord[23]);
- event.put("actor_2_type_3_code", nextRecord[24]);
-
- event.put("source_url", nextRecord[60]);
- adapterPipeline.process(event);
-
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void stopAdapter() throws AdapterException {
-
- }
-
- @Override
- public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
- return new GdeltAdapter(adapterDescription);
- }
-
- @Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) {
- GuessSchema guessSchema = new GuessSchema();
- EventSchema eventSchema = new EventSchema();
-
- List<EventProperty> allProperties = new ArrayList<>();
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "global_event_id").label("Global Event ID").description("Globally unique identifier").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "day").label("Day").description("Date the event took place in YYYYMMDD format").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "month_year").label("MonthYear").description("Date the event took place in YYYYMM format").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "year").label("Year").description("Date the event took place in YYYY format").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Float, "fraction_date").label("FractionDate").description("Date the event took place in YYYY.FFFF format (where FFFF is the percentage of the year completed)").build());
-
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_code").label("Actor1Code").description("The complete raw CAMEO code for Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_name").label("Actor1Name").description("The actual name of the Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_country_code").label("Actor1CountryCode").description("The 3-character CAMEO code for the country affiliation of Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_known_group_code").label("Actor1KnownGroupCode").description("The CAMEO code if Actor 1 is a known IGO/NGO/rebel organization").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_ethnic_code").label("Actor1EthnicCode").description("The CAMEO code if the source document specifies the ethnic affiliation of Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_religion_1_code").label("Actor1Religion1Code").description("The CAMEO code if the source document specifies the religious affiliation of Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_religion_2_code").label("Actor1Religion2Code").description("The CAMEO code if the source document specifies multiple religious affiliations of Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_type_1_code").label("Actor1Type1Code").description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_type_2_code").label("Actor1Type2Code").description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor1").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_type_3_code").label("Actor1Type3Code").description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor1").build());
-
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_code").label("Actor2Code").description("The complete raw CAMEO code for Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_name").label("Actor2Name").description("The actual name of the Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_country_code").label("Actor2CountryCode").description("The 3-character CAMEO code for the country affiliation of Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_known_group_code").label("Actor2KnownGroupCode").description("The CAMEO code if Actor 1 is a known IGO/NGO/rebel organization").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_ethnic_code").label("Actor2EthnicCode").description("The CAMEO code if the source document specifies the ethnic affiliation of Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_religion_1_code").label("Actor2Religion1Code").description("The CAMEO code if the source document specifies the religious affiliation of Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_religion_2_code").label("Actor2Religion2Code").description("The CAMEO code if the source document specifies multiple religious affiliations of Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_type_1_code").label("Actor2Type1Code").description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_type_2_code").label("Actor2Type2Code").description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor2").build());
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_type_3_code").label("Actor2Type3Code").description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor2").build());
-
- allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "source_url").label("URL").description("The url of the source of the article").build());
-
- eventSchema.setEventProperties(allProperties);
- guessSchema.setEventSchema(eventSchema);
- return guessSchema;
- }
-
- @Override
- public String getId() {
- return ID;
- }
+ }
+
+ @Override
+ public void stopAdapter() throws AdapterException {
+
+ }
+
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new GdeltAdapter(adapterDescription);
+ }
+
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) {
+ GuessSchema guessSchema = new GuessSchema();
+ EventSchema eventSchema = new EventSchema();
+
+ List<EventProperty> allProperties = new ArrayList<>();
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "global_event_id").label("Global Event ID")
+ .description("Globally unique identifier").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "day").label("Day")
+ .description("Date the event took place in YYYYMMDD format").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "month_year").label("MonthYear")
+ .description("Date the event took place in YYYYMM format").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Integer, "year").label("Year")
+ .description("Date the event took place in YYYY format").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.Float, "fraction_date").label("FractionDate")
+ .description(
+ "Date the event took place in YYYY.FFFF format (where FFFF is the percentage of the year completed)")
+ .build());
+
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_code").label("Actor1Code")
+ .description("The complete raw CAMEO code for Actor1").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_name").label("Actor1Name")
+ .description("The actual name of the Actor1").build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_country_code").label("Actor1CountryCode")
+ .description("The 3-character CAMEO code for the country affiliation of Actor1").build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_known_group_code").label("Actor1KnownGroupCode")
+ .description("The CAMEO code if Actor 1 is a known IGO/NGO/rebel organization").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_ethnic_code").label("Actor1EthnicCode")
+ .description("The CAMEO code if the source document specifies the ethnic affiliation of Actor1").build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_religion_1_code").label("Actor1Religion1Code")
+ .description("The CAMEO code if the source document specifies the religious affiliation of Actor1")
+ .build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_religion_2_code").label("Actor1Religion2Code")
+ .description("The CAMEO code if the source document specifies multiple religious affiliations of Actor1")
+ .build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_type_1_code").label("Actor1Type1Code")
+ .description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor1").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_type_2_code").label("Actor1Type2Code")
+ .description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor1").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_1_type_3_code").label("Actor1Type3Code")
+ .description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor1").build());
+
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_code").label("Actor2Code")
+ .description("The complete raw CAMEO code for Actor2").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_name").label("Actor2Name")
+ .description("The actual name of the Actor2").build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_country_code").label("Actor2CountryCode")
+ .description("The 3-character CAMEO code for the country affiliation of Actor2").build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_known_group_code").label("Actor2KnownGroupCode")
+ .description("The CAMEO code if Actor 1 is a known IGO/NGO/rebel organization").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_ethnic_code").label("Actor2EthnicCode")
+ .description("The CAMEO code if the source document specifies the ethnic affiliation of Actor2").build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_religion_1_code").label("Actor2Religion1Code")
+ .description("The CAMEO code if the source document specifies the religious affiliation of Actor2")
+ .build());
+ allProperties.add(
+ PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_religion_2_code").label("Actor2Religion2Code")
+ .description("The CAMEO code if the source document specifies multiple religious affiliations of Actor2")
+ .build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_type_1_code").label("Actor2Type1Code")
+ .description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor2").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_type_2_code").label("Actor2Type2Code")
+ .description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor2").build());
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "actor_2_type_3_code").label("Actor2Type3Code")
+ .description("The 3-character CAMEO code of the CAMEO “type” or “role” of Actor2").build());
+
+ allProperties.add(PrimitivePropertyBuilder.create(Datatypes.String, "source_url").label("URL")
+ .description("The url of the source of the article").build());
+
+ eventSchema.setEventProperties(allProperties);
+ guessSchema.setEventSchema(eventSchema);
+ return guessSchema;
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudAdapter.java
index 648eaa4a4..465fb5122 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudAdapter.java
@@ -17,18 +17,20 @@
*/
package org.apache.streampipes.connect.adapters.iex;
-import com.google.gson.Gson;
-import org.apache.http.client.fluent.Request;
+
import org.apache.streampipes.connect.adapter.sdk.ParameterExtractor;
import org.apache.streampipes.connect.adapters.PullAdapter;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
+import com.google.gson.Gson;
+import org.apache.http.client.fluent.Request;
+
import java.io.IOException;
public abstract class IexCloudAdapter extends PullAdapter {
- protected static final String IexCloudBaseUrl = "https://cloud.iexapis.com/stable/stock/";
- protected static final String Token = "?token=";
+ protected static final String IEX_CLOUD_BASE_URL = "https://cloud.iexapis.com/stable/stock/";
+ protected static final String TOKEN = "?token=";
protected static final String TOKEN_KEY = "token";
protected static final String STOCK_SYMBOL_KEY = "stock-symbol";
@@ -43,7 +45,7 @@ public abstract class IexCloudAdapter extends PullAdapter {
ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
this.apiToken = extractor.secretValue(TOKEN_KEY);
this.stockQuote = extractor.singleValue(STOCK_SYMBOL_KEY);
- this.iexCloudInstanceUrl = IexCloudBaseUrl + stockQuote + restPath + Token + apiToken;
+ this.iexCloudInstanceUrl = IEX_CLOUD_BASE_URL + stockQuote + restPath + TOKEN + apiToken;
}
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudNewsAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudNewsAdapter.java
index 916c698cf..15c8e33cd 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudNewsAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudNewsAdapter.java
@@ -19,10 +19,10 @@
package org.apache.streampipes.connect.adapters.iex;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
-import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.adapters.iex.model.IexNewsData;
+import org.apache.streampipes.connect.api.exception.AdapterException;
+import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -82,8 +82,7 @@ public class IexCloudNewsAdapter extends IexCloudAdapter {
adapterPipeline.process(outMap);
}
- } catch (
- IOException e) {
+ } catch (IOException e) {
e.printStackTrace();
}
}
@@ -96,12 +95,12 @@ public class IexCloudNewsAdapter extends IexCloudAdapter {
@Override
public SpecificAdapterStreamDescription declareModel() {
return SpecificDataStreamAdapterBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Finance, AdapterType.News)
- .requiredSecret(Labels.withId(TOKEN_KEY))
- .requiredTextParameter(Labels.withId(STOCK_SYMBOL_KEY))
- .build();
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Finance, AdapterType.News)
+ .requiredSecret(Labels.withId(TOKEN_KEY))
+ .requiredTextParameter(Labels.withId(STOCK_SYMBOL_KEY))
+ .build();
}
@Override
@@ -110,27 +109,28 @@ public class IexCloudNewsAdapter extends IexCloudAdapter {
}
@Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException, ParseException {
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
return GuessSchemaBuilder.create()
- .property(EpProperties.timestampProperty(Timestamp))
- .property(EpProperties.stringEp(Labels.from("headline", "Headline",
- "The headline of the article"), Headline, SO.Text))
- .property(EpProperties.stringEp(Labels.from("source", "Source",
- "The source of the article"), Source, SO.Text))
- .property(EpProperties.stringEp(Labels.from("url", "URL",
- "The URL of the article"), Url, SO.ContentUrl))
- .property(EpProperties.stringEp(Labels.from("summary", "Summary",
- "A short summary of the article"), Summary, SO.Text))
- .property(EpProperties.stringEp(Labels.from("related", "Related",
- "A comma-separated list of related stock symbols"), Related, SO.Text))
- .property(EpProperties.stringEp(Labels.from("image", "Image",
- "Link to an image related to the news article"), Image, SO.Image))
- .property(EpProperties.stringEp(Labels.from("lang", "Language",
- "The language the article is writte in"), Lang, SO.InLanguage))
- .property(EpProperties.stringEp(Labels.from("paywall", "Has Paywall",
- "Indicates whether the article is behind a paywall"), HasPaywall,
- SO.Text))
- .build();
+ .property(EpProperties.timestampProperty(Timestamp))
+ .property(EpProperties.stringEp(Labels.from("headline", "Headline",
+ "The headline of the article"), Headline, SO.Text))
+ .property(EpProperties.stringEp(Labels.from("source", "Source",
+ "The source of the article"), Source, SO.Text))
+ .property(EpProperties.stringEp(Labels.from("url", "URL",
+ "The URL of the article"), Url, SO.ContentUrl))
+ .property(EpProperties.stringEp(Labels.from("summary", "Summary",
+ "A short summary of the article"), Summary, SO.Text))
+ .property(EpProperties.stringEp(Labels.from("related", "Related",
+ "A comma-separated list of related stock symbols"), Related, SO.Text))
+ .property(EpProperties.stringEp(Labels.from("image", "Image",
+ "Link to an image related to the news article"), Image, SO.Image))
+ .property(EpProperties.stringEp(Labels.from("lang", "Language",
+ "The language the article is writte in"), Lang, SO.InLanguage))
+ .property(EpProperties.stringEp(Labels.from("paywall", "Has Paywall",
+ "Indicates whether the article is behind a paywall"), HasPaywall,
+ SO.Text))
+ .build();
}
@Override
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudStockAdapter.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudStockAdapter.java
index 04618688a..db05e7060 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudStockAdapter.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/IexCloudStockAdapter.java
@@ -19,10 +19,10 @@
package org.apache.streampipes.connect.adapters.iex;
import org.apache.streampipes.connect.adapter.Adapter;
-import org.apache.streampipes.connect.api.exception.AdapterException;
-import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.connect.adapter.util.PollingSettings;
import org.apache.streampipes.connect.adapters.iex.model.IexStockData;
+import org.apache.streampipes.connect.api.exception.AdapterException;
+import org.apache.streampipes.connect.api.exception.ParseException;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
@@ -59,12 +59,12 @@ public class IexCloudStockAdapter extends IexCloudAdapter {
@Override
public SpecificAdapterStreamDescription declareModel() {
return SpecificDataStreamAdapterBuilder.create(ID)
- .withAssets(Assets.DOCUMENTATION, Assets.ICON)
- .withLocales(Locales.EN)
- .category(AdapterType.Finance)
- .requiredSecret(Labels.withId(TOKEN_KEY))
- .requiredTextParameter(Labels.withId(STOCK_SYMBOL_KEY))
- .build();
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .withLocales(Locales.EN)
+ .category(AdapterType.Finance)
+ .requiredSecret(Labels.withId(TOKEN_KEY))
+ .requiredTextParameter(Labels.withId(STOCK_SYMBOL_KEY))
+ .build();
}
@@ -79,8 +79,7 @@ public class IexCloudStockAdapter extends IexCloudAdapter {
outMap.put(LatestPrice, rawModel.getLatestPrice());
adapterPipeline.process(outMap);
- } catch (
- IOException e) {
+ } catch (IOException e) {
e.printStackTrace();
}
}
@@ -96,14 +95,15 @@ public class IexCloudStockAdapter extends IexCloudAdapter {
}
@Override
- public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException, ParseException {
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription)
+ throws AdapterException, ParseException {
return GuessSchemaBuilder.create()
- .property(EpProperties.timestampProperty(LatestUpdate))
- .property(EpProperties.stringEp(Labels.from("symbol", "Symbol",
- "The stock symbol"), Symbol, SO.Text))
- .property(EpProperties.doubleEp(Labels.from("latest-price", "Latest price",
- "The latest stock price"), LatestPrice, SO.Number))
- .build();
+ .property(EpProperties.timestampProperty(LatestUpdate))
+ .property(EpProperties.stringEp(Labels.from("symbol", "Symbol",
+ "The stock symbol"), Symbol, SO.Text))
+ .property(EpProperties.doubleEp(Labels.from("latest-price", "Latest price",
+ "The latest stock price"), LatestPrice, SO.Number))
+ .build();
}
@Override
diff --git a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/model/IexNewsData.java b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/model/IexNewsData.java
index 85621e506..06c912c2c 100644
--- a/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/model/IexNewsData.java
+++ b/streampipes-extensions/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/iex/model/IexNewsData.java
@@ -26,95 +26,95 @@ import javax.annotation.Generated;
@SuppressWarnings("unused")
public class IexNewsData {
- @SerializedName("datetime")
- private Long mDatetime;
- @SerializedName("hasPaywall")
- private Boolean mHasPaywall;
- @SerializedName("headline")
- private String mHeadline;
- @SerializedName("image")
- private String mImage;
- @SerializedName("lang")
- private String mLang;
- @SerializedName("related")
- private String mRelated;
- @SerializedName("source")
- private String mSource;
- @SerializedName("summary")
- private String mSummary;
- @SerializedName("url")
- private String mUrl;
-
- public Long getDatetime() {
- return mDatetime;
- }
-
- public void setDatetime(Long datetime) {
- mDatetime = datetime;
- }
-
- public Boolean getHasPaywall() {
- return mHasPaywall;
- }
-
- public void setHasPaywall(Boolean hasPaywall) {
- mHasPaywall = hasPaywall;
- }
-
- public String getHeadline() {
- return mHeadline;
- }
-
- public void setHeadline(String headline) {
- mHeadline = headline;
- }
-
- public String getImage() {
- return mImage;
- }
-
- public void setImage(String image) {
- mImage = image;
- }
-
- public String getLang() {
- return mLang;
- }
-
- public void setLang(String lang) {
- mLang = lang;
- }
-
- public String getRelated() {
- return mRelated;
- }
-
- public void setRelated(String related) {
- mRelated = related;
- }
-
- public String getSource() {
- return mSource;
- }
-
- public void setSource(String source) {
- mSource = source;
- }
-
- public String getSummary() {
- return mSummary;
- }
-
- public void setSummary(String summary) {
- mSummary = summary;
- }
-
- public String getUrl() {
- return mUrl;
- }
-
- public void setUrl(String url) {
- mUrl = url;
- }
+ @SerializedName("datetime")
+ private Long mDatetime;
+ @SerializedName("hasPaywall")
+ private Boolean mHasPaywall;
+ @SerializedName("headline")
+ private String mHeadline;
+ @SerializedName("image")
+ private String mImage;
+ @SerializedName("lang")
+ private String mLang;
+ @SerializedName("related")
+ private String mRelated;
+ @SerializedName("source")
+ private String mSource;
+ @SerializedName("summary")
+ private String mSummary;
+ @SerializedName("url")
+ private String mUrl;
+
+ public Long getDatetime() {
+ return mDatetime;
+ }
+
+ public void setDatetime(Long datetime) {
+ mDatetime = datetime;
+ }
+
+ public Boolean getHasPaywall() {
+ return mHasPaywall;
+ }
+
+ public void setHasPaywall(Boolean hasPaywall) {
+ mHasPaywall = hasPaywall;
+ }
+
+ public String getHeadline() {
+ return mHeadline;
+ }
+
+ public void setHeadline(String headline) {
+ mHeadline = headline;
+ }
+
+ public String getImage() {
+ return mImage;
+ }
+
+ public void setImage(String image) {
+ mImage = image;
+ }
+
+ public String getLang() {
+ return mLang;
+ }
+
+ public void setLang(String lang) {
+ mLang = lang;
+ }
+
+ public String getRelated() {
... 5995 lines suppressed ...