You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/01/17 07:41:19 UTC

incubator-atlas git commit: ATLAS-1464: option to include only specified attributes in notification message

Repository: incubator-atlas
Updated Branches:
  refs/heads/master e0c6b98ef -> 9c0c46dbc


ATLAS-1464: option to include only specified attributes in notification message

Signed-off-by: Madhan Neethiraj <ma...@apache.org>


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

Branch: refs/heads/master
Commit: 9c0c46dbcb4687b0db199248610da327273cab1d
Parents: e0c6b98
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Mon Jan 16 11:52:12 2017 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Mon Jan 16 22:59:31 2017 -0800

----------------------------------------------------------------------
 release-log.txt                                 |  1 +
 .../NotificationEntityChangeListener.java       | 56 ++++++++++++++++++--
 2 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/9c0c46db/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 369a5c1..cffa567 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
 ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
 
 ALL CHANGES:
+ATLAS-1464 option to include only specified attributes in notification message (sarath.kum4r@gmail.com via mneethiraj)
 ATLAS-1460 v2 search API updated to return name/description/owner and classification names in result (vimalsharma via mneethiraj)
 ATLAS-1434 fixed unit test to use correct type names; updated error message per review comments (ashutoshm via mneethiraj)
 ATLAS-1391 Add exclusion mechanism for Atlas audit mechanism (guptaneeru via svimal2106)

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/9c0c46db/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java b/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
index d10194d..8a1991c 100644
--- a/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
+++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
@@ -19,6 +19,7 @@ package org.apache.atlas.notification;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.inject.Inject;
+import org.apache.atlas.ApplicationProperties;
 import org.apache.atlas.AtlasException;
 import org.apache.atlas.listener.EntityChangeListener;
 import org.apache.atlas.notification.entity.EntityNotification;
@@ -31,7 +32,11 @@ import org.apache.atlas.typesystem.Struct;
 import org.apache.atlas.typesystem.types.FieldMapping;
 import org.apache.atlas.typesystem.types.TraitType;
 import org.apache.atlas.typesystem.types.TypeSystem;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.configuration.Configuration;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -48,6 +53,11 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
     private final NotificationInterface notificationInterface;
     private final TypeSystem typeSystem;
 
+    private Map<String, List<String>> notificationAttributesCache = new HashMap<>();
+    private static final String ATLAS_ENTITY_NOTIFICATION_PROPERTY = "atlas.notification.entity";
+    static Configuration APPLICATION_PROPERTIES = null;
+
+
 
     // ----- Constructors ------------------------------------------------------
 
@@ -148,14 +158,54 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
         List<EntityNotification> messages = new LinkedList<>();
 
         for (IReferenceableInstance entityDefinition : entityDefinitions) {
-            Referenceable entity = new Referenceable(entityDefinition);
+            Referenceable       entity                  = new Referenceable(entityDefinition);
+            Map<String, Object> attributesMap           = entity.getValuesMap();
+            List<String>        entityNotificationAttrs = getNotificationAttributes(entity.getTypeName());
+
+            if (MapUtils.isNotEmpty(attributesMap) && CollectionUtils.isNotEmpty(entityNotificationAttrs)) {
+                for (String entityAttr : attributesMap.keySet()) {
+                    if (!entityNotificationAttrs.contains(entityAttr)) {
+                        entity.setNull(entityAttr);
+                    }
+                }
+            }
 
-            EntityNotificationImpl notification =
-                    new EntityNotificationImpl(entity, operationType, getAllTraits(entity, typeSystem));
+            EntityNotificationImpl notification = new EntityNotificationImpl(entity, operationType, getAllTraits(entity, typeSystem));
 
             messages.add(notification);
         }
 
         notificationInterface.send(NotificationInterface.NotificationType.ENTITIES, messages);
     }
+
+    private List<String> getNotificationAttributes(String entityType) {
+        List<String> ret = null;
+
+        initApplicationProperties();
+
+        if (notificationAttributesCache.containsKey(entityType)) {
+            ret = notificationAttributesCache.get(entityType);
+        } else if (APPLICATION_PROPERTIES != null) {
+            String[] notificationAttributes = APPLICATION_PROPERTIES.getStringArray(ATLAS_ENTITY_NOTIFICATION_PROPERTY + "." +
+                                                                                    entityType + "." + "attributes.include");
+
+            if (notificationAttributes != null) {
+                ret = Arrays.asList(notificationAttributes);
+            }
+
+            notificationAttributesCache.put(entityType, ret);
+        }
+
+        return ret;
+    }
+
+    private void initApplicationProperties() {
+        if (APPLICATION_PROPERTIES == null) {
+            try {
+                APPLICATION_PROPERTIES = ApplicationProperties.get();
+            } catch (AtlasException ex) {
+                // ignore
+            }
+        }
+    }
 }