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 2017/01/31 22:29:04 UTC

[01/12] incubator-iota git commit: Merge branch 'trivial' of https://github.com/shiv4nsh/incubator-iota

Repository: incubator-iota
Updated Branches:
  refs/heads/master 4775f9905 -> 49138d689


Merge branch 'trivial' of https://github.com/shiv4nsh/incubator-iota


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

Branch: refs/heads/master
Commit: d6c98cfde59a0cdbd6ce88f3eb71aed6b7d8d107
Parents: 9c41fb0 1d93185
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Nov 14 11:02:59 2016 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Nov 14 11:02:59 2016 -0800

----------------------------------------------------------------------
 Readme.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------



[07/12] incubator-iota git commit: [IOTA-36] - First version of global performers. In this version, global performers can not connect to any other performer.

Posted by to...@apache.org.
[IOTA-36] - First version of global performers. In this version, global performers can not connect to any other performer.


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

Branch: refs/heads/master
Commit: 580e30103d72d2448426a120eb6a39b544661e68
Parents: 7aae205
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Jan 30 16:03:39 2017 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Jan 30 16:03:39 2017 -0800

----------------------------------------------------------------------
 .../resources/fey-json-schema-validator.json    |  95 ++++++++++
 .../scala/org/apache/iota/fey/Ensemble.scala    |  25 ++-
 .../scala/org/apache/iota/fey/FeyCore.scala     |  34 ++--
 .../org/apache/iota/fey/GlobalPerformer.scala   | 186 +++++++++++++++++++
 .../org/apache/iota/fey/Orchestration.scala     |  53 +++++-
 .../main/scala/org/apache/iota/fey/Utils.scala  |   3 +
 6 files changed, 372 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/580e3010/fey-core/src/main/resources/fey-json-schema-validator.json
----------------------------------------------------------------------
diff --git a/fey-core/src/main/resources/fey-json-schema-validator.json b/fey-core/src/main/resources/fey-json-schema-validator.json
index 79952dd..a86c09f 100644
--- a/fey-core/src/main/resources/fey-json-schema-validator.json
+++ b/fey-core/src/main/resources/fey-json-schema-validator.json
@@ -13,6 +13,101 @@
   "name":{
     "type":"string"
   },
