You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2013/11/17 08:51:05 UTC

git commit: Refactor one-after-other autoscaler algorithm by replacing the recursive call with a loop so both round-robing and one-after-other alogorithm are same fashion

Updated Branches:
  refs/heads/master d57ee15fb -> bd279632c


Refactor one-after-other autoscaler algorithm by replacing the recursive call with a loop so both round-robing and one-after-other alogorithm are same fashion


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

Branch: refs/heads/master
Commit: bd279632cb1607e506605b6b304e3f3040ffd9f9
Parents: d57ee15
Author: Udara Liyanage <ud...@wso2.com>
Authored: Sun Nov 17 13:18:04 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Sun Nov 17 13:18:04 2013 -0500

----------------------------------------------------------------------
 .../stratos/autoscaler/ClusterContext.java      |   5 +-
 .../algorithm/AutoscaleAlgorithm.java           |   2 -
 .../autoscaler/algorithm/OneAfterAnother.java   | 149 ++++++++-----------
 .../autoscaler/algorithm/RoundRobin.java        |   8 +-
 4 files changed, 65 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bd279632/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
index 39b8c7e..7d7f8a2 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/ClusterContext.java
@@ -139,8 +139,7 @@ public class ClusterContext {
         partitionCountMap.put(partitionId, partitionCountMap.get(partitionId) - count);
     }
 
