EAGLE 304: Enable Advanced dedup configuration in policy definition

Author: Zhao, Qingwen & Jiang, jilin
Reviewer: Chen, Hao
Date:   Thu May 26 20:12:12 2016 +0800
Closes #209


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

Branch: refs/heads/master
Commit: 750b4c9a87732b9f69a83e908a819d174554745d
Parents: ffd5fdd
Author: Zhao, Qingwen <qingwz...@ebay.com>
Authored: Mon May 30 15:49:48 2016 +0800
Committer: Zhao, Qingwen <qingwz...@ebay.com>
Committed: Mon May 30 15:49:48 2016 +0800

----------------------------------------------------------------------
 .../eagle/alert/config/DeduplicatorConfig.java  | 17 ++++--
 .../dedup/AlertDeduplicationExecutorBase.java   | 22 +++----
 .../eagle/alert/dedup/DefaultDeduplicator.java  | 50 ++++++++++------
 .../eagle/alert/dedup/EntityDedupKey.java       | 62 ++++++++++++++++++++
 .../eagle/alert/dedup/EntityDeduplicator.java   |  9 ++-
 .../eagle/alert/config/TestAlertDedup.java      |  6 +-
 .../TestSiddhiStateSnapshotAndRestore.java      |  2 +-
 .../src/main/resources/application.conf         |  1 -
 .../app/public/feature/common/controller.js     | 12 +++-
 9 files changed, 132 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/config/DeduplicatorConfig.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/config/DeduplicatorConfig.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/config/DeduplicatorConfig.java
index 584abc7..1e65408 100644
--- 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/config/DeduplicatorConfig.java
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/config/DeduplicatorConfig.java
@@ -17,21 +17,26 @@
 package org.apache.eagle.alert.config;
 
 import java.io.Serializable;
