Adding dependent-scaling.drl to test
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c3dffc30 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c3dffc30 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c3dffc30 Branch: refs/heads/master Commit: c3dffc30e1ab57cdedd41bb8205d8a1eed65b16d Parents: ef636ec Author: Lahiru Sandaruwan <[email protected]> Authored: Wed Dec 3 21:57:01 2014 +0530 Committer: Lahiru Sandaruwan <[email protected]> Committed: Wed Dec 3 21:57:01 2014 +0530 ---------------------------------------------------------------------- .../stratos/autoscaler/TestRulesPackaged.java | 8 +- .../src/main/conf/drools/dependent-scaling.drl | 119 ------------------- 2 files changed, 4 insertions(+), 123 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/c3dffc30/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestRulesPackaged.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestRulesPackaged.java b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestRulesPackaged.java index 0826140..48c349e 100644 --- a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestRulesPackaged.java +++ b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestRulesPackaged.java @@ -45,10 +45,10 @@ public class TestRulesPackaged { } //FIXME add this when dependent scaling file is completed -// @Test -// public void testDependentScalingDroolsFile() { -// parseDroolsFile(dependentScalingDrlFilePath); -// } + @Test + public void testDependentScalingDroolsFile() { + parseDroolsFile(dependentScalingDrlFilePath); + } @Test public void testScalingDroolsFile() { http://git-wip-us.apache.org/repos/asf/stratos/blob/c3dffc30/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl index 383bb2e..3b4fe96 100644 --- a/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl +++ b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl @@ -19,132 +19,13 @@ package org.apache.stratos.autoscaler.rule; -import org.apache.stratos.messaging.domain.topology.Service; -import org.apache.stratos.messaging.domain.topology.Cluster; -import org.apache.stratos.autoscaler.context.AutoscalerContext; -import org.apache.stratos.autoscaler.context.member.MemberStatsContext; -import org.apache.stratos.autoscaler.Constants; -import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext; -import org.apache.stratos.autoscaler.pojo.policy.PolicyManager; -import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy; -import org.apache.stratos.autoscaler.client.CloudControllerClient; -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.context.partition.ClusterLevelPartitionContext; -import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; -import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.NetworkPartition; -import org.apache.stratos.cloud.controller.domain.xsd.Partition; -import org.apache.stratos.cloud.controller.domain.xsd.MemberContext; - -import org.apache.stratos.autoscaler.pojo.policy.autoscale.LoadAverage -import org.apache.stratos.autoscaler.pojo.policy.autoscale.MemoryConsumption - -global org.apache.stratos.autoscaler.rule.RuleLog log; -global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; -global org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy autoscalePolicy; -global java.lang.String clusterId; -global java.lang.String instanceId; -global java.lang.Float laReset; -global java.lang.Float numberOfRequiredInstances; -global java.lang.Boolean isPrimary; -global java.lang.String lbRef; -global java.util.List primaryMembers; - rule "Dependent Scaling Rule" dialect "mvel" when - networkPartitionContext : ClusterLevelNetworkPartitionContext () - algorithmName : String() from networkPartitionContext.getPartitionAlgorithm(); - autoscaleAlgorithm : AutoscaleAlgorithm() from $delegator.getAutoscaleAlgorithm(algorithmName) - - roundedRequiredInstanceCount : Integer() from networkPartitionContext.getRequiredInstanceCountBasedOnDependencies(); - activeInstancesCount : Integer() from $delegator.getMemberCount(clusterId , 0); - - scaleUp : Boolean() from (activeInstancesCount < roundedRequiredInstanceCount ) - scaleDown : Boolean() from (activeInstancesCount > roundedRequiredInstanceCount ) - - eval(log.debug("[dependent-scaling] " + " [cluster] " + clusterId + " Scale-up action: " + scaleUp)) - eval(log.debug("[dependent-scaling] " + " [cluster] " + clusterId + " Scale-down action: " + scaleDown)) then - if(scaleUp){ - - int additionalInstances = roundedRequiredInstanceCount - activeInstancesCount ; - int count = 0; - while(count != additionalInstances){ - Partition partition = autoscaleAlgorithm.getNextScaleUpPartition(networkPartitionContext, clusterId); - if(partition != null){ - log.info("[scale-up] Partition available, hence trying to spawn an instance to scale up!" ); - log.debug("[scale-up] " + " [partition] " + partition.getId() + " [cluster] " + clusterId ); - $delegator.delegateSpawn(networkPartitionContext.getPartitionCtxt(partition.getId()), clusterId, instanceId, lbRef, isPrimary); - count++; - } - } - } else if(scaleDown){ - - log.debug("[scale-down] Decided to Scale down [cluster] " + clusterId); - - MemberStatsContext selectedMemberStatsContext = null; - double lowestOverallLoad = 0.0; - boolean foundAValue = false; - Partition partition = autoscaleAlgorithm.getNextScaleDownPartition(networkPartitionContext, clusterId); - if(partition != null){ - log.info("[scale-down] Partition available to scale down "); - log.debug("[scale-down] " + " [partition] " + partition.getId() + " [cluster] " + clusterId); - partitionContext = networkPartitionContext.getPartitionCtxt(partition.getId()); - - - // In partition context member stat context, all the primary members need to be - // avoided being selected as the member to terminated - - for(MemberStatsContext memberStatsContext: partitionContext.getMemberStatsContexts().values()){ - - if( !primaryMembers.contains(memberStatsContext.getMemberId()) ) { - - LoadAverage loadAverage = memberStatsContext.getLoadAverage(); - log.debug("[scale-down] " + " [cluster] " - + clusterId + " [member] " + memberStatsContext.getMemberId() + " Load average: " + loadAverage); - - MemoryConsumption memoryConsumption = memberStatsContext.getMemoryConsumption(); - log.debug("[scale-down] " + " [partition] " + partition.getId() + " [cluster] " - + clusterId + " [member] " + memberStatsContext.getMemberId() + " Memory consumption: " + memoryConsumption); - - double predictedCpu = $delegator.getPredictedValueForNextMinute(loadAverage.getAverage(),loadAverage.getGradient(),loadAverage.getSecondDerivative(), 1); - log.debug("[scale-down] " + " [partition] " + partition.getId() + " [cluster] " - + clusterId + " [member] " + memberStatsContext.getMemberId() + " Predicted CPU: " + predictedCpu); - - double predictedMemoryConsumption = $delegator.getPredictedValueForNextMinute(memoryConsumption.getAverage(),memoryConsumption.getGradient(),memoryConsumption.getSecondDerivative(), 1); - log.debug("[scale-down] " + " [partition] " + partition.getId() + " [cluster] " - + clusterId + " [member] " + memberStatsContext.getMemberId() + " Predicted memory consumption: " + predictedMemoryConsumption); - - double overallLoad = (predictedCpu + predictedMemoryConsumption) / 2; - log.debug("[scale-down] " + " [partition] " + partition.getId() + " [cluster] " - + clusterId + " [member] " + memberStatsContext.getMemberId() + " Overall load: " + overallLoad); - - if(!foundAValue){ - foundAValue = true; - selectedMemberStatsContext = memberStatsContext; - lowestOverallLoad = overallLoad; - } else if(overallLoad < lowestOverallLoad){ - selectedMemberStatsContext = memberStatsContext; - lowestOverallLoad = overallLoad; - } - } - } - if(selectedMemberStatsContext != null) { - log.info("[scale-down] Trying to terminating an instance to scale down!" ); - log.debug("[scale-down] " + " [partition] " + partition.getId() + " [cluster] " - + clusterId + " Member with lowest overall load: " + selectedMemberStatsContext.getMemberId()); - - $delegator.delegateTerminate(partitionContext, selectedMemberStatsContext.getMemberId()); - } - } - } else{ - - } end
