You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/01/09 05:26:00 UTC

git commit: Adding terminate all rule and test case to parse it

Updated Branches:
  refs/heads/master 7e2b9d94e -> c866aa079


Adding terminate all rule and test case to parse it


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

Branch: refs/heads/master
Commit: c866aa0791989a4912b9227a001851438d063669
Parents: 7e2b9d9
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Thu Jan 9 10:00:16 2014 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Thu Jan 9 10:00:16 2014 +0530

----------------------------------------------------------------------
 .../rule/AutoscalerRuleEvaluator.java           | 52 ++++++++++----------
 .../stratos/autoscaler/TestRulesPackaged.java   |  6 +++
 .../distribution/src/main/conf/terminateall.drl | 44 +++++++++++++++++
 3 files changed, 76 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c866aa07/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 57e266d..21ab342 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
@@ -64,11 +64,11 @@ public class AutoscalerRuleEvaluator {
         if (log.isDebugEnabled()) {
             log.debug("Scale check rule is parsed successfully");
         }
-//        terminateAllKbase = readKnowledgeBase(TERMINATE_ALL_DRL_FILE_NAME);
-//
-//        if (log.isDebugEnabled()) {
-//            log.debug("Terminate all rule is parsed successfully");
-//        }
+        terminateAllKbase = readKnowledgeBase(TERMINATE_ALL_DRL_FILE_NAME);
+
+        if (log.isDebugEnabled()) {
+            log.debug("Terminate all rule is parsed successfully");
+        }
     }
 
     
@@ -108,21 +108,21 @@ public class AutoscalerRuleEvaluator {
 
 
 
-//    public static FactHandle evaluateTerminateAll(StatefulKnowledgeSession ksession, FactHandle handle, Object obj) {
-//
-//        if (handle == null) {
-//
-//            ksession.setGlobal("$delegator", new RuleTasksDelegator());
-//            handle = ksession.insert(obj);
-//        } else {
-//            ksession.update(handle, obj);
-//        }
-//        ksession.fireAllRules();
-//        if(log.isDebugEnabled()){
-//            log.debug(String.format("Terminate all check executed for : %s ", obj));
-//        }
-//        return handle;
-//    }
+    public static FactHandle evaluateTerminateAll(StatefulKnowledgeSession ksession, FactHandle handle, Object obj) {
+
+        if (handle == null) {
+
+            ksession.setGlobal("$delegator", new RuleTasksDelegator());
+            handle = ksession.insert(obj);
+        } else {
+            ksession.update(handle, obj);
+        }
+        ksession.fireAllRules();
+        if(log.isDebugEnabled()){
+            log.debug(String.format("Terminate all check executed for : %s ", obj));
+        }
+        return handle;
+    }
 
 
 
@@ -138,12 +138,12 @@ public class AutoscalerRuleEvaluator {
         ksession.setGlobal("log", RuleLog.getInstance());
         return ksession;
     }
-//    public StatefulKnowledgeSession getTerminateAllStatefulSession() {
-//        StatefulKnowledgeSession ksession;
-//        ksession = scaleCheckKbase.newStatefulKnowledgeSession();
-//        ksession.setGlobal("log", RuleLog.getInstance());
-//        return ksession;
-//    }
+    public StatefulKnowledgeSession getTerminateAllStatefulSession() {
+        StatefulKnowledgeSession ksession;
+        ksession = scaleCheckKbase.newStatefulKnowledgeSession();
+        ksession.setGlobal("log", RuleLog.getInstance());
+        return ksession;
+    }
 
     public static String getLbClusterId(PartitionContext partitionContext, NetworkPartitionContext ctxt) {
         Properties props = partitionContext.getProperties();

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c866aa07/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 1e09cc1..bdb6d16 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
@@ -34,6 +34,7 @@ public class TestRulesPackaged {
     private static final Log log = LogFactory.getLog(TestRulesPackaged.class);
     private String minCheckDrlFilePath = "../../products/autoscaler/modules/distribution/src/main/conf/mincheck.drl";
     private String scalingDrlFilePath = "../../products/autoscaler/modules/distribution/src/main/conf/scaling.drl";
+    private String terminateAllDrlFilePath = "../../products/autoscaler/modules/distribution/src/main/conf/terminateall.drl";
     private KnowledgeBase kbase;
     private StatefulKnowledgeSession ksession;
 
@@ -47,6 +48,11 @@ public class TestRulesPackaged {
         parseDroolsFile(scalingDrlFilePath);
     }
 
+    @Test
+    public void testTerminateAllDroolsFile() {
+        parseDroolsFile(terminateAllDrlFilePath);
+    }
+
     private void parseDroolsFile(String droolsFilePath) {
         KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
         Resource resource = ResourceFactory.newFileResource(droolsFilePath);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c866aa07/products/autoscaler/modules/distribution/src/main/conf/terminateall.drl
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/conf/terminateall.drl b/products/autoscaler/modules/distribution/src/main/conf/terminateall.drl
new file mode 100644
index 0000000..7150eca
--- /dev/null
+++ b/products/autoscaler/modules/distribution/src/main/conf/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(memberId);
+end
+
+
+