You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2017/11/02 03:22:00 UTC

[49/50] [abbrv] incubator-edgent git commit: getting started updates

getting started updates

- fix mvnw in samples/template
- add TempSensorSample

Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/e9c75964
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/e9c75964
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/e9c75964

Branch: refs/heads/develop
Commit: e9c75964598397db70bfee86fb73f8d6e9abc9c1
Parents: 709fb97
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Wed Nov 1 15:04:29 2017 -0400
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Wed Nov 1 15:04:29 2017 -0400

----------------------------------------------------------------------
 samples/README.md                               |   6 +-
 .../.mvn/wrapper/MavenWrapperDownloader.java    | 110 +++++++++++++++++++
 .../.mvn/wrapper/maven-wrapper.properties       |  20 ++++
 samples/template/README.md                      |   2 +-
 samples/template/app-run.sh                     |  15 ++-
 samples/topology/run-sample.sh                  |   1 +
 .../edgent/samples/topology/TempSensor.java     |  44 ++++++++
 .../samples/topology/TempSensorApplication.java |  44 ++++++++
 8 files changed, 239 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/README.md
----------------------------------------------------------------------
diff --git a/samples/README.md b/samples/README.md
index 09079d4..6bd26ed 100644
--- a/samples/README.md
+++ b/samples/README.md
@@ -172,7 +172,11 @@ Eclipse in the usual manner. E.g.,
 <pre>
 HelloEdgent          Basic mechanics of declaring a topology and executing
                      it. Prints Hello Edgent! to standard output.
