eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ralp...@apache.org
Subject incubator-eagle git commit: [Enhancement] eagle alert engine policy handler extensible for customized handler
Date Wed, 07 Sep 2016 05:51:38 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop fce6ae3f0 -> f81ae0621


[Enhancement] eagle alert engine policy handler extensible for customized handler

Author : ralphsu


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

Branch: refs/heads/develop
Commit: f81ae06217235a04745997f70ddcd1c4d92707e9
Parents: fce6ae3
Author: Ralph, Su <suliangfei@gmail.com>
Authored: Wed Sep 7 13:50:32 2016 +0800
Committer: Ralph, Su <suliangfei@gmail.com>
Committed: Wed Sep 7 13:50:32 2016 +0800

----------------------------------------------------------------------
 .../org/apache/eagle/alert/utils/JsonUtils.java |  2 +-
 .../engine/evaluator/PolicyHandlerContext.java  | 13 ++++-
 .../impl/PolicyGroupEvaluatorImpl.java          | 13 ++---
 .../engine/evaluator/PoilcyExtendedTest.java    | 51 ++++++++++++++++++++
 .../src/test/resources/extend_policy.json       | 22 +++++++++
 5 files changed, 92 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/f81ae062/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java
index de0c48b..09ee5f4 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java
@@ -16,10 +16,10 @@
  */
 package org.apache.eagle.alert.utils;
 
+import org.codehaus.jackson.map.ObjectMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 /**
  * @since May 1, 2016

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/f81ae062/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/PolicyHandlerContext.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/PolicyHandlerContext.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/PolicyHandlerContext.java
index 285ca13..335b237 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/PolicyHandlerContext.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/PolicyHandlerContext.java
@@ -1,8 +1,8 @@
 package org.apache.eagle.alert.engine.evaluator;
 
-import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
-
 import backtype.storm.metric.api.MultiCountMetric;
+import com.typesafe.config.Config;
+import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,6 +25,7 @@ public class PolicyHandlerContext {
     private PolicyGroupEvaluator policyEvaluator;
     private MultiCountMetric policyCounter;
     private String policyEvaluatorId;
+    private Config config;
 
     public PolicyDefinition getPolicyDefinition() {
         return policyDefinition;
@@ -57,4 +58,12 @@ public class PolicyHandlerContext {
     public void setPolicyEvaluatorId(String policyEvaluatorId) {
         this.policyEvaluatorId = policyEvaluatorId;
     }
+
+    public Config getConfig() {
+        return config;
+    }
+
+    public void setConfig(Config config) {
+        this.config = config;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/f81ae062/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/PolicyGroupEvaluatorImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/PolicyGroupEvaluatorImpl.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/PolicyGroupEvaluatorImpl.java
index 068df90..26ae19e 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/PolicyGroupEvaluatorImpl.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/PolicyGroupEvaluatorImpl.java
@@ -138,12 +138,13 @@ public class PolicyGroupEvaluatorImpl implements PolicyGroupEvaluator
{
             policies.put(policy.getName(), policy);
             CompositePolicyHandler handler = new CompositePolicyHandler(sds);
             try {
-                PolicyHandlerContext context = new PolicyHandlerContext();
-                context.setPolicyCounter(this.context.counter());
-                context.setPolicyDefinition(policy);
-                context.setPolicyEvaluator(this);
-                context.setPolicyEvaluatorId(policyEvaluatorId);
-                handler.prepare(collector, context);
+                PolicyHandlerContext handlerContext = new PolicyHandlerContext();
+                handlerContext.setPolicyCounter(this.context.counter());
+                handlerContext.setPolicyDefinition(policy);
+                handlerContext.setPolicyEvaluator(this);
+                handlerContext.setPolicyEvaluatorId(policyEvaluatorId);
+                handlerContext.setConfig(this.context.config());
+                handler.prepare(collector, handlerContext);
                 handlers.put(policy.getName(), handler);
             } catch (Exception e) {
                 LOG.error(e.getMessage(), e);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/f81ae062/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/evaluator/PoilcyExtendedTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/evaluator/PoilcyExtendedTest.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/evaluator/PoilcyExtendedTest.java
new file mode 100644
index 0000000..dd75efb
--- /dev/null
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/evaluator/PoilcyExtendedTest.java
@@ -0,0 +1,51 @@
+package org.apache.eagle.alert.engine.evaluator;
+
+import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.node.ArrayNode;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created on 9/7/16.
+ */
+public class PoilcyExtendedTest {
+
+    private static final ObjectMapper mapper = new ObjectMapper();
+
+    @Test
+    public void test() throws Exception {
+        ArrayNode arrayNode = (ArrayNode)
+                mapper.readTree(PoilcyExtendedTest.class.getResourceAsStream("/extend_policy.json"));
+        Assert.assertEquals(1, arrayNode.size());
+        for (JsonNode node : arrayNode) {
+            PolicyDefinition definition = mapper.readValue(node, PolicyDefinition.class);
+
+            Assert.assertNotNull(definition);
+            Assert.assertNotNull(definition.getName());
+            Assert.assertNotNull(definition.getDefinition());
+
+            Assert.assertEquals(PolicyStreamHandlers.CUSTOMIZED_ENGINE, definition.getDefinition().getType());
+            Assert.assertNotNull(definition.getDefinition().getProperties());
+
+            Assert.assertTrue(definition.getDefinition().getProperties().containsKey("parentKey"));
+            Map pkSetting = (Map) definition.getDefinition().getProperties().get("parentKey");
+            Assert.assertTrue(pkSetting.containsKey("syslogStream"));
+
+            Map syslogStreamSetting = (Map) pkSetting.get("syslogStream");
+            Assert.assertTrue(syslogStreamSetting.containsKey("pattern"));
+            Assert.assertEquals("%s-%s", syslogStreamSetting.get("pattern"));
+
+            Assert.assertTrue(syslogStreamSetting.containsKey("columns"));
+            Assert.assertEquals(3, ((List) syslogStreamSetting.get("columns")).size());
+
+            break;
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/f81ae062/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/extend_policy.json
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/extend_policy.json
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/extend_policy.json
new file mode 100644
index 0000000..3a5bd86
--- /dev/null
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/extend_policy.json
@@ -0,0 +1,22 @@
+[
+  {
+    "name": "extend-policy",
+    "definition": {
+      "type": "Custom",
+      "handlerClass": "i.o.x.Handler",
+      "value": "",
+      "properties": {
+        "parentKey": {
+          "syslogStream": {
+            "pattern": "%s-%s",
+            "columns": [
+              "a",
+              "b",
+              "d"
+            ]
+          }
+        }
+      }
+    }
+  }
+]


Mime
View raw message