+import java.util.List;
 
 public class DeduplicatorConfig implements Serializable{
        private static final long serialVersionUID = 1L;
+
+       private int alertDedupIntervalMin;
+       private List<String> fields;
+
        public int getAlertDedupIntervalMin() {
                return alertDedupIntervalMin;
        }
+
        public void setAlertDedupIntervalMin(int alertDedupIntervalMin) {
                this.alertDedupIntervalMin = alertDedupIntervalMin;
        }
-       public int getEmailDedupIntervalMin() {
-               return emailDedupIntervalMin;
+       public List<String> getFields() {
+               return fields;
        }
-       public void setEmailDedupIntervalMin(int emailDedupIntervalMin) {
-               this.emailDedupIntervalMin = emailDedupIntervalMin;
+
+       public void setFields(List<String> fields) {
+               this.fields = fields;
        }
-       private int alertDedupIntervalMin;
-       private int emailDedupIntervalMin;
 }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/AlertDeduplicationExecutorBase.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/AlertDeduplicationExecutorBase.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/AlertDeduplicationExecutorBase.java
index 051df33..25e5cff 100644
--- 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/AlertDeduplicationExecutorBase.java
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/AlertDeduplicationExecutorBase.java
@@ -46,7 +46,7 @@ public abstract class AlertDeduplicationExecutorBase extends 
JavaStormStreamExec
        protected DEDUP_TYPE dedupType;
 
        private List<String> alertExecutorIdList;
-       private volatile CopyOnWriteHashMap<String, 
DefaultDeduplicator<AlertAPIEntity>> alertDedups;
+       private volatile CopyOnWriteHashMap<String, DefaultDeduplicator> 
alertDedups;
        private PolicyDefinitionDAO<AlertDefinitionAPIEntity> dao;
 
        public enum DEDUP_TYPE {
@@ -65,21 +65,17 @@ public abstract class AlertDeduplicationExecutorBase 
extends JavaStormStreamExec
                this.config = config;
        }
        
-       public DefaultDeduplicator<AlertAPIEntity> 
createAlertDedup(AlertDefinitionAPIEntity alertDef) {
+       public DefaultDeduplicator createAlertDedup(AlertDefinitionAPIEntity 
alertDef) {
                DeduplicatorConfig dedupConfig = null;
                try {
                        dedupConfig = 
JsonSerDeserUtils.deserialize(alertDef.getDedupeDef(), 
DeduplicatorConfig.class);
                }
                catch (Exception ex) {
-                       LOG.warn("Initial dedupConfig error, " + 
ex.getMessage());
+                       LOG.warn("Initial dedup Config error, " + 
ex.getMessage());
                }
 
         if (dedupConfig != null) {
-                       if (dedupType.equals(DEDUP_TYPE.ENTITY)) {
-                               return new 
DefaultDeduplicator<>(dedupConfig.getAlertDedupIntervalMin());
-                       } else if (dedupType.equals(DEDUP_TYPE.EMAIL)) {
-                               return new 
DefaultDeduplicator<>(dedupConfig.getEmailDedupIntervalMin());
-                       }
+                       return new 
DefaultDeduplicator(dedupConfig.getAlertDedupIntervalMin(), 
dedupConfig.getFields());
                }
 
                return null;
@@ -97,7 +93,7 @@ public abstract class AlertDeduplicationExecutorBase extends 
JavaStormStreamExec
                        LOG.error("fail to initialize initialAlertDefs: ", ex);
                throw new IllegalStateException("fail to initialize 
initialAlertDefs: ", ex);
         }
-           Map<String, DefaultDeduplicator<AlertAPIEntity>> tmpDeduplicators = 
new HashMap<String, DefaultDeduplicator<AlertAPIEntity>>();
+           Map<String, DefaultDeduplicator> tmpDeduplicators = new HashMap<>();
         if(initialAlertDefs == null || initialAlertDefs.isEmpty()){
             LOG.warn("No alert definitions was found for site: "+site+", 
dataSource: "+dataSource);
         } else {
@@ -105,7 +101,7 @@ public abstract class AlertDeduplicationExecutorBase 
extends JavaStormStreamExec
                            if(initialAlertDefs.containsKey(alertExecutorId)){
                     for(AlertDefinitionAPIEntity alertDef : 
initialAlertDefs.get(alertExecutorId).values()){
                        try {
-                          DefaultDeduplicator<AlertAPIEntity> deduplicator = 
createAlertDedup(alertDef);
+                          DefaultDeduplicator deduplicator = 
createAlertDedup(alertDef);
                           if (deduplicator != null)
                               
tmpDeduplicators.put(alertDef.getTags().get(Constants.POLICY_ID), deduplicator);
                           else LOG.warn("The dedup interval is not set, 
alertDef: " + alertDef);
@@ -133,7 +129,7 @@ public abstract class AlertDeduplicationExecutorBase 
extends JavaStormStreamExec
     public void flatMap(java.util.List<Object> input, Collector<Tuple2<String, 
AlertAPIEntity>> outputCollector){
         String policyId = (String) input.get(0);
         AlertAPIEntity alertEntity = (AlertAPIEntity) input.get(1);
-        DefaultDeduplicator<AlertAPIEntity> dedup;
+        DefaultDeduplicator dedup;
         synchronized(alertDedups) {
             dedup = alertDedups.get(policyId);
         }
@@ -157,7 +153,7 @@ public abstract class AlertDeduplicationExecutorBase 
extends JavaStormStreamExec
                if(LOG.isDebugEnabled()) LOG.debug("Alert dedup config to be 
added : " + added);
                for(AlertDefinitionAPIEntity alertDef : added.values()){
                        LOG.info("Alert dedup config really added " + alertDef);
-                       DefaultDeduplicator<AlertAPIEntity> dedup = 
createAlertDedup(alertDef);
+                       DefaultDeduplicator dedup = createAlertDedup(alertDef);
                        if (dedup != null) {
                                synchronized(alertDedups) {             
                                        
alertDedups.put(alertDef.getTags().get(Constants.POLICY_ID), dedup);
@@ -170,7 +166,7 @@ public abstract class AlertDeduplicationExecutorBase 
extends JavaStormStreamExec
                LOG.info("Alert dedup config changed : " + changed);
                for(AlertDefinitionAPIEntity alertDef : changed.values()){
                        LOG.info("Alert dedup config really changed " + 
alertDef);
-                       DefaultDeduplicator<AlertAPIEntity> dedup = 
createAlertDedup(alertDef);
+                       DefaultDeduplicator dedup = createAlertDedup(alertDef);
                        if (dedup != null) {
                                synchronized(alertDedups) {
                                        
alertDedups.put(alertDef.getTags().get(Constants.POLICY_ID), dedup);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/DefaultDeduplicator.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/DefaultDeduplicator.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/DefaultDeduplicator.java
index b968e38..1d79f9f 100644
--- 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/DefaultDeduplicator.java
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/DefaultDeduplicator.java
@@ -23,14 +23,15 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.commons.lang.time.DateUtils;
+import org.apache.eagle.alert.entity.AlertAPIEntity;
+import org.apache.eagle.common.metric.AlertContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
-
-public class DefaultDeduplicator<T extends TaggedLogAPIEntity> implements 
EntityDeduplicator<T>{
+public class DefaultDeduplicator implements EntityDeduplicator {
        protected long dedupIntervalMin;
-       protected Map<EntityTagsUniq, Long> entites = new 
HashMap<EntityTagsUniq, Long>();
+       protected List<String> fields;
+       protected Map<EntityDedupKey, Long> entites = new HashMap<>();
        public static Logger LOG = 
LoggerFactory.getLogger(DefaultDeduplicator.class);
        
        public static enum AlertDeduplicationStatus{
@@ -41,26 +42,28 @@ public class DefaultDeduplicator<T extends 
TaggedLogAPIEntity> implements Entity
        
        public DefaultDeduplicator() {
                this.dedupIntervalMin = 0;
+               fields = null;
        }
-       
-       public DefaultDeduplicator(long intervalMin) {
+
+       public DefaultDeduplicator(long intervalMin, List<String> fields) {
                this.dedupIntervalMin = intervalMin;
+               this.fields = fields;
        }
        
        public void clearOldCache() {
-               List<EntityTagsUniq> removedkeys = new 
ArrayList<EntityTagsUniq>();
-               for (Entry<EntityTagsUniq, Long> entry : entites.entrySet()) {
-                       EntityTagsUniq entity = entry.getKey();
+               List<EntityDedupKey> removedkeys = new ArrayList<>();
+               for (Entry<EntityDedupKey, Long> entry : entites.entrySet()) {
+                       EntityDedupKey entity = entry.getKey();
                        if (System.currentTimeMillis() - 7 * 
DateUtils.MILLIS_PER_DAY > entity.createdTime) {
                                removedkeys.add(entry.getKey());
                        }
                }
-               for (EntityTagsUniq alertKey : removedkeys) {
+               for (EntityDedupKey alertKey : removedkeys) {
                        entites.remove(alertKey);
                }
        }
        
-       public AlertDeduplicationStatus checkDedup(EntityTagsUniq key){
+       public AlertDeduplicationStatus checkDedup(EntityDedupKey key){
                long current = key.timestamp;
                if(!entites.containsKey(key)){
                        entites.put(key, current);
@@ -75,17 +78,28 @@ public class DefaultDeduplicator<T extends 
TaggedLogAPIEntity> implements Entity
                
                return AlertDeduplicationStatus.IGNORED;
        }
-       
-       public List<T> dedup(List<T> list) {
+
+       private List<String> getKeyList(AlertAPIEntity entity) {
+               List<String> keys = new ArrayList<>(entity.getTags().values());
+               if(fields != null && !fields.isEmpty()) {
+                       for (String field: fields) {
+                               AlertContext context = 
entity.getWrappedAlertContext();
+                               keys.add(context.getProperty(field));
+                       }
+               }
+               return keys;
+       }
+
+       public List<AlertAPIEntity> dedup(List<AlertAPIEntity> list) {
                clearOldCache();
-               List<T> dedupList = new ArrayList<T>();
+               List<AlertAPIEntity> dedupList = new ArrayList<>();
         int totalCount = list.size();
         int dedupedCount = 0;
-               for(T entity: list) {
+               for(AlertAPIEntity entity: list) {
                        if (entity.getTags() == null) {
                                if(LOG.isDebugEnabled()) LOG.debug("Tags is 
null, don't know how to deduplicate, do nothing");
                        } else {
-                AlertDeduplicationStatus status = checkDedup(new 
EntityTagsUniq(entity.getTags(), entity.getTimestamp()));
+                AlertDeduplicationStatus status = checkDedup(new 
EntityDedupKey(getKeyList(entity), entity.getTimestamp()));
                 if (!status.equals(AlertDeduplicationStatus.IGNORED)) {
                     dedupList.add(entity);
                 } else {
@@ -97,7 +111,7 @@ public class DefaultDeduplicator<T extends 
TaggedLogAPIEntity> implements Entity
                }
 
         if(dedupedCount>0){
-            LOG.info(String.format("Skipped %s of %s alerts because they are 
duplicated",dedupedCount,totalCount));
+            LOG.info(String.format("Skipped %s of %s alerts because they are 
duplicated", dedupedCount, totalCount));
         }else if(LOG.isDebugEnabled()){
             LOG.debug(String.format("Skipped %s of %s duplicated 
alerts",dedupedCount,totalCount));
         }
@@ -105,7 +119,7 @@ public class DefaultDeduplicator<T extends 
TaggedLogAPIEntity> implements Entity
                return dedupList;
        }
 
-       public EntityDeduplicator<T> setDedupIntervalMin(long dedupIntervalMin) 
{
+       public EntityDeduplicator setDedupIntervalMin(long dedupIntervalMin) {
                this.dedupIntervalMin = dedupIntervalMin;
                return this;
        }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDedupKey.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDedupKey.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDedupKey.java
new file mode 100644
index 0000000..36b83e1
--- /dev/null
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDedupKey.java
@@ -0,0 +1,62 @@
+/*
+ * 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.eagle.alert.dedup;
+
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class EntityDedupKey {
+    public List<String> values;
+    public Long timestamp;     // entity's timestamp
+    public long createdTime; // entityTagsUniq's created time, for cache 
removal;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(EntityDedupKey.class);
+
+    public EntityDedupKey(List<String> values, long timestamp) {
+        this.values = new ArrayList<>(values);
+        this.timestamp = timestamp;
+        this.createdTime = System.currentTimeMillis();
+    }
+
+    public boolean equals(Object obj) {
+        if (obj instanceof EntityDedupKey) {
+            EntityDedupKey key = (EntityDedupKey) obj;
+            if (key == null || key.values.size() != values.size()) {
+                return false;
+            }
+            return values.equals(key.values);
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        HashCodeBuilder builder = new HashCodeBuilder();
+        for (String value : values) {
+            builder.append(value);
+        }
+        return builder.build();
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDeduplicator.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDeduplicator.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDeduplicator.java
index e108b94..85dd19a 100644
--- 
a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDeduplicator.java
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/dedup/EntityDeduplicator.java
@@ -18,19 +18,18 @@ package org.apache.eagle.alert.dedup;
 
 import java.util.List;
 
+import org.apache.eagle.alert.entity.AlertAPIEntity;
 import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
 
 /**
  * Dedup Eagle entities.
- *
- * @param <T> Eagle entity
  */
-public interface EntityDeduplicator<T extends TaggedLogAPIEntity> {
+public interface EntityDeduplicator {
        
-       EntityDeduplicator<T> setDedupIntervalMin(long intervalMin);
+       EntityDeduplicator setDedupIntervalMin(long intervalMin);
        
        long getDedupIntervalMin();
        
-       List<T> dedup(List<T> list);
+       List dedup(List<AlertAPIEntity> list);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java
index 4295bdc..f6d6a63 100644
--- 
a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java
@@ -25,10 +25,10 @@ public class TestAlertDedup {
 
        @Test
        public void test() throws Exception{
-               String alertDef = 
"{\"alertDedupIntervalMin\":\"720\",\"emailDedupIntervalMin\":\"1440\"}";
+               String alertDef = 
"{\"alertDedupIntervalMin\":\"10\",\"fields\":[\"key1\",\"key2\",\"key3\"]}";
                DeduplicatorConfig dedupConfig = 
JsonSerDeserUtils.deserialize(alertDef, DeduplicatorConfig.class);
-               Assert.assertEquals(dedupConfig.getAlertDedupIntervalMin(), 
720);
-               Assert.assertEquals(dedupConfig.getEmailDedupIntervalMin(), 
1440);
+               Assert.assertEquals(dedupConfig.getAlertDedupIntervalMin(), 10);
+               Assert.assertEquals(dedupConfig.getFields().size(), 3);
                
                alertDef = "null";
                dedupConfig = JsonSerDeserUtils.deserialize(alertDef, 
DeduplicatorConfig.class);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/state/TestSiddhiStateSnapshotAndRestore.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/state/TestSiddhiStateSnapshotAndRestore.java
 
b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/state/TestSiddhiStateSnapshotAndRestore.java
index 131be28..ccc6c87 100644
--- 
a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/state/TestSiddhiStateSnapshotAndRestore.java
+++ 
b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/state/TestSiddhiStateSnapshotAndRestore.java
@@ -206,7 +206,7 @@ public class TestSiddhiStateSnapshotAndRestore {
         return executionPlanRuntime;
     }
 
-    @Test
+    @Ignore
     public void testTimeSlideWindow() throws Exception{
         String tmpdir = System.getProperty("java.io.tmpdir");
         System.out.println("temporary directory: " + tmpdir);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-webservice/src/main/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-webservice/src/main/resources/application.conf 
b/eagle-webservice/src/main/resources/application.conf
index cfa6a0b..fff7d3f 100644
--- a/eagle-webservice/src/main/resources/application.conf
+++ b/eagle-webservice/src/main/resources/application.conf
@@ -25,4 +25,3 @@ eagle{
        }
 }
 
-

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/750b4c9a/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js
----------------------------------------------------------------------
diff --git 
a/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js 
b/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js
index 18df6f9..72af7eb 100644
--- a/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js
+++ b/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js
@@ -551,8 +551,10 @@
                                                        conditions: {},
                                                        notification: [],
                                                        dedupe: {
-                                                               
alertDedupIntervalMin: 10
+                                                               
alertDedupIntervalMin: 10,
+                                                               fields: []
                                                        },
+                                                       _dedupTags: {},
                                                        policy: {},
                                                        window: "externalTime",
                                                        group: "",
@@ -627,7 +629,11 @@
 
                                                // === Revert inner data ===
                                                // >> De-dupe
+                                               $scope.policy.__._dedupTags = 
{};
                                                $scope.policy.__.dedupe = 
common.parseJSON($scope.policy.dedupeDef, {});
+                                               
$.each($scope.policy.__.dedupe.fields || [], function (i, field) {
+                                                       
$scope.policy.__._dedupTags[field] = true;
+                                               });
 
                                                // >> Notification
                                                $scope.policy.__.notification = 
common.parseJSON($scope.policy.notificationDef, []);
@@ -953,6 +959,9 @@
                                $scope.lock = true;
 
                                // dedupeDef
+                               $scope.policy.__.dedupe.fields = 
$.map($scope.policy.__._dedupTags, function (value, key) {
+                                       if(value) return key;
+                               });
                                $scope.policy.dedupeDef = 
JSON.stringify($scope.policy.__.dedupe);
 
                                // notificationDef
@@ -961,7 +970,6 @@
                                $scope.policy.notificationDef = 
JSON.stringify($scope.policy.__.notification);
 
                                // policyDef
-                               $scope.policy.__._dedupTags = 
$scope.policy.__._dedupTags || {};
                                $scope.policy.__.policy = {
                                        expression: $scope.toQuery(),
                                        type: "siddhiCEPEngine"

Reply via email to