eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject eagle git commit: [EAGLE-960] Fix Alert detail and policy link url in alert template
Date Fri, 17 Mar 2017 05:33:15 GMT
Repository: eagle
Updated Branches:
  refs/heads/master c96c1927e -> a1c6a3948


[EAGLE-960] Fix Alert detail and policy link url in alert template

* Fix Alert detail and policy link url

Author: Hao Chen <hao@apache.org>

Closes #881 from haoch/EAGLE-960.


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

Branch: refs/heads/master
Commit: a1c6a3948c574e646e89ceb77396f35d9d49fad7
Parents: c96c192
Author: Hao Chen <hao@apache.org>
Authored: Fri Mar 17 13:32:58 2017 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Fri Mar 17 13:32:58 2017 +0800

----------------------------------------------------------------------
 .../eagle/alert/engine/model/AlertStreamEvent.java | 17 ++++++++++++++---
 .../alert/engine/model/AlertStreamEventTest.java   | 15 ---------------
 .../engine/evaluator/impl/AlertStreamCallback.java |  2 ++
 .../engine/evaluator/impl/SiddhiPolicyHandler.java |  4 ++--
 .../publisher/email/AlertEmailGenerator.java       |  8 ++++----
 .../publisher/template/AlertContextFields.java     |  1 +
 .../template/VelocityAlertTemplateEngine.java      |  1 +
 .../template/VelocityAlertTemplateEngineTest.java  |  4 ++--
 8 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java
