You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/11/13 05:37:12 UTC

git commit: Move autoscaler rule file location to /repository/conf

Updated Branches:
  refs/heads/master 20928a04d -> 9dc67d977


Move autoscaler rule file location to /repository/conf

Signed-off-by: Imesh Gunaratne <im...@apache.org>


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

Branch: refs/heads/master
Commit: 9dc67d9774a69055a28abbd6a0db2b5ce095e9c0
Parents: 20928a0
Author: Melan Nimesh <me...@gmail.com>
Authored: Tue Nov 12 12:47:13 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Wed Nov 13 10:06:44 2013 +0530

----------------------------------------------------------------------
 .../rule/AutoscalerRuleEvaluator.java           |  11 +-
 .../autoscaler/rule/ExecutorTaskScheduler.java  |   7 +-
 .../distribution/src/main/assembly/bin.xml      |   6 +
 .../distribution/src/main/conf/autoscaler.drl   | 114 +++++++++++++++++++
 4 files changed, 132 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9dc67d97/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 5f6627f..3d23e95 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
@@ -19,6 +19,8 @@
 
 package org.apache.stratos.autoscaler.rule;
 
+import java.io.File;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.AutoscalerContext;
@@ -33,6 +35,7 @@ import org.drools.builder.*;
 import org.drools.io.Resource;
 import org.drools.io.ResourceFactory;
 import org.drools.runtime.StatefulKnowledgeSession;
+import org.wso2.carbon.utils.CarbonUtils;
 import org.apache.stratos.autoscaler.Constants;
 import org.apache.stratos.autoscaler.algorithm.AutoscaleAlgorithm;
 import org.apache.stratos.autoscaler.algorithm.OneAfterAnother;
