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/12/27 06:32:27 UTC

git commit: Added new test case to validate drools files packaged with autoscaler product and corrected syntax errors

Updated Branches:
  refs/heads/master 56878f061 -> 19217e3c4


Added new test case to validate drools files packaged with autoscaler product and corrected syntax errors


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

Branch: refs/heads/master
Commit: 19217e3c4d2bdef40aa99a985fc7ff7933f74fda
Parents: 56878f0
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Dec 27 11:02:02 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Dec 27 11:02:02 2013 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/TestRulesPackaged.java   | 66 ++++++++++++++++++++
 .../distribution/src/main/conf/scaling.drl      | 30 ++++-----
 2 files changed, 81 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19217e3c/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
new file mode 100644
index 0000000..1e09cc1
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestRulesPackaged.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.drools.KnowledgeBase;
+import org.drools.builder.*;
+import org.drools.io.Resource;
+import org.drools.io.ResourceFactory;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+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 KnowledgeBase kbase;
+    private StatefulKnowledgeSession ksession;
+
+    @Test
+    public void testMinCheckDroolsFile() {
+        parseDroolsFile(minCheckDrlFilePath);
+    }
+
+    @Test
+    public void testScalingDroolsFile() {
+        parseDroolsFile(scalingDrlFilePath);
+    }
+
+    private void parseDroolsFile(String droolsFilePath) {
+        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+        Resource resource = ResourceFactory.newFileResource(droolsFilePath);
+        kbuilder.add(resource, ResourceType.DRL);
+        KnowledgeBuilderErrors errors = kbuilder.getErrors();
+        if (errors.size() > 0) {
+            StringBuilder sb = new StringBuilder();
+            for (KnowledgeBuilderError error : errors) {
+                sb.append(error.getMessage());
+            }
+            if(sb.length() > 0) {
+                log.error(sb.toString());
+            }
+            throw new IllegalArgumentException(String.format("Could not parse drools file: %s", droolsFilePath));
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19217e3c/products/autoscaler/modules/distribution/src/main/conf/scaling.drl
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/conf/scaling.drl b/products/autoscaler/modules/distribution/src/main/conf/scaling.drl
index eaf225a..5d3b6c9 100644
--- a/products/autoscaler/modules/distribution/src/main/conf/scaling.drl
+++ b/products/autoscaler/modules/distribution/src/main/conf/scaling.drl
@@ -80,7 +80,7 @@ dialect "mvel"
 
         eval(scaleUpAction)
 	then
-        log.debug(log.debug("[scale-up] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + cluster + " Scaling up cluster");
+        log.debug("[scale-up] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId + " Scaling up cluster");
         $delegator.delegateSpawn($networkPartitionContext.getPartitionCtxt(partition.getId()), clusterId, lbRef);
 end
 
@@ -119,24 +119,24 @@ dialect "mvel"
             for(MemberStatsContext memberStatsContext: partitionContext.getMemberStatsContexts().values()){
 
                 LoadAverage loadAverage = memberStatsContext.getLoadAverage();
-                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId
-                    + " [member] " + memberStatsContext.getMemberId() + " Load average: " + loadAverage.toString());
+                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] "
+                    + clusterId + " [member] " + memberStatsContext.getMemberId() + " Load average: " + loadAverage.toString());
 
                 MemoryConsumption memoryConsumption = memberStatsContext.getMemoryConsumption();
-                log.debug(log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId
-                    + " [member] " + memberStatsContext.getMemberId() + " Memory consumption: " + memoryConsumption.toString()));
+                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] "
+                    + clusterId + " [member] " + memberStatsContext.getMemberId() + " Memory consumption: " + memoryConsumption.toString());
 
                 double predictedCpu = $delegator.getPredictedValueForNextMinute(loadAverage.getAverage(),loadAverage.getGradient(),loadAverage.getSecondDerivative(), 1);
-                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId
-                    + " [member] " + memberStatsContext.getMemberId() + " Predicted CPU: " + predictedCpu);
+                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [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] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId
-                    + " [member] " + memberStatsContext.getMemberId() + " Predicted memory consumption: " + predictedMemoryConsumption);
+                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] "
+                    + clusterId + " [member] " + memberStatsContext.getMemberId() + " Predicted memory consumption: " + predictedMemoryConsumption);
 
                 double overallLoad = (predictedCpu + predictedMemoryConsumption) / 2;
-                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId
-                    + " [member] " + memberStatsContext.getMemberId() + " Overall load: " + overallLoad);
+                log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] "
+                    + clusterId + " [member] " + memberStatsContext.getMemberId() + " Overall load: " + overallLoad);
 
                 if(!foundAValue){
                     foundAValue = true;
@@ -148,14 +148,14 @@ dialect "mvel"
                 }
 
                 if(selectedMemberStatsContext != null) {
-                    log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId +
-                        + " Member with lowest overall load: " + memberStatsContext.getMemberId());
+                    log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] "
+                        + clusterId + " Member with lowest overall load: " + memberStatsContext.getMemberId());
                 }
             }
         }
         if(selectedMemberStatsContext != null) {
-            log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId +
-                        + " Terminating member: " + memberStatsContext.getMemberId());
+            log.debug("[scale-down] [network-partition] " + $networkPartitionContext.getId() + " [partition]" + partition.getId() + " [cluster] " + clusterId
+                + " Terminating member: " + selectedMemberStatsContext.getMemberId());
             $delegator.delegateTerminate(selectedMemberStatsContext.getMemberId());
         }
 end