Updated Branches:
  refs/heads/master 09f9165ca -> 417e18f42

Added a try catch block to one after another algorithm to trace any errors


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

Branch: refs/heads/master
Commit: 83b88803cff9a1218fdfc122dcfeb0adc425b599
Parents: 0063012
Author: Imesh Gunaratne <[email protected]>
Authored: Thu Dec 26 03:05:42 2013 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Thu Dec 26 03:05:42 2013 +0530

----------------------------------------------------------------------
 .../autoscaler/algorithm/OneAfterAnother.java   | 143 ++++++++++---------
 1 file changed, 73 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/83b88803/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 a10c4d0..1d69cbd 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
@@ -32,103 +32,106 @@ import java.util.List;
 /**
  *
  */
+
 /**
-* This class is used for selecting a {@link Partition} one after another and 
checking availability of
+ * This class is used for selecting a {@link Partition} one after another and 
checking availability of
  * partitions of a {@link NetworkPartitionContext}
  * One after another means it completes partitions in the order defined in
  * {@link org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy}, 
and go to next  if current one
  * reached the max limit
- *
-*/
+ */
 public class OneAfterAnother implements AutoscaleAlgorithm {
-       
-       private static final Log log = LogFactory.getLog(OneAfterAnother.class);
+
+    private static final Log log = LogFactory.getLog(OneAfterAnother.class);
 
     public Partition getNextScaleUpPartition(NetworkPartitionContext 
networkPartitionContext, String clusterId) {
+        try {
+            int currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
+            List<?> partitions = 
Arrays.asList(networkPartitionContext.getPartitions());
+            int noOfPartitions = partitions.size();
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Selecting a partition from 'One After 
Another' algorithm, " +
+                        "%s partitions in the [network partition]: %s ", 
noOfPartitions, networkPartitionContext.getId()));
+            }
 
