Commit 9c0c46db by Sarath Subramanian Committed by Madhan Neethiraj

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

parent e0c6b98e
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -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) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: 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-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-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) ATLAS-1391 Add exclusion mechanism for Atlas audit mechanism (guptaneeru via svimal2106)
......
...@@ -19,6 +19,7 @@ package org.apache.atlas.notification; ...@@ -19,6 +19,7 @@ package org.apache.atlas.notification;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.notification.entity.EntityNotification; import org.apache.atlas.notification.entity.EntityNotification;
...@@ -31,7 +32,11 @@ import org.apache.atlas.typesystem.Struct; ...@@ -31,7 +32,11 @@ import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.typesystem.types.FieldMapping; import org.apache.atlas.typesystem.types.FieldMapping;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.TypeSystem; 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.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -48,6 +53,11 @@ public class NotificationEntityChangeListener implements EntityChangeListener { ...@@ -48,6 +53,11 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
private final NotificationInterface notificationInterface; private final NotificationInterface notificationInterface;
private final TypeSystem typeSystem; 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 ------------------------------------------------------ // ----- Constructors ------------------------------------------------------
...@@ -149,13 +159,53 @@ public class NotificationEntityChangeListener implements EntityChangeListener { ...@@ -149,13 +159,53 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
for (IReferenceableInstance entityDefinition : entityDefinitions) { 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 = EntityNotificationImpl notification = new EntityNotificationImpl(entity, operationType, getAllTraits(entity, typeSystem));
new EntityNotificationImpl(entity, operationType, getAllTraits(entity, typeSystem));
messages.add(notification); messages.add(notification);
} }
notificationInterface.send(NotificationInterface.NotificationType.ENTITIES, messages); 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
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment