Adding dependency building logic with scaling orders

Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/3d4f25f5
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/3d4f25f5
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/3d4f25f5

Branch: refs/heads/master
Commit: 3d4f25f54242ca6aa15ef4be20c2dd541661f042
Parents: 3aaf37a
Author: Lahiru Sandaruwan <[email protected]>
Authored: Wed Nov 12 14:44:16 2014 +0530
Committer: Lahiru Sandaruwan <[email protected]>
Committed: Wed Nov 12 14:44:16 2014 +0530

----------------------------------------------------------------------
 .../dependency/DependencyBuilder.java           | 85 ++++++++++++++++++--
 .../monitor/ParentComponentMonitor.java         | 30 ++++---
 .../monitor/events/ClusterScalingEvent.java     | 19 ++---
 .../autoscaler/rule/RuleTasksDelegator.java     |  3 +
 4 files changed, 112 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3d4f25f5/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
index 8a12b97..5285e10 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
@@ -48,11 +48,11 @@ public class DependencyBuilder {
     }
 
     /**
-     * This will build the dependency tree based on the given dependency order
+     * This will build the dependency tree based on the given startup 
dependency order
      * @param component it will give the necessary information to build the 
tree
      * @return the dependency tree out of the dependency orders
      */
-    public DependencyTree buildDependency(ParentComponent component) throws 
DependencyBuilderException{
+    public DependencyTree buildStartupDependency(ParentComponent component) 
throws DependencyBuilderException{
 
         String identifier = component.getUniqueIdentifier();
         DependencyTree dependencyTree = new DependencyTree(identifier);
@@ -73,7 +73,7 @@ public class DependencyBuilder {
             }
 
             log.info("Setting the [terminationBehaviour] " + 
terminationBehaviour + " to the " +
-                        "[dependency-tree] " + dependencyTree.getId());
+                    "[dependency-tree] " + dependencyTree.getId());
 
 
             //Parsing the start up order
@@ -130,7 +130,6 @@ public class DependencyBuilder {
 
                 }
             }
-            //TODO need to parser the scalable dependencies
         }
 
 
@@ -146,11 +145,87 @@ public class DependencyBuilder {
         for (ClusterDataHolder dataHolder : 
component.getClusterDataMap().values()) {
             if 
(dependencyTree.findApplicationContextWithId(dataHolder.getClusterId()) == 
null) {
                 ApplicationContext context = 
ApplicationContextFactory.getClusterContext(dataHolder,
-                                                                
dependencyTree.isTerminateDependent());
+                        dependencyTree.isTerminateDependent());
                 dependencyTree.addApplicationContext(context);
 
             }
         }
         return dependencyTree;
     }
