Repository: stratos Updated Branches: refs/heads/container-autoscaling d2976b28f -> ff3722268
adding container drool files Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2a5cabed Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2a5cabed Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2a5cabed Branch: refs/heads/container-autoscaling Commit: 2a5cabed4bf8780e442bf602349acb2e4dcda7b2 Parents: 7162325 Author: R-Rajkumar <[email protected]> Authored: Thu Oct 9 10:50:08 2014 +0530 Committer: R-Rajkumar <[email protected]> Committed: Thu Oct 9 10:50:08 2014 +0530 ---------------------------------------------------------------------- .../modules/distribution/src/assembly/bin.xml | 16 +- .../src/main/conf/container-mincheck.drl | 48 ++++++ .../src/main/conf/container-scaling.drl | 148 +++++++++++++++++++ 3 files changed, 211 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/2a5cabed/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 e244ea4..76d0c14 100755 --- a/products/stratos/modules/distribution/src/assembly/bin.xml +++ b/products/stratos/modules/distribution/src/assembly/bin.xml @@ -662,7 +662,7 @@ <filtered>true</filtered> <fileMode>755</fileMode> </file> - <file> + <file> <source>src/main/conf/mincheck.drl</source> <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> <filtered>true</filtered> @@ -680,6 +680,20 @@ <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> + <filtered>true</filtered> + <fileMode>755</fileMode> + </file> + <file> + <source>src/main/conf/container-scaling.drl</source> + <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory> + <filtered>true</filtered> + <fileMode>755</fileMode> + </file> + <!-- container-drools files --> <!-- autoscaler --> <file> <source>${project.basedir}/INSTALL.txt</source> http://git-wip-us.apache.org/repos/asf/stratos/blob/2a5cabed/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 new file mode 100644 index 0000000..edea3cf --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/container-mincheck.drl @@ -0,0 +1,48 @@ +/* + * 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 "Minimum Rule" +dialect "mvel" + when + $kubernetesClusterContext : KubernetesClusterContext () + kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() + minReplicas : Integer() from $kubernetesClusterContext.getMinReplicas() + nonTerminatedReplicas : Integer() from $kubernetesClusterContext.getNonTerminatedMemberCount() + + eval(log.debug("Running minimum rule: [kub-cluster] " +kubernetesClusterId + " [cluster] " + clusterId)) + eval(log.debug("[min-check] [kub-cluster] " + kubernetesClusterId + + " [cluster] " + clusterId + " Non terminated member count: " + nonTerminatedReplicas)) + eval(log.debug("[min-check] [kub-cluster] " + kubernetesClusterId + + " [cluster] " + clusterId + " Minimum member count: " + minReplicas)) + eval (nonTerminatedReplicas < minReplicas) + then + log.info("[min-check] [kub-cluster] " + kubernetesClusterId + + " [cluster] " + clusterId + " : min-rule not satisfied, creating more containers") + $delegator.delegateExpandCluster($kubernetesClusterContext.getClusterId(), minReplicas); +end + http://git-wip-us.apache.org/repos/asf/stratos/blob/2a5cabed/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 new file mode 100644 index 0000000..c773264 --- /dev/null +++ b/products/stratos/modules/distribution/src/main/conf/container-scaling.drl @@ -0,0 +1,148 @@ +/* + * 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 "Scaling Rule" +dialect "mvel" + when + $kubernetesClusterContext : KubernetesClusterContext () + kubernetesClusterId : String() from $kubernetesClusterContext.getKubernetesClusterID() + minReplicas : Integer() from $kubernetesClusterContext.getMinReplicas() + maxReplicas : Integer() from $kubernetesClusterContext.getMaxReplicas() + + eval(log.debug("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 (rifReset && (rifPredictedValue < rifLowerLimit)) + scaleDownForMc : Boolean() from (mcReset && (mcPredictedValue < mcLowerLimit)) + scaleDownForLa : Boolean() from (laReset && (laPredictedValue < laLowerLimit)) + + scaleUp : Boolean() from (scaleUpForRif || scaleUpForMc || scaleUpForLa) + scaleDown : Boolean() from (scaleDownForRif && scaleDownForMc && scaleDownForLa) + + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [Replicas] minReplicas : " + minReplicas)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [Replicas] maxReplicas : " + maxReplicas)) + + 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.debug("[scaling] " + " [cluster] " + clusterId + " [MemoryConsumption] predicted value : " + mcPredictedValue)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [MemoryConsumption] upper limit : " + mcUpperLimit)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [MemoryConsumption] lower limit : " + mcLowerLimit)) + + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [LoadAverage] resetted ? : " + laReset)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [LoadAverage] predicted value : " + laPredictedValue)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [LoadAverage] upper limit : " + laUpperLimit)) + eval(log.debug("[scaling] " + " [cluster] " + clusterId + " [LoadAverage] 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) { + log.info("[scale-up] Decided to scale up : [kub-cluster] " + kubernetesClusterId + " [cluster] " + clusterId); + 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 + log.info("[scaling] " + " [cluster] " + clusterId + " valid number of replicas to expand : " + requiredReplicas); + $delegator.delegateExpandCluster(clusterId, requiredReplicas); + } else if (scaleDown) { + log.debug("[scale-down] Decided to scale down : [kub-cluster] " + kubernetesClusterId + " [cluster] " + clusterId); + //shrink the cluster to minReplicas + $delegator.delegateExpandCluster(clusterId, minReplicas); + } else { + log.debug("[scaling] No decision made to either scale up or down ... "); + } +end +
