You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iota.apache.org by to...@apache.org on 2016/07/13 05:03:53 UTC
incubator-iota git commit: Refactored Stream and Sensor Components to
take scalastyle into account and other minor improvements,
added basic documentation to Stream
Repository: incubator-iota
Updated Branches:
refs/heads/master c079ff9fa -> c22715c6b
Refactored Stream and Sensor Components to take scalastyle into account and other minor improvements, added basic documentation to Stream
Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/c22715c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/c22715c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/c22715c6
Branch: refs/heads/master
Commit: c22715c6b04bfa7f93241b4a3fb49b973b409da0
Parents: c079ff9
Author: tonyfaustini <to...@yahoo.com>
Authored: Tue Jul 12 22:03:46 2016 -0700
Committer: tonyfaustini <to...@yahoo.com>
Committed: Tue Jul 12 22:03:46 2016 -0700
----------------------------------------------------------------------
fey-examples/active-jar-repo/fey-stream.jar | Bin 30284 -> 30288 bytes
.../active-jar-repo/fey-virtual-sensor.jar | Bin 2140028 -> 2139819 bytes
fey-examples/active-jar-repo/fey-zmq.jar | Bin 267986 -> 267986 bytes
fey-examples/active-json-repo/temperature.json | 28 +++++++++
fey-examples/active-json-repo/timestamp.json | 27 --------
fey-examples/fey-json-samples/temperature.json | 28 ---------
fey-examples/fey-json-samples/timestamp.json | 27 ++++++++
performers/stream/README.md | 50 +++++++++++++--
.../apache/iota/fey/performer/Heartbeat.scala | 45 +++++++-------
.../iota/fey/performer/RandomDouble.scala | 32 +++++-----
.../iota/fey/performer/RandomInteger.scala | 31 +++++-----
.../org/apache/iota/fey/performer/Sensor.scala | 62 +++++++++----------
12 files changed, 182 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/active-jar-repo/fey-stream.jar
----------------------------------------------------------------------
diff --git a/fey-examples/active-jar-repo/fey-stream.jar b/fey-examples/active-jar-repo/fey-stream.jar
index 1d57ec8..309d1ec 100644
Binary files a/fey-examples/active-jar-repo/fey-stream.jar and b/fey-examples/active-jar-repo/fey-stream.jar differ
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/active-jar-repo/fey-virtual-sensor.jar
----------------------------------------------------------------------
diff --git a/fey-examples/active-jar-repo/fey-virtual-sensor.jar b/fey-examples/active-jar-repo/fey-virtual-sensor.jar
index 3cc9c2b..ea89c5c 100644
Binary files a/fey-examples/active-jar-repo/fey-virtual-sensor.jar and b/fey-examples/active-jar-repo/fey-virtual-sensor.jar differ
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/active-jar-repo/fey-zmq.jar
----------------------------------------------------------------------
diff --git a/fey-examples/active-jar-repo/fey-zmq.jar b/fey-examples/active-jar-repo/fey-zmq.jar
index 074db1d..0d23bb2 100644
Binary files a/fey-examples/active-jar-repo/fey-zmq.jar and b/fey-examples/active-jar-repo/fey-zmq.jar differ
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/active-json-repo/temperature.json
----------------------------------------------------------------------
diff --git a/fey-examples/active-json-repo/temperature.json b/fey-examples/active-json-repo/temperature.json
new file mode 100644
index 0000000..74c6e40
--- /dev/null
+++ b/fey-examples/active-json-repo/temperature.json
@@ -0,0 +1,28 @@
+{
+ "guid": "Orch1",
+ "command": "CREATE",
+ "timestamp": "591997890",
+ "name": "DESCRIPTION",
+ "ensembles": [
+ {
+ "guid": "En1",
+ "command": "NONE",
+ "performers": [
+ {
+ "guid": "S1",
+ "schedule": 5000,
+ "backoff": 0,
+ "source": {
+ "name": "fey-virtual-sensor.jar",
+ "classPath": "org.apache.iota.fey.performer.Sensor",
+ "parameters": {
+ "exceptions": "[ {\"start_time\":[9,28,30],\"end_time\":[9,29,0],\"expected_value\":900}, {\"start_time\":[11,0,0],\"end_time\":[11,21,3],\"expected_value\":99.0} ]"
+ }
+ }
+ }
+ ],
+ "connections": [
+ ]
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/active-json-repo/timestamp.json
----------------------------------------------------------------------
diff --git a/fey-examples/active-json-repo/timestamp.json b/fey-examples/active-json-repo/timestamp.json
deleted file mode 100644
index a62f8b6..0000000
--- a/fey-examples/active-json-repo/timestamp.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "guid": "Orch2",
- "command": "CREATE",
- "timestamp": "591997890",
- "name": "DESCRIPTION",
- "ensembles": [
- {
- "guid": "En2",
- "command": "NONE",
- "performers": [
- {
- "guid": "S2",
- "schedule": 1000,
- "backoff": 0,
- "source": {
- "name": "fey-stream.jar",
- "classPath": "org.apache.iota.fey.performer.RandomUUID",
- "parameters": {
- }
- }
- }
- ],
- "connections": [
- ]
- }
- ]
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/fey-json-samples/temperature.json
----------------------------------------------------------------------
diff --git a/fey-examples/fey-json-samples/temperature.json b/fey-examples/fey-json-samples/temperature.json
deleted file mode 100644
index 00db835..0000000
--- a/fey-examples/fey-json-samples/temperature.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "guid": "Orch1",
- "command": "CREATE",
- "timestamp": "591997890",
- "name": "DESCRIPTION",
- "ensembles": [
- {
- "guid": "En1",
- "command": "NONE",
- "performers": [
- {
- "guid": "S1",
- "schedule": 5000,
- "backoff": 0,
- "source": {
- "name": "fey-virtual-sensors.jar",
- "classPath": "org.apache.iota.fey.performer.Sensor",
- "parameters": {
- "exceptions": "[ {\"start_time\":[9,28,30],\"end_time\":[9,29,0],\"expected_value\":900}, {\"start_time\":[11,0,0],\"end_time\":[11,21,3],\"expected_value\":99.0} ]"
- }
- }
- }
- ],
- "connections": [
- ]
- }
- ]
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/fey-examples/fey-json-samples/timestamp.json
----------------------------------------------------------------------
diff --git a/fey-examples/fey-json-samples/timestamp.json b/fey-examples/fey-json-samples/timestamp.json
new file mode 100644
index 0000000..36a82a8
--- /dev/null
+++ b/fey-examples/fey-json-samples/timestamp.json
@@ -0,0 +1,27 @@
+{
+ "guid": "Orch2",
+ "command": "CREATE",
+ "timestamp": "591997890",
+ "name": "DESCRIPTION",
+ "ensembles": [
+ {
+ "guid": "En2",
+ "command": "NONE",
+ "performers": [
+ {
+ "guid": "S2",
+ "schedule": 1000,
+ "backoff": 0,
+ "source": {
+ "name": "fey-stream.jar",
+ "classPath": "org.apache.iota.fey.performer.Timestamp",
+ "parameters": {
+ }
+ }
+ }
+ ],
+ "connections": [
+ ]
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/performers/stream/README.md
----------------------------------------------------------------------
diff --git a/performers/stream/README.md b/performers/stream/README.md
index 7443f83..1014370 100644
--- a/performers/stream/README.md
+++ b/performers/stream/README.md
@@ -1,11 +1,49 @@
# STREAM
-The Purpose of the stream performer is to create a stream of output messages including
+The Purpose of the stream performer is to create a stream of output messages.
+Each instance of a performer will generate a stream from one of the following types
## Types of stream
-1. **Heartbeat**
-2. **Timestamp**
-3. **RandomInteger**
-4. **RandomFloat**
-5. **RandomUUID**
+1. **Heartbeat** outputs the string "alive"
+2. **Timestamp** outputs an epoch timestamp in milliseconds e.g. 1468378490974
+3. **RandomInteger** outputs a random integer e.g. -1146318359
+4. **RandomDouble** outputs a random double e.g. 0.6905682320596791
+5. **RandomUUID** outputs a random UUID e.g. 2905d0ce-fe0f-46b5-b94e-77e38ccff789
+
+## Example Orchestration
+
+Note this Performer requires you to set a "schedule". In the example below we
+that the schedule is set to 1000 milliseconds (1 second). if you don't set the schedule the
+performer will not send any output message. In this example you might want to set the
+log-level=debug in your configuration file so you can see the messages that are being generated.
+
+```json
+{
+ "guid": "Orchestration",
+ "command": "CREATE",
+ "timestamp": "591997890",
+ "name": "DESCRIPTION",
+ "ensembles": [
+ {
+ "guid": "Ensemble",
+ "command": "NONE",
+ "performers": [
+ {
+ "guid": "Timestamp",
+ "schedule": 1000,
+ "backoff": 0,
+ "source": {
+ "name": "fey-stream.jar",
+ "classPath": "org.apache.iota.fey.performer.Timestamp",
+ "parameters": {
+ }
+ }
+ }
+ ],
+ "connections": [
+ ]
+ }
+ ]
+}
+```
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/performers/stream/src/main/scala/org/apache/iota/fey/performer/Heartbeat.scala
----------------------------------------------------------------------
diff --git a/performers/stream/src/main/scala/org/apache/iota/fey/performer/Heartbeat.scala b/performers/stream/src/main/scala/org/apache/iota/fey/performer/Heartbeat.scala
index 73dd4f8..cf2e87d 100644
--- a/performers/stream/src/main/scala/org/apache/iota/fey/performer/Heartbeat.scala
+++ b/performers/stream/src/main/scala/org/apache/iota/fey/performer/Heartbeat.scala
@@ -1,19 +1,18 @@
-/*
- * 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.
- */
+
+// 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.
+// ee the License for the specific language governing permissions and
+// limitations under the License.
package org.apache.iota.fey.performer
@@ -31,26 +30,26 @@ class Heartbeat(override val params: Map[String, String] = Map.empty,
override val orchestrationID: String = "",
override val autoScale: Boolean = false) extends FeyGenericActor {
- override def onStart = {
+ override def onStart : Unit = {
}
- override def onStop = {
+ override def onStop : Unit= {
}
- override def onRestart(reason: Throwable) = {
+ override def onRestart(reason: Throwable) : Unit = {
// Called after actor is up and running - after self restart
}
override def customReceive: Receive = {
- case x => log.info(s"Untreated $x")
+ case x => log.debug(s"Untreated $x")
}
override def processMessage[T](message: T, sender: ActorRef): Unit = {
}
- override def execute() = {
- log.debug("Alive")
- propagateMessage("Alive")
+ override def execute() : Unit = {
+ log.debug("alive")
+ propagateMessage("alive")
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomDouble.scala
----------------------------------------------------------------------
diff --git a/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomDouble.scala b/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomDouble.scala
index d0efb5e..5f04791 100644
--- a/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomDouble.scala
+++ b/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomDouble.scala
@@ -1,19 +1,19 @@
-/*
- * 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.
- */
+
+// 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.
+// ee the License for the specific language governing permissions and
+// limitations under the License.
+
package org.apache.iota.fey.performer
import akka.actor.ActorRef
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomInteger.scala
----------------------------------------------------------------------
diff --git a/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomInteger.scala b/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomInteger.scala
index 72de479..a694111 100644
--- a/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomInteger.scala
+++ b/performers/stream/src/main/scala/org/apache/iota/fey/performer/RandomInteger.scala
@@ -1,19 +1,18 @@
-/*
- * 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.
- */
+
+// 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.
+// ee the License for the specific language governing permissions and
+// limitations under the License.
package org.apache.iota.fey.performer
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c22715c6/performers/virtual_sensor/src/main/scala/org/apache/iota/fey/performer/Sensor.scala
----------------------------------------------------------------------
diff --git a/performers/virtual_sensor/src/main/scala/org/apache/iota/fey/performer/Sensor.scala b/performers/virtual_sensor/src/main/scala/org/apache/iota/fey/performer/Sensor.scala
index 01ffb71..c80669c 100644
--- a/performers/virtual_sensor/src/main/scala/org/apache/iota/fey/performer/Sensor.scala
+++ b/performers/virtual_sensor/src/main/scala/org/apache/iota/fey/performer/Sensor.scala
@@ -1,19 +1,18 @@
-/*
- * 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.
- */
+
+// 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.
+// ee the License for the specific language governing permissions and
+// limitations under the License.
package org.apache.iota.fey.performer
@@ -26,6 +25,7 @@ import org.apache.commons.math3.distribution.NormalDistribution
import org.joda.time.DateTime
import play.api.libs.json.{JsObject, JsValue, Json}
+
class Sensor(override val params: Map[String, String] = Map.empty,
override val backoff: FiniteDuration = 1.minutes,
override val connectTo: Map[String, ActorRef] = Map.empty,
@@ -39,7 +39,7 @@ class Sensor(override val params: Map[String, String] = Map.empty,
var expected_value: Double = 70.0
var sigma: Double = 1.0
var exceptions: JsValue = null
- var value: NormalDistribution = null
+ var output: NormalDistribution = null
var sensor_type = "environmental"
// wav vibration
var vib = ""
@@ -49,9 +49,9 @@ class Sensor(override val params: Map[String, String] = Map.empty,
var normal_sound = ""
var exception_sound = ""
- override def onStart = {
+ override def onStart : Unit = {
- _params_check()
+ paramsCheck()
if (sensor_type == "vibration") {
normal_vib = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/vibration"))
@@ -69,10 +69,10 @@ class Sensor(override val params: Map[String, String] = Map.empty,
}
}
- override def onStop = {
+ override def onStop : Unit = {
}
- override def onRestart(reason: Throwable) = {
+ override def onRestart(reason: Throwable) : Unit = {
// Called after actor is up and running - after self restart
}
@@ -83,19 +83,19 @@ class Sensor(override val params: Map[String, String] = Map.empty,
override def processMessage[T](message: T, sender: ActorRef): Unit = {
}
- override def execute() = {
+ override def execute() : Unit = {
val ts = java.lang.System.currentTimeMillis().toString
var out = ""
if (!isException) {
- value = new NormalDistribution(expected_value, sigma)
+ output = new NormalDistribution(expected_value, sigma)
sound = normal_sound
vib = normal_vib
}
sensor_type match {
- case "environmental" => out = "DATA|cloud|" + lrn + "|" + ts + "|{\"x\":\"" + value.sample() + "\"}"
- case "vibration" => out = "DATA|cloud|" + lrn + "|" + ts + "|{\"blob\":\"" + vib + "\"}"
- case "wav" => out = "DATA|cloud|" + lrn + "|" + ts + "|{\"wav\":\"" + sound + "\"}"
+ case "environmental" => out = s"""$lrn|$ts|{"x":${output.sample()}}"""
+ case "vibration" => out = s"""$lrn|$ts|{"blob":$vib}"""
+ case "wav" => out = s"""$lrn|$ts|{"wav":$sound}"""
}
log.debug(out)
propagateMessage(out)
@@ -120,9 +120,9 @@ class Sensor(override val params: Map[String, String] = Map.empty,
sound = exception_sound
} else {
ev = (x \ "expected_value").as[Double]
- value = new NormalDistribution(ev, sigma)
+ output = new NormalDistribution(ev, sigma)
}
- return true
+ true
}
} catch {
case e: Exception => log.error(s"Bad exception specified $x")
@@ -133,7 +133,7 @@ class Sensor(override val params: Map[String, String] = Map.empty,
false
}
- def _params_check() = {
+ def paramsCheck() : Unit = {
if (params.contains("lrn")) {
lrn = params("lrn")
}
@@ -160,9 +160,7 @@ class Sensor(override val params: Map[String, String] = Map.empty,
if (params.contains("sensor_type")) {
sensor_type = params("sensor_type")
sensor_type match {
- case "wav" =>
- case "vibration" =>
- case "environmental" =>
+ case "wav" | "vibration" | "environmental" =>
case default => log.error(s"""Only "vibration", "wav", and "environmental" are permitted you have $sensor_type""")
sensor_type = "environmental"
}