index 50512b1..00170df 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java
@@ -31,6 +31,7 @@ import java.util.*;
 public class AlertStreamEvent extends StreamEvent {
     private static final long serialVersionUID = 2392131134670106397L;
 
+    private String siteId;
     private String alertId;
     private String policyId;
     private StreamDefinition schema;
@@ -53,6 +54,7 @@ public class AlertStreamEvent extends StreamEvent {
     }
 
     public AlertStreamEvent(AlertStreamEvent event) {
+        this.siteId = event.getSiteId();
         this.alertId = event.getAlertId();
         this.policyId = event.policyId;
         this.schema = event.schema;
@@ -84,9 +86,10 @@ public class AlertStreamEvent extends StreamEvent {
             }
         }
 
-        return String.format("Alert {stream=%S,timestamp=%s,data=%s, policyId=%s, createdBy=%s,
metaVersion=%s}",
-                this.getStreamId(), DateTimeUtil.millisecondsToHumanDateWithMilliseconds(this.getTimestamp()),
-                this.getDataMap(), this.getPolicyId(), this.getCreatedBy(), this.getMetaVersion());
+        return String.format("Alert {site=%s, stream=%s,timestamp=%s,data=%s, policyId=%s,
createdBy=%s, metaVersion=%s}",
+            this.getSiteId(),
+            this.getStreamId(), DateTimeUtil.millisecondsToHumanDateWithMilliseconds(this.getTimestamp()),
+            this.getDataMap(), this.getPolicyId(), this.getCreatedBy(), this.getMetaVersion());
     }
 
     public String getCreatedBy() {
@@ -176,4 +179,12 @@ public class AlertStreamEvent extends StreamEvent {
     public void setSeverity(AlertSeverity severity) {
         this.severity = severity;
     }
+
+    public String getSiteId() {
+        return siteId;
+    }
+
+    public void setSiteId(String siteId) {
+        this.siteId = siteId;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java
index beaa8fa..6706b1a 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java
@@ -47,22 +47,7 @@ public class AlertStreamEventTest {
         AlertStreamEvent alertStreamEvent = new AlertStreamEvent();
         alertStreamEvent.setSchema(streamDefinition);
         alertStreamEvent.setData(new Object[]{"namevalue", "hostvalue", "1", 10, 0.1, -0.2,
"{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 1});
-        Assert.assertEquals(
-                "Alert {stream=NULL,timestamp=1970-01-01 00:00:00,000,data={flag=1, data=0.1,
name=namevalue, host=hostvalue, salary=-0.2, value=10, int=1, object={\"name\":\"heap.COMMITTED\",
\"Value\":\"175636480\"}}, policyId=null, createdBy=null, metaVersion=null}",
-                alertStreamEvent.toString());
-        Assert.assertEquals(
-                "{flag=1, data=0.1, name=namevalue, host=hostvalue, salary=-0.2, value=10,
int=1, object={\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}}",
-                alertStreamEvent.getDataMap().toString());
-
         AlertStreamEvent alertStreamEvent1 = new AlertStreamEvent(alertStreamEvent);
-
-        Assert.assertEquals(
-                "Alert {stream=NULL,timestamp=1970-01-01 00:00:00,000,data={flag=1, data=0.1,
name=namevalue, host=hostvalue, salary=-0.2, value=10, int=1, object={\"name\":\"heap.COMMITTED\",
\"Value\":\"175636480\"}}, policyId=null, createdBy=null, metaVersion=null}",
-                alertStreamEvent1.toString());
-        Assert.assertEquals(
-                "{flag=1, data=0.1, name=namevalue, host=hostvalue, salary=-0.2, value=10,
int=1, object={\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}}",
-                alertStreamEvent1.getDataMap().toString());
-
         Assert.assertFalse(alertStreamEvent1 == alertStreamEvent);
         Assert.assertTrue(alertStreamEvent1.equals(alertStreamEvent));
         Assert.assertTrue(alertStreamEvent1.hashCode() == alertStreamEvent.hashCode());

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/AlertStreamCallback.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/AlertStreamCallback.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/AlertStreamCallback.java
index 6b6e0d5..25ebfca 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/AlertStreamCallback.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/AlertStreamCallback.java
@@ -57,12 +57,14 @@ public class AlertStreamCallback extends StreamCallback {
     @Override
     public void receive(Event[] events) {
         String policyName = context.getPolicyDefinition().getName();
+        String siteId = context.getPolicyDefinition().getSiteId();
         CompositePolicyHandler handler = ((PolicyGroupEvaluatorImpl) context.getPolicyEvaluator()).getPolicyHandler(policyName);
         if (LOG.isDebugEnabled()) {
             LOG.debug("Generated {} alerts from policy '{}' in {}, index of definiton {}
", events.length, policyName, context.getPolicyEvaluatorId(), currentIndex);
         }
         for (Event e : events) {
             AlertStreamEvent event = new AlertStreamEvent();
+            event.setSiteId(siteId);
             event.setTimestamp(e.getTimestamp());
             event.setData(e.getData());
             event.setStreamId(outputStream);

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/SiddhiPolicyHandler.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/SiddhiPolicyHandler.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/SiddhiPolicyHandler.java
index 72aca06..628b2e4 100755
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/SiddhiPolicyHandler.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/impl/SiddhiPolicyHandler.java
@@ -70,9 +70,9 @@ public class SiddhiPolicyHandler implements PolicyStreamHandler {
         List<String> outputStreams = getOutputStreams(policy);
         for (final String outputStream : outputStreams) {
             if (executionRuntime.getStreamDefinitionMap().containsKey(outputStream)) {
+                StreamDefinition streamDefinition = SiddhiDefinitionAdapter.convertFromSiddiDefinition(executionRuntime.getStreamDefinitionMap().get(outputStream));
                 this.executionRuntime.addCallback(outputStream,
-                    new AlertStreamCallback(
-                        outputStream, SiddhiDefinitionAdapter.convertFromSiddiDefinition(executionRuntime.getStreamDefinitionMap().get(outputStream)),
+                    new AlertStreamCallback(outputStream, streamDefinition,
                         collector, context, currentIndex));
             } else {
                 throw new IllegalStateException("Undefined output stream " + outputStream);

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java
index 8aaf310..1bcac17 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java
@@ -148,15 +148,15 @@ public class AlertEmailGenerator {
             : String.format("http://%s:%s", this.getServerHost(), this.getServerPort());
         try {
             alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_DETAIL_URL,
-                String.format("%s/#/alert/detail/%s", rootUrl, URIUtil.encodeQuery(event.getAlertId(),
"UTF-8")));
+                String.format("%s/#/site/%s/alert/detail/%s", rootUrl, event.getSiteId(),
URIUtil.encodeQuery(event.getAlertId(), "UTF-8")));
             alertContext.put(PublishConstants.ALERT_EMAIL_POLICY_DETAIL_URL,
-                String.format("%s/#/policy/detail/%s", rootUrl, URIUtil.encodeQuery(event.getPolicyId(),
"UTF-8")));
+                String.format("%s/#/site/%s/policy/detail/%s", rootUrl, event.getSiteId(),
URIUtil.encodeQuery(event.getPolicyId(), "UTF-8")));
         } catch (URIException e) {
             LOG.warn(e.getMessage(), e);
             alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_DETAIL_URL,
-                String.format("%s/#/alert/detail/%s", rootUrl, event.getAlertId()));
+                String.format("%s/#/site/%s/alert/detail/%s?timestamp=%s", event.getSiteId(),
rootUrl, event.getAlertId(), event.getTimestamp()));
             alertContext.put(PublishConstants.ALERT_EMAIL_POLICY_DETAIL_URL,
-                String.format("%s/#/policy/detail/%s", rootUrl, event.getPolicyId()));
+                String.format("%s/#/site/%s/policy/detail/%s", event.getSiteId(), rootUrl,
event.getPolicyId()));
         }
         alertContext.put(PublishConstants.ALERT_EMAIL_HOME_URL, rootUrl);
         return alertContext;

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/AlertContextFields.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/AlertContextFields.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/AlertContextFields.java
index 9f85952..1fe318e 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/AlertContextFields.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/AlertContextFields.java
@@ -21,6 +21,7 @@ import java.util.List;
 
 public class AlertContextFields {
     public static final String STREAM_ID = "STREAM_ID";
+    public static final String SITE_ID = "SITE_ID";
     public static final String ALERT_ID = "ALERT_ID";
     public static final String CREATED_BY = "CREATED_BY";
     public static final String POLICY_ID = "POLICY_ID";

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngine.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngine.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngine.java
index a019ca6..87a067f 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngine.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngine.java
@@ -146,6 +146,7 @@ public class VelocityAlertTemplateEngine implements AlertTemplateEngine
{
 
     private static VelocityContext buildAlertContext(PolicyDefinition policyDefinition, AlertStreamEvent
event) {
         VelocityContext context = new VelocityContext();
+        context.put(AlertContextFields.SITE_ID, event.getSiteId());
         context.put(AlertContextFields.STREAM_ID, event.getStreamId());
         context.put(AlertContextFields.ALERT_ID, event.getAlertId());
         context.put(AlertContextFields.CREATED_BY, event.getCreatedBy());

http://git-wip-us.apache.org/repos/asf/eagle/blob/a1c6a394/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngineTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngineTest.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngineTest.java
index b893213..7b1d494 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngineTest.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/template/VelocityAlertTemplateEngineTest.java
@@ -49,8 +49,7 @@ public class VelocityAlertTemplateEngineTest {
         templateEngine.init(ConfigFactory.load());
         templateEngine.register(mockPolicyWithoutTemplate("testPolicyName"));
         AlertStreamEvent event = templateEngine.filter(mockAlertEvent("testPolicyName"));
-        System.out.print(event.getBody());
-        Assert.assertEquals("Message: Alert {stream=ALERT_STREAM,timestamp=2016-11-30 07:31:15,923,"
+
+        Assert.assertEquals("Message: Alert {site=test, stream=ALERT_STREAM,timestamp=2016-11-30
07:31:15,923," +
             "data={site=test_cluster, role=hadoop, metric=cpu.usage, host=localhost, value=0.98},
" +
             "policyId=testPolicyName, createdBy=junit, metaVersion=SAMPLE_META_VERSION} "
+
             "(Auto-generated alert message as template not defined in policy testPolicyName)",
event.getBody());
@@ -91,6 +90,7 @@ public class VelocityAlertTemplateEngineTest {
 
     private AlertStreamEvent mockAlertEvent (String policyId) {
         AlertStreamEvent event = new AlertStreamEvent();
+        event.setSiteId("test");
         event.setCreatedBy("junit");
         event.setCreatedTime(1480491075923L);
         event.setPolicyId(policyId);


Mime
View raw message