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: [Fix] : Have alert stream event only refer to the policy id, not the policy definition
Date Wed, 07 Sep 2016 10:12:12 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop 0a2ce9ed3 -> 3324279e4


[Fix] : Have alert stream event only refer to the policy id, not the policy definition

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/3324279e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/3324279e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/3324279e

Branch: refs/heads/develop
Commit: 3324279e42e17c0a063922be355a135cce8c975c
Parents: 0a2ce9e
Author: Ralph, Su <suliangfei@gmail.com>
Authored: Wed Sep 7 18:11:15 2016 +0800
Committer: Ralph, Su <suliangfei@gmail.com>
Committed: Wed Sep 7 18:11:15 2016 +0800

----------------------------------------------------------------------
 .../alert/engine/model/AlertStreamEvent.java      | 18 ++++++------------
 .../evaluator/impl/AlertStreamCallback.java       |  2 +-
 .../evaluator/nodata/NoDataPolicyHandler.java     | 11 +++--------
 .../nodata/NoDataPolicyTimeBatchHandler.java      | 10 +++-------
 .../alert/engine/utils/AlertStreamUtils.java      |  2 +-
 .../engine/router/TestAlertPublisherBolt.java     |  4 ++--
 6 files changed, 16 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3324279e/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 6e784c5..13881a1 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
@@ -17,7 +17,6 @@
 package org.apache.eagle.alert.engine.model;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
 import org.apache.eagle.alert.engine.coordinator.StreamDefinition;
 import org.apache.eagle.alert.utils.DateTimeUtil;
 
