You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/11/06 15:23:31 UTC

[plc4x] branch feature/reproducible-builds updated: - Added some more documentation - Started making it configurable

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

cdutz pushed a commit to branch feature/reproducible-builds
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/reproducible-builds by this push:
     new a543456  - Added some more documentation - Started making it configurable
a543456 is described below

commit a54345672fdb3bd74c4aff1c39f282996f240a71
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Nov 6 16:23:20 2019 +0100

    - Added some more documentation
    - Started making it configurable
---
 sandbox/streampipes-connectors/READMME.adoc        | 15 +++++++--
 sandbox/streampipes-connectors/env/development     |  5 +--
 .../java/streampipes/bacnetip/BacNetIpAdapter.java | 37 +++++++++++++++++++++-
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/sandbox/streampipes-connectors/READMME.adoc b/sandbox/streampipes-connectors/READMME.adoc
index d64a576..fa94660 100644
--- a/sandbox/streampipes-connectors/READMME.adoc
+++ b/sandbox/streampipes-connectors/READMME.adoc
@@ -19,6 +19,7 @@
 
 1. Install StreamPipes (Using `./streampipes start` with the installer, choosing a real IP address)
 2. When asked for the IP address, enter: `host.docker.internal`
+3. Edit your `hosts` file (Mac: `/private/ect/hosts`) to direct `host.docker.internal` to `127.0.0.1_`
 
 == Setting up the Worker
 
@@ -28,13 +29,21 @@
 4. Check the `Enable EnvFile`
 5. Add the env file in `env/development`
 
-== Runing the Worker
+== Running the Worker
 
 1. Execute the new run configuration (This will fail with an error: `Web server failed to start. Port 8098 was already in use.`)
 2. Stop the running configuration.