+
+    /**
+     * This will build the dependency tree based on the given scaling 
dependency order
+     * @param component it will give the necessary information to build the 
tree
+     * @return the dependency tree out of the dependency orders
+     */
+    public DependencyTree buildScalingDependency(ParentComponent component) 
throws DependencyBuilderException{
+
+        String identifier = component.getUniqueIdentifier();
+        DependencyTree dependencyTree = new DependencyTree(identifier);
+        DependencyOrder dependencyOrder = component.getDependencyOrder();
+
+        if (dependencyOrder != null) {
+            log.info("Building dependency for the Application/Group " + 
identifier);
+
+
+            //Parsing the scaling order
+            Set<ScalingOrder> scalingOrders = 
dependencyOrder.getScalingOrders();
+            ApplicationContext foundContext;
+            ApplicationContext parentContext;
+
+            if (scalingOrders != null) {
+                for (ScalingOrder scalingOrder : scalingOrders) {
+                    foundContext = null;
+                    parentContext = null;
+                    for (String scalingOrderElement : 
scalingOrder.getScalingOrderList()) {
+
+                        if (scalingOrderElement != null) {
+                            ApplicationContext applicationContext = 
ApplicationContextFactory.
+                                    getApplicationContext(scalingOrderElement, 
component, dependencyTree);
+                            String id = applicationContext.getId();
+
+                            ApplicationContext existingApplicationContext =
+                                    
dependencyTree.findApplicationContextWithId(id);
+                            if (existingApplicationContext == null) {
+                                if (parentContext != null) {
+                                    //appending the scaling order to already 
added parent group/cluster
+                                    
parentContext.addApplicationContext(applicationContext);
+                                    parentContext = applicationContext;
+                                    if (log.isDebugEnabled()) {
+                                        log.debug("Found an existing 
[dependency] " + parentContext.getId() +
+                                                " and adding the [dependency] 
" + id + " as the child");
+                                    }
+                                } else {
+                                    //adding list of scaling order to the 
dependency tree
+                                    
dependencyTree.addApplicationContext(applicationContext);
+                                    parentContext = applicationContext;
+                                }
+                            } else {
+                                if (foundContext == null) {
+                                    //if existing context found, add it to 
child of existing context and
+                                    //set the existing context as the next 
parent
+                                    
existingApplicationContext.addApplicationContext(applicationContext);
+                                    parentContext = existingApplicationContext;
+                                    if (log.isDebugEnabled()) {
+                                        log.debug("Found an existing 
[dependency] " + id + " and setting it " +
+                                                "for the next dependency to 
follow");
+                                    }
+                                } else {
+                                    String msg = "Scaling order is not 
consistent. It contains the group/cluster " +
+                                            "which has been used more than one 
in another scaling order";
+                                    throw new DependencyBuilderException(msg);
+                                }
+
+                            }
+                        }
+                    }
+
+                }
+            }
+        }
+
+        return dependencyTree;
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3d4f25f5/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
index c900f49..77d6165 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
@@ -45,15 +45,21 @@ public abstract class ParentComponentMonitor extends 
Monitor {
     private static final Log log = 
LogFactory.getLog(ParentComponentMonitor.class);
 
     //The monitors dependency tree with all the start-able/kill-able 
dependencies
-    protected DependencyTree dependencyTree;
+    protected DependencyTree startupDependencyTree;
+
+    //The monitors dependency tree with all the scaling dependencies
+    protected DependencyTree scalingDependencyTree;
 
     public ParentComponentMonitor(ParentComponent component) throws 
DependencyBuilderException {
         aliasToActiveMonitorsMap = new HashMap<String, Monitor>();
         aliasToInactiveMonitorsMap = new HashMap<String, Monitor>();
         //clusterIdToClusterMonitorsMap = new HashMap<String, 
AbstractClusterMonitor>();
         this.id = component.getUniqueIdentifier();
-        //Building the dependency for this monitor within the immediate 
children
-        dependencyTree = 
DependencyBuilder.getInstance().buildDependency(component);
+        //Building the startup dependencies for this monitor within the 
immediate children
+        startupDependencyTree = 
DependencyBuilder.getInstance().buildStartupDependency(component);
+
+        //Building the scaling dependencies for this monitor within the 
immediate children
+        scalingDependencyTree = 
DependencyBuilder.getInstance().buildStartupDependency(component);
     }
 
     /**
@@ -126,7 +132,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
             //need to notify the parent
             StatusChecker.getInstance().onChildStatusChange(idOfEvent, 
this.id, this.appId);
         } else {
-            terminationList = 
this.dependencyTree.getTerminationDependencies(idOfEvent);
+            terminationList = 
this.startupDependencyTree.getTerminationDependencies(idOfEvent);
             //Checking whether all children are to be terminated.
             if (terminationList.size() ==
                     (this.aliasToActiveMonitorsMap.size() + 
this.aliasToInactiveMonitorsMap.size())) {
@@ -179,10 +185,10 @@ public abstract class ParentComponentMonitor extends 
Monitor {
         List<ApplicationContext> terminationList;
         boolean allDependentTerminated = false;
 
-        ApplicationContext context = 
this.dependencyTree.findApplicationContextWithId(idOfEvent);
+        ApplicationContext context = 
this.startupDependencyTree.findApplicationContextWithId(idOfEvent);
         context.setTerminated(true);
 
-        terminationList = 
this.dependencyTree.getTerminationDependencies(idOfEvent);
+        terminationList = 
this.startupDependencyTree.getTerminationDependencies(idOfEvent);
 
 
         /**
@@ -192,7 +198,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
             allDependentTerminated = allDependentTerminated(terminationList);
         }
 
-        List<ApplicationContext> parentContexts = 
this.dependencyTree.findAllParentContextWithId(idOfEvent);
+        List<ApplicationContext> parentContexts = 
this.startupDependencyTree.findAllParentContextWithId(idOfEvent);
         boolean parentsTerminated = false;
         if (parentContexts != null) {
             parentsTerminated = allParentTerminated(parentContexts);
@@ -203,7 +209,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
             //Find the non existent monitor by traversing dependency tree
             try {
                 this.startDependencyOnTermination();
-                List<ApplicationContext> applicationContexts = 
this.dependencyTree.
+                List<ApplicationContext> applicationContexts = 
this.startupDependencyTree.
                         getStarAbleDependenciesByTermination();
             } catch (TopologyInConsistentException e) {
                 //TODO revert the siblings and notify parent, change a flag 
for reverting/un-subscription
@@ -266,7 +272,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
      */
     public void startDependency() throws TopologyInConsistentException {
         //start the first dependency
-        List<ApplicationContext> applicationContexts = 
this.dependencyTree.getStarAbleDependencies();
+        List<ApplicationContext> applicationContexts = 
this.startupDependencyTree.getStarAbleDependencies();
         startDependency(applicationContexts);
 
     }
@@ -278,7 +284,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
      */
     public void startDependencyOnTermination() throws 
TopologyInConsistentException {
         //start the first dependency which went to terminated
-        List<ApplicationContext> applicationContexts = this.dependencyTree.
+        List<ApplicationContext> applicationContexts = 
this.startupDependencyTree.
                 getStarAbleDependenciesByTermination();
         startDependency(applicationContexts);
 
@@ -290,7 +296,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
      * @param id alias/clusterId of which receive the activated event
      */
     public boolean startDependency(String id) throws 
TopologyInConsistentException {
-        List<ApplicationContext> applicationContexts = 
this.dependencyTree.getStarAbleDependencies(id);
+        List<ApplicationContext> applicationContexts = 
this.startupDependencyTree.getStarAbleDependencies(id);
         return startDependency(applicationContexts);
     }
 
@@ -420,4 +426,6 @@ public abstract class ParentComponentMonitor extends 
Monitor {
             }
         }
     }
+
+    onScaling()
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3d4f25f5/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterScalingEvent.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterScalingEvent.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterScalingEvent.java
index 1f9c462..0da4e0b 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterScalingEvent.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterScalingEvent.java
@@ -21,22 +21,23 @@ package org.apache.stratos.autoscaler.monitor.events;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 
 /**
- * This will use to notify observers upon a cluster activation events received 
in Topology.
+ * This will use to notify observers upon a cluster scaling events received.
  */
-public class ClusterScalingEvent extends MonitorStatusEvent {
+public class ClusterScalingEvent extends MonitorScalingEvent {
 
-    private ClusterStatus status;
+    private String scalingAction;
+    private float factor;
 
-    public ClusterScalingEvent(ClusterStatus status, String id) {
+    public ClusterScalingEvent(String scalingAction, String id) {
         super(id);
-        this.status = status;
+        this.scalingAction = scalingAction;
     }
 
-    public ClusterStatus getStatus() {
-        return this.status;
+    public String getScalingAction() {
+        return scalingAction;
     }
 
-    public void setStatus(ClusterStatus status) {
-        this.status = status;
+    public void setScalingAction(String scalingAction) {
+        this.scalingAction = scalingAction;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3d4f25f5/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
index 9cac559..602795f 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
@@ -179,6 +179,9 @@ public class RuleTasksDelegator {
                     log.debug(String.format("Pending member added, [member] %s 
[partition] %s", memberContext.getMemberId(),
                             memberContext.getPartition().getId()));
                 }
+                //Notify parent for checking scaling dependencies
+
+
             } else if(log.isDebugEnabled()){
                 log.debug("Returned member context is null, did not add to 
pending members");
             }

Reply via email to