-    public void addPartitionCount(String partitionId, int count){
-
+    public void addPartitionCount(String partitionId, int count){    	
         partitionCountMap.put(partitionId, count);
     }
 
@@ -153,7 +152,7 @@ public class ClusterContext {
         return partitionCountMap.containsKey(partitionId);
     }
 
-    public int getPartitionCount(String partitionId){
+    public int getMemberCount(String partitionId){
         return partitionCountMap.get(partitionId);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bd279632/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/AutoscaleAlgorithm.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/AutoscaleAlgorithm.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/AutoscaleAlgorithm.java
index 043fc7f..1effaa8 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/AutoscaleAlgorithm.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/AutoscaleAlgorithm.java
@@ -27,8 +27,6 @@ import org.apache.stratos.autoscaler.policy.model.Partition;
 public interface AutoscaleAlgorithm {
 public Partition getNextScaleUpPartition(String clusterId);
 public Partition getNextScaleDownPartition(String clusterId);
-public Partition getScaleUpPartition(String clusterId);
-public Partition getScaleDownPartition(String clusterId);
 public boolean scaleUpPartitionAvailable(String clusterId);
 public boolean scaleDownPartitionAvailable(String clusterId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bd279632/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
index 040a85f..e69d5e9 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
@@ -43,36 +43,39 @@ public class OneAfterAnother implements AutoscaleAlgorithm {
 
         // Find number of partitions
         int noOfPartitions = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().size();
-
-        // Here in "one after another" algorithm, next partition is also the current partition unless it reached its max
-        int nextPartitionIndex = clusterContext.getCurrentPartitionIndex();;
-
-        //Find next partition
-        Partition nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().get(nextPartitionIndex);
-        String nextPartitionId = nextPartition.getId();
-
-        if (clusterContext.partitionCountExists(nextPartitionId)) {
-            if (clusterContext.getPartitionCount(nextPartitionId) >= nextPartition.getPartitionMembersMax()) {
-                if(nextPartitionIndex == (noOfPartitions - 1)) {
-                    // All partitions have reached their max
-                    return null;
+        
+        for(int i=0; i<noOfPartitions;i++)
+        {
+            // Here in "one after another" algorithm, next partition is also the current partition unless it reached its max
+            int nextPartitionIndex = clusterContext.getCurrentPartitionIndex();;
+
+            //Find next partition
+            Partition nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().get(nextPartitionIndex);
+            String nextPartitionId = nextPartition.getId();
+
+            if (clusterContext.partitionCountExists(nextPartitionId)) {            	
+                if (clusterContext.getMemberCount(nextPartitionId) >= nextPartition.getPartitionMembersMax()) {
+                    if(nextPartitionIndex == (noOfPartitions - 1)) {
+                        // All partitions have reached their max
+                        return null;
+                    }
+                    // Selected partition's max has reached, it will try next partition
+                    AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex + 1);
                 }
+                else {
+                    // Increase member partition member count by one
+                    AutoscalerContext.getInstance().getClusterContext(clusterId).increaseMemberCountInPartition(nextPartitionId, 1);
+                    return nextPartition;
+                }
+            } else {
 
-                // Selected partition's max has reached, it will try next partition
-                AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex + 1);
-
-                return getNextScaleUpPartition(clusterId);
+                // Add the partition count entry to cluster context
+                AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(nextPartitionId, 1);
             }
-            else {
-                // Increase member partition member count by one
-                AutoscalerContext.getInstance().getClusterContext(clusterId).increaseMemberCountInPartition(nextPartitionId, 1);
-            }
-        } else {
 
-            // Add the partition count entry to cluster context
-            AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(nextPartitionId, 1);
         }
-        return nextPartition;
+
+        return null;
     }
 
     public Partition getNextScaleDownPartition(String clusterId) {
@@ -88,56 +91,42 @@ public class OneAfterAnother implements AutoscaleAlgorithm {
 
         // Find number of partitions
         int noOfPartitions = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().size();
-
-        // Here in "one after another" algorithm, next partition is also the current partition unless it reached its max
-        int nextPartitionIndex = clusterContext.getCurrentPartitionIndex();;
-
-        //Find next partition
-        Partition nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().get(nextPartitionIndex);
-        String nextPartitionId = nextPartition.getId();
-
-        if (clusterContext.partitionCountExists(nextPartitionId)) {
-            if (clusterContext.getPartitionCount(nextPartitionId) >= nextPartition.getPartitionMembersMax()) {
-                if(nextPartitionIndex == 0) {
-                    // All partitions have reached their max
-                    return null;
+        
+        for(int i=0;i<noOfPartitions;i++)
+        {
+
+            // Here in "one after another" algorithm, next partition is also the current partition unless it reached its max
+            int nextPartitionIndex = clusterContext.getCurrentPartitionIndex();;
+
+            //Find next partition
+            Partition nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().get(nextPartitionIndex);
+            String nextPartitionId = nextPartition.getId();
+
+            if (clusterContext.partitionCountExists(nextPartitionId)) {
+                if (clusterContext.getMemberCount(nextPartitionId) >= nextPartition.getPartitionMembersMax()) {
+                    if(nextPartitionIndex == 0) {
+                        // All partitions have reached their min
+                        return null;
+                    }
+
+                    // Selected partition's min has reached, it will try next partition
+                    AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex - 1);
                 }
+                else {
+                    // Increase member partition member count by one
+                    AutoscalerContext.getInstance().getClusterContext(clusterId).increaseMemberCountInPartition(nextPartitionId, 1);
+                    return nextPartition;
+                }
+            } else {
 
-                // Selected partition's max has reached, it will try next partition
-                AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex - 1);
-
-                return getNextScaleUpPartition(clusterId);
+                // Add the partition count entry to cluster context
+                AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(nextPartitionId, 1);
             }
-            else {
-                // Increase member partition member count by one
-                AutoscalerContext.getInstance().getClusterContext(clusterId).increaseMemberCountInPartition(nextPartitionId, 1);
-            }
-        } else {
-
-            // Add the partition count entry to cluster context
-            AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(nextPartitionId, 1);
         }
-        return nextPartition;
-    }
-
-    public Partition getScaleDownPartition(String clusterId) {
-        Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
-                .get(0);
-
-        ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-        int currentPartitionMemberCount = 0;
-
-        if (clusterContext.partitionCountExists(partition.getId())) {
-
-            currentPartitionMemberCount = clusterContext.getPartitionCount(partition.getId());
-        }
-        if (currentPartitionMemberCount <= partition.getPartitionMembersMin()) {
-
-            partition = null;
-        }
-
-        return partition;
+        
+        return null;
     }
+    
 
     @Override
     public boolean scaleUpPartitionAvailable(String clusterId) {
@@ -148,24 +137,4 @@ public class OneAfterAnother implements AutoscaleAlgorithm {
     public boolean scaleDownPartitionAvailable(String clusterId) {
         return false;  //To change body of implemented methods use File | Settings | File Templates.
     }
-
-
-    public Partition getScaleUpPartition(String clusterId) {
-        Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
-                .get(0);
-
-        ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-        int currentPartitionMemberCount = 0;
-
-        if (clusterContext.partitionCountExists(partition.getId())) {
-
-            currentPartitionMemberCount = clusterContext.getPartitionCount(partition.getId());
-        }
-        if (currentPartitionMemberCount >= partition.getPartitionMembersMax()) {
-            partition = null;
-        }
-
-        return partition;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bd279632/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
index 6dc9d77..4ab56fd 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
@@ -52,7 +52,7 @@ public class RoundRobin implements AutoscaleAlgorithm{
     	        AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(currentPartitionIndex);
     	        
     	        
-    	        if(clusterContext.getPartitionCount(currentPartitionId) < currentPartition.getPartitionMembersMax()){
+    	        if(clusterContext.getMemberCount(currentPartitionId) < currentPartition.getPartitionMembersMax()){
     	        	// current partition is free
     	        	AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(currentPartitionId, 1);
 	                return currentPartition;
@@ -98,7 +98,7 @@ public class RoundRobin implements AutoscaleAlgorithm{
                      .get(previousPartitionIndex);
              String previousPartitionId = previousPartition.getId();
              if(clusterContext.partitionCountExists(previousPartitionId)
-                     && (clusterContext.getPartitionCount(previousPartitionId) > previousPartition.getPartitionMembersMin())){
+                     && (clusterContext.getMemberCount(previousPartitionId) > previousPartition.getPartitionMembersMin())){
             	 return previousPartition;
              }
          }
@@ -113,7 +113,7 @@ public class RoundRobin implements AutoscaleAlgorithm{
                             .get(0);
 
         ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-        int partitionMemberCount = clusterContext.getPartitionCount(partition.getId());
+        int partitionMemberCount = clusterContext.getMemberCount(partition.getId());
 
         if(partitionMemberCount >= partition.getPartitionMembersMin())       {
 
@@ -142,7 +142,7 @@ public class RoundRobin implements AutoscaleAlgorithm{
                             .get(0);
 
         ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-        int partitionMemberCount = clusterContext.getPartitionCount(partition.getId());
+        int partitionMemberCount = clusterContext.getMemberCount(partition.getId());
 
         if(partitionMemberCount <= partition.getPartitionMembersMax())       {