-
+        
+TempSensorApplication A basic Edgent application used by the Edgent
+                     "Getting Started Guide":
+                     https://edgent.apache.org/docs/edgent-getting-started.html
+                     
 PeriodicSource       Create a stream by polling a random number generator
                      for a new value every second and then prints out the
                      raw tuple value and a filtered and transformed stream.

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/template/.mvn/wrapper/MavenWrapperDownloader.java
----------------------------------------------------------------------
diff --git a/samples/template/.mvn/wrapper/MavenWrapperDownloader.java b/samples/template/.mvn/wrapper/MavenWrapperDownloader.java
new file mode 100644
index 0000000..44f8e00
--- /dev/null
+++ b/samples/template/.mvn/wrapper/MavenWrapperDownloader.java
@@ -0,0 +1,110 @@
+/*
+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.
+*/
+
+import java.net.*;
+import java.io.*;
+import java.nio.channels.*;
+import java.util.Properties;
+
+public class MavenWrapperDownloader {
+
+    /**
+     * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
+     */
+    private static final String DEFAULT_DOWNLOAD_URL =
+            "https://repo1.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar";
+
+    /**
+     * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
+     * use instead of the default one.
+     */
+    private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
+            ".mvn/wrapper/maven-wrapper.properties";
+
+    /**
+     * Path where the maven-wrapper.jar will be saved to.
+     */
+    private static final String MAVEN_WRAPPER_JAR_PATH =
+            ".mvn/wrapper/maven-wrapper.jar";
+
+    /**
+     * Name of the property which should be used to override the default download url for the wrapper.
+     */
+    private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
+
+    public static void main(String args[]) {
+        System.out.println("- Downloader started");
+        File baseDirectory = new File(args[0]);
+        System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
+
+        // If the maven-wrapper.properties exists, read it and check if it contains a custom
+        // wrapperUrl parameter.
+        File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
+        String url = DEFAULT_DOWNLOAD_URL;
+        if(mavenWrapperPropertyFile.exists()) {
+            FileInputStream mavenWrapperPropertyFileInputStream = null;
+            try {
+                mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
+                Properties mavenWrapperProperties = new Properties();
+                mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
+                url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
+            } catch (IOException e) {
+                System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
+            } finally {
+                try {
+                    if(mavenWrapperPropertyFileInputStream != null) {
+                        mavenWrapperPropertyFileInputStream.close();
+                    }
+                } catch (IOException e) {
+                    // Ignore ...
+                }
+            }
+        }
+        System.out.println("- Downloading from: : " + url);
+
+        File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
+        if(!outputFile.getParentFile().exists()) {
+            if(!outputFile.getParentFile().mkdirs()) {
+                System.out.println(
+                        "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
+            }
+        }
+        System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
+        try {
+            downloadFileFromURL(url, outputFile);
+            System.out.println("Done");
+            System.exit(0);
+        } catch (Throwable e) {
+            System.out.println("- Error downloading");
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
+
+    private static void downloadFileFromURL(String urlString, File destination) throws Exception {
+        URL website = new URL(urlString);
+        ReadableByteChannel rbc;
+        rbc = Channels.newChannel(website.openStream());
+        FileOutputStream fos = new FileOutputStream(destination);
+        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+        fos.close();
+        rbc.close();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/template/.mvn/wrapper/maven-wrapper.properties
----------------------------------------------------------------------
diff --git a/samples/template/.mvn/wrapper/maven-wrapper.properties b/samples/template/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 0000000..7e8f382
--- /dev/null
+++ b/samples/template/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,20 @@
+# 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.
+
+distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
+
+#wrapperUrl=https://repo1.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/template/README.md
----------------------------------------------------------------------
diff --git a/samples/template/README.md b/samples/template/README.md
index a0763fd..365dc46 100644
--- a/samples/template/README.md
+++ b/samples/template/README.md
@@ -1,6 +1,6 @@
 An Edgent Application template project.
 
-Clone this template project to start your Edgent application project.
+Clone this template project folder to create your Edgent application project.
 
 The project's pom supports
 

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/template/app-run.sh
----------------------------------------------------------------------
diff --git a/samples/template/app-run.sh b/samples/template/app-run.sh
index 996bfbb..8437275 100755
--- a/samples/template/app-run.sh
+++ b/samples/template/app-run.sh
@@ -20,10 +20,23 @@ APP_DIR=.
 
 UBER_JAR=`echo ${APP_DIR}/target/*-uber.jar`
 
+FQ_MAIN_CLASS=com.mycompany.app.TemplateApp
+
+USAGE="usage: [--main <main-class>] [<args...>]"
+
+if [ "$1" = "--main" ]; then
+  shift;
+  if [ $# = 0 ]; then
+    echo ${USAGE}
+    exit 1;
+  fi 
+  FQ_MAIN_CLASS=$1; shift
+fi
+
 # Runs the application
 #
 # ./app-run.sh
 
 export CLASSPATH=${UBER_JAR}
 
-java com.mycompany.app.TemplateApp "$*"
+java ${FQ_MAIN_CLASS} "$*"

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/topology/run-sample.sh
----------------------------------------------------------------------
diff --git a/samples/topology/run-sample.sh b/samples/topology/run-sample.sh
index 1614a7d..d6fa8af 100755
--- a/samples/topology/run-sample.sh
+++ b/samples/topology/run-sample.sh
@@ -36,6 +36,7 @@ ${SAMPLE_PACKAGE_BASE}.PeriodicSource
 ${SAMPLE_PACKAGE_BASE}.SensorsAggregates
 ${SAMPLE_PACKAGE_BASE}.SimpleFilterTransform
 ${SAMPLE_PACKAGE_BASE}.SplitWithEnumSample
+${SAMPLE_PACKAGE_BASE}.TempSensorApplication
 ${SAMPLE_PACKAGE_BASE}.TerminateAfterNTuples
 EOF
 `

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensor.java
----------------------------------------------------------------------
diff --git a/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensor.java b/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensor.java
new file mode 100644
index 0000000..d9b8a40
--- /dev/null
+++ b/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensor.java
@@ -0,0 +1,44 @@
+/*
+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.edgent.samples.topology;
+
+import java.util.Random;
+
+import org.apache.edgent.function.Supplier;
+
+/**
+ * Every time get() is called, TempSensor generates a temperature reading.
+ */
+public class TempSensor implements Supplier<Double> {
+    double currentTemp = 65.0;
+    Random rand;
+
+    TempSensor(){
+        rand = new Random();
+    }
+
+    @Override
+    public Double get() {
+        // Change the current temperature some random amount
+        double newTemp = rand.nextGaussian() + currentTemp;
+        currentTemp = newTemp;
+        return currentTemp;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e9c75964/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensorApplication.java
----------------------------------------------------------------------
diff --git a/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensorApplication.java b/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensorApplication.java
new file mode 100644
index 0000000..b1aba6b
--- /dev/null
+++ b/samples/topology/src/main/java/org/apache/edgent/samples/topology/TempSensorApplication.java
@@ -0,0 +1,44 @@
+/*
+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.edgent.samples.topology;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.edgent.providers.direct.DirectProvider;
+import org.apache.edgent.topology.TStream;
+import org.apache.edgent.topology.Topology;
+
+/*
+ * A basic application used in the Edgent "Getting Started Guide":
+ * https://edgent.apache.org/docs/edgent-getting-started.html
+ */
+public class TempSensorApplication {
+    public static void main(String[] args) throws Exception {
+        TempSensor sensor = new TempSensor();
+        DirectProvider dp = new DirectProvider();
+        Topology topology = dp.newTopology();
+
+        TStream<Double> tempReadings = topology.poll(sensor, 1, TimeUnit.MILLISECONDS);
+        TStream<Double> filteredReadings = tempReadings.filter(reading -> reading < 50 || reading > 80);
+        filteredReadings.print();
+
+        dp.submit(topology);
+    }
+}