You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2015/04/30 13:35:03 UTC

stratos git commit: fixing termination behavior issue and adding support to remove GroupInstances when they are beyond max

Repository: stratos
Updated Branches:
  refs/heads/master 7359fa68a -> 472cd1ba0


fixing termination behavior issue and adding support to remove GroupInstances when they are beyond max


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

Branch: refs/heads/master
Commit: 472cd1ba0a2fb2a72621e4deef4ed99b4d4a5815
Parents: 7359fa6
Author: reka <rt...@gmail.com>
Authored: Thu Apr 30 16:26:24 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Thu Apr 30 17:05:01 2015 +0530

----------------------------------------------------------------------
 .../dependency/DependencyBuilder.java           |  9 ++++-
 .../applications/dependency/DependencyTree.java | 37 ++++++--------------
 .../context/cluster/ClusterContext.java         |  2 +-
 .../monitor/component/GroupMonitor.java         | 27 ++++++++++++--
 4 files changed, 43 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/472cd1ba/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 8df87c3..b3dfeb6 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
@@ -96,6 +96,14 @@ public class DependencyBuilder {
                             ApplicationChildContext applicationChildContext = ApplicationChildContextFactory.
                                     createApplicationChildContext(identifier, startupOrderComponent,
                                             component, dependencyTree);
+                            String parentContextId = null;
+                            ApplicationChildContext tmpParentContext = null;
+                            if(parentContext != null) {
+                                parentContextId = parentContext.getId();
+                                tmpParentContext = dependencyTree.
+                                        getApplicationChildContextByIdInPrimaryTree(parentContextId);
+                            }
+                            applicationChildContext.setParent(tmpParentContext);
                             String applicationChildContextId = applicationChildContext.getId();
 
                             ApplicationChildContext existingApplicationChildContext =
@@ -111,7 +119,6 @@ public class DependencyBuilder {
                                                 applicationChildContext.getId(), parentContext.getId(), dependencyTree));
                                     }
                                     parentContext = applicationChildContext;
