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/14 07:14:02 UTC

[1/2] git commit: Fixing stackoverflow error of RoundRobin algorithmn

Updated Branches:
  refs/heads/master 2954a0d0b -> 03ff87973


Fixing stackoverflow error of RoundRobin algorithmn


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

Branch: refs/heads/master
Commit: c237127e236af4458156014fef54401f468020cb
Parents: 9dc67d9
Author: Udara Liyanage <ud...@wso2.com>
Authored: Thu Nov 14 11:33:36 2013 +0530
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Thu Nov 14 11:33:36 2013 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/ClusterContext.java      |   2 +-
 .../autoscaler/algorithm/RoundRobin.java        | 133 +++++++++----------
 2 files changed, 62 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c237127e/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 764d759..39b8c7e 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
@@ -40,7 +40,7 @@ public class ClusterContext {
     
     private int memberCount;
 
-    //This map will keep number of instance count against partitionId
+    //This map will keep number of currently spawned instance count against partitionId
     private Map<String, Integer> partitionCountMap;
 
     private int currentPartitionIndex;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c237127e/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 ebfcb2a..6dc9d77 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
@@ -31,95 +31,84 @@ import org.apache.stratos.autoscaler.policy.model.Partition;
 public class RoundRobin implements AutoscaleAlgorithm{
 
     public Partition getNextScaleUpPartition(String clusterId){
-
-        String policyId;
-        int nextPartitionIndex;
-        ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-        int currentPartitionIndex = clusterContext.getCurrentPartitionIndex();
-
+    	
+        ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);    	            	       
         String serviceId = AutoscalerContext.getInstance().getClusterContext(clusterId).getServiceId();
-
-        //Find relevant policyId using topology
-        policyId = TopologyManager.getTopology().getService(serviceId).getCluster(clusterId).getAutoscalePolicyName();
-
-
-        int noOfPartitions = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().size();
-
-        if (currentPartitionIndex + 1 >= noOfPartitions) {
-
-            nextPartitionIndex = 0;
-        } else {
-
-            nextPartitionIndex = currentPartitionIndex++;
-        }
-
-        //Set next partition as current partition in Autoscaler Context
-        AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex);
-
-        //Find next partition
-        Partition nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions()
-                .get(nextPartitionIndex);
-        String nextPartitionId = nextPartition.getId();
-
-        if(clusterContext.partitionCountExists(nextPartitionId)){
-
-            //If the current partitions max is reached, it will try next partition
-            if(clusterContext.getPartitionCount(nextPartitionId) >= nextPartition.getPartitionMembersMax()){
-
-                nextPartition = getNextScaleUpPartition(clusterId);
-            }
-        } else {
-
-            //Add the partition count entry to cluster context
-            AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(nextPartitionId, 1);
-        }
-        return nextPartition;
+    	//Find relevant policyId using topology
+    	String policyId = TopologyManager.getTopology().getService(serviceId).getCluster(clusterId).getAutoscalePolicyName();
+    	int noOfPartitions = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().size();
+    	for(int i=0; i < noOfPartitions; i++)
+    	{
+    	        
+    	        int currentPartitionIndex = clusterContext.getCurrentPartitionIndex();
+    	        Partition currentPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions()
+    	                .get(currentPartitionIndex); 
+    	        String currentPartitionId =  currentPartition.getId();
+    	        
+    	        // point to next partition
+    	        currentPartitionIndex = currentPartitionIndex + 1 == noOfPartitions ? 0 : currentPartitionIndex+1;
+
+    	        //Set next partition as current partition in Autoscaler Context
+    	        AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(currentPartitionIndex);
+    	        
+    	        
+    	        if(clusterContext.getPartitionCount(currentPartitionId) < currentPartition.getPartitionMembersMax()){
+    	        	// current partition is free
+    	        	AutoscalerContext.getInstance().getClusterContext(clusterId).addPartitionCount(currentPartitionId, 1);
+	                return currentPartition;
+	            }    	            	      
+    	        
+    	}
+    	
+    	// coming here means non of the partitions has space for another instance to be created. All partitions are full.
+        return null;
     }
 
 
     public Partition getNextScaleDownPartition(String clusterId){
 
-        String policyId;
-        int nextPartitionIndex;
-        ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-        int currentPartitionIndex = clusterContext.getCurrentPartitionIndex();
-
-        String serviceId = AutoscalerContext.getInstance().getClusterContext(clusterId).getServiceId();
-
-        //Find relevant policyId using topology
-        policyId = TopologyManager.getTopology().getService(serviceId).getCluster(clusterId).getAutoscalePolicyName();
-
+    	 String policyId;
+         int previousPartitionIndex;
+         ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
+         int currentPartitionIndex = clusterContext.getCurrentPartitionIndex();
 
-        int noOfPartitions = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().size();
+         String serviceId = AutoscalerContext.getInstance().getClusterContext(clusterId).getServiceId();
 
-        if (currentPartitionIndex - 1 >= noOfPartitions) {
+         //Find relevant policyId using topology
+         policyId = TopologyManager.getTopology().getService(serviceId).getCluster(clusterId).getAutoscalePolicyName();
 
-            nextPartitionIndex = 0;
-        } else {
-
-            nextPartitionIndex = currentPartitionIndex--;
-        }
 
-        //Set next partition as current partition in Autoscaler Context
-        AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex);
+         int noOfPartitions = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions().size();
+         
+         for(int i=0; i<noOfPartitions;i++)
+         {
+         	if (currentPartitionIndex == 0) {
 
-        //Find next partition
-        Partition nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions()
-                .get(nextPartitionIndex);
-        String nextPartitionId = nextPartition.getId();
-
-        if(clusterContext.partitionCountExists(nextPartitionId)
-                && (clusterContext.getPartitionCount(nextPartitionId) <= nextPartition.getPartitionMembersMin())){
+         		previousPartitionIndex = noOfPartitions - 1;
+            }else {
 
+            	previousPartitionIndex = currentPartitionIndex - 1;
+            }
 
-            //If the current partitions max is reached, it will try next partition
-            nextPartition = getNextScaleDownPartition(clusterId);
-        }
-        return nextPartition;
+             //Set next partition as current partition in Autoscaler Context
+             AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(previousPartitionIndex);
+
+             //Find next partition
+             Partition previousPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions()
+                     .get(previousPartitionIndex);
+             String previousPartitionId = previousPartition.getId();
+             if(clusterContext.partitionCountExists(previousPartitionId)
+                     && (clusterContext.getPartitionCount(previousPartitionId) > previousPartition.getPartitionMembersMin())){
+            	 return previousPartition;
+             }
+         }
+         
+         return null;
     }
 
 
     public Partition getScaleDownPartition(String clusterId){
+    	
         Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
                             .get(0);
 


[2/2] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by ud...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


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

Branch: refs/heads/master
Commit: 03ff87973006168642a96edc433b994a301cb8f8
Parents: c237127 2954a0d
Author: Udara Liyanage <ud...@wso2.com>
Authored: Thu Nov 14 11:41:13 2013 +0530
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Thu Nov 14 11:41:13 2013 +0530

----------------------------------------------------------------------
 .../factory/CartridgeSubscriptionFactory.java   |  9 ++---
 .../adc/mgt/test/CartridgeSubscriptionTest.java |  6 +--
 .../controller/topology/TopologyBuilder.java    | 11 +++++-
 .../messaging/domain/topology/Member.java       |  9 +++++
 .../event/topology/InstanceSpawnedEvent.java    | 40 +++++---------------
 .../topology/InstanceSpawnedEventProcessor.java |  4 +-
 6 files changed, 39 insertions(+), 40 deletions(-)
----------------------------------------------------------------------