-3. Go to the `Consul` configuration page on `hppt://localhost:9500`
+3. Go to the `Consul` configuration page on `http://localhost:8500`
 4. Select `Key/Value`
 5. Navigate to `sp/v1/{name of your worker}
 6. Change `SP_CONNECT_CONTAINER_WORKER_PORT` to an unused port: `8198`
-7. Change `SP_CONNECT_CONTAINER_MASTER_HOST` and `SP_CONNECT_CONTAINER_WORKER_HOST` from `localhost` to the fixed ip you told the setup to use
+7. Change `SP_CONNECT_CONTAINER_WORKER_HOST` and `SP_KAFKA_HOST` from `localhost` to the fixed ip you told the setup to use
 8. Restart the run configuration
+
+== Using the Worker
+
+1. Go to the StreamPipes UI section `StreamPipes connect`
+2. Search for your Worker
+3. Give it a name
+4. Start it
+5. Now it should appear in the `Data Streams` section of the pipeline editor
\ No newline at end of file
diff --git a/sandbox/streampipes-connectors/env/development b/sandbox/streampipes-connectors/env/development
index 935543b..8e06237 100644
--- a/sandbox/streampipes-connectors/env/development
+++ b/sandbox/streampipes-connectors/env/development
@@ -18,9 +18,10 @@
 # ----------------------------------------------------------------------------
 
 # Redirect some parameters for local development.
-SP_KAFKA_HOST=localhost
+SP_KAFKA_HOST=host.docker.internal
 SP_CONNECT_CONTAINER_HOST=localhost
 SP_CONNECT_CONTAINER_MASTER_HOST=localhost
-SP_CONNECT_CONTAINER_WORKER_HOST=localhost
+SP_CONNECT_CONTAINER_WORKER_HOST=host.docker.internal
+SP_CONNECT_CONTAINER_WORKER_PORT=8198
 SP_DATA_LOCATION=./test_data/
 
diff --git a/sandbox/streampipes-connectors/src/main/java/org/apache/plc4x/java/streampipes/bacnetip/BacNetIpAdapter.java b/sandbox/streampipes-connectors/src/main/java/org/apache/plc4x/java/streampipes/bacnetip/BacNetIpAdapter.java
index aa9a2d8..c2c6cbd 100644
--- a/sandbox/streampipes-connectors/src/main/java/org/apache/plc4x/java/streampipes/bacnetip/BacNetIpAdapter.java
+++ b/sandbox/streampipes-connectors/src/main/java/org/apache/plc4x/java/streampipes/bacnetip/BacNetIpAdapter.java
@@ -31,6 +31,7 @@ import org.apache.plc4x.java.streampipes.bacnetip.config.ConnectWorkerConfig;
 import org.apache.plc4x.java.utils.pcapsockets.netty.PcapSocketAddress;
 import org.apache.plc4x.java.utils.pcapsockets.netty.PcapSocketChannelConfig;
 import org.apache.plc4x.java.utils.pcapsockets.netty.UdpIpPacketHandler;
+import org.pcap4j.core.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.streampipes.connect.adapter.Adapter;
@@ -44,8 +45,11 @@ import org.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
 import org.streampipes.model.connect.guess.GuessSchema;
 import org.streampipes.model.schema.EventProperty;
 import org.streampipes.model.schema.EventSchema;
+import org.streampipes.model.staticproperty.FileStaticProperty;
+import org.streampipes.sdk.StaticProperties;
 import org.streampipes.sdk.builder.PrimitivePropertyBuilder;
 import org.streampipes.sdk.builder.adapter.SpecificDataStreamAdapterBuilder;
+import org.streampipes.sdk.helpers.*;
 import org.streampipes.sdk.utils.Datatypes;
 
 import java.io.File;
@@ -70,9 +74,40 @@ public class BacNetIpAdapter extends SpecificDataStreamAdapter {
 
     @Override
     public SpecificAdapterStreamDescription declareModel() {
+        Label fileLabel = Labels.from("pcap-file", "PCAP File", "File containing the network traffic recording");
+
+        Tuple2<String, String>[] deviceList = null;
+        try {
+            final List<PcapNetworkInterface> allDevs = Pcaps.findAllDevs();
+            deviceList = new Tuple2[allDevs.size()];
+            for (int i = 0; i < allDevs.size(); i++) {
+                final PcapNetworkInterface pcapNetworkInterface = allDevs.get(i);
+                StringBuilder deviceName = new StringBuilder((pcapNetworkInterface.getDescription() != null) ? pcapNetworkInterface.getDescription() : pcapNetworkInterface.getName());
+                deviceName.append(" (");
+                for (PcapAddress address : pcapNetworkInterface.getAddresses()) {
+                    if(address instanceof PcapIpV4Address) {
+                        deviceName.append(address.getAddress().toString()).append("/").append(address.getNetmask().toString()).append(", ");
+                    }
+                }
+                String name = deviceName.toString();
+                name = name.substring(0, name.length() - 2) + ((name.endsWith(", ")) ? ")": "");
+                deviceList[i] = new Tuple2<>(pcapNetworkInterface.getName(), name);
+            }
+        } catch (PcapNativeException e) {
+            logger.error("Error getting the list of installed network devices");
+        }
+
         SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID, "BACnet/IP", "")
             .iconUrl("bacnetip.png")
             .category(AdapterType.Manufacturing)
+            .requiredAlternatives(Labels.from("source", "Source", "Select the source, where the data is read from"),
+                Alternatives.from(Labels.from("device", "Network", "Capture data via network device"),
+                    StaticProperties.group(Labels.withId("device-group"),
+                        StaticProperties.singleValueSelection(Labels.from("network-device", "Network Device", "Network device used for capturing"),
+                            Options.from(deviceList)))),
+                Alternatives.from(Labels.from("file", "File", "Capture data from a PCAP network recording"),
+                    StaticProperties.group(Labels.withId("file-group"),
+                        new FileStaticProperty(fileLabel.getInternalId(), fileLabel.getLabel(), fileLabel.getDescription()))))
             .build();
         description.setAppId(ID);
         return description;
@@ -153,7 +188,7 @@ public class BacNetIpAdapter extends SpecificDataStreamAdapter {
         try {
             connection = new PassiveBacNetIpPlcConnection(new PcapChannelFactory(
                 //new File("/Users/christofer.dutz/Projects/Apache/PLC4X-Documents/BacNET/Captures/Merck/BACnetWhoIsRouterToNetwork.pcapng"), null,
-                new File("/Users/christofer.dutz/Downloads/20190906_udp.pcapng"), null,
+                new File("/Users/christofer.dutz/Projects/Apache/PLC4X-Documents/BacNET/Captures/Merck/BACnet.pcapng"), null,
                 PassiveBacNetIpDriver.BACNET_IP_PORT, PcapSocketAddress.ALL_PROTOCOLS,
                 PcapSocketChannelConfig.SPEED_REALTIME, new UdpIpPacketHandler()), "",
                 new PlcMessageToMessageCodec<BVLC, PlcRequestContainer>() {