-       int currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
-       List<?> partitions = 
Arrays.asList(networkPartitionContext.getPartitions());
-       int noOfPartitions = partitions.size();
-        if(log.isDebugEnabled()){
-            log.debug(String.format("Selecting a partition from 'One After 
Another' algorithm, " +
-                    "%s partitions in the [network partition]: %s ", 
noOfPartitions, networkPartitionContext.getId()));
-        }
-       
-       for(int i=currentPartitionIndex; i< noOfPartitions; i++)
-       {
-            if (partitions.get(currentPartitionIndex) instanceof Partition) {
-                currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
-                Partition currentPartition = (Partition) 
partitions.get(currentPartitionIndex);
-                String currentPartitionId = currentPartition.getId();
+            for (int i = currentPartitionIndex; i < noOfPartitions; i++) {
+                if (partitions.get(currentPartitionIndex) instanceof 
Partition) {
+                    currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
+                    Partition currentPartition = (Partition) 
partitions.get(currentPartitionIndex);
+                    String currentPartitionId = currentPartition.getId();
 
 //                if 
(networkPartitionContext.partitionCountExists(currentPartitionId)) {
 //                    
networkPartitionContext.addPartitionCount(currentPartitionId, 0);
 //                }
 
-                if 
(networkPartitionContext.getMemberCountOfPartition(currentPartitionId) < 
currentPartition.getPartitionMax()) {
-                    // current partition is free
+                    if 
(networkPartitionContext.getMemberCountOfPartition(currentPartitionId) < 
currentPartition.getPartitionMax()) {
+                        // current partition is free
 //                    
networkPartitionContext.increaseMemberCountOfPartition(currentPartitionId, 1);
-                    if (log.isDebugEnabled())
-                        log.debug("Free space found in partition " + 
currentPartition.getId());
-
-                    return currentPartition;
-                } else {
-                    // last partition is reached which is not free
-                    if (currentPartitionIndex == noOfPartitions - 1) {
                         if (log.isDebugEnabled())
-                            log.debug("Last partition also has no space");
-                        return null;
+                            log.debug("Free space found in partition " + 
currentPartition.getId());
+
+                        return currentPartition;
+                    } else {
+                        // last partition is reached which is not free
+                        if (currentPartitionIndex == noOfPartitions - 1) {
+                            if (log.isDebugEnabled())
+                                log.debug("Last partition also has no space");
+                            return null;
+                        }
+
+                        
networkPartitionContext.setCurrentPartitionIndex(currentPartitionIndex + 1);
                     }
-
-                    
networkPartitionContext.setCurrentPartitionIndex(currentPartitionIndex + 1);
                 }
             }
-       }
-       
-       if(log.isDebugEnabled())
-               log.debug("No free partition found at network partition " + 
networkPartitionContext);
-       
-       return null;
+
+            if (log.isDebugEnabled())
+                log.debug("No free partition found at network partition " + 
networkPartitionContext);
+        } catch (Exception e) {
+            log.error("Could not find next scale up partition", e);
+        }
+        return null;
     }
 
     public Partition getNextScaleDownPartition(NetworkPartitionContext 
networkPartitionContext, String clusterId) {
-
-       int currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
-       List<?> partitions = 
Arrays.asList(networkPartitionContext.getPartitions());
-       
-       for(int i = currentPartitionIndex; i >= 0; i--)
-       {
-            if (partitions.get(currentPartitionIndex) instanceof Partition) {
-                currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
-                Partition currentPartition = (Partition) 
partitions.get(currentPartitionIndex);
-                String currentPartitionId = currentPartition.getId();
-
-                // has more than minimum instances.
-                if 
(networkPartitionContext.getMemberCountOfPartition(currentPartitionId) > 
currentPartition.getPartitionMin()) {
-                    // current partition is free
+        try {
+            int currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
+            List<?> partitions = 
Arrays.asList(networkPartitionContext.getPartitions());
+
+            for (int i = currentPartitionIndex; i >= 0; i--) {
+                if (partitions.get(currentPartitionIndex) instanceof 
Partition) {
+                    currentPartitionIndex = 
networkPartitionContext.getCurrentPartitionIndex();
+                    Partition currentPartition = (Partition) 
partitions.get(currentPartitionIndex);
+                    String currentPartitionId = currentPartition.getId();
+
+                    // has more than minimum instances.
+                    if 
(networkPartitionContext.getMemberCountOfPartition(currentPartitionId) > 
currentPartition.getPartitionMin()) {
+                        // current partition is free
 //                    
networkPartitionContext.decreaseMemberCountOfPartition(currentPartitionId, 1);
-                    if (log.isDebugEnabled())
-                        log.debug("A free space found for scale down in 
partition" +
-                                  currentPartition.getId());
-                    return currentPartition;
-                } else {
-                    if (currentPartitionIndex == 0) {
                         if (log.isDebugEnabled())
-                            log.debug("First partition reached with no space 
to scale down");
-                        return null;
+                            log.debug("A free space found for scale down in 
partition" +
+                                    currentPartition.getId());
+                        return currentPartition;
+                    } else {
+                        if (currentPartitionIndex == 0) {
+                            if (log.isDebugEnabled())
+                                log.debug("First partition reached with no 
space to scale down");
+                            return null;
+                        }
+                        // Set next partition as current partition in 
Autoscaler Context
+                        currentPartitionIndex = currentPartitionIndex - 1;
+                        
networkPartitionContext.setCurrentPartitionIndex(currentPartitionIndex);
                     }
-                    // Set next partition as current partition in Autoscaler 
Context
-                    currentPartitionIndex = currentPartitionIndex - 1;
-                    
networkPartitionContext.setCurrentPartitionIndex(currentPartitionIndex);
                 }
+
             }
-               
-       }
-       if(log.isDebugEnabled())
-               log.debug("No space found in this network partition " + 
networkPartitionContext.getId());
-       return null;
+            if (log.isDebugEnabled())
+                log.debug("No space found in this network partition " + 
networkPartitionContext.getId());
+        } catch (Exception e) {
+            log.error("Could not find next scale down partition", e);
+        }
+        return null;
     }
-    
+
 
     @Override
     public boolean scaleUpPartitionAvailable(String clusterId) {
@@ -139,5 +142,5 @@ public class OneAfterAnother implements AutoscaleAlgorithm {
     public boolean scaleDownPartitionAvailable(String clusterId) {
         return false;  //To change body of implemented methods use File | 
Settings | File Templates.
     }
-    
+
 }

Reply via email to