eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: [EAGLE-49] Handle the bad-format message in smarter way instead of throwing exception
Date Sun, 22 Nov 2015 16:41:43 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master 86fe855d0 -> 5bffdfd3a


[EAGLE-49] Handle the bad-format message in smarter way instead of throwing exception


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

Branch: refs/heads/master
Commit: 5bffdfd3a9af0f65fd7257d4de114a198a73cce9
Parents: 86fe855
Author: Hao Chen <hao@apache.org>
Authored: Mon Nov 23 00:31:05 2015 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Mon Nov 23 00:31:05 2015 +0800

----------------------------------------------------------------------
 .../alert/siddhi/SiddhiPolicyEvaluator.java     | 25 ++++++++++++--------
 1 file changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5bffdfd3/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiPolicyEvaluator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiPolicyEvaluator.java
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiPolicyEvaluator.java
index 6ba2826..87eaf48 100644
--- a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiPolicyEvaluator.java
+++ b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiPolicyEvaluator.java
@@ -17,11 +17,7 @@
 package org.apache.eagle.alert.siddhi;
 
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
+import java.util.*;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 
@@ -182,16 +178,25 @@ public class SiddhiPolicyEvaluator implements PolicyEvaluator{
 	}
 
 	/**
-	 * this is a heavy operation, we should avoid to use
-	 * @param sourceStream
-	 * @param data
+	 * This is a heavy operation, we should avoid to use.
+     *
+     * This validation method will skip invalid fields in event which are not declared in
stream schema otherwise it will cause exception for siddhi engine.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/EAGLE-49">https://issues.apache.org/jira/browse/EAGLE-49</a>
+     *
+	 * @param sourceStream source steam id
+	 * @param data input event
 	 */
 	private void validateEventInRuntime(String sourceStream, SortedMap data){
 		if(!needValidation)
 			return;
 		SortedMap<String, AlertStreamSchemaEntity> map = StreamMetadataManager.getInstance().getMetadataEntityMapForStream(sourceStream);
-		if(!map.keySet().equals(data.keySet()))
-			throw new IllegalStateException("incoming data schema is different from supported data
schema, incoming data: " + data.keySet() + ", schema: " + map.keySet());
+        if(!map.keySet().equals(data.keySet())){
+            Set<Object> badKeys = new TreeSet<>();
+            for(Object key:data.keySet()) if(!map.containsKey(key)) badKeys.add(key);
+            LOG.warn(String.format("Ignore invalid fields %s in event: %s from stream: %s,
valid fields are: %s", badKeys.toString(),data.toString(), sourceStream,map.keySet().toString()));
+            for(Object key:badKeys) data.remove(key);
+        }
 	}
 
 	private void putAttrsIntoInputStream(List<Object> input, String streamName, SortedMap
map) {


Mime
View raw message