@@ -50,7 +53,6 @@ public class AutoscalerRuleEvaluator {
 	
 	private static AutoscalerRuleEvaluator instance = null;
 	private static final String DRL_FILE_NAME = "autoscaler.drl";
-    //TODO move .drl file outside jar
 	
 	private KnowledgeBase kbase;
 	private StatefulKnowledgeSession ksession;
@@ -64,7 +66,7 @@ public class AutoscalerRuleEvaluator {
     }
     
     
-    public void evaluate(Service service){
+    public void evaluate(Service service) throws Exception{
         try {
 
             for (Cluster cluster: service.getClusters()){
@@ -81,7 +83,7 @@ public class AutoscalerRuleEvaluator {
 			ksession.insert(service);
 			ksession.fireAllRules();
 		} catch (Exception e) {
-			log.error("Rule evaluate error", e);
+			throw new Exception("Rule evaluate error", e);
 		}
     }
     
@@ -144,7 +146,8 @@ public class AutoscalerRuleEvaluator {
     
     private KnowledgeBase readKnowledgeBase() throws Exception {
         KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-        Resource resource = ResourceFactory.newClassPathResource(DRL_FILE_NAME);
+        String configDir = CarbonUtils.getCarbonConfigDirPath();
+        Resource resource = ResourceFactory.newFileResource(configDir + File.separator + DRL_FILE_NAME);
 		kbuilder.add(resource, ResourceType.DRL);
         KnowledgeBuilderErrors errors = kbuilder.getErrors();
         if (errors.size() > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9dc67d97/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
index c92996c..5722a57 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
@@ -51,6 +51,7 @@ public class ExecutorTaskScheduler implements Runnable {
 
     @Override
     public void run() {
+    	final ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
         final Runnable rulesEvaluator = new Runnable() {
             public void run() {
 
@@ -78,11 +79,13 @@ public class ExecutorTaskScheduler implements Runnable {
                     }
 
                 } catch (Exception e) {
-                    log.error("Error ", e);
+                    log.error("Error", e);
+                    log.debug("Shutting down rule scheduler");
+                    ex.shutdownNow();
                 }
             }
         };
-        ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
+        
         ex.scheduleWithFixedDelay(rulesEvaluator, initialDelay, period, TimeUnit.SECONDS);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9dc67d97/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/assembly/bin.xml b/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
index a7c21ba..ed08150 100644
--- a/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
+++ b/products/autoscaler/modules/distribution/src/main/assembly/bin.xml
@@ -230,6 +230,12 @@
             <fileMode>755</fileMode>
         </file>
         <file>
+            <source>src/main/conf/autoscaler.drl</source>
+            <outputDirectory>apache-stratos-autoscaler-${pom.version}/repository/conf</outputDirectory>
+            <filtered>true</filtered>
+            <fileMode>755</fileMode>
+        </file>
+        <file>
             <source>src/main/resources/log4j.properties</source>
             <outputDirectory>apache-stratos-autoscaler-${pom.version}/repository/conf</outputDirectory>
             <filtered>true</filtered>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9dc67d97/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl b/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
new file mode 100644
index 0000000..138dfc6
--- /dev/null
+++ b/products/autoscaler/modules/distribution/src/main/conf/autoscaler.drl
@@ -0,0 +1,114 @@
+/*
+ * 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.ClusterContext;
+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.Partition;
+import org.apache.stratos.autoscaler.policy.model.HAPolicy;
+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.messaging.message.receiver.topology.TopologyManager;
+import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
+import org.apache.commons.logging.Log;
+
+global org.apache.stratos.autoscaler.policy.PolicyManager $manager;
+global org.apache.stratos.autoscaler.AutoscalerContext $context; 
+global org.apache.commons.logging.Log log;
+global org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator $evaluator;
+global org.apache.stratos.messaging.domain.topology.Topology $topology;
+
+
+rule "Minimum Rule"
+dialect "mvel"
+	when
+        $service : Service ()
+        $cluster : Cluster () from  $service.getClusters()
+        $policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+        $partition : Partition () from $policy.getHAPolicy().getPartitions()
+        $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+        eval($clusterContext.getPartitionCount($partition.getId()) < $partition.getPartitionMembersMin() )
+	then
+        int memberCountToBeIncreased =  $partition.getPartitionMembersMin() - $clusterContext.getPartitionCount($partition.getId());
+        if($evaluator.delegateSpawn($partition,$cluster.getClusterId(), memberCountToBeIncreased)){
+            $clusterContext.increaseMemberCountInPartition($partition.getId(), memberCountToBeIncreased);
+        }
+end
+
+rule "Scaler-up Rule"
+dialect "mvel"
+	when
+        $service : Service ()
+        $cluster : Cluster () from  $service.getClusters()
+        $policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+        $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+        $loadThresholds :LoadThresholds() from  $policy.getLoadThresholds()
+        autoscaleAlgorithm : AutoscaleAlgorithm() from  $evaluator.getAutoscaleAlgorithm($policy.getHAPolicy().getPartitionAlgo())
+        lbStatAverage : Float() from  $clusterContext.getAverageRequestsInFlight()
+        lbStatGradient : Float() from  $clusterContext.getRequestsInFlightGradient()
+        lbStatSecondDerivative : Float() from  $clusterContext.getRequestsInFlightSecondDerivative()
+        averageLimit : Float() from  $loadThresholds.getRequestsInFlight().getAverage()
+        gradientLimit : Float() from  $loadThresholds.getRequestsInFlight().getGradient()
+        secondDerivative  : Float() from  $loadThresholds.getRequestsInFlight().getSecondDerivative()
+        partition :  Partition() from autoscaleAlgorithm.getNextScaleUpPartition($cluster.getClusterId())
+        eval (lbStatAverage > averageLimit && lbStatGradient > gradientLimit)
+	then
+        int numberOfInstancesToBeSpawned = (lbStatSecondDerivative > secondDerivative) ? 2 : 1; //  take from a config
+        $evaluator.delegateSpawn(partition,$cluster.getClusterId(), numberOfInstancesToBeSpawned);
+        $clusterContext.setRequestsInFlightGradient(gradientLimit);
+        $clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+        $clusterContext.setAverageRequestsInFlight(averageLimit);
+end
+
+rule "Scaler-down Rule"
+dialect "mvel"
+	when
+	    $service : Service ()
+	    $cluster : Cluster () from  $service.getClusters()
+	    $policy : AutoscalePolicy(id == $cluster.autoscalePolicyName ) from $manager.getPolicyList()
+	    $clusterContext : ClusterContext() from $context.getClusterContext($cluster.getClusterId())
+        $loadThresholds :LoadThresholds() from  $policy.getLoadThresholds()
+        autoscaleAlgorithm : AutoscaleAlgorithm() from  $evaluator.getAutoscaleAlgorithm($policy.getHAPolicy().getPartitionAlgo())
+        lbStatAverage : Float() from  $clusterContext.getAverageRequestsInFlight()
+        lbStatGradient : Float() from  $clusterContext.getRequestsInFlightGradient()
+        lbStatSecondDerivative : Float() from  $clusterContext.getRequestsInFlightSecondDerivative()
+        averageLimit : Float() from  $loadThresholds.getRequestsInFlight().getAverage()
+        gradientLimit : Float() from  $loadThresholds.getRequestsInFlight().getGradient()
+        secondDerivative  : Float() from  $loadThresholds.getRequestsInFlight().getSecondDerivative()
+        scaleDownSlowerMarginOfGradient : Float() from  $loadThresholds.getRequestsInFlight().getScaleDownMarginOfGradient()
+        scaleDownSlowerMarginOfSecondDerivative : Float() from  $loadThresholds.getRequestsInFlight().getScaleDownMarginOfSecondDerivative()
+        partition : Partition() from autoscaleAlgorithm.getNextScaleDownPartition($cluster.getClusterId())
+        eval(lbStatAverage < averageLimit  && lbStatGradient < gradientLimit - scaleDownSlowerMarginOfSecondDerivative
+                         && lbStatSecondDerivative < secondDerivative - scaleDownSlowerMarginOfSecondDerivative)
+	then
+        $evaluator.delegateTerminate(partition,$cluster.getClusterId());
+        $clusterContext.setRequestsInFlightGradient(gradientLimit);
+        $clusterContext.setRequestsInFlightSecondDerivative(secondDerivative);
+        $clusterContext.setAverageRequestsInFlight(averageLimit);
+end