Fixing STRATOS-889
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/d189b136 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/d189b136 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/d189b136 Branch: refs/heads/master Commit: d189b136e7134b531714e22550eb1e785c0786de Parents: 27f2a6d Author: R-Rajkumar <[email protected]> Authored: Tue Oct 14 19:49:04 2014 +0530 Committer: R-Rajkumar <[email protected]> Committed: Tue Oct 14 19:49:04 2014 +0530 ---------------------------------------------------------------------- .../rule/AutoscalerRuleEvaluator.java | 4 +- .../stratos/autoscaler/TestRulesPackaged.java | 6 +- .../common/constants/StratosConstants.java | 1 + .../modules/distribution/src/assembly/bin.xml | 22 +- .../src/main/conf/container-mincheck.drl | 73 ------- .../src/main/conf/container-scaling.drl | 173 ---------------- .../src/main/conf/drools/container-mincheck.drl | 73 +++++++ .../src/main/conf/drools/container-scaling.drl | 173 ++++++++++++++++ .../src/main/conf/drools/mincheck.drl | 83 ++++++++ .../src/main/conf/drools/scaling.drl | 205 +++++++++++++++++++ .../src/main/conf/drools/terminateall.drl | 44 ++++ .../distribution/src/main/conf/mincheck.drl | 83 -------- .../distribution/src/main/conf/scaling.drl | 205 ------------------- .../distribution/src/main/conf/terminateall.drl | 44 ---- 14 files changed, 597 insertions(+), 592 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/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 a402ab4..094aa86 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 @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.stratos.autoscaler.NetworkPartitionLbHolder; import org.apache.stratos.autoscaler.PartitionContext; import org.apache.stratos.autoscaler.partition.PartitionManager; +import org.apache.stratos.common.constants.StratosConstants; import org.drools.KnowledgeBase; import org.drools.KnowledgeBaseFactory; import org.drools.builder.*; @@ -176,7 +177,8 @@ public class AutoscalerRuleEvaluator { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); String configDir = CarbonUtils.getCarbonConfigDirPath(); - Resource resource = ResourceFactory.newFileResource(configDir + File.separator + drlFileName ); + String droolsDir = configDir + File.separator + StratosConstants.DROOLS_DIR_NAME; + Resource resource = ResourceFactory.newFileResource(droolsDir + File.separator + drlFileName); kbuilder.add(resource, ResourceType.DRL); KnowledgeBuilderErrors errors = kbuilder.getErrors(); if (errors.size() > 0) { http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/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 1c6c687..f6f0148 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 @@ -32,9 +32,9 @@ import static org.junit.Assert.assertEquals; public class TestRulesPackaged { private static final Log log = LogFactory.getLog(TestRulesPackaged.class); - private String minCheckDrlFilePath = "../../products/stratos/modules/distribution/src/main/conf/mincheck.drl"; - private String scalingDrlFilePath = "../../products/stratos/modules/distribution/src/main/conf/scaling.drl"; - private String terminateAllDrlFilePath = "../../products/stratos/modules/distribution/src/main/conf/terminateall.drl"; + private String minCheckDrlFilePath = "../../products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl"; + private String scalingDrlFilePath = "../../products/stratos/modules/distribution/src/main/conf/drools/scaling.drl"; + private String terminateAllDrlFilePath = "../../products/stratos/modules/distribution/src/main/conf/drools/terminateall.drl"; private KnowledgeBase kbase; private StatefulKnowledgeSession ksession; http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java index 5d3ad8c..72cbb26 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java @@ -155,6 +155,7 @@ public class StratosConstants { public static final String ALLOCATED_SERVICE_HOST_PORT = "ALLOCATED_SERVICE_HOST_PORT"; //drools related constants + public static final String DROOLS_DIR_NAME = "drools"; public static final String CONTAINER_SCALE_CHECK_DROOL_FILE = "container-scaling.drl"; public static final String VM_SCALE_CHECK_DROOL_FILE = "scaling.drl"; public static final String CONTAINER_MIN_CHECK_DROOL_FILE = "container-mincheck.drl"; http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/assembly/bin.xml ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/assembly/bin.xml b/products/stratos/modules/distribution/src/assembly/bin.xml index 4295576..8614acf 100755 --- a/products/stratos/modules/distribution/src/assembly/bin.xml +++ b/products/stratos/modules/distribution/src/assembly/bin.xml @@ -660,38 +660,40 @@ <filtered>true</filtered> <fileMode>755</fileMode> </file> + <!-- drools files start--> <file> - <source>src/main/conf/mincheck.drl</source> - <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> + <source>src/main/conf/drools/mincheck.drl</source> + <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf/drools</outputDirectory> <filtered>true</filtered> <fileMode>755</fileMode> </file> <file> - <source>src/main/conf/scaling.drl</source> - <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> + <source>src/main/conf/drools/scaling.drl</source> + <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf/drools</outputDirectory> <filtered>true</filtered> <fileMode>755</fileMode> </file> <file> - <source>src/main/conf/terminateall.drl</source> - <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> + <source>src/main/conf/drools/terminateall.drl</source> + <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf/drools</outputDirectory> <filtered>true</filtered> <fileMode>755</fileMode> </file> <!-- container-drools files --> <file> - <source>src/main/conf/container-mincheck.drl</source> - <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> + <source>src/main/conf/drools/container-mincheck.drl</source> + <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf/drools</outputDirectory> <filtered>true</filtered> <fileMode>755</fileMode> </file> <file> - <source>src/main/conf/container-scaling.drl</source> - <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> + <source>src/main/conf/drools/container-scaling.drl</source> + <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf/drools</outputDirectory> <filtered>true</filtered> <fileMode>755</fileMode> </file> <!-- container-drools files --> + <!-- /drools files end--> <!-- autoscaler --> <file> <source>${project.basedir}/INSTALL.txt</source> http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/container-mincheck.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/container-mincheck.drl b/products/stratos/modules/distribution/src/main/conf/container-mincheck.drl deleted file mode 100644 index f87a556..0000000 --- a/products/stratos/modules/distribution/src/main/conf/container-mincheck.drl +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.rule; - -import org.apache.commons.logging.Log; -import org.apache.stratos.autoscaler.KubernetesClusterContext; - -global org.apache.stratos.autoscaler.rule.RuleLog log; -global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; -global java.lang.String clusterId; - -rule "Container Minimum Rule" -dialect "mvel" - when - $kubernetesClusterContext : KubernetesClusterContext () - kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() - minReplicas : Integer() from $kubernetesClusterContext.getMinReplicas() - nonTerminatedReplicas : Integer() from $kubernetesClusterContext.getNonTerminatedMemberCount() - isServiceClusterCreated : Boolean() from $kubernetesClusterContext.isServiceClusterCreated() - - eval(log.info("Running minimum rule: [kub-cluster] " + kubernetesClusterId + " [cluster] " + clusterId)) - eval(log.info("[min-check] " + " [cluster] : " + clusterId + " [Replicas] nonTerminated : " + nonTerminatedReplicas)) - eval(log.info("[min-check] " + " [cluster] : " + clusterId + " [Replicas] minReplicas : " + minReplicas)) - eval(nonTerminatedReplicas < minReplicas) - then - if (isServiceClusterCreated) { - // we suceeded calling startContainer() once, can't call it again - log.info("[min-check] Decided to scale-up : [cluster] : " + clusterId); - log.info("[min-check] " + " [cluster] : " + clusterId + " ; min-rule not satisfied, scaling up to minReplicas : " + minReplicas); - $delegator.delegateScaleUpContainers($kubernetesClusterContext, minReplicas); - } else { - // we should call startContainer - log.info("[min-check] Decided to create the cluster : [cluster] : " + clusterId); - log.info("[min-check] " + " [cluster] : " + clusterId + " ; min-rule not satisfied, no containers created yet, creating minReplicas : " + minReplicas); - $delegator.delegateStartContainers($kubernetesClusterContext); - } -end - -rule "Terminate Obsoleted Containers" -dialect "mvel" - when - $kubernetesClusterContext : KubernetesClusterContext () - kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() - obsoleteReplicas : Integer() from $kubernetesClusterContext.getObsoletedMembers().size() - - eval(log.info("Running obsolete containers rule [kub-cluster] : " + kubernetesClusterId + " [cluster] : " + clusterId)) - eval(log.info("[obsolete-check] " + "[cluster] : " + clusterId + " [Replicas] obsoleteReplicas : " + obsoleteReplicas)) - eval($kubernetesClusterContext.getObsoletedMembers().keySet().size() > 0) - memberId : String() from $kubernetesClusterContext.getObsoletedMembers().keySet() - eval(log.debug("[obsolete-check] [kub-cluster] : " + kubernetesClusterId + " [cluster] : " + clusterId + " Member id : " + memberId)) - then - log.info("[obsolete-check] Terminating the obsolete member with id : " + memberId + " in the cluster : " + clusterId); - $delegator.delegateTerminateContainer($kubernetesClusterContext, memberId); -end - - http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/container-scaling.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/container-scaling.drl b/products/stratos/modules/distribution/src/main/conf/container-scaling.drl deleted file mode 100644 index c5d4272..0000000 --- a/products/stratos/modules/distribution/src/main/conf/container-scaling.drl +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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.rule; - -import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; -import org.apache.stratos.autoscaler.policy.model.LoadThresholds; -import org.apache.stratos.autoscaler.KubernetesClusterContext; - -global org.apache.stratos.autoscaler.rule.RuleLog log; -global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; -global org.apache.stratos.autoscaler.policy.model.AutoscalePolicy autoscalePolicy; -global java.lang.String clusterId; -global java.lang.Boolean rifReset; -global java.lang.Boolean mcReset; -global java.lang.Boolean laReset; - -rule "Containers Scaling Rule" -dialect "mvel" - when - $kubernetesClusterContext : KubernetesClusterContext () - kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() - minReplicas : Integer() from $kubernetesClusterContext.getMinReplicas() - maxReplicas : Integer() from $kubernetesClusterContext.getMaxReplicas() - nonTerminatedReplicas : Integer() from $kubernetesClusterContext.getNonTerminatedMemberCount() - activeReplicas : Integer() from $kubernetesClusterContext.getActiveMemberCount() - - eval(log.info("Running scaling rule [kub-cluster] : " + kubernetesClusterId + " [cluster] : " + clusterId)) - - $loadThresholds : LoadThresholds() from autoscalePolicy.getLoadThresholds() - - rifUpperLimit : Float() from $loadThresholds.getRequestsInFlight().getUpperLimit() - rifLowerLimit : Float() from $loadThresholds.getRequestsInFlight().getLowerLimit() - - rifAverage : Float() from $kubernetesClusterContext.getAverageRequestsInFlight() - rifGradient : Float() from $kubernetesClusterContext.getRequestsInFlightGradient() - rifSecondDerivative : Float() from $kubernetesClusterContext.getRequestsInFlightSecondDerivative() - rifPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(rifAverage, rifGradient, rifSecondDerivative, 1) - - mcUpperLimit : Float() from $loadThresholds.getMemoryConsumption().getUpperLimit() - mcLowerLimit : Float() from $loadThresholds.getMemoryConsumption().getLowerLimit() - - memoryConsumptionAverage : Float() from $kubernetesClusterContext.getAverageMemoryConsumption() - memoryConsumptionGradient : Float() from $kubernetesClusterContext.getMemoryConsumptionGradient() - memoryConsumptionSecondDerivative : Float() from $kubernetesClusterContext.getMemoryConsumptionSecondDerivative() - mcPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(memoryConsumptionAverage, memoryConsumptionGradient, memoryConsumptionSecondDerivative, 1) - - laUpperLimit : Float() from $loadThresholds.getLoadAverage().getUpperLimit() - laLowerLimit : Float() from $loadThresholds.getLoadAverage().getLowerLimit() - - loadAverageAverage : Float() from $kubernetesClusterContext.getAverageLoadAverage() - loadAverageGradient : Float() from $kubernetesClusterContext.getLoadAverageGradient() - loadAverageSecondDerivative : Float() from $kubernetesClusterContext.getLoadAverageSecondDerivative() - laPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(loadAverageAverage, loadAverageGradient, loadAverageSecondDerivative, 1) - - scaleUpForRif : Boolean() from (rifReset && (rifPredictedValue > rifUpperLimit)) - scaleUpForMc : Boolean() from (mcReset && (mcPredictedValue > mcUpperLimit)) - scaleUpForLa : Boolean() from (laReset && (laPredictedValue > laUpperLimit)) - - scaleDownForRif : Boolean() from (rifPredictedValue < rifUpperLimit) - scaleDownForMc : Boolean() from (mcReset && (mcPredictedValue < mcUpperLimit)) - scaleDownForLa : Boolean() from (laReset && (laPredictedValue < laUpperLimit)) - - scaleUp : Boolean() from (scaleUpForRif || scaleUpForMc || scaleUpForLa) - scaleDown : Boolean() from (scaleDownForRif && scaleDownForMc && scaleDownForLa) - - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] minReplicas : " + minReplicas)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] maxReplicas : " + maxReplicas)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] nonTerminated : " + nonTerminatedReplicas)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] activeReplicas : " + activeReplicas)) - - eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] resetted ? : " + rifReset)) - eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] predicted value : " + rifPredictedValue)) - eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] upper limit : " + rifUpperLimit)) - eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] lower limit : " + rifLowerLimit)) - - eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] resetted ? : " + mcReset)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] predicted value : " + mcPredictedValue)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] upper limit : " + mcUpperLimit)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] lower limit : " + mcLowerLimit)) - - eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] resetted ? : " + laReset)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] predicted value : " + laPredictedValue)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] upper limit : " + laUpperLimit)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] lower limit : " + laLowerLimit)) - - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " scale-up action : " + scaleUp)) - eval(log.info("[scaling] " + " [cluster] : " + clusterId + " scale-down action : " + scaleDown)) - - then - if (scaleUp) { - int requiredReplicas = 0; - if (scaleUpForRif) { - int predictedReplicasForRif = $delegator.getPredictedReplicasForStat(minReplicas, rifUpperLimit, rifPredictedValue); - log.info("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] predicted replicas : " + predictedReplicasForRif); - if (predictedReplicasForRif > requiredReplicas ) { - requiredReplicas = predictedReplicasForRif; - } - } - if (scaleUpForMc) { - int predictedReplicasForMc = $delegator.getPredictedReplicasForStat(minReplicas, mcUpperLimit, mcPredictedValue); - log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] predicted replicas : " + predictedReplicasForMc); - if (predictedReplicasForMc > requiredReplicas ) { - requiredReplicas = predictedReplicasForMc; - } - } - if (scaleUpForLa) { - int predictedReplicasForLa = $delegator.getPredictedReplicasForStat(minReplicas, laUpperLimit, laPredictedValue); - log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] predicted replicas : " + predictedReplicasForLa); - if (predictedReplicasForLa > requiredReplicas ) { - requiredReplicas = predictedReplicasForLa; - } - } - //max-check - if (requiredReplicas > maxReplicas) { - log.info("[scaling] " + " [cluster] : " + clusterId + " predicted replicas > max replicas : "); - requiredReplicas = maxReplicas; - } - //min-check - if (requiredReplicas < minReplicas) { - log.info("[scaling] " + " [cluster] : " + clusterId + " predicted replicas < min replicas : "); - requiredReplicas = minReplicas; - } - //expand the cluster - if (requiredReplicas > nonTerminatedReplicas) { - log.info("[scaling] Decided to scale-up : [cluster] : " + clusterId); - log.info("[scaling-up] " + " [cluster] : " + clusterId + " valid number of replicas to expand : " + requiredReplicas); - $delegator.delegateScaleUpContainers($kubernetesClusterContext, requiredReplicas); - } - //shrink the cluster - if (requiredReplicas < nonTerminatedReplicas) { - if (requiredReplicas < activeReplicas) { - log.info("[scaling] Decided to scale-down : [cluster] : " + clusterId); - log.info("[scaling-down] " + " [cluster] : " + clusterId + " valid number of replicas to shrink : " + requiredReplicas); - $delegator.delegateScaleDownContainers($kubernetesClusterContext, requiredReplicas); - } else { - log.info("[scaling] " + " [cluster] : " + clusterId + " Even if requiredReplicas < nonTerminatedReplicas, still requiredReplicas >= activeReplicas ; hence not scaling down "); - } - } - if (requiredReplicas == nonTerminatedReplicas) { - log.info("[scaling] " + " [cluster] : " + clusterId + " Non terminated replicas and predicted replicas are same"); - } - - } else if (scaleDown) { - if (activeReplicas > minReplicas) { - log.info("[scaling] Decided to scale-down [cluster] : " + clusterId); - log.info("[scaling-down] " + " [cluster] : " + clusterId + " shrink the cluster to minReplicas : " + minReplicas); - //shrink the cluster to minReplicas - $delegator.delegateScaleDownContainers($kubernetesClusterContext, minReplicas); - } else { - log.info("[scaling] " + " [cluster] : " + clusterId + " Even if all predicted stats < upperLimit, still activeReplicas <= minReplicas ; hence not scaling down "); - } - } else { - log.info("[scaling] No decision made to either scale up or down ... "); - } -end - http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/drools/container-mincheck.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/drools/container-mincheck.drl b/products/stratos/modules/distribution/src/main/conf/drools/container-mincheck.drl new file mode 100644 index 0000000..f87a556 --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/drools/container-mincheck.drl @@ -0,0 +1,73 @@ +/* + * 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.rule; + +import org.apache.commons.logging.Log; +import org.apache.stratos.autoscaler.KubernetesClusterContext; + +global org.apache.stratos.autoscaler.rule.RuleLog log; +global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; +global java.lang.String clusterId; + +rule "Container Minimum Rule" +dialect "mvel" + when + $kubernetesClusterContext : KubernetesClusterContext () + kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() + minReplicas : Integer() from $kubernetesClusterContext.getMinReplicas() + nonTerminatedReplicas : Integer() from $kubernetesClusterContext.getNonTerminatedMemberCount() + isServiceClusterCreated : Boolean() from $kubernetesClusterContext.isServiceClusterCreated() + + eval(log.info("Running minimum rule: [kub-cluster] " + kubernetesClusterId + " [cluster] " + clusterId)) + eval(log.info("[min-check] " + " [cluster] : " + clusterId + " [Replicas] nonTerminated : " + nonTerminatedReplicas)) + eval(log.info("[min-check] " + " [cluster] : " + clusterId + " [Replicas] minReplicas : " + minReplicas)) + eval(nonTerminatedReplicas < minReplicas) + then + if (isServiceClusterCreated) { + // we suceeded calling startContainer() once, can't call it again + log.info("[min-check] Decided to scale-up : [cluster] : " + clusterId); + log.info("[min-check] " + " [cluster] : " + clusterId + " ; min-rule not satisfied, scaling up to minReplicas : " + minReplicas); + $delegator.delegateScaleUpContainers($kubernetesClusterContext, minReplicas); + } else { + // we should call startContainer + log.info("[min-check] Decided to create the cluster : [cluster] : " + clusterId); + log.info("[min-check] " + " [cluster] : " + clusterId + " ; min-rule not satisfied, no containers created yet, creating minReplicas : " + minReplicas); + $delegator.delegateStartContainers($kubernetesClusterContext); + } +end + +rule "Terminate Obsoleted Containers" +dialect "mvel" + when + $kubernetesClusterContext : KubernetesClusterContext () + kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() + obsoleteReplicas : Integer() from $kubernetesClusterContext.getObsoletedMembers().size() + + eval(log.info("Running obsolete containers rule [kub-cluster] : " + kubernetesClusterId + " [cluster] : " + clusterId)) + eval(log.info("[obsolete-check] " + "[cluster] : " + clusterId + " [Replicas] obsoleteReplicas : " + obsoleteReplicas)) + eval($kubernetesClusterContext.getObsoletedMembers().keySet().size() > 0) + memberId : String() from $kubernetesClusterContext.getObsoletedMembers().keySet() + eval(log.debug("[obsolete-check] [kub-cluster] : " + kubernetesClusterId + " [cluster] : " + clusterId + " Member id : " + memberId)) + then + log.info("[obsolete-check] Terminating the obsolete member with id : " + memberId + " in the cluster : " + clusterId); + $delegator.delegateTerminateContainer($kubernetesClusterContext, memberId); +end + + http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/drools/container-scaling.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/drools/container-scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/container-scaling.drl new file mode 100644 index 0000000..c5d4272 --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/drools/container-scaling.drl @@ -0,0 +1,173 @@ +/* + * 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.rule; + +import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; +import org.apache.stratos.autoscaler.policy.model.LoadThresholds; +import org.apache.stratos.autoscaler.KubernetesClusterContext; + +global org.apache.stratos.autoscaler.rule.RuleLog log; +global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; +global org.apache.stratos.autoscaler.policy.model.AutoscalePolicy autoscalePolicy; +global java.lang.String clusterId; +global java.lang.Boolean rifReset; +global java.lang.Boolean mcReset; +global java.lang.Boolean laReset; + +rule "Containers Scaling Rule" +dialect "mvel" + when + $kubernetesClusterContext : KubernetesClusterContext () + kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() + minReplicas : Integer() from $kubernetesClusterContext.getMinReplicas() + maxReplicas : Integer() from $kubernetesClusterContext.getMaxReplicas() + nonTerminatedReplicas : Integer() from $kubernetesClusterContext.getNonTerminatedMemberCount() + activeReplicas : Integer() from $kubernetesClusterContext.getActiveMemberCount() + + eval(log.info("Running scaling rule [kub-cluster] : " + kubernetesClusterId + " [cluster] : " + clusterId)) + + $loadThresholds : LoadThresholds() from autoscalePolicy.getLoadThresholds() + + rifUpperLimit : Float() from $loadThresholds.getRequestsInFlight().getUpperLimit() + rifLowerLimit : Float() from $loadThresholds.getRequestsInFlight().getLowerLimit() + + rifAverage : Float() from $kubernetesClusterContext.getAverageRequestsInFlight() + rifGradient : Float() from $kubernetesClusterContext.getRequestsInFlightGradient() + rifSecondDerivative : Float() from $kubernetesClusterContext.getRequestsInFlightSecondDerivative() + rifPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(rifAverage, rifGradient, rifSecondDerivative, 1) + + mcUpperLimit : Float() from $loadThresholds.getMemoryConsumption().getUpperLimit() + mcLowerLimit : Float() from $loadThresholds.getMemoryConsumption().getLowerLimit() + + memoryConsumptionAverage : Float() from $kubernetesClusterContext.getAverageMemoryConsumption() + memoryConsumptionGradient : Float() from $kubernetesClusterContext.getMemoryConsumptionGradient() + memoryConsumptionSecondDerivative : Float() from $kubernetesClusterContext.getMemoryConsumptionSecondDerivative() + mcPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(memoryConsumptionAverage, memoryConsumptionGradient, memoryConsumptionSecondDerivative, 1) + + laUpperLimit : Float() from $loadThresholds.getLoadAverage().getUpperLimit() + laLowerLimit : Float() from $loadThresholds.getLoadAverage().getLowerLimit() + + loadAverageAverage : Float() from $kubernetesClusterContext.getAverageLoadAverage() + loadAverageGradient : Float() from $kubernetesClusterContext.getLoadAverageGradient() + loadAverageSecondDerivative : Float() from $kubernetesClusterContext.getLoadAverageSecondDerivative() + laPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(loadAverageAverage, loadAverageGradient, loadAverageSecondDerivative, 1) + + scaleUpForRif : Boolean() from (rifReset && (rifPredictedValue > rifUpperLimit)) + scaleUpForMc : Boolean() from (mcReset && (mcPredictedValue > mcUpperLimit)) + scaleUpForLa : Boolean() from (laReset && (laPredictedValue > laUpperLimit)) + + scaleDownForRif : Boolean() from (rifPredictedValue < rifUpperLimit) + scaleDownForMc : Boolean() from (mcReset && (mcPredictedValue < mcUpperLimit)) + scaleDownForLa : Boolean() from (laReset && (laPredictedValue < laUpperLimit)) + + scaleUp : Boolean() from (scaleUpForRif || scaleUpForMc || scaleUpForLa) + scaleDown : Boolean() from (scaleDownForRif && scaleDownForMc && scaleDownForLa) + + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] minReplicas : " + minReplicas)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] maxReplicas : " + maxReplicas)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] nonTerminated : " + nonTerminatedReplicas)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [Replicas] activeReplicas : " + activeReplicas)) + + eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] resetted ? : " + rifReset)) + eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] predicted value : " + rifPredictedValue)) + eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] upper limit : " + rifUpperLimit)) + eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] lower limit : " + rifLowerLimit)) + + eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] resetted ? : " + mcReset)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] predicted value : " + mcPredictedValue)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] upper limit : " + mcUpperLimit)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] lower limit : " + mcLowerLimit)) + + eval(log.debug("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] resetted ? : " + laReset)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] predicted value : " + laPredictedValue)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] upper limit : " + laUpperLimit)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] lower limit : " + laLowerLimit)) + + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " scale-up action : " + scaleUp)) + eval(log.info("[scaling] " + " [cluster] : " + clusterId + " scale-down action : " + scaleDown)) + + then + if (scaleUp) { + int requiredReplicas = 0; + if (scaleUpForRif) { + int predictedReplicasForRif = $delegator.getPredictedReplicasForStat(minReplicas, rifUpperLimit, rifPredictedValue); + log.info("[scaling] " + " [cluster] : " + clusterId + " [RequestInFlight] predicted replicas : " + predictedReplicasForRif); + if (predictedReplicasForRif > requiredReplicas ) { + requiredReplicas = predictedReplicasForRif; + } + } + if (scaleUpForMc) { + int predictedReplicasForMc = $delegator.getPredictedReplicasForStat(minReplicas, mcUpperLimit, mcPredictedValue); + log.info("[scaling] " + " [cluster] : " + clusterId + " [MemoryConsumption] predicted replicas : " + predictedReplicasForMc); + if (predictedReplicasForMc > requiredReplicas ) { + requiredReplicas = predictedReplicasForMc; + } + } + if (scaleUpForLa) { + int predictedReplicasForLa = $delegator.getPredictedReplicasForStat(minReplicas, laUpperLimit, laPredictedValue); + log.info("[scaling] " + " [cluster] : " + clusterId + " [LoadAverage] predicted replicas : " + predictedReplicasForLa); + if (predictedReplicasForLa > requiredReplicas ) { + requiredReplicas = predictedReplicasForLa; + } + } + //max-check + if (requiredReplicas > maxReplicas) { + log.info("[scaling] " + " [cluster] : " + clusterId + " predicted replicas > max replicas : "); + requiredReplicas = maxReplicas; + } + //min-check + if (requiredReplicas < minReplicas) { + log.info("[scaling] " + " [cluster] : " + clusterId + " predicted replicas < min replicas : "); + requiredReplicas = minReplicas; + } + //expand the cluster + if (requiredReplicas > nonTerminatedReplicas) { + log.info("[scaling] Decided to scale-up : [cluster] : " + clusterId); + log.info("[scaling-up] " + " [cluster] : " + clusterId + " valid number of replicas to expand : " + requiredReplicas); + $delegator.delegateScaleUpContainers($kubernetesClusterContext, requiredReplicas); + } + //shrink the cluster + if (requiredReplicas < nonTerminatedReplicas) { + if (requiredReplicas < activeReplicas) { + log.info("[scaling] Decided to scale-down : [cluster] : " + clusterId); + log.info("[scaling-down] " + " [cluster] : " + clusterId + " valid number of replicas to shrink : " + requiredReplicas); + $delegator.delegateScaleDownContainers($kubernetesClusterContext, requiredReplicas); + } else { + log.info("[scaling] " + " [cluster] : " + clusterId + " Even if requiredReplicas < nonTerminatedReplicas, still requiredReplicas >= activeReplicas ; hence not scaling down "); + } + } + if (requiredReplicas == nonTerminatedReplicas) { + log.info("[scaling] " + " [cluster] : " + clusterId + " Non terminated replicas and predicted replicas are same"); + } + + } else if (scaleDown) { + if (activeReplicas > minReplicas) { + log.info("[scaling] Decided to scale-down [cluster] : " + clusterId); + log.info("[scaling-down] " + " [cluster] : " + clusterId + " shrink the cluster to minReplicas : " + minReplicas); + //shrink the cluster to minReplicas + $delegator.delegateScaleDownContainers($kubernetesClusterContext, minReplicas); + } else { + log.info("[scaling] " + " [cluster] : " + clusterId + " Even if all predicted stats < upperLimit, still activeReplicas <= minReplicas ; hence not scaling down "); + } + } else { + log.info("[scaling] No decision made to either scale up or down ... "); + } +end + http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl b/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl new file mode 100755 index 0000000..71187d6 --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl @@ -0,0 +1,83 @@ +/* + * 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.rule; + +import org.apache.stratos.messaging.domain.topology.Service; +import org.apache.stratos.messaging.domain.topology.Cluster; +import org.apache.stratos.autoscaler.AutoscalerContext; +import org.apache.stratos.autoscaler.Constants; +import org.apache.stratos.autoscaler.policy.PolicyManager; +import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; +import org.apache.stratos.autoscaler.policy.model.RequestsInFlight; +import org.apache.stratos.autoscaler.policy.model.LoadThresholds; +import org.apache.stratos.autoscaler.client.cloud.controller.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.PartitionContext; +import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; +import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; +import org.apache.commons.logging.Log; +import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; +import org.apache.stratos.autoscaler.partition.PartitionGroup; +import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; +import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; + +global org.apache.stratos.autoscaler.rule.RuleLog log; +global org.apache.stratos.autoscaler.policy.PolicyManager $manager; +global org.apache.stratos.autoscaler.AutoscalerContext $context; +global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; +global org.apache.stratos.messaging.domain.topology.Topology $topology; +global java.util.Map partitionCtxts; +global java.lang.String clusterId; +global java.lang.String lbRef; +global java.lang.Boolean isPrimary; +global Integer primaryMemberCount; + +rule "Minimum Rule" +dialect "mvel" + when + $ctxt : PartitionContext () + eval(log.debug("Running minimum rule: [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId())) + eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Non terminated member count: " + $ctxt.getNonTerminatedMemberCount())) + eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Minimum member count: " + $ctxt.getMinimumMemberCount())) + eval ( (isPrimary && (primaryMemberCount < $ctxt.getMinimumMemberCount() )) || ( !isPrimary && ($ctxt.getNonTerminatedMemberCount() < $ctxt.getMinimumMemberCount() )) ) + then + if (isPrimary){ + log.debug("[min-check] true [primary] true [primary member count] " + primaryMemberCount); + } else{ + log.debug("[min-check] true [primary] false"); + } + $delegator.delegateSpawn($ctxt, clusterId, lbRef, isPrimary); +end + +rule "Terminate Obsoleted Instances" +dialect "mvel" + when + $ctxt : PartitionContext () + eval(log.debug("Running obsolete instances rule: [partition] " + $ctxt.getPartitionId() + " [network-partition] " + $ctxt.getNetworkPartitionId())) + eval(log.debug("[obsolete-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() +" Obsolete member count: " + $ctxt.getObsoletedMembers().size())) + eval($ctxt.getObsoletedMembers().keySet().size() > 0) + memberId : String() from $ctxt.getObsoletedMembers().keySet() + eval(log.debug("[obsolete-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Member id: " + memberId)) + then + $delegator.terminateObsoleteInstance(memberId); +end + http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl new file mode 100644 index 0000000..bd331e7 --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl @@ -0,0 +1,205 @@ +/* + * 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.rule; + +import org.apache.stratos.messaging.domain.topology.Service; +import org.apache.stratos.messaging.domain.topology.Cluster; +import org.apache.stratos.autoscaler.AutoscalerContext; +import org.apache.stratos.autoscaler.MemberStatsContext; +import org.apache.stratos.autoscaler.Constants; +import org.apache.stratos.autoscaler.NetworkPartitionContext; +import org.apache.stratos.autoscaler.policy.PolicyManager; +import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; +import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; +import org.apache.stratos.autoscaler.policy.model.RequestsInFlight; +import org.apache.stratos.autoscaler.policy.model.LoadThresholds; +import org.apache.stratos.autoscaler.policy.model.MemoryConsumption; +import org.apache.stratos.autoscaler.policy.model.LoadAverage; +import org.apache.stratos.autoscaler.client.cloud.controller.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.PartitionContext; +import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; +import org.apache.stratos.autoscaler.partition.PartitionGroup; +import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; +import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; + +import org.apache.stratos.autoscaler.policy.model.LoadAverage +import org.apache.stratos.autoscaler.policy.model.MemoryConsumption + +global org.apache.stratos.autoscaler.rule.RuleLog log; +global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; +global org.apache.stratos.autoscaler.policy.model.AutoscalePolicy autoscalePolicy; +global java.lang.String clusterId; +global java.lang.String lbRef; +global java.lang.Boolean rifReset; +global java.lang.Boolean mcReset; +global java.lang.Boolean laReset; +global java.lang.Boolean isPrimary; +global java.util.List primaryMembers; + +rule "Scaling Rule" +dialect "mvel" + when + $networkPartitionContext : NetworkPartitionContext () + + $loadThresholds : LoadThresholds() from autoscalePolicy.getLoadThresholds() + algorithmName : String() from $networkPartitionContext.getPartitionAlgorithm(); + autoscaleAlgorithm : AutoscaleAlgorithm() from $delegator.getAutoscaleAlgorithm(algorithmName) + + eval(log.debug("Running scale up rule: [network-partition] " + $networkPartitionContext.getId() + " [cluster] " + clusterId)) + eval(log.debug("[scaling] [network-partition] " + $networkPartitionContext.getId() + " [cluster] " + clusterId + " Algorithm name: " + algorithmName)) + eval(log.debug("[scaling] [network-partition] " + $networkPartitionContext.getId() + " [cluster] " + clusterId + " Algorithm: " + autoscaleAlgorithm)) + + + rifUpperLimit : Float() from $loadThresholds.getRequestsInFlight().getUpperLimit() + rifLowerLimit : Float() from $loadThresholds.getRequestsInFlight().getLowerLimit() + + rifAverage : Float() from $networkPartitionContext.getAverageRequestsInFlight() + rifGradient : Float() from $networkPartitionContext.getRequestsInFlightGradient() + rifSecondDerivative : Float() from $networkPartitionContext.getRequestsInFlightSecondDerivative() + rifPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(rifAverage, rifGradient, rifSecondDerivative, 1) + + mcUpperLimit : Float() from $loadThresholds.getMemoryConsumption().getUpperLimit() + mcLowerLimit : Float() from $loadThresholds.getMemoryConsumption().getLowerLimit() + + memoryConsumptionAverage : Float() from $networkPartitionContext.getAverageMemoryConsumption() + memoryConsumptionGradient : Float() from $networkPartitionContext.getMemoryConsumptionGradient() + memoryConsumptionSecondDerivative : Float() from $networkPartitionContext.getMemoryConsumptionSecondDerivative() + mcPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(memoryConsumptionAverage, memoryConsumptionGradient, memoryConsumptionSecondDerivative, 1) + + laUpperLimit : Float() from $loadThresholds.getLoadAverage().getUpperLimit() + laLowerLimit : Float() from $loadThresholds.getLoadAverage().getLowerLimit() + + loadAverageAverage : Float() from $networkPartitionContext.getAverageLoadAverage() + loadAverageGradient : Float() from $networkPartitionContext.getLoadAverageGradient() + loadAverageSecondDerivative : Float() from $networkPartitionContext.getLoadAverageSecondDerivative() + laPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(loadAverageAverage, loadAverageGradient, loadAverageSecondDerivative, 1) + + scaleUp : Boolean() from ((rifReset && (rifPredictedValue > rifUpperLimit)) || (mcReset && (mcPredictedValue > mcUpperLimit)) || (laReset && (laPredictedValue > laUpperLimit))) + scaleDown : Boolean() from ((rifReset && (rifPredictedValue < rifLowerLimit )) && (mcReset && (mcPredictedValue < mcLowerLimit)) && (laReset && (laPredictedValue < laLowerLimit))) + + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF Resetted?: " + rifReset)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF predicted value: " + rifPredictedValue)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF upper limit: " + rifUpperLimit)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF lower limit: " + rifLowerLimit)) + + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " MC predicted value: " + mcPredictedValue)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " MC upper limit: " + mcUpperLimit)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " MC lower limit: " + mcLowerLimit)) + + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " LA predicted value: " + laPredictedValue)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " LA upper limit: " + laUpperLimit)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " LA lower limit: " + laLowerLimit)) + + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " Scale-up action: " + scaleUp)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " Scale-down action: " + scaleDown)) + + then + if(scaleUp){ + + $networkPartitionContext.resetScaleDownRequestsCount(); + 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, lbRef, isPrimary); + } + } else if(scaleDown){ + + log.debug("[scale-down] Decided to Scale down [cluster] " + clusterId); + if($networkPartitionContext.getScaleDownRequestsCount() > 5 ){ + log.debug("[scale-down] Reached scale down requests threshold [cluster] " + clusterId + " Count " + $networkPartitionContext.getScaleDownRequestsCount()); + $networkPartitionContext.resetScaleDownRequestsCount(); + 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 instace 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{ + log.debug("[scale-down] Not reached scale down requests threshold. " + clusterId + " Count " + $networkPartitionContext.getScaleDownRequestsCount()); + $networkPartitionContext.increaseScaleDownRequestsCount(); + + } + } else{ + log.debug("[scaling] No decision made to either scale up or scale down ... "); + + } + +end + + + + http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/drools/terminateall.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/drools/terminateall.drl b/products/stratos/modules/distribution/src/main/conf/drools/terminateall.drl new file mode 100644 index 0000000..75c26fc --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/drools/terminateall.drl @@ -0,0 +1,44 @@ +/* + * 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.rule; + +import org.apache.stratos.messaging.domain.topology.Cluster; +import org.apache.stratos.autoscaler.PartitionContext; + +global org.apache.stratos.autoscaler.rule.RuleLog log; +global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; + +rule "Terminate all Rule" + +dialect "mvel" + when + $ctxt : PartitionContext () + eval(log.debug("Running terminate all rule: [partition] " + $ctxt.getPartitionId() + " [network-partition] " + $ctxt.getNetworkPartitionId())) + eval(log.debug("[terminate all] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() +" Member count: " + $ctxt.getMemberStatsContexts().size())) + eval($ctxt.getMemberStatsContexts().size() > 0) + memberId : String() from $ctxt.getMemberStatsContexts().keySet() + eval(log.debug("[terminate all] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Member id: " + memberId)) + + then + $delegator.delegateTerminate($ctxt, memberId); +end + + + http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/mincheck.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/mincheck.drl b/products/stratos/modules/distribution/src/main/conf/mincheck.drl deleted file mode 100755 index 71187d6..0000000 --- a/products/stratos/modules/distribution/src/main/conf/mincheck.drl +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.rule; - -import org.apache.stratos.messaging.domain.topology.Service; -import org.apache.stratos.messaging.domain.topology.Cluster; -import org.apache.stratos.autoscaler.AutoscalerContext; -import org.apache.stratos.autoscaler.Constants; -import org.apache.stratos.autoscaler.policy.PolicyManager; -import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; -import org.apache.stratos.autoscaler.policy.model.RequestsInFlight; -import org.apache.stratos.autoscaler.policy.model.LoadThresholds; -import org.apache.stratos.autoscaler.client.cloud.controller.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.PartitionContext; -import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; -import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; -import org.apache.commons.logging.Log; -import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; -import org.apache.stratos.autoscaler.partition.PartitionGroup; -import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; -import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; - -global org.apache.stratos.autoscaler.rule.RuleLog log; -global org.apache.stratos.autoscaler.policy.PolicyManager $manager; -global org.apache.stratos.autoscaler.AutoscalerContext $context; -global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; -global org.apache.stratos.messaging.domain.topology.Topology $topology; -global java.util.Map partitionCtxts; -global java.lang.String clusterId; -global java.lang.String lbRef; -global java.lang.Boolean isPrimary; -global Integer primaryMemberCount; - -rule "Minimum Rule" -dialect "mvel" - when - $ctxt : PartitionContext () - eval(log.debug("Running minimum rule: [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId())) - eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Non terminated member count: " + $ctxt.getNonTerminatedMemberCount())) - eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Minimum member count: " + $ctxt.getMinimumMemberCount())) - eval ( (isPrimary && (primaryMemberCount < $ctxt.getMinimumMemberCount() )) || ( !isPrimary && ($ctxt.getNonTerminatedMemberCount() < $ctxt.getMinimumMemberCount() )) ) - then - if (isPrimary){ - log.debug("[min-check] true [primary] true [primary member count] " + primaryMemberCount); - } else{ - log.debug("[min-check] true [primary] false"); - } - $delegator.delegateSpawn($ctxt, clusterId, lbRef, isPrimary); -end - -rule "Terminate Obsoleted Instances" -dialect "mvel" - when - $ctxt : PartitionContext () - eval(log.debug("Running obsolete instances rule: [partition] " + $ctxt.getPartitionId() + " [network-partition] " + $ctxt.getNetworkPartitionId())) - eval(log.debug("[obsolete-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() +" Obsolete member count: " + $ctxt.getObsoletedMembers().size())) - eval($ctxt.getObsoletedMembers().keySet().size() > 0) - memberId : String() from $ctxt.getObsoletedMembers().keySet() - eval(log.debug("[obsolete-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Member id: " + memberId)) - then - $delegator.terminateObsoleteInstance(memberId); -end - http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/scaling.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/scaling.drl b/products/stratos/modules/distribution/src/main/conf/scaling.drl deleted file mode 100644 index bd331e7..0000000 --- a/products/stratos/modules/distribution/src/main/conf/scaling.drl +++ /dev/null @@ -1,205 +0,0 @@ -/* - * 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.rule; - -import org.apache.stratos.messaging.domain.topology.Service; -import org.apache.stratos.messaging.domain.topology.Cluster; -import org.apache.stratos.autoscaler.AutoscalerContext; -import org.apache.stratos.autoscaler.MemberStatsContext; -import org.apache.stratos.autoscaler.Constants; -import org.apache.stratos.autoscaler.NetworkPartitionContext; -import org.apache.stratos.autoscaler.policy.PolicyManager; -import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; -import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; -import org.apache.stratos.autoscaler.policy.model.RequestsInFlight; -import org.apache.stratos.autoscaler.policy.model.LoadThresholds; -import org.apache.stratos.autoscaler.policy.model.MemoryConsumption; -import org.apache.stratos.autoscaler.policy.model.LoadAverage; -import org.apache.stratos.autoscaler.client.cloud.controller.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.PartitionContext; -import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; -import org.apache.stratos.autoscaler.partition.PartitionGroup; -import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; -import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; - -import org.apache.stratos.autoscaler.policy.model.LoadAverage -import org.apache.stratos.autoscaler.policy.model.MemoryConsumption - -global org.apache.stratos.autoscaler.rule.RuleLog log; -global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; -global org.apache.stratos.autoscaler.policy.model.AutoscalePolicy autoscalePolicy; -global java.lang.String clusterId; -global java.lang.String lbRef; -global java.lang.Boolean rifReset; -global java.lang.Boolean mcReset; -global java.lang.Boolean laReset; -global java.lang.Boolean isPrimary; -global java.util.List primaryMembers; - -rule "Scaling Rule" -dialect "mvel" - when - $networkPartitionContext : NetworkPartitionContext () - - $loadThresholds : LoadThresholds() from autoscalePolicy.getLoadThresholds() - algorithmName : String() from $networkPartitionContext.getPartitionAlgorithm(); - autoscaleAlgorithm : AutoscaleAlgorithm() from $delegator.getAutoscaleAlgorithm(algorithmName) - - eval(log.debug("Running scale up rule: [network-partition] " + $networkPartitionContext.getId() + " [cluster] " + clusterId)) - eval(log.debug("[scaling] [network-partition] " + $networkPartitionContext.getId() + " [cluster] " + clusterId + " Algorithm name: " + algorithmName)) - eval(log.debug("[scaling] [network-partition] " + $networkPartitionContext.getId() + " [cluster] " + clusterId + " Algorithm: " + autoscaleAlgorithm)) - - - rifUpperLimit : Float() from $loadThresholds.getRequestsInFlight().getUpperLimit() - rifLowerLimit : Float() from $loadThresholds.getRequestsInFlight().getLowerLimit() - - rifAverage : Float() from $networkPartitionContext.getAverageRequestsInFlight() - rifGradient : Float() from $networkPartitionContext.getRequestsInFlightGradient() - rifSecondDerivative : Float() from $networkPartitionContext.getRequestsInFlightSecondDerivative() - rifPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(rifAverage, rifGradient, rifSecondDerivative, 1) - - mcUpperLimit : Float() from $loadThresholds.getMemoryConsumption().getUpperLimit() - mcLowerLimit : Float() from $loadThresholds.getMemoryConsumption().getLowerLimit() - - memoryConsumptionAverage : Float() from $networkPartitionContext.getAverageMemoryConsumption() - memoryConsumptionGradient : Float() from $networkPartitionContext.getMemoryConsumptionGradient() - memoryConsumptionSecondDerivative : Float() from $networkPartitionContext.getMemoryConsumptionSecondDerivative() - mcPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(memoryConsumptionAverage, memoryConsumptionGradient, memoryConsumptionSecondDerivative, 1) - - laUpperLimit : Float() from $loadThresholds.getLoadAverage().getUpperLimit() - laLowerLimit : Float() from $loadThresholds.getLoadAverage().getLowerLimit() - - loadAverageAverage : Float() from $networkPartitionContext.getAverageLoadAverage() - loadAverageGradient : Float() from $networkPartitionContext.getLoadAverageGradient() - loadAverageSecondDerivative : Float() from $networkPartitionContext.getLoadAverageSecondDerivative() - laPredictedValue : Double() from $delegator.getPredictedValueForNextMinute(loadAverageAverage, loadAverageGradient, loadAverageSecondDerivative, 1) - - scaleUp : Boolean() from ((rifReset && (rifPredictedValue > rifUpperLimit)) || (mcReset && (mcPredictedValue > mcUpperLimit)) || (laReset && (laPredictedValue > laUpperLimit))) - scaleDown : Boolean() from ((rifReset && (rifPredictedValue < rifLowerLimit )) && (mcReset && (mcPredictedValue < mcLowerLimit)) && (laReset && (laPredictedValue < laLowerLimit))) - - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF Resetted?: " + rifReset)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF predicted value: " + rifPredictedValue)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF upper limit: " + rifUpperLimit)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " RIF lower limit: " + rifLowerLimit)) - - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " MC predicted value: " + mcPredictedValue)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " MC upper limit: " + mcUpperLimit)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " MC lower limit: " + mcLowerLimit)) - - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " LA predicted value: " + laPredictedValue)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " LA upper limit: " + laUpperLimit)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " LA lower limit: " + laLowerLimit)) - - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " Scale-up action: " + scaleUp)) - eval(log.debug("[scaling] " + " [cluster] " + clusterId + " Scale-down action: " + scaleDown)) - - then - if(scaleUp){ - - $networkPartitionContext.resetScaleDownRequestsCount(); - 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, lbRef, isPrimary); - } - } else if(scaleDown){ - - log.debug("[scale-down] Decided to Scale down [cluster] " + clusterId); - if($networkPartitionContext.getScaleDownRequestsCount() > 5 ){ - log.debug("[scale-down] Reached scale down requests threshold [cluster] " + clusterId + " Count " + $networkPartitionContext.getScaleDownRequestsCount()); - $networkPartitionContext.resetScaleDownRequestsCount(); - 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 instace 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{ - log.debug("[scale-down] Not reached scale down requests threshold. " + clusterId + " Count " + $networkPartitionContext.getScaleDownRequestsCount()); - $networkPartitionContext.increaseScaleDownRequestsCount(); - - } - } else{ - log.debug("[scaling] No decision made to either scale up or scale down ... "); - - } - -end - - - - http://git-wip-us.apache.org/repos/asf/stratos/blob/d189b136/products/stratos/modules/distribution/src/main/conf/terminateall.drl ---------------------------------------------------------------------- diff --git a/products/stratos/modules/distribution/src/main/conf/terminateall.drl b/products/stratos/modules/distribution/src/main/conf/terminateall.drl deleted file mode 100644 index 75c26fc..0000000 --- a/products/stratos/modules/distribution/src/main/conf/terminateall.drl +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.rule; - -import org.apache.stratos.messaging.domain.topology.Cluster; -import org.apache.stratos.autoscaler.PartitionContext; - -global org.apache.stratos.autoscaler.rule.RuleLog log; -global org.apache.stratos.autoscaler.rule.RuleTasksDelegator $delegator; - -rule "Terminate all Rule" - -dialect "mvel" - when - $ctxt : PartitionContext () - eval(log.debug("Running terminate all rule: [partition] " + $ctxt.getPartitionId() + " [network-partition] " + $ctxt.getNetworkPartitionId())) - eval(log.debug("[terminate all] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() +" Member count: " + $ctxt.getMemberStatsContexts().size())) - eval($ctxt.getMemberStatsContexts().size() > 0) - memberId : String() from $ctxt.getMemberStatsContexts().keySet() - eval(log.debug("[terminate all] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Member id: " + memberId)) - - then - $delegator.delegateTerminate($ctxt, memberId); -end - - -
