You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2015/03/11 11:02:25 UTC

[2/2] stratos git commit: Fixing dependent scaling issue when group is involved

Fixing dependent scaling issue when group is involved


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

Branch: refs/heads/master
Commit: 428674b9c1e3145bd870c918b508998ff9fba5fa
Parents: e588749
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Wed Mar 11 15:17:41 2015 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Wed Mar 11 15:17:41 2015 +0530

----------------------------------------------------------------------
 .../monitor/component/GroupMonitor.java         | 34 +++++++++++++-------
 1 file changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/428674b9/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 a272e72..bbc19df 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
@@ -480,19 +480,29 @@ public class GroupMonitor extends ParentComponentMonitor {
         int currentInstances = networkPartitionContext.getNonTerminatedInstancesCount();
         float requiredInstances = factor * ((GroupLevelNetworkPartitionContext)
                                 networkPartitionContext).getMinInstanceCount();
-        float additionalInstances = requiredInstances - currentInstances;
-        if(additionalInstances >= 1) {
-            createGroupInstanceOnScaling(networkPartitionContext, parentInstanceId);
-        } else {
-            //have to scale down
-            if(networkPartitionContext.getPendingInstancesCount() != 0) {
-                ApplicationBuilder.handleGroupTerminatingEvent(appId, this.id,
-                        networkPartitionContext.getPendingInstances().get(0).getId());
+        int ceilingRequiredInstances = (int) Math.ceil(requiredInstances);
+        if(ceilingRequiredInstances > currentInstances) {
 
-            } else {
-                List<InstanceContext> activeInstances = networkPartitionContext.getActiveInstances();
-                ApplicationBuilder.handleGroupTerminatingEvent(appId, this.id,
-                        activeInstances.get(activeInstances.size() - 1).toString());
+            int instancesToBeCreated = ceilingRequiredInstances - currentInstances;
+            for(int count = 0; count < instancesToBeCreated; count++){
+
+                createGroupInstanceOnScaling(networkPartitionContext, parentInstanceId);
+            }
+        } else if(ceilingRequiredInstances < currentInstances){
+
+            int instancesToBeTerminated = currentInstances - ceilingRequiredInstances;
+            for(int count = 0; count < instancesToBeTerminated; count++){
+
+                //have to scale down
+                if(networkPartitionContext.getPendingInstancesCount() != 0) {
+                    ApplicationBuilder.handleGroupTerminatingEvent(appId, this.id,
+                            networkPartitionContext.getPendingInstances().get(0).getId());
+
+                } else {
+                    List<InstanceContext> activeInstances = networkPartitionContext.getActiveInstances();
+                    ApplicationBuilder.handleGroupTerminatingEvent(appId, this.id,
+                            activeInstances.get(activeInstances.size() - 1).toString());
+                }
             }
         }