You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/11/12 06:09:23 UTC
[1/2] git commit: Improving autoscaler rules implementation
Updated Branches:
refs/heads/master bc485e9a8 -> 5762983c6
Improving autoscaler rules implementation
Signed-off-by: Imesh Gunaratne <im...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/b18748fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/b18748fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/b18748fc
Branch: refs/heads/master
Commit: b18748fc349100d614f42290b892b457e5b26324
Parents: d978cc4
Author: Melan Nimesh <me...@gmail.com>
Authored: Tue Nov 12 10:23:55 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue Nov 12 10:38:25 2013 +0530
----------------------------------------------------------------------
.../stratos/autoscaler/ClusterContext.java | 58 ++--
.../algorithm/AutoscaleAlgorithm.java | 14 +-
.../autoscaler/algorithm/OneAfterAnother.java | 260 +++++++++--------
.../autoscaler/algorithm/RoundRobin.java | 280 ++++++++++---------
.../policy/deployers/PolicyReader.java | 2 -
.../autoscaler/policy/model/Partition.java | 53 ----
.../rule/AutoscalerRuleEvaluator.java | 24 ++
.../stratos/autoscaler/util/AutoscalerUtil.java | 75 +++++
.../src/main/resources/autoscaler.drl | 185 ++++--------
.../distribution/src/main/assembly/bin.xml | 9 +
.../src/main/policies/economyPolicy.xml | 35 +++
11 files changed, 514 insertions(+), 481 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/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 152afab..764d759 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
@@ -41,7 +41,7 @@ public class ClusterContext {
private int memberCount;
//This map will keep number of instance count against partitionId
-// TODO private Map<String, Integer> partitionCountMap;
+ private Map<String, Integer> partitionCountMap;
private int currentPartitionIndex;
@@ -54,7 +54,7 @@ public class ClusterContext {
this.clusterId = clusterId;
this.serviceId = serviceId;
memberContextMap = new HashMap<String, MemberContext>();
- //TODO partitionCountMap = new HashMap<String, Integer>();
+ partitionCountMap = new HashMap<String, Integer>();
memberCount = 0;
}
@@ -129,33 +129,33 @@ public class ClusterContext {
}
-// TODO public void increaseMemberCountInPartition(String partitionId, int count){
-//
-// partitionCountMap.put(partitionId, partitionCountMap.get(partitionId) + count);
-// }
-//
-// public void decreaseMemberCountInPartition(String partitionId, int count){
-//
-// partitionCountMap.put(partitionId, partitionCountMap.get(partitionId) - count);
-// }
-//
-// public void addPartitionCount(String partitionId, int count){
-//
-// partitionCountMap.put(partitionId, count);
-// }
-//
-// public void removePartitionCount(String partitionId){
-//
-// partitionCountMap.remove(partitionId);
-// }
-//
-// public boolean partitionCountExists(String partitionId){
-// return partitionCountMap.containsKey(partitionId);
-// }
-//
-// public int getPartitionCount(String partitionId){
-// return partitionCountMap.get(partitionId);
-// }
+ public void increaseMemberCountInPartition(String partitionId, int count){
+
+ partitionCountMap.put(partitionId, partitionCountMap.get(partitionId) + count);
+ }
+
+ public void decreaseMemberCountInPartition(String partitionId, int count){
+
+ partitionCountMap.put(partitionId, partitionCountMap.get(partitionId) - count);
+ }
+
+ public void addPartitionCount(String partitionId, int count){
+
+ partitionCountMap.put(partitionId, count);
+ }
+
+ public void removePartitionCount(String partitionId){
+
+ partitionCountMap.remove(partitionId);
+ }
+
+ public boolean partitionCountExists(String partitionId){
+ return partitionCountMap.containsKey(partitionId);
+ }
+
+ public int getPartitionCount(String partitionId){
+ return partitionCountMap.get(partitionId);
+ }
public void setMemberContextMap(Map<String, MemberContext> memberContextMap) {
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/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 8bccfe5..043fc7f 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,14 +19,16 @@
package org.apache.stratos.autoscaler.algorithm;
+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);
+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/b18748fc/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 92329cf..a113300 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
@@ -19,126 +19,142 @@
package org.apache.stratos.autoscaler.algorithm;
+import org.apache.stratos.autoscaler.AutoscalerContext;
+import org.apache.stratos.autoscaler.ClusterContext;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+import org.apache.stratos.autoscaler.policy.PolicyManager;
+import org.apache.stratos.autoscaler.policy.model.Partition;
+
/**
-* Completes partitions in the order defined in autoscaler policy, go to next if current one reached the max limit
-*/
-public class OneAfterAnother implements AutoscaleAlgorithm{
-
-// public Partition getNextScaleUpPartition(String clusterId){
-//
-// String policyId = null;
-// 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();
-//
-//
-// 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
-// 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;
-// }
-//
-// public Partition getNextScaleDownPartition(String clusterId){
-//
-// String policyId = null;
-// int nextPartitionIndex;
-// Partition nextPartition = null;
-// 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();
-//
-// //Find number of partitions relevant for this clusters policy
-// 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
-// nextPartitionIndex = currentPartitionIndex;
-//
-// //Set next partition as current partition in Autoscaler Context
-// AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex);
-//
-// //Find next partition
-// nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions()
-// .get(nextPartitionIndex);
-// String nextPartitionId = nextPartition.getId();
-//
-// if(clusterContext.partitionCountExists(nextPartitionId) &&
-// (clusterContext.getPartitionCount(nextPartitionId) <= nextPartition.getPartitionMembersMin())){
-//
-// //If the current partitions max is reached, it will try next partition
-// nextPartition = getNextScaleDownPartition(clusterId);
-// } else {
-//
-// }
-// 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;
-// }
-//
-//
-//
-// 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;
-// }
-}
\ No newline at end of file
+ * Completes partitions in the order defined in autoscaler policy, go to next if current one reached the max limit
+ */
+public class OneAfterAnother implements AutoscaleAlgorithm {
+
+ public Partition getNextScaleUpPartition(String clusterId) {
+
+ String policyId = null;
+ 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();
+
+
+ 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
+ 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;
+ }
+
+ public Partition getNextScaleDownPartition(String clusterId) {
+
+ String policyId = null;
+ int nextPartitionIndex;
+ Partition nextPartition = null;
+ 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();
+
+ //Find number of partitions relevant for this clusters policy
+ 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
+ nextPartitionIndex = currentPartitionIndex;
+
+ //Set next partition as current partition in Autoscaler Context
+ AutoscalerContext.getInstance().getClusterContext(clusterId).setCurrentPartitionIndex(nextPartitionIndex);
+
+ //Find next partition
+ nextPartition = PolicyManager.getInstance().getPolicy(policyId).getHAPolicy().getPartitions()
+ .get(nextPartitionIndex);
+ String nextPartitionId = nextPartition.getId();
+
+ if (clusterContext.partitionCountExists(nextPartitionId) &&
+ (clusterContext.getPartitionCount(nextPartitionId) <= nextPartition.getPartitionMembersMin())) {
+
+ //If the current partitions max is reached, it will try next partition
+ nextPartition = getNextScaleDownPartition(clusterId);
+ } else {
+
+ }
+ 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;
+ }
+
+ @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.
+ }
+
+
+ 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/b18748fc/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 e62affe..ebfcb2a 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
@@ -19,147 +19,149 @@
package org.apache.stratos.autoscaler.algorithm;
+import org.apache.stratos.autoscaler.AutoscalerContext;
+import org.apache.stratos.autoscaler.ClusterContext;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+import org.apache.stratos.autoscaler.policy.PolicyManager;
+import org.apache.stratos.autoscaler.policy.model.Partition;
+
/**
* Select partition in round robin manner and return
*/
public class RoundRobin implements AutoscaleAlgorithm{
-// public Partition getNextScaleUpPartition(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();
-//
-//
-// 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;
-// }
-//
-//
-// 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();
-//
-//
-// 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)
-// && (clusterContext.getPartitionCount(nextPartitionId) <= nextPartition.getPartitionMembersMin())){
-//
-//
-// //If the current partitions max is reached, it will try next partition
-// nextPartition = getNextScaleDownPartition(clusterId);
-// }
-// return nextPartition;
-// }
-
-
-// public Partition getScaleDownPartition(String clusterId){
-// Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
-// .get(0);
-//
-// ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-// int partitionMemberCount = clusterContext.getPartitionCount(partition.getId());
-//
-// if(partitionMemberCount >= partition.getPartitionMembersMin()) {
-//
-// clusterContext.increaseMemberCountInPartition(partition.getId(), partitionMemberCount - 1);
-// } else{
-// partition = null;
-// }
-// return partition;
-// }
-
-
-// @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.
-// } partition = null;
-// }
-//
-// return partition;
-// }
-
-
-
-// public Partition getScaleUpPartition(String clusterId){
-// Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
-// .get(0);
-//
-// ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
-// int partitionMemberCount = clusterContext.getPartitionCount(partition.getId());
-//
-// if(partitionMemberCount <= partition.getPartitionMembersMax()) {
-//
-// clusterContext.increaseMemberCountInPartition(partition.getId(), partitionMemberCount + 1);
-// } else{
-// partition = null;
-// }
-//
-// return partition;
-// }
-}
\ No newline at end of file
+ public Partition getNextScaleUpPartition(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();
+
+
+ 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;
+ }
+
+
+ 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();
+
+
+ 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)
+ && (clusterContext.getPartitionCount(nextPartitionId) <= nextPartition.getPartitionMembersMin())){
+
+
+ //If the current partitions max is reached, it will try next partition
+ nextPartition = getNextScaleDownPartition(clusterId);
+ }
+ return nextPartition;
+ }
+
+
+ public Partition getScaleDownPartition(String clusterId){
+ Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
+ .get(0);
+
+ ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
+ int partitionMemberCount = clusterContext.getPartitionCount(partition.getId());
+
+ if(partitionMemberCount >= partition.getPartitionMembersMin()) {
+
+ clusterContext.increaseMemberCountInPartition(partition.getId(), partitionMemberCount - 1);
+ } else{
+ partition = null;
+ }
+ return partition;
+ }
+
+
+ @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.
+ }
+
+
+
+ public Partition getScaleUpPartition(String clusterId){
+ Partition partition = PolicyManager.getInstance().getPolicy("economyPolicy").getHAPolicy().getPartitions()
+ .get(0);
+
+ ClusterContext clusterContext = AutoscalerContext.getInstance().getClusterContext(clusterId);
+ int partitionMemberCount = clusterContext.getPartitionCount(partition.getId());
+
+ if(partitionMemberCount <= partition.getPartitionMembersMax()) {
+
+ clusterContext.increaseMemberCountInPartition(partition.getId(), partitionMemberCount + 1);
+ } else{
+ partition = null;
+ }
+
+ return partition;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/PolicyReader.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/PolicyReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/PolicyReader.java
index 42f77cd..67d0154 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/PolicyReader.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/PolicyReader.java
@@ -132,8 +132,6 @@ public class PolicyReader {
if(next instanceof OMElement){
OMElement partitionEle = (OMElement) next;
Partition partition = new Partition();
- partition.setIaas(partitionEle.getAttributeValue(new QName("iaas")));
- partition.setZone(partitionEle.getAttributeValue(new QName("zone")));
partition.setId(partitionEle.getAttributeValue(new QName("id")));
partition.setPartitionMax(Integer.valueOf(readValue(partitionEle, "PartitionMax")));
partition.setPartitionMin(Integer.valueOf(readValue(partitionEle, "PartitionMin")));
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/Partition.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/Partition.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/Partition.java
index d8cb78d..e65dd05 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/Partition.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/Partition.java
@@ -27,10 +27,6 @@ public class Partition {
private int partitionMax;
private int partitionMin;
private String id;
- private String iaas;
- private String zone;
- private boolean maxReached;
- private boolean minReached;
/**
@@ -64,55 +60,6 @@ public class Partition {
public void setPartitionMin(int value) {
this.partitionMin = value;
}
-
- /**
- * Gets the value of the iaas property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getIaas() {
- return iaas;
- }
-
- /**
- * Sets the value of the iaas property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setIaas(String value) {
- this.iaas = value;
- }
-
- /**
- * Gets the value of the zone property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getZone() {
- return zone;
- }
-
- /**
- * Sets the value of the zone property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setZone(String value) {
- this.zone = value;
- }
-
/**
* Gets the value of the id property.
*
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java
index 209db3b..ef1b568 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java
@@ -33,6 +33,12 @@ import org.drools.builder.*;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
+import org.apache.stratos.autoscaler.Constants;
+import org.apache.stratos.autoscaler.algorithm.AutoscaleAlgorithm;
+import org.apache.stratos.autoscaler.algorithm.OneAfterAnother;
+import org.apache.stratos.autoscaler.algorithm.RoundRobin;
+import org.apache.stratos.autoscaler.util.AutoscalerUtil;
+import org.apache.stratos.messaging.domain.topology.Cluster;
/**
* This class is responsible for evaluating the current details of topology, statistics, and health
@@ -61,6 +67,11 @@ public class AutoscalerRuleEvaluator {
public void evaluate(Service service){
try {
+ for (Cluster cluster: service.getClusters()){
+ //update cluster-context
+ AutoscalerUtil.updateClusterContext(cluster);
+ }
+
ksession = kbase.newStatefulKnowledgeSession();
ksession.setGlobal("$context", AutoscalerContext.getInstance());
ksession.setGlobal("log", log);
@@ -147,4 +158,17 @@ public class AutoscalerRuleEvaluator {
return kbase;
}
+ public AutoscaleAlgorithm getAutoscaleAlgorithm(String partitionAlgorithm){
+ AutoscaleAlgorithm autoscaleAlgorithm = null;
+ if(Constants.ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)){
+
+ autoscaleAlgorithm = new RoundRobin();
+ } else if(Constants.ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)){
+
+ autoscaleAlgorithm = new OneAfterAnother();
+ }
+ return autoscaleAlgorithm;
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
new file mode 100644
index 0000000..7f4468d
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.autoscaler.util;
+
+import org.apache.stratos.autoscaler.AutoscalerContext;
+import org.apache.stratos.autoscaler.ClusterContext;
+import org.apache.stratos.autoscaler.policy.PolicyManager;
+import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
+import org.apache.stratos.autoscaler.policy.model.LoadThresholds;
+import org.apache.stratos.autoscaler.policy.model.Partition;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+
+/**
+ * This class contains utility methods used by Autoscaler.
+ */
+public class AutoscalerUtil {
+
+ private AutoscalerUtil() {
+
+ }
+
+ /**
+ * Updates ClusterContext for given cluster
+ * @param cluster
+ * @return ClusterContext - Updated ClusterContext
+ */
+ public static ClusterContext updateClusterContext(Cluster cluster) {
+ AutoscalerContext context = AutoscalerContext.getInstance();
+ ClusterContext clusterContext = context.getClusterContext(cluster.getClusterId());
+ if (null == clusterContext) {
+
+ clusterContext = new ClusterContext(cluster.getClusterId(), cluster.getServiceName());
+ AutoscalePolicy policy = PolicyManager.getInstance().getPolicy(cluster.getAutoscalePolicyName());
+
+ if(policy!=null){
+
+ //get values from policy
+ LoadThresholds loadThresholds = policy.getLoadThresholds();
+ float averageLimit = loadThresholds.getRequestsInFlight().getAverage();
+ float gradientLimit = loadThresholds.getRequestsInFlight().getGradient();
+ float secondDerivative = loadThresholds.getRequestsInFlight().getSecondDerivative();
+
+
+ clusterContext.setRequestsInFlightGradient(gradientLimit);
+ clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+ clusterContext.setAverageRequestsInFlight(averageLimit);
+
+ for (Partition partition : policy.getHAPolicy().getPartitions()) {
+ clusterContext.addPartitionCount(partition.getId(), 0);
+ }
+ }
+
+ context.addClusterContext(clusterContext);
+ }
+ return clusterContext;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/components/org.apache.stratos.autoscaler/src/main/resources/autoscaler.drl
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/resources/autoscaler.drl b/components/org.apache.stratos.autoscaler/src/main/resources/autoscaler.drl
index 86341e2..1f8b509 100644
--- a/components/org.apache.stratos.autoscaler/src/main/resources/autoscaler.drl
+++ b/components/org.apache.stratos.autoscaler/src/main/resources/autoscaler.drl
@@ -44,146 +44,71 @@ global org.apache.commons.logging.Log log;
global org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator $evaluator;
global org.apache.stratos.messaging.domain.topology.Topology $topology;
+
rule "Minimum Rule"
dialect "mvel"
-
when
$service : Service ()
- cluster : Cluster () from $service.getClusters()
- $policy : AutoscalePolicy(id == cluster.autoscalePolicyName ) from $manager.getPolicyList()
+ $cluster : Cluster () from $service.getClusters()
+ $policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
$partition : Partition () from $policy.getHAPolicy().getPartitions()
-
+ $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+ eval($clusterContext.getPartitionCount($partition.getId()) < $partition.getPartitionMembersMin() )
then
- String clusterId = cluster.getClusterId();
-
- ClusterContext clusterContext = $context.getClusterContext(clusterId);
-
- if(null==clusterContext){
-
- //get values from policy
- LoadThresholds loadThresholds = $policy.getLoadThresholds();
- float averageLimit = loadThresholds.getRequestsInFlight().getAverage();
- float gradientLimit = loadThresholds.getRequestsInFlight().getGradient();
- float secondDerivative = loadThresholds.getRequestsInFlight().getSecondDerivative();
-
- clusterContext = new ClusterContext(clusterId, cluster.getServiceName()) ;
-
- clusterContext.setRequestsInFlightGradient(gradientLimit);
- clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
- clusterContext.setAverageRequestsInFlight(averageLimit);
-
- AutoscalePolicy policy = PolicyManager.getInstance().getPolicy(cluster.getAutoscalePolicyName());
-
- //for(Partition partition: $policy.getHAPolicy().getPartitions()){
- // clusterContext.addPartitionCount(partition.getId(), 0);
- //}
- $context.addClusterContext(clusterContext);
- }
-
- //int currentMemberCount = clusterContext.getPartitionCount($partition.getId());
- int currentMemberCount = clusterContext.getMemberCount();
- int partitionMin = $partition.getPartitionMembersMin();
-
- if(currentMemberCount < partitionMin) {
-
- int memberCountToBeIncreased = partitionMin - currentMemberCount;
- if($evaluator.delegateSpawn($partition,clusterId, memberCountToBeIncreased)){
- }
-
+ int memberCountToBeIncreased = $partition.getPartitionMembersMin() - $clusterContext.getPartitionCount($partition.getId());
+ if($evaluator.delegateSpawn($partition,$cluster.getClusterId(), memberCountToBeIncreased)){
+ $clusterContext.increaseMemberCountInPartition($partition.getId(), memberCountToBeIncreased);
}
-
-
end
-rule "Autoscaler Rule"
- dialect "mvel"
+rule "Scaler-up Rule"
+dialect "mvel"
when
$service : Service ()
- cluster : Cluster () from $service.getClusters()
- $policy : AutoscalePolicy(id == cluster.autoscalePolicyName ) from $manager.getPolicyList()
-
+ $cluster : Cluster () from $service.getClusters()
+ $policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+ $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+ $loadThresholds :LoadThresholds() from $policy.getLoadThresholds()
+ autoscaleAlgorithm : AutoscaleAlgorithm() from $evaluator.getAutoscaleAlgorithm($policy.getHAPolicy().getPartitionAlgo())
+ lbStatAverage : Float() from $clusterContext.getAverageRequestsInFlight()
+ lbStatGradient : Float() from $clusterContext.getRequestsInFlightGradient()
+ lbStatSecondDerivative : Float() from $clusterContext.getRequestsInFlightSecondDerivative()
+ averageLimit : Float() from $loadThresholds.getRequestsInFlight().getAverage()
+ gradientLimit : Float() from $loadThresholds.getRequestsInFlight().getGradient()
+ secondDerivative : Float() from $loadThresholds.getRequestsInFlight().getSecondDerivative()
+ partition : Partition() from autoscaleAlgorithm.getNextScaleUpPartition($cluster.getClusterId())
+ eval (lbStatAverage > averageLimit && lbStatGradient > gradientLimit)
then
+ int numberOfInstancesToBeSpawned = (lbStatSecondDerivative > secondDerivative) ? 2 : 1; // take from a config
+ $evaluator.delegateSpawn(partition,$cluster.getClusterId(), numberOfInstancesToBeSpawned);
+ $clusterContext.setRequestsInFlightGradient(gradientLimit);
+ $clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+ $clusterContext.setAverageRequestsInFlight(averageLimit);
+end
- String clusterId = cluster.getClusterId();
-
- LoadThresholds loadThresholds = $policy.getLoadThresholds();
- float averageLimit = loadThresholds.getRequestsInFlight().getAverage();
- float gradientLimit = loadThresholds.getRequestsInFlight().getGradient();
- float secondDerivative = loadThresholds.getRequestsInFlight().getSecondDerivative();
-
- ClusterContext clusterContext = $context.getClusterContext(clusterId);
-
- if(null==clusterContext){
-
- clusterContext = new ClusterContext(cluster.getClusterId(), cluster.getServiceName()) ;
-
-
- clusterContext.setRequestsInFlightGradient(gradientLimit);
- clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
- clusterContext.setAverageRequestsInFlight(averageLimit);
-
- //for(Partition partition: $policy.getHAPolicy().getPartitions()){
- // clusterContext.addPartitionCount(partition.getId(), 0);
- //}
- $context.addClusterContext(clusterContext);
-
- }
-
- //get current stats from cluster context
- float lbStatAverage = clusterContext.getAverageRequestsInFlight();
- float lbStatGradient = clusterContext.getRequestsInFlightGradient();
- float lbStatSecondDerivative = clusterContext.getRequestsInFlightSecondDerivative();
-
- //get values from policy
- LoadThresholds loadThresholds = $manager.getPolicy(cluster.autoscalePolicyName).getLoadThresholds();
- float averageLimit = loadThresholds.getRequestsInFlight().getAverage();
- float gradientLimit = loadThresholds.getRequestsInFlight().getGradient();
- float secondDerivative = loadThresholds.getRequestsInFlight().getSecondDerivative()
- //String partitionAlgorithm = $manager.getPolicy(cluster.autoscalePolicyName).getHAPolicy().getPartitionAlgo();
-
-
- //AutoscaleAlgorithm autoscaleAlgorithm = null;
- //if(Constants.ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)){
-
- // autoscaleAlgorithm = new RoundRobin();
- //} else if(Constants.ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)){
-
- // autoscaleAlgorithm = new OneAfterAnother();
- //}
-
- float scaleDownSlowerMarginOfGradient = 1.0; //TODO get from config
- float scaleDownSlowerMarginOfSecondDerivative = 0.2; //TODO get from config
-
- Partition partition = $policy.getHAPolicy().getPartitions().get(0);
-
- if(lbStatAverage > averageLimit && lbStatGradient > gradientLimit && lbStatSecondDerivative > secondDerivative){
-
- int i = 0;
- //TODO Partition partition = autoscaleAlgorithm.getScaleUpPartition(clusterId);
-
- if(partition != null){
-
- $evaluator.delegateSpawn(partition,clusterId);
-
- clusterContext.setRequestsInFlightGradient(gradientLimit);
- clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
- clusterContext.setAverageRequestsInFlight(averageLimit);
- //spawnInstances One
-
- }
- } else if(lbStatAverage < averageLimit && lbStatGradient < gradientLimit - scaleDownSlowerMarginOfSecondDerivative
- && lbStatSecondDerivative < secondDerivative - scaleDownSlowerMarginOfSecondDerivative){
-
- //terminate one
- //TODO Partition partition = autoscaleAlgorithm.getScaleDownPartition(clusterId);
- if(partition != null){
- $evaluator.delegateTerminate(partition,clusterId);
-
- clusterContext.setRequestsInFlightGradient(gradientLimit);
- clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
- clusterContext.setAverageRequestsInFlight(averageLimit);
- }
- }
-
-
-end
\ No newline at end of file
+rule "Scaler-down Rule"
+dialect "mvel"
+ when
+ $service : Service ()
+ $cluster : Cluster () from $service.getClusters()
+ $policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+ $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+ $loadThresholds :LoadThresholds() from $policy.getLoadThresholds()
+ autoscaleAlgorithm : AutoscaleAlgorithm() from $evaluator.getAutoscaleAlgorithm($policy.getHAPolicy().getPartitionAlgo())
+ lbStatAverage : Float() from $clusterContext.getAverageRequestsInFlight()
+ lbStatGradient : Float() from $clusterContext.getRequestsInFlightGradient()
+ lbStatSecondDerivative : Float() from $clusterContext.getRequestsInFlightSecondDerivative()
+ averageLimit : Float() from $loadThresholds.getRequestsInFlight().getAverage()
+ gradientLimit : Float() from $loadThresholds.getRequestsInFlight().getGradient()
+ secondDerivative : Float() from $loadThresholds.getRequestsInFlight().getSecondDerivative()
+ scaleDownSlowerMarginOfGradient : Float() from $loadThresholds.getRequestsInFlight().getScaleDownMarginOfGradient()
+ scaleDownSlowerMarginOfSecondDerivative : Float() from $loadThresholds.getRequestsInFlight().getScaleDownMarginOfSecondDerivative()
+ partition : Partition() from autoscaleAlgorithm.getNextScaleDownPartition($cluster.getClusterId())
+ eval(lbStatAverage < averageLimit && lbStatGradient < gradientLimit - scaleDownSlowerMarginOfSecondDerivative
+ && lbStatSecondDerivative < secondDerivative - scaleDownSlowerMarginOfSecondDerivative)
+ then
+ $evaluator.delegateTerminate(partition,$cluster.getClusterId());
+ $clusterContext.setRequestsInFlightGradient(gradientLimit);
+ $clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+ $clusterContext.setAverageRequestsInFlight(averageLimit);
+end
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/assembly/bin.xml b/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
index 614b9f8..a7c21ba 100644
--- a/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
+++ b/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
@@ -170,6 +170,15 @@
<include>**/patch0002/axis2_1.6.1.wso2v9.jar</include>
</includes>
</fileSet>
+
+ <fileSet>
+ <directory>src/main/policies</directory>
+ <outputDirectory>apache-stratos-autoscaler-${pom.version}/repository/deployment/server/policies</outputDirectory>
+ <directoryMode>0755</directoryMode>
+ <includes>
+ <include>*.xml</include>
+ </includes>
+ </fileSet>
</fileSets>
<dependencySets>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b18748fc/products/autoscaler/modules/distribution/src/main/policies/economyPolicy.xml
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/policies/economyPolicy.xml b/products/autoscaler/modules/distribution/src/main/policies/economyPolicy.xml
new file mode 100644
index 0000000..2a82964
--- /dev/null
+++ b/products/autoscaler/modules/distribution/src/main/policies/economyPolicy.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<AutoscalePolicy id="economyPolicy">
+ <LoadThresholds>
+ <RequestsInFlight>
+ <Average value="20" />
+ <Gradient value="1" />
+ <SecondDerivative value="0" />
+ <ScaleDownMarginOfGradient value="1.0" />
+ <ScaleDownMarginOfSecondDerivative value="0.2" />
+ </RequestsInFlight>
+ <MemoryConsumption>
+ <Average value="20" />
+ <Gradient value="1" />
+ <SecondDerivative value="0" />
+ <ScaleDownMarginOfGradient value="1.0" />
+ <ScaleDownMarginOfSecondDerivative value="0.2" />
+ </MemoryConsumption>
+ <LoadAverage>
+ <Average value="20" />
+ <Gradient value="1" />
+ <SecondDerivative value="0" />
+ <ScaleDownMarginOfGradient value="1.0" />
+ <ScaleDownMarginOfSecondDerivative value="0.2" />
+ </LoadAverage>
+ </LoadThresholds>
+ <HAPolicy>
+ <PartitionAlgo>one-after-another</PartitionAlgo>
+ <Partitions>
+ <Partition id="part1">
+ <PartitionMax>3</PartitionMax>
+ <PartitionMin>1</PartitionMin>
+ </Partition>
+ </Partitions>
+ </HAPolicy>
+</AutoscalePolicy>
[2/2] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-stratos
Posted by im...@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/5762983c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/5762983c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/5762983c
Branch: refs/heads/master
Commit: 5762983c65b0df688a19a887a88e8e391e8b5ffd
Parents: b18748f bc485e9
Author: Imesh Gunaratne <im...@apache.org>
Authored: Tue Nov 12 10:39:03 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue Nov 12 10:39:03 2013 +0530
----------------------------------------------------------------------
.../cloud/controller/CloudControllerClient.java | 31 +--
.../internal/AutoscalerServerComponent.java | 88 +++++----
.../message/receiver/TopologyManager.java | 71 -------
.../health/HealthEventMessageDelegator.java | 2 +-
.../topology/TopologyEventMessageDelegator.java | 110 -----------
.../topology/TopologyEventMessageReceiver.java | 56 ------
.../receiver/topology/TopologyEventQueue.java | 44 -----
.../rule/AutoscalerRuleEvaluator.java | 2 +-
.../autoscaler/rule/ExecutorTaskScheduler.java | 36 ++--
.../controller/deployers/CartridgeDeployer.java | 19 +-
.../cloud/controller/iaases/AWSEC2Iaas.java | 6 +-
.../controller/iaases/OpenstackNovaIaas.java | 7 +-
.../cloud/controller/iaases/VCloudIaas.java | 22 +--
.../impl/CloudControllerServiceImpl.java | 197 +++++++++----------
.../interfaces/CloudControllerService.java | 30 +--
.../cloud/controller/interfaces/Iaas.java | 2 +
.../controller/topology/TopologyBuilder.java | 2 +-
.../stratos/cloud/controller/util/Host.java | 31 ++-
.../stratos/cloud/controller/util/Region.java | 23 +--
.../cloud/controller/util/ServiceContext.java | 22 ++-
.../stratos/cloud/controller/util/Zone.java | 30 ++-
.../distribution/src/main/conf/log4j.properties | 2 +
.../cartridge-agent/ec2/php/cartridge-agent.sh | 35 +++-
.../event/subscriber/ArtifactListener.java | 20 +-
.../cartridge/agent/event/subscriber/Main.java | 46 +----
.../main/resources/CloudControllerService.wsdl | 113 ++++-------
26 files changed, 386 insertions(+), 661 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5762983c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java
----------------------------------------------------------------------