-                                    applicationChildContext.setParent(parentContext);
                                 } else {
                                     // This is the first element, add it as the root
                                     dependencyTree.addPrimaryApplicationContext(applicationChildContext);

http://git-wip-us.apache.org/repos/asf/stratos/blob/472cd1ba/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
index 945f91c..f6b11bc 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
@@ -92,42 +92,25 @@ public class DependencyTree {
     }
 
     public ApplicationChildContext findParentContextWithId(String id) {
-        return findParentContextWithId(null, id, this.primaryApplicationContextList);
+        ApplicationChildContext context = getApplicationChildContextByIdInPrimaryTree(id);
+        return context.getParent();
     }
 
     public List<ApplicationChildContext> findAllParentContextWithId(String id) {
+        ApplicationChildContext context = getApplicationChildContextByIdInPrimaryTree(id);
         List<ApplicationChildContext> applicationContexts = new ArrayList<ApplicationChildContext>();
-        return findAllParent(applicationContexts, id);
+        return findAllParent(applicationContexts, context);
     }
 
-    private List<ApplicationChildContext> findAllParent(List<ApplicationChildContext> parentContexts, String id) {
-        ApplicationChildContext context = findParentContextWithId(null, id, this.primaryApplicationContextList);
-        if (context != null) {
-            parentContexts.add(context);
-            findAllParent(parentContexts, context.getId());
+    private List<ApplicationChildContext> findAllParent(List<ApplicationChildContext> parentContexts,
+                                                        ApplicationChildContext context) {
+        if (context.getParent() != null) {
+            parentContexts.add(context.getParent());
+            return findAllParent(parentContexts, context.getParent());
         }
         return parentContexts;
     }
-
-
-    private ApplicationChildContext findParentContextWithId(ApplicationChildContext parent, String id,
-                                                            List<ApplicationChildContext> contexts) {
-        for (ApplicationChildContext context : contexts) {
-            //TODO check for the status
-            if (context.getParent() != null && context.getParent().equals(id)) {
-                return context;
-            }
-        }
-        //if not found in the top level search recursively
-        for (ApplicationChildContext context : this.primaryApplicationContextList) {
-            if (context.getApplicationChildContextList() != null &&
-                    !context.getApplicationChildContextList().isEmpty()) {
-                return findParentContextWithId(context, id, context.getApplicationChildContextList());
-            }
-        }
-        return null;
-    }
-
+    
     /**
      * Getting the next start able dependencies upon the activate event
      * received for a group/cluster which is part of this tree.

http://git-wip-us.apache.org/repos/asf/stratos/blob/472cd1ba/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
index d39a071..318075d 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
@@ -162,7 +162,7 @@ public class ClusterContext extends AbstractClusterContext {
                     networkPartitionContext);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster instance context has been added to network partition," +
-                                " [application] %s [cluster] %s  [cluster instance] %s " +
+                                " [application] %s [cluster] %s  [cluster-instance] %s " +
                                 "[network partition] %s", cluster.getAppId(), cluster.getClusterId(),
                         clusterInstance.getInstanceId(),
                         clusterInstance.getNetworkPartitionId()));

http://git-wip-us.apache.org/repos/asf/stratos/blob/472cd1ba/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
index 56837f5..ce5dc1e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
@@ -137,7 +137,8 @@ public class GroupMonitor extends ParentComponentMonitor {
 
                             } else if (!instanceContext.getIdToScalingDownBeyondMinEvent().isEmpty()) {
                                 //scale down only when extra instances found
-                                handleScalingDownBeyondMin(instanceContext, networkPartitionContext);
+                                handleScalingDownBeyondMin(instanceContext,
+                                        networkPartitionContext, false);
                             }
                         }
                     }
@@ -146,6 +147,10 @@ public class GroupMonitor extends ParentComponentMonitor {
                             getNonTerminatedInstancesCount();
                     int minInstances = ((GroupLevelNetworkPartitionContext) networkPartitionContext).
                             getMinInstanceCount();
+                    int maxInstances = ((GroupLevelNetworkPartitionContext) networkPartitionContext).
+                            getMaxInstanceCount();
+                    int activeInstances = ((GroupLevelNetworkPartitionContext) networkPartitionContext).
+                            getActiveInstancesCount();
                     if (nonTerminatedInstancesCount < minInstances) {
                         int instancesToBeCreated = minInstances - nonTerminatedInstancesCount;
                         for (int i = 0; i < instancesToBeCreated; i++) {
@@ -166,6 +171,21 @@ public class GroupMonitor extends ParentComponentMonitor {
 
                         }
                     }
+                    //If the active instances are higher than the max instances,
+                    // the group instance has to get terminated
+                    if (activeInstances > maxInstances) {
+                        int instancesToBeTerminated = activeInstances - maxInstances;
+                        Collection<InstanceContext> contexts = networkPartitionContext.
+                                getInstanceIdToInstanceContextMap().values();
+                        List<InstanceContext> contextList = new ArrayList<InstanceContext>();
+                        for (int i = 0; i < instancesToBeTerminated; i++) {
+                            InstanceContext instanceContext = contextList.get(i);
+                            //scale down only when extra instances found
+                            handleScalingDownBeyondMin(instanceContext,
+                                    networkPartitionContext, true);
+
+                        }
+                    }
                 }
             }
         };
@@ -188,7 +208,8 @@ public class GroupMonitor extends ParentComponentMonitor {
     }
 
     private void handleScalingDownBeyondMin(InstanceContext instanceContext,
-                                            NetworkPartitionContext nwPartitionContext) {
+                                            NetworkPartitionContext nwPartitionContext,
+                                            boolean forceScaleDown) {
         //Traverse through all the children to see whether all have sent the scale down
         boolean allChildrenScaleDown = false;
         for (Monitor monitor : this.aliasToActiveMonitorsMap.values()) {
@@ -200,7 +221,7 @@ public class GroupMonitor extends ParentComponentMonitor {
             }
         }
         //all the children sent the scale down only, it will try to scale down
-        if (allChildrenScaleDown) {
+        if (allChildrenScaleDown || forceScaleDown) {
             if (hasScalingDependents) {
                 if (nwPartitionContext.getNonTerminatedInstancesCount() >
                         ((GroupLevelNetworkPartitionContext)