@@ -30,22 +29,17 @@ import java.util.List;
 public class AlertStreamEvent extends StreamEvent {
     private static final long serialVersionUID = 2392131134670106397L;
 
-    // TODO: Keep policy name only instead of policy entity
-    private PolicyDefinition policy;
+    private String policyId;
     private StreamDefinition schema;
     private String createdBy;
     private long createdTime;
 
-    public PolicyDefinition getPolicy() {
-        return policy;
-    }
-
-    public void setPolicy(PolicyDefinition policy) {
-        this.policy = policy;
+    public void setPolicyId(String policyId) {
+        this.policyId = policyId;
     }
 
     public String getPolicyId() {
-        return policy.getName();
+        return policyId;
     }
 
     @Override
@@ -58,8 +52,8 @@ public class AlertStreamEvent extends StreamEvent {
                 dataStrings.add(null);
             }
         }
-        return String.format("AlertStreamEvent[stream=%S,timestamp=%s,data=[%s], policy=%s,
createdBy=%s, metaVersion=%s]",
-                this.getStreamId(), DateTimeUtil.millisecondsToHumanDateWithMilliseconds(this.getTimestamp()),
StringUtils.join(dataStrings,","),this.getPolicy().getName(),this.getCreatedBy(),this.getMetaVersion());
+        return String.format("AlertStreamEvent[stream=%S,timestamp=%s,data=[%s], policyId=%s,
createdBy=%s, metaVersion=%s]",
+                this.getStreamId(), DateTimeUtil.millisecondsToHumanDateWithMilliseconds(this.getTimestamp()),
StringUtils.join(dataStrings,","),this.getPolicyId(),this.getCreatedBy(),this.getMetaVersion());
     }
 
     public String getCreatedBy() {

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3324279e/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 50e3377..b9a109c 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
@@ -68,7 +68,7 @@ public class AlertStreamCallback extends StreamCallback {
             event.setTimestamp(e.getTimestamp());
             event.setData(e.getData());
             event.setStreamId(outputStream);
-            event.setPolicy(context.getPolicyDefinition());
+            event.setPolicyId(context.getPolicyDefinition().getName());
             if (this.context.getPolicyEvaluator() != null) {
                 event.setCreatedBy(context.getPolicyEvaluator().getName());
             }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3324279e/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyHandler.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyHandler.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyHandler.java
index 9ad7529..8f37b93 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyHandler.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyHandler.java
@@ -16,13 +16,6 @@
  */
 package org.apache.eagle.alert.engine.evaluator.nodata;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.eagle.alert.engine.Collector;
 import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
@@ -36,6 +29,8 @@ import org.joda.time.Period;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.*;
+
 /**
  * Since 6/28/16.
  * No Data Policy engine
@@ -190,7 +185,7 @@ public class NoDataPolicyHandler implements PolicyStreamHandler{
         event.setTimestamp(timestamp);
         event.setData(triggerEvent);
         event.setStreamId(policyDef.getOutputStreams().get(0));
-        event.setPolicy(context.getPolicyDefinition());
+        event.setPolicyId(context.getPolicyDefinition().getName());
         if (this.context.getPolicyEvaluator() != null) {
             event.setCreatedBy(context.getPolicyEvaluator().getName());
         }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3324279e/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyTimeBatchHandler.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyTimeBatchHandler.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyTimeBatchHandler.java
index 741fce4..53a7af0 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyTimeBatchHandler.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/evaluator/nodata/NoDataPolicyTimeBatchHandler.java
@@ -16,12 +16,6 @@
  */
 package org.apache.eagle.alert.engine.evaluator.nodata;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.eagle.alert.engine.Collector;
 import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
@@ -36,6 +30,8 @@ import org.joda.time.Period;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.*;
+
 public class NoDataPolicyTimeBatchHandler implements PolicyStreamHandler {
 	
 	private static final Logger LOG = LoggerFactory.getLogger(NoDataPolicyTimeBatchHandler.class);
@@ -151,7 +147,7 @@ public class NoDataPolicyTimeBatchHandler implements PolicyStreamHandler
{
 		event.setTimestamp(timestamp);
 		event.setData(triggerEvent);
 		event.setStreamId(policyDef.getOutputStreams().get(0));
-		event.setPolicy(context.getPolicyDefinition());
+		event.setPolicyId(context.getPolicyDefinition().getName());
 		if (this.context.getPolicyEvaluator() != null) {
 			event.setCreatedBy(context.getPolicyEvaluator().getName());
 		}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3324279e/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/utils/AlertStreamUtils.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/utils/AlertStreamUtils.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/utils/AlertStreamUtils.java
index 0eaf065..fc9cc8a 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/utils/AlertStreamUtils.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/utils/AlertStreamUtils.java
@@ -41,7 +41,7 @@ public class AlertStreamUtils {
         alertStreamEvent.setTimestamp(event.getTimestamp());
         alertStreamEvent.setData(event.getData());
         alertStreamEvent.setStreamId(policyDef.getOutputStreams().get(0));
-        alertStreamEvent.setPolicy(policyDef);
+        alertStreamEvent.setPolicyId(policyDef.getName());
 
         if (context.getPolicyEvaluator() != null) {
             alertStreamEvent.setCreatedBy(context.getPolicyEvaluator().getName());

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3324279e/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertPublisherBolt.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertPublisherBolt.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertPublisherBolt.java
index 1854c41..1e52036 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertPublisherBolt.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertPublisherBolt.java
@@ -70,7 +70,7 @@ public class TestAlertPublisherBolt {
         AlertStreamEvent alert = new AlertStreamEvent();
         PolicyDefinition policy = new PolicyDefinition();
         policy.setName("policy1");
-        alert.setPolicy(policy);
+        alert.setPolicyId(policy.getName());
         alert.setCreatedTime(System.currentTimeMillis());
         alert.setData(new Object[]{"field_1", 2, "field_3"});
         alert.setStreamId(streamId);
@@ -169,7 +169,7 @@ public class TestAlertPublisherBolt {
         AlertStreamEvent alert = new AlertStreamEvent();
         PolicyDefinition policy = new PolicyDefinition();
         policy.setName("perfmon_cpu_host_check");
-        alert.setPolicy(policy);
+        alert.setPolicyId(policy.getName());
         alert.setCreatedTime(System.currentTimeMillis());
         alert.setData(new Object[]{appName, hostname});
         alert.setStreamId("testAlertStream");


Mime
View raw message