Repository: stratos
Updated Branches:
  refs/heads/master 403d5a45d -> 5c83cf817


Updating algorithms to use PartitionContext


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

Branch: refs/heads/master
Commit: 935faafea29c05a9dcf21dbb76696450f633305e
Parents: 403d5a4
Author: Lahiru Sandaruwan <[email protected]>
Authored: Mon Dec 1 00:37:57 2014 +0530
Committer: Lahiru Sandaruwan <[email protected]>
Committed: Mon Dec 1 00:37:57 2014 +0530

----------------------------------------------------------------------
 .../algorithm/AutoscaleAlgorithm.java           | 48 ++++++------
 .../autoscaler/algorithm/OneAfterAnother.java   | 24 +++---
 .../autoscaler/algorithm/RoundRobin.java        | 82 ++++----------------
 3 files changed, 49 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/935faafe/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 aa08581..c237c62 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
@@ -19,9 +19,7 @@
 
 package org.apache.stratos.autoscaler.algorithm;
 
-import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext;
-import 
org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext;
-import org.apache.stratos.cloud.controller.stub.domain.Partition;
+import org.apache.stratos.autoscaler.context.partition.PartitionContext;
 
 
 /**
@@ -30,33 +28,31 @@ import 
org.apache.stratos.cloud.controller.stub.domain.Partition;
  */
 public interface AutoscaleAlgorithm {
 
-    /**
-     * Returns whether there is available {@link Partition} to scale up 
considering the current count and maximum
-     * @param clusterId Id of the cluster which need the availability 
information
-     * @return availability of {@link Partition}s to scale up
-     */
-    public boolean scaleUpPartitionAvailable(String clusterId);
-
-    /**
-     * Returns whether there is available {@link Partition} to scale down 
considering the current count and minimum
-     * @param clusterId Id of the cluster which need the availability 
information
-     * @return availability of {@link Partition}s to scale down
-     */
-    public boolean scaleDownPartitionAvailable(String clusterId);
+//    /**
+//     * Returns whether there is available {@link Partition} to scale up 
considering the current count and maximum
+//     * @param clusterId Id of the cluster which need the availability 
information
+//     * @return availability of {@link Partition}s to scale up
+//     */
+//    public boolean scaleUpPartitionAvailable(String clusterId);
+//
+//    /**
+//     * Returns whether there is available {@link Partition} to scale down 
considering the current count and minimum
+//     * @param clusterId Id of the cluster which need the availability 
information
+//     * @return availability of {@link Partition}s to scale down
+//     */
+//    public boolean scaleDownPartitionAvailable(String clusterId);
 
     /**
-     * Returns a {@link Partition} to scale up from the given {@link 
org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.NetworkPartition}
 according to algorithm
-     * @param clusterInstanceContext {@link 
org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext}
 which need the {@link Partition}
-     * @param clusterId Id of the cluster which need the {@link Partition}
-     * @return {@link Partition} to scale up
+     * Returns a {@link PartitionContext} to scale up from the given list
+     * @param partitionContexts
+     * @return {@link PartitionContext} to scale up
      */
-    public Partition getNextScaleUpPartition(ClusterInstanceContext 
clusterInstanceContext, String clusterId);
+    public PartitionContext getNextScaleUpPartitionContext(PartitionContext[] 
partitionContexts);
 
     /**
-     * Returns a {@link Partition} to scale down from the given {@link 
org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.NetworkPartition}
 according to algorithm
-     * @param clusterInstanceContext {@link 
org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext}
 which need the {@link Partition}
-     * @param clusterId Id of the cluster which need the {@link Partition}
-     * @return {@link Partition} to scale down
+     * Returns a {@link PartitionContext} to scale down from the given list
+     * @param partitionContexts
+     * @return {@link PartitionContext} to scale down
      */
-    public Partition getNextScaleDownPartition(ClusterInstanceContext 
clusterInstanceContext, String clusterId);
+    public PartitionContext 
getNextScaleDownPartitionContext(PartitionContext[] partitionContexts);
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/935faafe/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 f900bb5..eaeb6dc 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
@@ -22,6 +22,7 @@ package org.apache.stratos.autoscaler.algorithm;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext;
+import org.apache.stratos.autoscaler.context.partition.PartitionContext;
 import 
org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext;
 import org.apache.stratos.cloud.controller.stub.domain.Partition;
 
@@ -137,24 +138,25 @@ public class OneAfterAnother implements 
AutoscaleAlgorithm {
     }
 */
 
-    @Override
-    public boolean scaleUpPartitionAvailable(String clusterId) {
-        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
-    }
-
-    @Override
-    public boolean scaleDownPartitionAvailable(String clusterId) {
-        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
-    }
+//    @Override
+//    public boolean scaleUpPartitionAvailable(String clusterId) {
+//        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+//    }
+//
+//    @Override
+//    public boolean scaleDownPartitionAvailable(String clusterId) {
+//        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+//    }
 
     @Override
-    public Partition getNextScaleUpPartition(ClusterInstanceContext 
clusterInstanceContext, String clusterId) {
+    public PartitionContext getNextScaleUpPartitionContext(PartitionContext[] 
partitionContexts) {
         return null;
     }
 
     @Override
-    public Partition getNextScaleDownPartition(ClusterInstanceContext 
clusterInstanceContext, String clusterId) {
+    public PartitionContext 
getNextScaleDownPartitionContext(PartitionContext[] partitionContexts) {
         return null;
     }
 
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/935faafe/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 202d0ea..df98a6b 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
@@ -22,6 +22,7 @@ package org.apache.stratos.autoscaler.algorithm;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext;
+import org.apache.stratos.autoscaler.context.partition.PartitionContext;
 import 
org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext;
 import org.apache.stratos.cloud.controller.stub.domain.Partition;
 
@@ -37,7 +38,8 @@ public class RoundRobin implements AutoscaleAlgorithm{
 
        private static final Log log = LogFactory.getLog(RoundRobin.class);
 
-    public Partition getNextScaleUpPartition(ClusterInstanceContext 
instanceContext, String clusterId){
+    @Override
+    public PartitionContext getNextScaleUpPartitionContext(PartitionContext[] 
partitionContexts){
         /*try{
 
             if (log.isDebugEnabled())
@@ -81,75 +83,19 @@ public class RoundRobin implements AutoscaleAlgorithm{
     return null;
     }
 
-
-       @Override
-    public Partition getNextScaleDownPartition(ClusterInstanceContext 
instanceContext, String clusterId) {
-        /*try{
-            if (log.isDebugEnabled())
-                log.debug(String.format("Searching for a partition to scale up 
[network partition] %s",
-                        clusterLevelNetworkPartitionContext.getId()))  ;
-            List<?> partitions = 
Arrays.asList(clusterLevelNetworkPartitionContext.getPartitions());
-            int noOfPartitions = partitions.size();
-
-            for (int i = 0; i < noOfPartitions; i++) {
-                int currentPartitionIndex = 
clusterLevelNetworkPartitionContext.getCurrentPartitionIndex();
-                // point to next partition
-                if (currentPartitionIndex == 0) {
-
-                    currentPartitionIndex = noOfPartitions - 1;
-                } else {
-
-                    currentPartitionIndex = currentPartitionIndex - 1;
-                }
-
-                // Set next partition as current partition in Autoscaler 
Context
-                
clusterLevelNetworkPartitionContext.setCurrentPartitionIndex(currentPartitionIndex);
-
-                if (partitions.get(currentPartitionIndex) instanceof 
Partition) {
-
-                    Partition currentPartition = (Partition) 
partitions.get(currentPartitionIndex);
-                    String currentPartitionId = currentPartition.getId();
-
-                    // has more than minimum instances.
-                    int currentlyActiveMemberCount = 
clusterLevelNetworkPartitionContext.getActiveMemberCount(currentPartitionId);
-                    if (currentlyActiveMemberCount > 
currentPartition.getPartitionMin()) {
-                        // current partition is free
-                        if (log.isDebugEnabled())
-                            log.debug(String.format("A free space found for 
scale down in partition %s [current] %s [min] %s",
-                                    currentPartitionId, 
currentlyActiveMemberCount, currentPartition.getPartitionMin()))  ;
-                        return currentPartition;
-                    }else {
-
-                        if (currentPartitionIndex == 0) {
-                            if (log.isDebugEnabled())
-                                log.debug(String.format("Partition %s reached 
with no space to scale down," +
-                                        "[current] %s [min] %s", 
currentPartitionId, currentlyActiveMemberCount,
-                                        currentPartition.getPartitionMin()));
-                            return null;
-                        }
-                    }
-                }
-            }
-
-            if (log.isDebugEnabled())
-                log.debug("No partition found for scale down at network 
partition " +
-                          clusterLevelNetworkPartitionContext.getId());
-            // none of the partitions were free.
-
-        } catch (Exception e) {
-            log.error("Error occurred while searching for next scale down 
partition", e);
-        }*/
+    @Override
+    public PartitionContext 
getNextScaleDownPartitionContext(PartitionContext[] partitionContexts) {
         return null;
     }
 
 
-    @Override
-    public boolean scaleUpPartitionAvailable(String clusterId) {
-        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
-    }
-
-    @Override
-    public boolean scaleDownPartitionAvailable(String clusterId) {
-        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
-    }
+//    @Override
+//    public boolean scaleUpPartitionContextAvailable(String clusterId) {
+//        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+//    }
+//
+//    @Override
+//    public boolean scaleDownPartitionContextAvailable(String clusterId) {
+//        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+//    }
 }

Reply via email to