+  "global-performers":{
+    "type":"array",
+    "items": {
+      "guid": {
+        "type": "string"
+      },
+      "controlAware": {
+        "type": "boolean"
+      },
+      "dispatcher": {
+        "type": "string"
+      },
+      "autoScale": {
+        "type": "object",
+        "lowerBound": {
+          "type": "integer",
+          "minimum": 1
+        },
+        "upperBound": {
+          "type": "integer",
+          "minimum": 1
+        },
+        "backoffThreshold": {
+          "type": "number",
+          "minimum": 0.0
+        },
+        "roundRobin": {
+          "type": "boolean"
+        },
+        "required": [
+          "lowerBound",
+          "upperBound"
+        ]
+      },
+      "schedule": {
+        "type": "integer",
+        "minimum": 0
+      },
+      "backoff": {
+        "type": "integer",
+        "minimum": 0
+      },
+      "source": {
+        "type": "object",
+        "name": {
+          "type": "string",
+          "pattern": "\\w+(\\.jar)"
+        },
+        "location": {
+          "type": "object",
+          "url": {
+            "type": "string",
+            "pattern": "(?i)(^(http|https|file)):\/\/"
+          },
+          "credentials": {
+            "user": {
+              "type": "string"
+            },
+            "password": {
+              "type": "string"
+            },
+            "required": [
+              "user",
+              "password"
+            ]
+          },
+          "required": [
+            "url"
+          ]
+        },
+        "classPath": {
+          "type": "string",
+          "pattern": "\\w+"
+        },
+        "parameters": {
+          "patternProperties": {
+            ".*": {
+              "type": "string"
+            }
+          }
+        },
+        "required": [
+          "name",
+          "classPath",
+          "parameters"
+        ]
+      },
+      "required":[
+        "guid",
+        "schedule",
+        "backoff",
+        "source"
+      ]
+    }
+  },
   "ensembles":{
     "type":"array",
     "items":{

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/580e3010/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
index 4db5f98..15b6ead 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
@@ -162,7 +162,16 @@ protected class Ensemble(val orchestrationID: String,
     * @return (performerID, ActorRef of the performer)
     */
   private def createFeyActor(performerID: String, connectionIDs: Array[String], tmpActors:HashMap[String, ActorRef]):(String, ActorRef) = {
-    if(!tmpActors.contains(performerID)){
+    // Performer is a global performer and is already created
+    if(GlobalPerformer.activeGlobalPerformers.contains(orchestrationID)
+      && GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.contains(performerID)){
+      (performerID, GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.get(performerID).get)
+    }
+      // performer was already created
+    else if(tmpActors.contains(performerID)){
+      (performerID, tmpActors.get(performerID).get)
+    }
+    else{
       val performerInfo = performers_metadata.get(performerID)
       if (performerInfo.isDefined) {
         val connections: Map[String, ActorRef] = connectionIDs.map(connID => {
@@ -178,12 +187,12 @@ protected class Ensemble(val orchestrationID: String,
 
           val strategy =
             if(performerInfo.get.isRoundRobin) {
-               log.info(s"Using Round Robin for performer ${performerID}")
-               RoundRobinPool(1, Some(resizer))
-             } else {
-               log.info(s"Using Smallest mailbox for performer ${performerID}")
-               SmallestMailboxPool(1, Some(resizer))
-             }
+              log.info(s"Using Round Robin for performer ${performerID}")
+              RoundRobinPool(1, Some(resizer))
+            } else {
+              log.info(s"Using Smallest mailbox for performer ${performerID}")
+              SmallestMailboxPool(1, Some(resizer))
+            }
 
           actor = context.actorOf(strategy.props(actorProps), name = performerID)
 
@@ -197,8 +206,6 @@ protected class Ensemble(val orchestrationID: String,
       }else{
         throw new IllegalPerformerCreation(s"Performer $performerID is not defined in the JSON")
       }
-    }else{
-      (performerID, tmpActors.get(performerID).get)
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/580e3010/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
index 9c2b61d..99dc7c4 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
@@ -24,7 +24,7 @@ import akka.actor.{Actor, ActorLogging, ActorRef, OneForOneStrategy, PoisonPill,
 import akka.routing.GetRoutees
 import com.eclipsesource.schema._
 import org.apache.iota.fey.JSON_PATH._
-import org.apache.iota.fey.Orchestration.{CREATE_ENSEMBLES, DELETE_ENSEMBLES, UPDATE_ENSEMBLES}
+import org.apache.iota.fey.Orchestration.{CREATE_ENSEMBLES, CREATE_GLOBAL_PERFORMERS_AND_ENSEMBLES, DELETE_ENSEMBLES, UPDATE_ENSEMBLES}
 import org.apache.iota.fey.Utils._
 import play.api.libs.json._
 
@@ -101,6 +101,7 @@ protected class FeyCore extends Actor with ActorLogging{
     log.info(s"TERMINATED ${actorRef.path.name}")
     FEY_CACHE.activeOrchestrations.remove(actorRef.path.name)
     ORCHESTRATION_CACHE.orchestration_metadata.remove(actorRef.path.name)
+    ORCHESTRATION_CACHE.orchestration_globals.remove(actorRef.path.name)
     if(!FEY_CACHE.orchestrationsAwaitingTermination.isEmpty) {
       checkForOrchestrationWaitingForTermination(actorRef.path.name)
     }
@@ -155,10 +156,12 @@ protected class FeyCore extends Actor with ActorLogging{
     val orchestrationCommand = (orchestrationJSON \ COMMAND).as[String].toUpperCase()
     val orchestrationTimestamp = (orchestrationJSON \ ORCHESTRATION_TIMESTAMP).as[String]
     val ensembles = (orchestrationJSON \ ENSEMBLES).as[List[JsObject]]
+    val globalPerformers = (orchestrationJSON \ GLOBAL_PERFORMERS).asOpt[List[JsObject]]
+
     orchestrationCommand match {
-      case "RECREATE" => recreateOrchestration(ensembles, orchestrationID, orchestrationName, orchestrationTimestamp)
-      case "CREATE" => createOrchestration(ensembles, orchestrationID, orchestrationName, orchestrationTimestamp)
-      case "UPDATE" => updateOrchestration(ensembles, orchestrationID, orchestrationName, orchestrationTimestamp)
+      case "RECREATE" => recreateOrchestration(ensembles, orchestrationID, orchestrationName, orchestrationTimestamp, globalPerformers)
+      case "CREATE" => createOrchestration(ensembles, orchestrationID, orchestrationName, orchestrationTimestamp, globalPerformers)
+      case "UPDATE" => updateOrchestration(ensembles, orchestrationID, orchestrationName, orchestrationTimestamp, globalPerformers)
       case "DELETE" => deleteOrchestration(orchestrationID,true)
       case x => throw new CommandNotRecognized(s"Command: $x")
     }
@@ -177,13 +180,13 @@ protected class FeyCore extends Actor with ActorLogging{
     * @return
     */
   private def recreateOrchestration(ensemblesSpecJson: List[JsObject], orchestrationID: String,
-                              orchestrationName: String, orchestrationTimestamp: String) = {
+                              orchestrationName: String, orchestrationTimestamp: String, globalPerformers:Option[List[JsObject]]) = {
     FEY_CACHE.activeOrchestrations.get(orchestrationID) match {
       case Some(orchestration) =>
         try{
           // If timestamp is greater than the last timestamp
           if(orchestration._1 != orchestrationTimestamp){
-            val orchestrationInfo = new OrchestrationInformation(ensemblesSpecJson,orchestrationID,orchestrationName,orchestrationTimestamp)
+            val orchestrationInfo = new OrchestrationInformation(ensemblesSpecJson,orchestrationID,orchestrationName,orchestrationTimestamp, globalPerformers)
             FEY_CACHE.orchestrationsAwaitingTermination.put(orchestrationID, orchestrationInfo)
             deleteOrchestration(orchestrationID, true)
           }else{
@@ -192,7 +195,7 @@ protected class FeyCore extends Actor with ActorLogging{
         }catch{
           case e: Exception =>
         }
-      case None => createOrchestration(ensemblesSpecJson,orchestrationID,orchestrationName,orchestrationTimestamp)
+      case None => createOrchestration(ensemblesSpecJson,orchestrationID,orchestrationName,orchestrationTimestamp, globalPerformers)
     }
   }
 
@@ -206,7 +209,7 @@ protected class FeyCore extends Actor with ActorLogging{
       case Some(orchestrationAwaiting) =>
         FEY_CACHE.orchestrationsAwaitingTermination.remove(terminatedOrchestrationName)
         createOrchestration(orchestrationAwaiting.ensembleSpecJson, orchestrationAwaiting.orchestrationID,
-          orchestrationAwaiting.orchestrationName, orchestrationAwaiting.orchestrationTimestamp)
+          orchestrationAwaiting.orchestrationName, orchestrationAwaiting.orchestrationTimestamp, orchestrationAwaiting.globalPerformers)
       case None =>
     }
   }
@@ -222,7 +225,7 @@ protected class FeyCore extends Actor with ActorLogging{
     * @param orchestrationTimestamp
     */
   private def createOrchestration(ensemblesSpecJson: List[JsObject], orchestrationID: String,
-                            orchestrationName: String, orchestrationTimestamp: String) = {
+                            orchestrationName: String, orchestrationTimestamp: String, globalPerformers:Option[List[JsObject]]) = {
     try{
       if(!FEY_CACHE.activeOrchestrations.contains(orchestrationID)) {
         val orchestration = context.actorOf(
@@ -230,7 +233,13 @@ protected class FeyCore extends Actor with ActorLogging{
           name = orchestrationID)
         FEY_CACHE.activeOrchestrations.put(orchestrationID, (orchestrationTimestamp, orchestration))
         context.watch(orchestration)
-        orchestration ! CREATE_ENSEMBLES(ensemblesSpecJson)
+
+        if(globalPerformers.isDefined && globalPerformers.get.size > 0){
+          orchestration ! CREATE_GLOBAL_PERFORMERS_AND_ENSEMBLES(globalPerformers.get, ensemblesSpecJson)
+        }else {
+          orchestration ! CREATE_ENSEMBLES(ensemblesSpecJson)
+        }
+
       }else{
         log.error(s"Orchestration $orchestrationID is already defined in the network.")
       }
@@ -270,8 +279,9 @@ protected class FeyCore extends Actor with ActorLogging{
     }
   }
 
+  // TODO: Check out how to manage global performers for updating
   private def updateOrchestration(ensemblesSpecJson: List[JsObject], orchestrationID: String,
-                            orchestrationName: String, orchestrationTimestamp: String) = {
+                            orchestrationName: String, orchestrationTimestamp: String, globalPerformers:Option[List[JsObject]]) = {
     FEY_CACHE.activeOrchestrations.get(orchestrationID) match {
       case None => log.warning(s"Orchestration not update. No active Orchestration $orchestrationID.")
       case Some(orchestration) => {
@@ -368,4 +378,4 @@ private object FEY_CACHE{
 }
 
 sealed case class OrchestrationInformation(ensembleSpecJson: List[JsObject], orchestrationID: String,
-                                     orchestrationName: String, orchestrationTimestamp: String)
+                                     orchestrationName: String, orchestrationTimestamp: String, globalPerformers:Option[List[JsObject]])

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/580e3010/fey-core/src/main/scala/org/apache/iota/fey/GlobalPerformer.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/GlobalPerformer.scala b/fey-core/src/main/scala/org/apache/iota/fey/GlobalPerformer.scala
new file mode 100644
index 0000000..e343f2e
--- /dev/null
+++ b/fey-core/src/main/scala/org/apache/iota/fey/GlobalPerformer.scala
@@ -0,0 +1,186 @@
+/*
+ * 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.iota.fey
+
+import akka.actor.SupervisorStrategy.Restart
+import akka.actor.{Actor, ActorLogging, ActorRef, OneForOneStrategy, Props, Terminated}
+import akka.routing._
+import play.api.libs.json.JsObject
+
+import scala.collection.mutable.HashMap
+import scala.concurrent.duration._
+
+protected class GlobalPerformer(val orchestrationID: String,
+                                val orchestrationName: String,
+                                val globalPerformers: List[JsObject],
+                                val ensemblesSpec :  List[JsObject]) extends Actor with ActorLogging{
+
+  val monitoring_actor = FEY_MONITOR.actorRef
+  var global_metadata: Map[String, Performer] = Map.empty[String, Performer]
+  var global_performer: Map[String,ActorRef] = Map.empty[String,ActorRef]
+
+  override def receive: Receive = {
+
+    case GlobalPerformer.PRINT_GLOBAL =>
+      context.actorSelection(s"*") ! FeyGenericActor.PRINT_PATH
+
+    case Terminated(actor) =>
+      monitoring_actor  ! Monitor.TERMINATE(actor.path.toString, Utils.getTimestamp)
+      log.error(s"DEAD Global Performers ${actor.path.name}")
+      context.children.foreach{ child =>
+        context.unwatch(child)
+        context.stop(child)
+      }
+      throw new RestartGlobalPerformers(s"DEAD Global Performer ${actor.path.name}")
+
+    case GetRoutees => //Discard
+
+    case x => log.warning(s"Message $x not treated by Global Performers")
+  }
+
+  /**
+    * If any of the global performer dies, it tries to restart it.
+    * If we could not be restarted, then the terminated message will be received
+    * and Global Performer is going to throw an Exception to its orchestration
+    * asking it to Restart all the entire orchestration. The restart will then stop all of its
+    * children when call the preStart.
+    */
+  override val supervisorStrategy =
+  OneForOneStrategy(maxNrOfRetries = 3, withinTimeRange = 1 minute) {
+    case e: Exception => Restart
+  }
+
+  /**
+    * Uses the json spec to create the performers
+    */
+  override def preStart() : Unit = {
+
+    monitoring_actor ! Monitor.START(Utils.getTimestamp)
+
+    global_metadata = Ensemble.extractPerformers(globalPerformers)
+
+    createGlobalPerformers()
+
+  }
+
+  override def postStop() : Unit = {
+    monitoring_actor  ! Monitor.STOP(Utils.getTimestamp)
+  }
+
+  override def postRestart(reason: Throwable): Unit = {
+    monitoring_actor  ! Monitor.RESTART(reason, Utils.getTimestamp)
+    preStart()
+  }
+
+  private def createGlobalPerformers() = {
+    try {
+      global_metadata.foreach((global_performer) => {
+        createFeyActor(global_performer._1, global_performer._2)
+      })
+      context.parent ! Orchestration.CREATE_ENSEMBLES(ensemblesSpec)
+    } catch {
+      /* if the creation fails, it will stop the orchestration */
+      case e: Exception =>
+        log.error(e,"During Global Manager creation")
+        throw new RestartGlobalPerformers("Could not create global performer")
+    }
+  }
+
+  private def createFeyActor(performerID: String, performerInfo: Performer) = {
+    val actor: ActorRef = {
+      val actorProps = getPerformer(performerInfo)
+      if (performerInfo.autoScale) {
+
+        val resizer = DefaultResizer(lowerBound = performerInfo.lowerBound, upperBound = performerInfo.upperBound,
+          messagesPerResize = CONFIG.MESSAGES_PER_RESIZE, backoffThreshold = performerInfo.backoffThreshold, backoffRate = 0.1)
+
+        val strategy =
+          if (performerInfo.isRoundRobin) {
+            log.info(s"Using Round Robin for performer ${performerID}")
+            RoundRobinPool(1, Some(resizer))
+          } else {
+            log.info(s"Using Smallest mailbox for performer ${performerID}")
+            SmallestMailboxPool(1, Some(resizer))
+          }
+
+        context.actorOf(strategy.props(actorProps), name = performerID)
+      } else {
+        context.actorOf(actorProps, name = performerID)
+      }
+    }
+
+    context.watch(actor)
+    GlobalPerformer.activeGlobalPerformers.get(orchestrationID) match {
+      case Some(globals) => GlobalPerformer.activeGlobalPerformers.put(orchestrationID, (globals ++ Map(performerID -> actor)))
+      case None => GlobalPerformer.activeGlobalPerformers.put(orchestrationID, Map(performerID -> actor))
+    }
+  }
+
+  /**
+    * Creates actor props based on JSON configuration
+    *
+    * @param performerInfo Performer object
+    * @return Props of actor based on JSON config
+    */
+  private def getPerformer(performerInfo: Performer): Props = {
+
+    val clazz = loadClazzFromJar(performerInfo.classPath, s"${performerInfo.jarLocation}/${performerInfo.jarName}", performerInfo.jarName)
+
+    val dispatcher = if(performerInfo.dispatcher != "") s"fey-custom-dispatchers.${performerInfo.dispatcher}" else ""
+
+    val actorProps = Props(clazz,
+      performerInfo.parameters, performerInfo.backoff, Map.empty, performerInfo.schedule, orchestrationName, orchestrationID, performerInfo.autoScale)
+
+    // dispatcher has higher priority than controlAware. That means that if both are defined
+    // then the custom dispatcher will be used
+    if(dispatcher != ""){
+      log.info(s"Using dispatcher: $dispatcher")
+      actorProps.withDispatcher(dispatcher)
+    }
+    else if(performerInfo.controlAware){
+      actorProps.withDispatcher(CONFIG.CONTROL_AWARE_MAILBOX)
+    }else{
+      actorProps
+    }
+  }
+
+  /**
+    * Load a clazz instance of FeyGenericActor from a jar
+    *
+    * @param classPath class path
+    * @param jarLocation Full path where to load the jar from
+    * @return clazz instance of FeyGenericActor
+    */
+  private def loadClazzFromJar(classPath: String, jarLocation: String, jarName: String):Class[FeyGenericActor] = {
+    try {
+      Utils.loadActorClassFromJar(jarLocation,classPath,jarName)
+    }catch {
+      case e: Exception =>
+        log.error(e,s"Could not load class $classPath from jar $jarLocation. Please, check the Jar repository path as well the jar name")
+        throw e
+    }
+  }
+
+}
+
+object GlobalPerformer{
+
+  val activeGlobalPerformers:HashMap[String, Map[String, ActorRef]] = HashMap.empty[String, Map[String, ActorRef]]
+
+  case object PRINT_GLOBAL
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/580e3010/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
index 1e47a80..0b9152b 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
@@ -44,6 +44,7 @@ protected class Orchestration(val name: String,
     case CREATE_ENSEMBLES(ensemblesJsonSpec) => createEnsembles(ensemblesJsonSpec)
     case DELETE_ENSEMBLES(ensemblesJsonSpec) => deleteEnsembles(ensemblesJsonSpec)
     case UPDATE_ENSEMBLES(ensemblesJsonSpec) => updateEnsembles(ensemblesJsonSpec)
+    case CREATE_GLOBAL_PERFORMERS_AND_ENSEMBLES(globalSpec, ensembleSpec) => createGlobalsAndEnsembles(globalSpec, ensembleSpec)
 
     case PRINT_PATH =>
       log.info(s"** ${self.path} **")
@@ -64,6 +65,7 @@ protected class Orchestration(val name: String,
 
   override val supervisorStrategy =
     OneForOneStrategy(maxNrOfRetries = 3, withinTimeRange = 1 minute) {
+      case e: RestartGlobalPerformers => akka.actor.SupervisorStrategy.Escalate
       case e: RestartEnsemble => Restart
       case e: Exception => Restart
     }
@@ -103,9 +105,18 @@ protected class Orchestration(val name: String,
     */
   private def replayOrchestrationState() = {
     val ensemblesSpec = ORCHESTRATION_CACHE.orchestration_metadata.get(guid).get.map(_._2).toList
-    ORCHESTRATION_CACHE.orchestration_metadata.remove(guid)
-    ORCHESTRATION_CACHE.orchestration_name.remove(guid)
-    self ! CREATE_ENSEMBLES(ensemblesSpec)
+    val global = ORCHESTRATION_CACHE.orchestration_globals.get(guid)
+    if(global.isDefined){
+      val globalSpec = global.get.map(_._2).toList
+      ORCHESTRATION_CACHE.orchestration_metadata.remove(guid)
+      ORCHESTRATION_CACHE.orchestration_name.remove(guid)
+      ORCHESTRATION_CACHE.orchestration_globals.remove(guid)
+      self ! CREATE_GLOBAL_PERFORMERS_AND_ENSEMBLES(globalSpec, ensemblesSpec)
+    }else{
+      ORCHESTRATION_CACHE.orchestration_metadata.remove(guid)
+      ORCHESTRATION_CACHE.orchestration_name.remove(guid)
+      self ! CREATE_ENSEMBLES(ensemblesSpec)
+    }
   }
 
   /**
@@ -168,6 +179,40 @@ protected class Orchestration(val name: String,
     * @param ensemblesJsonSpec
     * @return
     */
+  private def createGlobalsAndEnsembles(globalSpec: List[JsObject], ensemblesJsonSpec: List[JsObject]) = {
+    log.info(s"Creating global performers: ${globalSpec}")
+    try{
+      // Actor will send message to orchestration to create ensembles once global performers are created
+      val global_manager = context.actorOf(Props(classOf[GlobalPerformer], guid, name, globalSpec, ensemblesJsonSpec), name = "GLOBAL_MANAGER")
+      context.watch(global_manager)
+    }catch{
+      case e: Exception =>
+        log.error(s"Could not create Global Performers manager actor for orchestration $guid")
+        throw new RestartOrchestration(s"Could not create global actors")
+    }
+
+    //Fill orchestration_globals
+    ORCHESTRATION_CACHE.orchestration_globals.get(guid) match {
+      case None =>
+        ORCHESTRATION_CACHE.orchestration_globals.put(guid, (globalSpec.map(global => {
+          val guid = (global \ GUID).as[String]
+          (guid, global)
+        }).toMap))
+      case Some(cachedGlobals) =>
+        ORCHESTRATION_CACHE.orchestration_metadata.put(guid, cachedGlobals ++ (globalSpec.map(global => {
+          val guid = (global \ GUID).as[String]
+          (guid, global)
+        }).toMap))
+    }
+  }
+
+  /**
+    * Creates Ensembles from the json specification and make it
+    * a member of the orchestration Ensembles
+    *
+    * @param ensemblesJsonSpec
+    * @return
+    */
   private def createEnsembles(ensemblesJsonSpec: List[JsObject]) = {
     log.info(s"Creating Ensembles: ${ensemblesJsonSpec}")
     val newEnsembles = ensemblesJsonSpec.map(ensembleSpec => {
@@ -236,6 +281,7 @@ protected object Orchestration{
   case class CREATE_ENSEMBLES(ensemblesJsonSpec: List[JsObject])
   case class DELETE_ENSEMBLES(ensemblesJsonSpec: List[JsObject])
   case class UPDATE_ENSEMBLES(ensemblesJsonSpec: List[JsObject])
+  case class CREATE_GLOBAL_PERFORMERS_AND_ENSEMBLES(globalPerformersSpec: List[JsObject], ensemblesJsonSpec: List[JsObject])
   case object PRINT_PATH
 }
 
@@ -249,5 +295,6 @@ protected object ORCHESTRATION_CACHE{
     * Value = Map[Ensemble GUID, JsObject of the ensemble]
     */
   val orchestration_metadata: HashMap[String, Map[String,JsObject]] = HashMap.empty[String, Map[String,JsObject]]
+  val orchestration_globals : HashMap[String, Map[String,JsObject]] = HashMap.empty[String, Map[String,JsObject]]
   val orchestration_name: HashMap[String, String] = HashMap.empty
 }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/580e3010/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
index fda1a30..3bf0eb8 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
@@ -201,6 +201,7 @@ object JSON_PATH{
   val JAR_CRED_USER = "user"
   val JAR_CRED_PASSWORD = "password"
   val PERFORMER_DISPATCHER = "dispatcher"
+  val GLOBAL_PERFORMERS = "global-performers"
 }
 
 object CONFIG{
@@ -329,3 +330,5 @@ case class IllegalPerformerCreation(message:String)  extends Exception(message)
 case class NetworkNotDefined(message:String)  extends Exception(message)
 case class CommandNotRecognized(message:String)  extends Exception(message)
 case class RestartEnsemble(message:String)  extends Exception(message)
+case class RestartGlobalPerformers(message: String) extends  Exception(message)
+case class RestartOrchestration(message: String) extends  Exception(message)
\ No newline at end of file


[10/12] incubator-iota git commit: [IOTA-36] Unit test for GlobalPerformer

Posted by to...@apache.org.
[IOTA-36] Unit test for GlobalPerformer


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

Branch: refs/heads/master
Commit: 35a83e9ae451b78331e0b10f0b5dd202514d4b42
Parents: 048934f
Author: Barbara Gomes <ba...@gmail.com>
Authored: Tue Jan 31 11:56:53 2017 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Tue Jan 31 11:56:53 2017 -0800

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/Ensemble.scala    | 17 ++--
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala | 17 ++++
 .../apache/iota/fey/GlobalPerformerSpec.scala   | 98 ++++++++++++++++++++
 3 files changed, 124 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/35a83e9a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
index 15b6ead..3f74cec 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
@@ -162,13 +162,8 @@ protected class Ensemble(val orchestrationID: String,
     * @return (performerID, ActorRef of the performer)
     */
   private def createFeyActor(performerID: String, connectionIDs: Array[String], tmpActors:HashMap[String, ActorRef]):(String, ActorRef) = {
-    // Performer is a global performer and is already created
-    if(GlobalPerformer.activeGlobalPerformers.contains(orchestrationID)
-      && GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.contains(performerID)){
-      (performerID, GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.get(performerID).get)
-    }
-      // performer was already created
-    else if(tmpActors.contains(performerID)){
+    // performer was already created
+    if(tmpActors.contains(performerID)){
       (performerID, tmpActors.get(performerID).get)
     }
     else{
@@ -204,7 +199,13 @@ protected class Ensemble(val orchestrationID: String,
         tmpActors.put(performerID, actor)
         (performerID, actor)
       }else{
-        throw new IllegalPerformerCreation(s"Performer $performerID is not defined in the JSON")
+        // Performer is a global performer and is already created
+        if(GlobalPerformer.activeGlobalPerformers.contains(orchestrationID)
+          && GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.contains(performerID)){
+          (performerID, GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.get(performerID).get)
+        }else {
+          throw new IllegalPerformerCreation(s"Performer $performerID is not defined in the JSON")
+        }
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/35a83e9a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
index 927b87a..5db4760 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -275,6 +275,23 @@ class FeyCoreSpec extends BaseAkkaSpec  {
       TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
       TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL")
     }
+    "all previous actors restarted" in {
+      val routee = """$a"""
+      val routee2 = """$b"""
+      val routee3 = """$c"""
+      val routee4 = """$d"""
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(s"${feyCoreRef.path.toString}/$global_orch_name")
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size (8)
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/GLOBAL_MANAGER")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/GLOBAL_MANAGER/GLOBAL-TEST")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee2")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee3")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee4")
+    }
   }
 
   "Stopping orchestration with global performer" should {

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/35a83e9a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
index 0acc44c..9bed93b 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
@@ -45,6 +45,9 @@ class GlobalPerformerSpec extends BaseAkkaSpec{
   var global_managerRef:TestActorRef[GlobalPerformer] = null
   var global_managerState:GlobalPerformer = null
 
+  var ensembleglobal:ActorRef = null
+  var childPerformer:ActorRef = null
+  var globalPerformer: ActorRef = null
 
   "Creating an Global Manager " should {
     "result in sending START message to Monitor actor" in {
@@ -54,5 +57,100 @@ class GlobalPerformerSpec extends BaseAkkaSpec{
       global_managerState = global_managerRef.underlyingActor
       monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
     }
+    s"result in creating an Orchestration child actor with the name '$orch_id'" in {
+      TestProbe().expectActor(s"${orchRef.path.toString}")
+    }
+    s"result in creating an Ensemble child actor with the name '${orchRef.path.toString}/ENS-GLOBAL'" in {
+      ensembleglobal = TestProbe().expectActor(s"${orchRef.path.toString}/ENS-GLOBAL")
+    }
+    s"result in creating a global Performer child actor with the name '${orchRef.path.toString}/GLOBAL_MANAGER/GLOBAL-TEST'" in {
+      globalPerformer = TestProbe().expectActor(s"${orchRef.path.toString}/$global_name/GLOBAL-TEST")
+      TestProbe().expectActor(s"${orchRef.path.toString}/$global_name")
+    }
+    s"result in creating a Performer child actor with the name '${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER'" in {
+      childPerformer = TestProbe().expectActor(s"${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER")
+    }
+    s"result in one global actor created for orchestration" in {
+      GlobalPerformer.activeGlobalPerformers should have size(1)
+      GlobalPerformer.activeGlobalPerformers should contain key(orch_id)
+    }
+    s"result in right number of running actors" in {
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size (9)
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER")
+    }
+  }
+
+  "Stopping performer inside ensemble" should {
+    "Send stop message to monitor" in {
+      EventFilter.error(pattern = s".*DEAD nPerformers.*", occurrences = 1) intercept {
+        childPerformer ! PoisonPill
+      }
+      //Restarted ensemble
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
+    }
+  }
+
+  "Stopping ensemble" should {
+    "Send stop message to monitor" in {
+      EventFilter.warning(pattern = s".*ACTOR DEAD.*", occurrences = 1) intercept {
+        ensembleglobal ! PoisonPill
+      }
+      //Restarted ensemble
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+    }
+    "result in no orchestration running" in {
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size (3)
+      IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+    }
+    "not affect global performer" in {
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size (3)
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+    }
+  }
+
+  "Stopping global performer" should {
+    "result in restart the orchestration" in {
+      EventFilter.error(pattern = s".*DEAD Global Performers.*", occurrences = 1) intercept {
+        globalPerformer ! PoisonPill
+      }
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+    }
+    "all previous actors restarted" in {
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size (7)
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}")
+      //TestProbe does not contain the right supervisor estrategy to restart global
+      //IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+      //IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+      IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER")
+    }
+  }
+
+  "Stopping orchestration" should {
+    "result in empty global" in {
+      orchRef ! PoisonPill
+      GlobalPerformer.activeGlobalPerformers.remove("GLOBAL-ORCH")
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+      IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+      IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+
+      GlobalPerformer.activeGlobalPerformers should have size(0)
+    }
   }
 }


[02/12] incubator-iota git commit: Merge branch 'IOTA-29' of https://github.com/shiv4nsh/incubator-iota

Posted by to...@apache.org.
Merge branch 'IOTA-29' of https://github.com/shiv4nsh/incubator-iota


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

Branch: refs/heads/master
Commit: d212cda1dbc6cab4150d5f0edbf5f824d9428c98
Parents: d6c98cf d4a151a
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Nov 14 11:04:20 2016 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Nov 14 11:04:20 2016 -0800

----------------------------------------------------------------------
 fey-core/src/main/resources/application.conf    |   1 -
 .../scala/org/apache/iota/fey/Application.scala |   1 -
 .../apache/iota/fey/CheckpointProcessor.scala   |   1 -
 .../scala/org/apache/iota/fey/Ensemble.scala    |  27 +-
 .../scala/org/apache/iota/fey/FeyCore.scala     |  17 +-
 .../org/apache/iota/fey/FeyGenericActor.scala   |  14 +-
 .../iota/fey/FeyGenericActorReceiver.scala      |   3 +-
 .../org/apache/iota/fey/FeyUIService.scala      |   3 +-
 .../org/apache/iota/fey/JsonReceiver.scala      |   3 +-
 .../org/apache/iota/fey/JsonReceiverActor.scala |   1 -
 .../scala/org/apache/iota/fey/Monitor.scala     |   8 +-
 .../org/apache/iota/fey/Orchestration.scala     |   4 +-
 .../scala/org/apache/iota/fey/TrieNode.scala    |  20 +-
 .../main/scala/org/apache/iota/fey/Utils.scala  |   9 +-
 .../apache/iota/fey/WatchServiceReceiver.scala  |   1 -
 .../apache/iota/fey/performer/Application.scala |  22 +-
 .../apache/iota/fey/performer/Heartbeat.scala   |  33 +--
 .../iota/fey/performer/RandomDouble.scala       |  33 +--
 .../iota/fey/performer/RandomInteger.scala      |  33 +--
 .../apache/iota/fey/performer/RandomUUID.scala  |  33 +--
 .../apache/iota/fey/performer/Timestamp.scala   |  33 +--
 .../org/apache/iota/fey/performer/Sensor.scala  |  54 ++--
 .../apache/iota/fey/performer/Application.scala |   2 +-
 .../iota/fey/performer/ZMQPublisher.scala       |  40 +--
 .../iota/fey/performer/ZMQSubscriber.scala      |  29 +--
 scalastyle-config.xml                           | 249 ++++++++++---------
 26 files changed, 354 insertions(+), 320 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/d212cda1/fey-core/src/main/resources/application.conf
----------------------------------------------------------------------


[06/12] incubator-iota git commit: Merge branch 'master' of github.com:apache/incubator-iota

Posted by to...@apache.org.
Merge branch 'master' of github.com:apache/incubator-iota


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

Branch: refs/heads/master
Commit: 7aae2054f0316adff4be42fea129e036b9815090
Parents: 09e596b 2895047
Author: Barbara Gomes <ba...@gmail.com>
Authored: Tue Nov 29 16:30:10 2016 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Tue Nov 29 16:30:10 2016 -0800

----------------------------------------------------------------------
 fey-core/README.md | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------



[08/12] incubator-iota git commit: [IOTA-36] Adding test to fey core

Posted by to...@apache.org.
[IOTA-36] Adding test to fey core


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

Branch: refs/heads/master
Commit: a2e6fac1b64657d7edbb83cfac65853a95933759
Parents: 580e301
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Jan 30 17:27:45 2017 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Jan 30 17:27:45 2017 -0800

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/FeyCore.scala     |  1 +
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala | 64 ++++++++++++++++++++
 .../org/apache/iota/fey/Utils_JSONTest.scala    | 57 +++++++++++++++++
 3 files changed, 122 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/a2e6fac1/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
index 99dc7c4..5dc6f7d 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
@@ -102,6 +102,7 @@ protected class FeyCore extends Actor with ActorLogging{
     FEY_CACHE.activeOrchestrations.remove(actorRef.path.name)
     ORCHESTRATION_CACHE.orchestration_metadata.remove(actorRef.path.name)
     ORCHESTRATION_CACHE.orchestration_globals.remove(actorRef.path.name)
+    GlobalPerformer.activeGlobalPerformers.remove(actorRef.path.name)
     if(!FEY_CACHE.orchestrationsAwaitingTermination.isEmpty) {
       checkForOrchestrationWaitingForTermination(actorRef.path.name)
     }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/a2e6fac1/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
index 5ae55c2..927b87a 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -225,6 +225,70 @@ class FeyCoreSpec extends BaseAkkaSpec  {
     }
   }
 
+
+  val global_orch_name = "GLOBAL-PERFORMER"
+  var globalRef:ActorRef= null
+
+  "Sending FeyCore.ORCHESTRATION_RECEIVED with CREATE AND GLOBAL performer command to FeyCore" should {
+    s"result in creating an Orchestration child actor with the name '$global_orch_name'" in {
+      feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.global_perf_test), None)
+      orchestrationref = TestProbe().expectActor(s"$feyPath/$global_orch_name")
+    }
+    s"result in creating an Ensemble child actor with the name '$global_orch_name/ENS-GLOBAL'" in {
+      ensemble1ref = TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL")
+    }
+    s"result in creating a global Performer child actor with the name '$global_orch_name/GLOBAL_MANAGER/GLOBAL-TEST'" in {
+      globalRef = TestProbe().expectActor(s"$feyPath/$global_orch_name/GLOBAL_MANAGER/GLOBAL-TEST")
+    }
+    s"result in creating a Performer child actor with the name '$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER'" in {
+      ensemble2Test1ref = TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
+    }
+    s"result in new entry to FEY_CACHE.activeOrchestrations with key '$global_orch_name'" in {
+      FEY_CACHE.activeOrchestrations should contain key(global_orch_name)
+    }
+    s"result in one global actor created for orchestration" in {
+      GlobalPerformer.activeGlobalPerformers should have size(1)
+      GlobalPerformer.activeGlobalPerformers should contain key(global_orch_name)
+    }
+    s"result in globa metadata add to table" in {
+      ORCHESTRATION_CACHE.orchestration_globals should have size(1)
+      ORCHESTRATION_CACHE.orchestration_globals should contain key(global_orch_name)
+    }
+    s"result in right running actors" in {
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(feyCoreRef.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/GLOBAL_MANAGER")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/GLOBAL_MANAGER/GLOBAL-TEST")
+      IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
+    }
+  }
+
+  "Stopping Global actor" should {
+    "result in sending logging error" in {
+      EventFilter.error(pattern = s".*DEAD Global Performer.*", occurrences = 1) intercept {
+        globalRef ! PoisonPill
+      }
+    }
+    "result in orchestration restarted" in {
+      TestProbe().expectActor(s"$feyPath/$global_orch_name/GLOBAL_MANAGER/GLOBAL-TEST")
+      TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
+      TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL")
+    }
+  }
+
+  "Stopping orchestration with global performer" should {
+    "result in sending TERMINATE message to Monitor actor" in {
+      orchestrationref ! PoisonPill
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+    }
+    "result in no global actors for orchestration" in {
+      GlobalPerformer.activeGlobalPerformers should have size(0)
+      ORCHESTRATION_CACHE.orchestration_globals should have size(0)
+      ORCHESTRATION_CACHE.orchestration_metadata should not contain key(global_orch_name)
+    }
+  }
+
   "Stopping FeyCore" should {
     "result in sending STOP message to Monitor actor" in {
       feyCoreRef ! PoisonPill

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/a2e6fac1/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
index 106a406..a900df5 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
@@ -551,4 +551,61 @@ object Utils_JSONTest {
          }
        ]
      }"""
+
+
+  val global_perf_test =
+    """
+      {
+        "guid":"GLOBAL-PERFORMER",
+        "command":"RECREATE",
+        "timestamp":"12347896906",
+        "name":"recreate global",
+        "global-performers":[
+          {
+            "guid":"GLOBAL-TEST",
+            "schedule":0,
+            "backoff":1000,
+            "source":{
+              "name":"fey-test-actor.jar",
+              "classPath":"org.apache.iota.fey.TestActor",
+              "parameters":{
+                "param-1":"test",
+                "param-2":"test2"
+              }
+            }
+          }
+        ],
+        "ensembles":[
+          {
+            "guid":"ENS-GLOBAL",
+            "command":"NONE",
+            "performers":[
+              {
+                "guid":"PERFORMER-SCHEDULER",
+                "schedule":200,
+                "backoff":0,
+                "autoScale":{
+                  "lowerBound":4,
+                  "upperBound":6
+                },
+                "source":{
+                  "name":"fey-test-actor.jar",
+                  "classPath":"org.apache.iota.fey.TestActor",
+                  "parameters":{
+
+                  }
+                }
+              }
+            ],
+            "connections":[
+              {
+                "PERFORMER-SCHEDULER":[
+                  "GLOBAL-TEST"
+                ]
+              }
+            ]
+          }
+        ]
+      }
+    """
 }


[05/12] incubator-iota git commit: Merge branch 'IOTA-29' of https://github.com/shiv4nsh/incubator-iota

Posted by to...@apache.org.
Merge branch 'IOTA-29' of https://github.com/shiv4nsh/incubator-iota


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

Branch: refs/heads/master
Commit: 09e596baba1b81c8491fee608a5aff1075ab621a
Parents: 29fe93a 800ceea
Author: Barbara Gomes <ba...@gmail.com>
Authored: Tue Nov 29 14:44:29 2016 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Tue Nov 29 14:44:29 2016 -0800

----------------------------------------------------------------------
 .../src/main/scala/org/apache/iota/fey/FeyGenericActor.scala     | 2 +-
 fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala        | 2 +-
 fey-core/src/main/scala/org/apache/iota/fey/TrieNode.scala       | 4 ++--
 fey-core/src/test/scala/org/apache/iota/fey/MonitorSpec.scala    | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[03/12] incubator-iota git commit: Merge branch 'master' of github.com:apache/incubator-iota

Posted by to...@apache.org.
Merge branch 'master' of github.com:apache/incubator-iota


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

Branch: refs/heads/master
Commit: 7830ba38fc1bf4799ad820e6bfb35516bfe2ac6e
Parents: d212cda 626e043
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Nov 14 17:00:15 2016 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Nov 14 17:00:15 2016 -0800

----------------------------------------------------------------------
 Readme.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[11/12] incubator-iota git commit: [IOTA-36] Unit test - forcing clean up of loaded jars before get into Utils

Posted by to...@apache.org.
[IOTA-36] Unit test - forcing clean up of loaded jars before get into Utils


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

Branch: refs/heads/master
Commit: 7896e36fd1689d9d906877cdd8fd803b90458333
Parents: 35a83e9
Author: Barbara Gomes <ba...@gmail.com>
Authored: Tue Jan 31 12:37:12 2017 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Tue Jan 31 12:37:12 2017 -0800

----------------------------------------------------------------------
 fey-core/src/test/scala/org/apache/iota/fey/UtilsSpec.scala | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7896e36f/fey-core/src/test/scala/org/apache/iota/fey/UtilsSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/UtilsSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/UtilsSpec.scala
index 8a4b73b..865e10d 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/UtilsSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/UtilsSpec.scala
@@ -26,6 +26,7 @@ import ch.qos.logback.classic.Level
 import play.api.libs.json._
 import java.nio.file.{Files, Paths}
 
+import scala.collection.mutable
 import scala.io.Source
 import scala.concurrent.duration._
 
@@ -33,6 +34,7 @@ class UtilsSpec extends BaseAkkaSpec{
 
   "Global variable loadedJars" should{
     "be empty when starting" in {
+      Utils.loadedJars.remove("fey-test-actor.jar")
       Utils.loadedJars shouldBe empty
     }
   }


[12/12] incubator-iota git commit: Merge branch 'IOTA-36' of https://github.com/barbaragomes/incubator-iota

Posted by to...@apache.org.
Merge branch 'IOTA-36' of https://github.com/barbaragomes/incubator-iota


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

Branch: refs/heads/master
Commit: 49138d689ba7c3f73cd3d2dbd71bfe6f4bcece89
Parents: 4775f99 7896e36
Author: tonyfaustini <to...@yahoo.com>
Authored: Tue Jan 31 14:26:50 2017 -0800
Committer: tonyfaustini <to...@yahoo.com>
Committed: Tue Jan 31 14:26:50 2017 -0800

----------------------------------------------------------------------
 .../resources/fey-json-schema-validator.json    |  95 ++++++++++
 .../scala/org/apache/iota/fey/Ensemble.scala    |  28 ++-
 .../scala/org/apache/iota/fey/FeyCore.scala     |  35 ++--
 .../org/apache/iota/fey/GlobalPerformer.scala   | 186 +++++++++++++++++++
 .../org/apache/iota/fey/Orchestration.scala     |  53 +++++-
 .../main/scala/org/apache/iota/fey/Utils.scala  |   3 +
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala |  81 ++++++++
 .../apache/iota/fey/GlobalPerformerSpec.scala   | 156 ++++++++++++++++
 .../scala/org/apache/iota/fey/UtilsSpec.scala   |   2 +
 .../org/apache/iota/fey/Utils_JSONTest.scala    |  57 ++++++
 10 files changed, 671 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/49138d68/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
----------------------------------------------------------------------
diff --cc fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
index 0acedda,5dc6f7d..14c4cc0
--- a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
@@@ -23,9 -23,8 +23,9 @@@ import akka.actor.SupervisorStrategy.
  import akka.actor.{Actor, ActorLogging, ActorRef, OneForOneStrategy, PoisonPill, Props, Terminated}
  import akka.routing.GetRoutees
  import com.eclipsesource.schema._
 +import org.apache.iota.fey.GlobalWatchService.REGISTER_WATCHER_PERFORMER
  import org.apache.iota.fey.JSON_PATH._
- import org.apache.iota.fey.Orchestration.{CREATE_ENSEMBLES, DELETE_ENSEMBLES, UPDATE_ENSEMBLES}
+ import org.apache.iota.fey.Orchestration.{CREATE_ENSEMBLES, CREATE_GLOBAL_PERFORMERS_AND_ENSEMBLES, DELETE_ENSEMBLES, UPDATE_ENSEMBLES}
  import org.apache.iota.fey.Utils._
  import play.api.libs.json._
  

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/49138d68/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------


[09/12] incubator-iota git commit: [IOTA-36] Unit test for GlobalPerformer

Posted by to...@apache.org.
[IOTA-36] Unit test for GlobalPerformer


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

Branch: refs/heads/master
Commit: 048934f51073d5c824e70dc04b34264957f9602f
Parents: a2e6fac
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Jan 30 17:38:13 2017 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Jan 30 17:38:13 2017 -0800

----------------------------------------------------------------------
 .../apache/iota/fey/GlobalPerformerSpec.scala   | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/048934f5/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
new file mode 100644
index 0000000..0acc44c
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
@@ -0,0 +1,58 @@
+
+/*
+ * 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.iota.fey
+
+import play.api.libs.json._
+import akka.actor.{ActorRef, PoisonPill, Props}
+import akka.testkit.{EventFilter, TestActorRef, TestProbe}
+
+import scala.concurrent.duration.DurationInt
+
+class GlobalPerformerSpec extends BaseAkkaSpec{
+
+  // Orchestration that is the parent of ensembles and global
+  val orch_id = "GLOBAL-ORCH"
+  val parent = TestProbe("CORE")
+
+  val monitor = TestProbe()
+
+  val orchRef = TestActorRef[Orchestration]( Props(new Orchestration("TESTING-GLOBAL",orch_id,"123124324324"){
+    override val monitoring_actor = monitor.ref
+  }), parent.ref, orch_id)
+  val orchState = orchRef.underlyingActor
+
+  val orchestrationJson = getJSValueFromString(Utils_JSONTest.global_perf_test)
+  val ensembles = (orchestrationJson \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
+  val globals = (orchestrationJson \ JSON_PATH.GLOBAL_PERFORMERS).as[List[JsObject]]
+
+  val global_name = "GLOBAL-MANAGER"
+  var global_managerRef:TestActorRef[GlobalPerformer] = null
+  var global_managerState:GlobalPerformer = null
+
+
+  "Creating an Global Manager " should {
+    "result in sending START message to Monitor actor" in {
+      global_managerRef =  TestActorRef[GlobalPerformer]( Props(new GlobalPerformer(orch_id,"TESTING-GLOBAL",globals,ensembles){
+        override val monitoring_actor = monitor.ref
+      }), orchRef, global_name)
+      global_managerState = global_managerRef.underlyingActor
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
+    }
+  }
+}


[04/12] incubator-iota git commit: Merge branch 'IOTA-29' of https://github.com/shiv4nsh/incubator-iota

Posted by to...@apache.org.
Merge branch 'IOTA-29' of https://github.com/shiv4nsh/incubator-iota


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

Branch: refs/heads/master
Commit: 29fe93a0400007f151a58c250a807424aa542636
Parents: 7830ba3 e96b066
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Nov 21 10:38:14 2016 -0800
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Nov 21 10:38:14 2016 -0800

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/Ensemble.scala    | 14 ++---
 .../org/apache/iota/fey/FeyGenericActor.scala   | 14 ++---
 .../scala/org/apache/iota/fey/Monitor.scala     | 10 ++--
 .../scala/org/apache/iota/fey/TrieNode.scala    | 60 ++++++++++----------
 4 files changed, 50 insertions(+), 48 deletions(-)
----------------------------------------------------------------------