This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 921cf3c - Removed the ElasticSearch example - Moved the hello-influx
example from the sandbox into the official examples
921cf3c is described below
commit 921cf3cde0151cf662c5dff6b00c238882697622
Author: cdutz <[email protected]>
AuthorDate: Tue May 25 11:50:40 2021 +0200
- Removed the ElasticSearch example
- Moved the hello-influx example from the sandbox into the official examples
---
.../hello-influx-data-collection/README.adoc | 0
.../example.properties | 0
.../examples}/hello-influx-data-collection/pom.xml | 26 +-
.../java/examples/helloinflux/HelloInflux.java | 0
.../src/main/resources/logback.xml | 0
.../hello-storage-elasticsearch/README.adoc | 66 -----
plc4j/examples/hello-storage-elasticsearch/pom.xml | 168 -------------
.../examples/storage/elasticsearch/CliOptions.java | 82 -------
.../elasticsearch/ElasticsearchStorage.java | 270 ---------------------
.../src/main/resources/log4j2.xml | 35 ---
.../src/main/resources/logback.xml | 40 ---
plc4j/examples/pom.xml | 2 +-
sandbox/pom.xml | 3 -
13 files changed, 4 insertions(+), 688 deletions(-)
diff --git a/sandbox/hello-influx-data-collection/README.adoc
b/plc4j/examples/hello-influx-data-collection/README.adoc
similarity index 100%
rename from sandbox/hello-influx-data-collection/README.adoc
rename to plc4j/examples/hello-influx-data-collection/README.adoc
diff --git a/sandbox/hello-influx-data-collection/example.properties
b/plc4j/examples/hello-influx-data-collection/example.properties
similarity index 100%
rename from sandbox/hello-influx-data-collection/example.properties
rename to plc4j/examples/hello-influx-data-collection/example.properties
diff --git a/sandbox/hello-influx-data-collection/pom.xml
b/plc4j/examples/hello-influx-data-collection/pom.xml
similarity index 80%
rename from sandbox/hello-influx-data-collection/pom.xml
rename to plc4j/examples/hello-influx-data-collection/pom.xml
index 7a7459d..f7ed69e 100644
--- a/sandbox/hello-influx-data-collection/pom.xml
+++ b/plc4j/examples/hello-influx-data-collection/pom.xml
@@ -22,13 +22,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.plc4x.sandbox</groupId>
- <artifactId>plc4x-sandbox</artifactId>
+ <groupId>org.apache.plc4x.examples</groupId>
+ <artifactId>plc4j-examples</artifactId>
<version>0.9.0-SNAPSHOT</version>
</parent>
<artifactId>plc4j-hello-influx-data-collection</artifactId>
- <name>Sandbox: PLC4J: Examples: Hello InfluxDB Data Collection</name>
+ <name>PLC4J: Examples: Hello InfluxDB Data Collection</name>
<description>Data Collection with PLC4X and InfluxDB.</description>
<properties>
@@ -63,29 +63,9 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </dependency>
- <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.plc4x.sandbox</groupId>
- <artifactId>test-java-bacnetip-driver</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-transport-pcap-replay</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-transport-raw-socket</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </dependency>
</dependencies>
<build>
diff --git
a/sandbox/hello-influx-data-collection/src/main/java/org/apache/plc4x/java/examples/helloinflux/HelloInflux.java
b/plc4j/examples/hello-influx-data-collection/src/main/java/org/apache/plc4x/java/examples/helloinflux/HelloInflux.java
similarity index 100%
rename from
sandbox/hello-influx-data-collection/src/main/java/org/apache/plc4x/java/examples/helloinflux/HelloInflux.java
rename to
plc4j/examples/hello-influx-data-collection/src/main/java/org/apache/plc4x/java/examples/helloinflux/HelloInflux.java
diff --git
a/sandbox/hello-influx-data-collection/src/main/resources/logback.xml
b/plc4j/examples/hello-influx-data-collection/src/main/resources/logback.xml
similarity index 100%
rename from sandbox/hello-influx-data-collection/src/main/resources/logback.xml
rename to
plc4j/examples/hello-influx-data-collection/src/main/resources/logback.xml
diff --git a/plc4j/examples/hello-storage-elasticsearch/README.adoc
b/plc4j/examples/hello-storage-elasticsearch/README.adoc
deleted file mode 100644
index 869730f..0000000
--- a/plc4j/examples/hello-storage-elasticsearch/README.adoc
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// 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.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-== IoT Factory example
-
-In this example we will be running the full stack of tools for a rudimentary
factory dashboard.
-
-This example however is everything but production ready.
-First of all we use create an Elasticsearch single node cluster embedded
within the applications VM.
-Secondly we communicate with the `cluster` using the NodeClient, which is
super-easy to use, but shouldn't be used in production type environments.
-
-We decided to go this path because this way it's super-easy to setup
everything and running the example is nothing but starting a Java application.
-
-=== What else do I need?
-
-In General:
-- A PLC
-- A Factory
-
-Even if you might be able to get your hands on a PLC I doubt you have a spare
factory available.
-
-This example is built to visualize a virtual factory simulated with
https://factoryio.com/[Factory I/O].
-
-We have decided to stick with one of the on-board examples, to make it as easy
as possible for you to reproduce.
-The example we used is: "Sorting by Height".
-
-Here's a video demonstrating this:
-https://www.youtube.com/watch?v=B0n8gT1vto4
-
-You can run this with a real PLC or use a PLC simulator.
-In our IoT lab we are currently running this with the real S7-1200.
-
-=== What happens in detail?
-
-When the application is started it first starts up an Elasticsearch node.
-
-After that is up and running, it checks if the indexes we are going to write
to exist.
-
-If they don't and we would just have ES create them on the fly, we wouldn't be
able to use the time-data in the time fields as they would be treated as
numbers.
-
-Any non-existent indexes are created.
-
-After that an `Apache Edgent` instance is created and one stream is created to
fetch the state of all 8 outputs of the PLC every 100ms.
-
-This stream is then split up.
-
-One branch simply dumps the data into the `factory-data` index.
-
-The second branch is a little more complex as it monitors the state of the
left and right conveyors to extrapolate if a new `big` or `small box is being
transported.
-
-Only when a new box is detected an entry is written into the `product-data`
index.
-
diff --git a/plc4j/examples/hello-storage-elasticsearch/pom.xml
b/plc4j/examples/hello-storage-elasticsearch/pom.xml
deleted file mode 100644
index 9ee9db8..0000000
--- a/plc4j/examples/hello-storage-elasticsearch/pom.xml
+++ /dev/null
@@ -1,168 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<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>
- <groupId>org.apache.plc4x.examples</groupId>
- <artifactId>plc4j-examples</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>plc4j-hello-storage-elasticsearch</artifactId>
- <name>PLC4J: Examples: Storage: ElasticSearch</name>
- <description>Client application demonstrating PLC4X in our virtual IoT
Factory using ElasticSearch.</description>
-
- <properties>
-
<app.main.class>org.apache.plc4x.java.examples.storage.elasticsearch.ElasticsearchStorage</app.main.class>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-api</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-apache-edgent</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>commons-cli</groupId>
- <artifactId>commons-cli</artifactId>
- <version>1.4</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.edgent</groupId>
- <artifactId>edgent-api-function</artifactId>
- <version>1.2.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.edgent</groupId>
- <artifactId>edgent-api-topology</artifactId>
- <version>1.2.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.edgent</groupId>
- <artifactId>edgent-providers-direct</artifactId>
- <version>1.2.0</version>
- </dependency>
-
- <!-- Elasticsearch dependencies -->
- <dependency>
- <groupId>org.elasticsearch</groupId>
- <artifactId>elasticsearch</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch</groupId>
- <artifactId>elasticsearch-x-content</artifactId>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch.plugin</groupId>
- <artifactId>transport-netty4-client</artifactId>
- </dependency>
- <dependency>
- <groupId>org.locationtech.spatial4j</groupId>
- <artifactId>spatial4j</artifactId>
- <version>0.7</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <version>2.11.2</version>
- </dependency>
- </dependencies>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.elasticsearch</groupId>
- <artifactId>elasticsearch</artifactId>
- <version>${elasticsearch.version}</version>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch</groupId>
- <artifactId>elasticsearch-x-content</artifactId>
- <version>${elasticsearch.version}</version>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch.plugin</groupId>
- <artifactId>transport-netty4-client</artifactId>
- <version>${elasticsearch.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <build>
- <plugins>
- <!-- Filter out some resources -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-uber-jar</id>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <filters>
- <filter>
- <artifact>*:*</artifact>
- <excludes>
- <exclude>META-INF/*.RSA</exclude>
- <exclude>META-INF/*.SF</exclude>
- </excludes>
- </filter>
- </filters>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <configuration>
- <usedDependencies combine.children="append">
-
<usedDependency>org.apache.logging.log4j:log4j-slf4j-impl</usedDependency>
-
<usedDependency>org.locationtech.spatial4j:spatial4j</usedDependency>
- </usedDependencies>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
\ No newline at end of file
diff --git
a/plc4j/examples/hello-storage-elasticsearch/src/main/java/org/apache/plc4x/java/examples/storage/elasticsearch/CliOptions.java
b/plc4j/examples/hello-storage-elasticsearch/src/main/java/org/apache/plc4x/java/examples/storage/elasticsearch/CliOptions.java
deleted file mode 100644
index 77b3107..0000000
---
a/plc4j/examples/hello-storage-elasticsearch/src/main/java/org/apache/plc4x/java/examples/storage/elasticsearch/CliOptions.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- 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. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-package org.apache.plc4x.java.examples.storage.elasticsearch;
-
-
-import org.apache.commons.cli.*;
-
-public class CliOptions {
-
- private static Options options;
-
- private final String plc4xConnectionString;
- private final String plc4xFieldAddress;
-
- public static CliOptions fromArgs(String[] args) {
- options = new Options();
- // Required arguments
- options.addOption(
- Option.builder()
- .type(String.class)
- .longOpt("plc4x-connection-string")
- .hasArg()
- .desc("Connection String")
- .build());
- options.addOption(
- Option.builder()
- .type(String.class)
- .longOpt("plc4x-field-address")
- .hasArg()
- .desc("Field Address")
- .build());
-
- CommandLineParser parser = new DefaultParser();
- CommandLine commandLine;
- try {
- commandLine = parser.parse(options, args);
-
- String plc4xConnectionString =
commandLine.getOptionValue("plc4x-connection-string");
- String plc4xFieldAddress =
commandLine.getOptionValue("plc4x-field-address");
-
- return new CliOptions(plc4xConnectionString, plc4xFieldAddress);
- } catch (ParseException e) {
- System.err.println(e.getMessage());
- return null;
- }
- }
-
- public static void printHelp() {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("S7PlcToElasticSearchSample", options);
- }
-
- public CliOptions(String plc4xConnectionString, String plc4xFieldAddress) {
- this.plc4xConnectionString = plc4xConnectionString != null ?
plc4xConnectionString : "s7://10.10.64.20/1/1";
- this.plc4xFieldAddress = plc4xFieldAddress != null ? plc4xFieldAddress
: "%Q0:BYTE";
- }
-
- public String getPlc4xConnectionString() {
- return plc4xConnectionString;
- }
-
- public String getPlc4xFieldAddress() {
- return plc4xFieldAddress;
- }
-}
\ No newline at end of file
diff --git
a/plc4j/examples/hello-storage-elasticsearch/src/main/java/org/apache/plc4x/java/examples/storage/elasticsearch/ElasticsearchStorage.java
b/plc4j/examples/hello-storage-elasticsearch/src/main/java/org/apache/plc4x/java/examples/storage/elasticsearch/ElasticsearchStorage.java
deleted file mode 100644
index f258aa1..0000000
---
a/plc4j/examples/hello-storage-elasticsearch/src/main/java/org/apache/plc4x/java/examples/storage/elasticsearch/ElasticsearchStorage.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- 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. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-package org.apache.plc4x.java.examples.storage.elasticsearch;
-
-import org.apache.edgent.function.Supplier;
-import org.apache.edgent.providers.direct.DirectProvider;
-import org.apache.edgent.topology.TStream;
-import org.apache.edgent.topology.Topology;
-import org.apache.plc4x.edgent.PlcConnectionAdapter;
-import org.apache.plc4x.edgent.PlcFunctions;
-import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
-import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
-import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
-import
org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
-import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.client.IndicesAdminClient;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
-import org.elasticsearch.node.InternalSettingsPreparer;
-import org.elasticsearch.node.Node;
-import org.elasticsearch.node.NodeValidationException;
-import org.elasticsearch.plugins.Plugin;
-import org.elasticsearch.transport.Netty4Plugin;
-
-import java.io.IOException;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-public class ElasticsearchStorage {
- private static CliOptions options;
-
- public enum ConveyorState {
- STOPPED,
- RUNNING_LEFT,
- RUNNING_RIGHT
- }
-
- private static class IotElasticsearchFactoryException extends
RuntimeException {
- private IotElasticsearchFactoryException(String message) {
- super(message);
- }
- private IotElasticsearchFactoryException(String message, Throwable
cause) {
- super(message, cause);
- }
- }
-
- private static class MyNode extends Node {
- private MyNode(Settings preparedSettings, Collection<Class<? extends
Plugin>> classpathPlugins) {
- super(InternalSettingsPreparer.prepareEnvironment(
- preparedSettings, Collections.emptyMap(), null, () ->
"hello-es"), classpathPlugins, true);
- }
- }
-
- private ConveyorState conveyorState = ConveyorState.STOPPED;
-
- private Node startElasticsearchNode() {
- try {
- Node node = new MyNode(Settings.builder()
- .put("transport.type", "netty4")
- .put("http.type", "netty4")
- .put("http.cors.enabled", "true")
- .put("path.home", "elasticsearch-data")
- .put("network.host", "0.0.0.0")
- .build(), Collections.singletonList(Netty4Plugin.class));
- node.start();
- return node;
- } catch (NodeValidationException e) {
- throw new IotElasticsearchFactoryException("Could not start
Elasticsearch node.", e);
- }
- }
-
- private void prepareIndexes(Client esClient) {
- IndicesAdminClient indicesAdminClient = esClient.admin().indices();
-
- // Check if the factory-data index exists and create it, if it doesn't.
- IndicesExistsRequest factoryDataIndexExistsRequest =
- indicesAdminClient.prepareExists("iot-factory-data").request();
-
if(!indicesAdminClient.exists(factoryDataIndexExistsRequest).actionGet().isExists())
{
- CreateIndexRequest createIndexRequest = new
CreateIndexRequest("iot-factory-data");
- createIndexRequest.mapping("FactoryData",
- "{\n" +
- " \"properties\": {\n" +
- " \"time\": {\n" +
- " \"type\": \"date\"\n" +
- " }\n" +
- " }\n" +
- " }", XContentType.JSON);
- CreateIndexResponse createIndexResponse =
indicesAdminClient.create(createIndexRequest).actionGet();
- if(!createIndexResponse.isAcknowledged()) {
- throw new IotElasticsearchFactoryException("Could not create
index 'iot-factory-data'");
- }
- }
-
- // Check if the product-data index exists and create it, if it doesn't.
- IndicesExistsRequest productDataIndexExistsRequest =
- indicesAdminClient.prepareExists("iot-product-data").request();
-
if(!indicesAdminClient.exists(productDataIndexExistsRequest).actionGet().isExists())
{
- CreateIndexRequest createIndexRequest = new
CreateIndexRequest("iot-product-data");
- createIndexRequest.mapping("ProductData",
- "{\n" +
- " \"properties\": {\n" +
- " \"time\": {\n" +
- " \"type\": \"date\"\n" +
- " },\n" +
- " \"type\": {\n" +
- " \"type\": \"keyword\"\n" +
- " }\n" +
- " }\n" +
- " }", XContentType.JSON);
- CreateIndexResponse createIndexResponse =
indicesAdminClient.create(createIndexRequest).actionGet();
- if(!createIndexResponse.isAcknowledged()) {
- throw new IotElasticsearchFactoryException("Could not create
index 'iot-product-data'");
- }
- }
- }
-
- private void runFactory() {
- // Start an Elasticsearch node.
- Node esNode = startElasticsearchNode();
- Client esClient = esNode.client();
- // Register a shutdown hook.
- final Thread mainThread = Thread.currentThread();
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- try {
- esNode.close();
- mainThread.join();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new PlcRuntimeException("Error closing ES Node", e);
- } catch (IOException e) {
- throw new PlcRuntimeException("Error closing ES Node", e);
- }
- }));
- System.out.println("Started Elasticsearch node on port 9200");
-
- // Make sure the indexes exist prior to writing to them.
- prepareIndexes(esClient);
-
- // Get a plc connection.
- try (PlcConnectionAdapter plcAdapter = new
PlcConnectionAdapter(options.getPlc4xConnectionString())) {
- // Initialize the Edgent core.
- DirectProvider dp = new DirectProvider();
- Topology top = dp.newTopology();
-
- // Define the event stream.
- // 1) PLC4X source generating a stream of bytes.
- Supplier<List<Boolean>> plcSupplier =
PlcFunctions.booleanListSupplier(plcAdapter,
- options.getPlc4xFieldAddress());
- // 2) Use polling to get an item from the byte-stream in regular
intervals.
- TStream<List<Boolean>> plcOutputStates = top.poll(plcSupplier,
100, TimeUnit.MILLISECONDS);
-
- // 3a) Create a stream that pumps all data into a 'factory-data'
index.
- TStream<XContentBuilder> factoryData =
plcOutputStates.map(this::translatePlcInput);
- TStream<IndexResponse> factoryDataResponses = factoryData.map(
- value -> esClient.prepareIndex("iot-factory-data",
"FactoryData").setSource(value).get());
- factoryDataResponses.print();
-
- // 3b) Create a stream that does some local analysis to detect big
and small boxes and to only output
- // something to the 'product-data' index, if a new item is
detected.
- TStream<XContentBuilder> productData =
plcOutputStates.map(this::handlePlcInput);
- TStream<IndexResponse> productDataResponses = productData.map(
- value -> esClient.prepareIndex("iot-product-data",
"ProductData").setSource(value).get());
- productDataResponses.print();
-
- // Submit the topology and hereby start the event streams.
- dp.submit(top);
- } catch (Exception e) {
- throw new IotElasticsearchFactoryException("Error while connecting
or disconnecting from the PLC.", e);
- }
- }
-
- private XContentBuilder translatePlcInput(List<Boolean> input) {
- boolean conveyorEntry = input.get(0);
- boolean load = input.get(1);
- boolean unload = input.get(2);
- boolean transferLeft = input.get(3);
- boolean transferRight = input.get(4);
- boolean conveyorLeft = input.get(5);
- boolean conveyorRight = input.get(6);
-
- try(XContentBuilder builder = XContentFactory.jsonBuilder()
- .startObject()
- .field("time", Calendar.getInstance().getTimeInMillis())
- .field("conveyorEntry", conveyorEntry)
- .field("load", load)
- .field( "unload", unload)
- .field( "transferLeft", transferLeft)
- .field( "transferRight", transferRight)
- .field( "conveyorLeft", conveyorLeft)
- .field( "conveyorRight", conveyorRight)
- .endObject()) {
- return builder;
- } catch (IOException e) {
- throw new IotElasticsearchFactoryException("Error building JSON
message.", e);
- }
- }
-
- private XContentBuilder handlePlcInput(List<Boolean> input) {
- boolean transferLeft = input.get(3);
- boolean transferRight = input.get(4);
-
- if (conveyorState == ConveyorState.STOPPED) {
- if (transferLeft) {
- conveyorState = ConveyorState.RUNNING_LEFT;
- try (XContentBuilder builder = XContentFactory.jsonBuilder()
- .startObject()
- .field("time", Calendar.getInstance().getTimeInMillis())
- .field("type", "small")
- .endObject()) {
- return builder;
- } catch (IOException e) {
- throw new IotElasticsearchFactoryException("Error building
JSON message.", e);
- }
- } else if (transferRight){
- conveyorState = ConveyorState.RUNNING_RIGHT;
- try (XContentBuilder builder = XContentFactory.jsonBuilder()
- .startObject()
- .field("time", Calendar.getInstance().getTimeInMillis())
- .field("type", "large")
- .endObject()) {
- return builder;
- } catch (IOException e) {
- throw new IotElasticsearchFactoryException("Error building
JSON message.", e);
- }
- }
- } else if (!(transferLeft || transferRight)) {
- conveyorState = ConveyorState.STOPPED;
- }
- return null;
- }
-
- public static void main(String[] args) {
- options = CliOptions.fromArgs(args);
- if (options == null) {
- CliOptions.printHelp();
- // Could not parse.
- System.exit(1);
- }
-
- System.out.println("Connecting to " +
options.getPlc4xConnectionString()+ " with field address " +
- options.getPlc4xFieldAddress());
-
- ElasticsearchStorage factory = new ElasticsearchStorage();
- factory.runFactory();
- }
-
-}
diff --git
a/plc4j/examples/hello-storage-elasticsearch/src/main/resources/log4j2.xml
b/plc4j/examples/hello-storage-elasticsearch/src/main/resources/log4j2.xml
deleted file mode 100644
index d82c7c3..0000000
--- a/plc4j/examples/hello-storage-elasticsearch/src/main/resources/log4j2.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<Configuration package="log4j.test"
- status="WARN">
- <Appenders>
- <Console name="Console" target="SYSTEM_OUT">
- <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
%msg%n"/>
- </Console>
- </Appenders>
- <Loggers>
- <Logger name="io.netty.util.ResourceLeakDetector" level="fatal">
- <AppenderRef ref="Console"/>
- </Logger>
- <Root level="info">
- <AppenderRef ref="Console"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
diff --git
a/plc4j/examples/hello-storage-elasticsearch/src/main/resources/logback.xml
b/plc4j/examples/hello-storage-elasticsearch/src/main/resources/logback.xml
deleted file mode 100644
index 71652b3..0000000
--- a/plc4j/examples/hello-storage-elasticsearch/src/main/resources/logback.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<configuration xmlns="http://ch.qos.logback/xml/ns/logback"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback
https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd">
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <!-- encoders are assigned the type
- ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n</pattern>
- </encoder>
- </appender>
-
- <logger level="OFF" name="io.netty.util" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
- <root level="warn">
- <appender-ref ref="STDOUT" />
- </root>
-
-</configuration>
\ No newline at end of file
diff --git a/plc4j/examples/pom.xml b/plc4j/examples/pom.xml
index 2d34598..5a974cb 100644
--- a/plc4j/examples/pom.xml
+++ b/plc4j/examples/pom.xml
@@ -44,10 +44,10 @@
<module>hello-cloud-google</module>
<module>hello-connectivity-kafka</module>
<module>hello-connectivity-mqtt</module>
+ <module>hello-influx-data-collection</module>
<module>hello-integration-edgent</module>
<module>hello-integration-iotdb</module>
<module>hello-opm</module>
- <module>hello-storage-elasticsearch</module>
<module>hello-webapp</module>
<module>hello-webservice</module>
<module>hello-world-plc4x</module>
diff --git a/sandbox/pom.xml b/sandbox/pom.xml
index 56cefb7..d8de46e 100644
--- a/sandbox/pom.xml
+++ b/sandbox/pom.xml
@@ -41,9 +41,6 @@
<module>test-java-bacnetip-driver</module>
<module>test-java-df1-driver</module>
-
- <!-- Examples -->
- <module>hello-influx-data-collection</module>
</modules>
<build>