You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dj...@apache.org on 2016/04/04 17:14:33 UTC
[5/6] incubator-quarks git commit: Add Iotf scenario sample
Add Iotf scenario sample
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/911870c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/911870c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/911870c2
Branch: refs/heads/master
Commit: 911870c2801249f038eefda76e4bd0526bc20e2d
Parents: f9170f9
Author: Dan Debrunner <dj...@debrunners.com>
Authored: Sat Apr 2 10:05:56 2016 -0700
Committer: Dan Debrunner <dj...@debrunners.com>
Committed: Sat Apr 2 10:05:56 2016 -0700
----------------------------------------------------------------------
build.xml | 1 +
samples/.classpath | 3 +
.../samples/connectors/iotf/IotfSensors.java | 21 ++++--
samples/scenarios/build.xml | 43 ++++++++++++
.../scenarios/iotf/IotfFullScenario.java | 74 ++++++++++++++++++++
5 files changed, 138 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/911870c2/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index ad95287..480b526 100644
--- a/build.xml
+++ b/build.xml
@@ -142,6 +142,7 @@
<ant dir="samples/topology" target="@{target}" useNativeBasedir="true"/>
<ant dir="samples/connectors" target="@{target}" useNativeBasedir="true"/>
<ant dir="samples/console" target="@{target}" useNativeBasedir="true" />
+ <ant dir="samples/scenarios" target="@{target}" useNativeBasedir="true" />
<ant dir="android/topology" target="@{target}" useNativeBasedir="true" />
<ant dir="android/hardware" target="@{target}" useNativeBasedir="true" />
<ant dir="test/fvtiot" target="@{target}" useNativeBasedir="true" />
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/911870c2/samples/.classpath
----------------------------------------------------------------------
diff --git a/samples/.classpath b/samples/.classpath
index 9fb15d8..cc18a78 100644
--- a/samples/.classpath
+++ b/samples/.classpath
@@ -3,6 +3,7 @@
<classpathentry kind="src" path="apps/src/main/java"/>
<classpathentry kind="src" path="connectors/src/main/java"/>
<classpathentry kind="src" path="console/src/main/java"/>
+ <classpathentry kind="src" path="scenarios/src/main/java"/>
<classpathentry kind="src" path="topology/src/main/java"/>
<classpathentry kind="src" path="utils/src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
@@ -16,5 +17,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/runtime"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/provider_iot"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/apps"/>
<classpathentry kind="output" path="bin"/>
</classpath>
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/911870c2/samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java b/samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java
index d4d15fe..7feb291 100644
--- a/samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java
+++ b/samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java
@@ -54,6 +54,17 @@ import quarks.topology.TStream;
*/
public class IotfSensors {
+ /**
+ * Run the IotfSensors application.
+ *
+ * Takes a single argument that is the path to the
+ * device configuration file containing the connection
+ * authentication information.
+ *
+ * @param args Must contain the path to the device configuration file.
+ *
+ * @see IotfDevice#IotfDevice(quarks.topology.Topology, File)
+ */
public static void main(String[] args) {
String deviceCfg = args[0];
@@ -72,8 +83,7 @@ public class IotfSensors {
// Subscribe to commands of id "display" for this
// device and print them to standard out
- TStream<String> statusMsgs = displayMessages(device);
- statusMsgs.print();
+ displayMessages(device, true);
tp.submit(topology);
}
@@ -142,7 +152,7 @@ public class IotfSensors {
*
* @see IotDevice#commands(String...)
*/
- public static TStream<String> displayMessages(IotDevice device) {
+ public static TStream<String> displayMessages(IotDevice device, boolean print) {
// Subscribe to commands of id "status" for this device
TStream<JsonObject> statusMsgs = device.commands("display");
@@ -151,6 +161,9 @@ public class IotfSensors {
// payload.msg - Status message (this is specific to this application)
// Map to a String object containing the message
- return statusMsgs.map(j -> j.getAsJsonObject("payload").getAsJsonPrimitive("msg").getAsString());
+ TStream<String> messages = statusMsgs.map(j -> j.getAsJsonObject("payload").getAsJsonPrimitive("msg").getAsString());
+ if (print)
+ messages.print();
+ return messages;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/911870c2/samples/scenarios/build.xml
----------------------------------------------------------------------
diff --git a/samples/scenarios/build.xml b/samples/scenarios/build.xml
new file mode 100644
index 0000000..429288a
--- /dev/null
+++ b/samples/scenarios/build.xml
@@ -0,0 +1,43 @@
+<!--
+ 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 name="quarks.samples.scenarios" default="all" xmlns:jacoco="antlib:org.jacoco.ant">
+ <description>
+ Build scenario applications.
+ </description>
+
+ <property name="component.path" value="samples"/>
+ <import file="../../common-build.xml"/>
+
+ <path id="compile.classpath">
+ <path refid="quarks.samples.classpath"/>
+ <pathelement location="${quarks.samples}/lib/quarks.samples.connectors.jar"/>
+ <pathelement location="${quarks.lib}/quarks.providers.iot.jar"/>
+ <pathelement location="${quarks.connectors}/iotf/lib/quarks.connectors.iotf.jar"/>
+ </path>
+
+ <path id="test.compile.classpath">
+ <pathelement location="${jar}" />
+ <path refid="compile.classpath"/>
+ </path>
+
+ <path id="test.classpath">
+ <pathelement location="${test.classes}" />
+ <path refid="test.compile.classpath"/>
+ <path refid="test.common.classpath" />
+ </path>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/911870c2/samples/scenarios/src/main/java/quarks/samples/scenarios/iotf/IotfFullScenario.java
----------------------------------------------------------------------
diff --git a/samples/scenarios/src/main/java/quarks/samples/scenarios/iotf/IotfFullScenario.java b/samples/scenarios/src/main/java/quarks/samples/scenarios/iotf/IotfFullScenario.java
new file mode 100644
index 0000000..5944b16
--- /dev/null
+++ b/samples/scenarios/src/main/java/quarks/samples/scenarios/iotf/IotfFullScenario.java
@@ -0,0 +1,74 @@
+package quarks.samples.scenarios.iotf;
+
+
+import java.io.File;
+
+import quarks.connectors.iotf.IotfDevice;
+import quarks.providers.iot.IotProvider;
+import quarks.samples.connectors.iotf.IotfSensors;
+
+/**
+ * Sample IotProvider scenario using IBM Watson IoT Platform.
+ * <BR>
+ * IotProvider with three registered applications that
+ * are not started but can be started by a a remote
+ * application sending device commands through
+ * IBM Watson IoT Platform.
+ * <P>
+ * This is equivalent to the {@link IotfSensors} application
+ * but executing as three separate applications using
+ * {@link IotProvider} rather than the lower level
+ * {@link quarks.providers.direct.DirectProvider}.
+ *
+ * </P>
+ *
+ * @see quarks.topology.mbeans.ApplicationServiceMXBean
+ * @see quarks.topology.mbeans
+ */
+public class IotfFullScenario {
+
+ /**
+ * Run the IotfFullScenario application.
+ *
+ * Takes a single argument that is the path to the
+ * device configuration file containing the connection
+ * authentication information.
+ *
+ * @param args Must contain the path to the device configuration file.
+ *
+ * @see IotfDevice#IotfDevice(quarks.topology.Topology, File)
+ */
+ public static void main(String[] args) throws Exception {
+ String deviceCfg = args[0];
+
+ // Create an IotProvider that will use
+ // an IotfDevice as the connectivity to
+ // the IBM Watson IoT Platform message hub.
+ IotProvider provider = new IotProvider(
+ topology -> new IotfDevice(topology, new File(deviceCfg)));
+
+ // Register three applications
+ registerHeartbeat(provider);
+ registerSensors(provider);
+ registerDisplay(provider);
+
+ // Start this provider
+ // the two applications will not start
+ provider.start();
+ }
+
+ public static void registerHeartbeat(IotProvider provider) {
+ provider.registerTopology("Heartbeat",
+ (iotDevice,config) -> IotfSensors.heartBeat(iotDevice, true));
+ }
+
+ public static void registerSensors(IotProvider provider) {
+ provider.registerTopology("Sensors",
+ (iotDevice,config) -> IotfSensors.simulatedSensors(iotDevice, true));
+ }
+ public static void registerDisplay(IotProvider provider) {
+ provider.registerTopology("Display",
+ (iotDevice,config) -> IotfSensors.displayMessages(iotDevice, true));
+ }
+
+}
\ No newline at end of file