Repository: atlas
Updated Branches:
  refs/heads/branch-1.0 641323dba -> de61f6abd


ATLAS-2830: Tag Propagation, Entity Delete : Classification update notification 
not sent to entities down the lineage present after the deleted entity

(cherry picked from commit 4b2324f360b212d7495ce72e1b24075d04d05f6b)


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

Branch: refs/heads/branch-1.0
Commit: de61f6abd5e7c44cc2fb11a916f391a90c9f6f42
Parents: 641323d
Author: Sarath Subramanian <[email protected]>
Authored: Tue Aug 21 12:14:05 2018 -0700
Committer: Sarath Subramanian <[email protected]>
Committed: Tue Aug 21 12:15:36 2018 -0700

----------------------------------------------------------------------
 .../atlas/repository/graph/GraphHelper.java     |  8 ++++-
 .../store/graph/v2/EntityGraphMapper.java       | 36 ++++++++++++--------
 2 files changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/de61f6ab/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
index 7c48831..3079603 100755
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
@@ -26,6 +26,7 @@ import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.AtlasException;
 import org.apache.atlas.RequestContext;
 import org.apache.atlas.exception.AtlasBaseException;
+import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasEntity.Status;
 import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.instance.AtlasRelationship;
@@ -76,6 +77,7 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
 
+import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE;
 import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED;
 import static 
org.apache.atlas.repository.Constants.ATTRIBUTE_INDEX_PROPERTY_KEY;
 import static org.apache.atlas.repository.Constants.ATTRIBUTE_KEY_PROPERTY_KEY;
@@ -124,7 +126,7 @@ public final class GraphHelper {
         try {
             maxRetries           = 
ApplicationProperties.get().getInt(RETRY_COUNT, 3);
             retrySleepTimeMillis = 
ApplicationProperties.get().getLong(RETRY_DELAY, 1000);
-            removePropagations   = 
ApplicationProperties.get().getBoolean(DEFAULT_REMOVE_PROPAGATIONS_ON_ENTITY_DELETE,
 true);
+            removePropagations   = 
ApplicationProperties.get().getBoolean(DEFAULT_REMOVE_PROPAGATIONS_ON_ENTITY_DELETE,
 false);
         } catch (AtlasException e) {
             LOG.error("Could not load configuration. Setting to default value 
for " + RETRY_COUNT, e);
         }
@@ -1289,6 +1291,10 @@ public final class GraphHelper {
         return 
element.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
     }
 
+    public static boolean isActive(AtlasEntity entity) {
+        return entity != null ? entity.getStatus() == ACTIVE : false;
+    }
+
     /**
      * For the given type, finds an unique attribute and checks if there is an 
existing instance with the same
      * unique value

http://git-wip-us.apache.org/repos/asf/atlas/blob/de61f6ab/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
index 066af7b..541f038 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
@@ -1541,6 +1541,7 @@ public class EntityGraphMapper {
         AtlasEntityType           entityType             = 
typeRegistry.getEntityTypeByName(entityTypeName);
         List<AtlasClassification> updatedClassifications = new ArrayList<>();
         List<AtlasVertex>         entitiesToPropagateTo  = new ArrayList<>();
+        Set<AtlasVertex>          notificationVertices   = new 
HashSet<AtlasVertex>() {{ add(entityVertex); }};
 
         Map<AtlasVertex, List<AtlasClassification>> addedPropagations   = null;
         Map<AtlasVertex, List<AtlasClassification>> removedPropagations = null;
@@ -1594,8 +1595,20 @@ public class EntityGraphMapper {
                 isClassificationUpdated = true;
             }
 
-            if (isClassificationUpdated && 
CollectionUtils.isEmpty(entitiesToPropagateTo)) {
-                entitiesToPropagateTo = 
graphHelper.getImpactedVerticesWithRestrictions(guid, 
classificationVertex.getIdForDisplay());
+            // check for removePropagationsOnEntityDelete update
+            Boolean currentRemovePropagations = 
currentClassification.getRemovePropagationsOnEntityDelete();
+            Boolean updatedRemovePropagations = 
classification.getRemovePropagationsOnEntityDelete();
+
+            if (updatedRemovePropagations != null && 
(updatedRemovePropagations != currentRemovePropagations)) {
+                AtlasGraphUtilsV2.setProperty(classificationVertex, 
CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, updatedRemovePropagations);
+
+                isClassificationUpdated = true;
+            }
+
+            if (isClassificationUpdated) {
+                List<AtlasVertex> propagatedEntityVertices = 
graphHelper.getAllPropagatedEntityVertices(classificationVertex);
+
+                notificationVertices.addAll(propagatedEntityVertices);
             }
 
             if (LOG.isDebugEnabled()) {
@@ -1655,20 +1668,9 @@ public class EntityGraphMapper {
                 }
             }
 
-            // handle update of 'removePropagationsOnEntityDelete' flag
-            Boolean currentRemovePropagations = 
currentClassification.getRemovePropagationsOnEntityDelete();
-            Boolean updatedRemovePropagations = 
classification.getRemovePropagationsOnEntityDelete();
-
-            if (updatedRemovePropagations != null && 
(updatedRemovePropagations != currentRemovePropagations)) {
-                AtlasGraphUtilsV2.setProperty(classificationVertex, 
CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, updatedRemovePropagations);
-            }
-
             updatedClassifications.add(currentClassification);
         }
 
-        // notify listeners on classification update
-        List<AtlasVertex> notificationVertices = new ArrayList<AtlasVertex>() 
{{ add(entityVertex); }};
-
         if (CollectionUtils.isNotEmpty(entitiesToPropagateTo)) {
             notificationVertices.addAll(entitiesToPropagateTo);
         }
@@ -1678,7 +1680,9 @@ public class EntityGraphMapper {
             AtlasEntityWithExtInfo    entityWithExtInfo = 
instanceConverter.getAndCacheEntity(entityGuid);
             AtlasEntity               entity            = (entityWithExtInfo 
!= null) ? entityWithExtInfo.getEntity() : null;
 
-            entityChangeNotifier.onClassificationUpdatedToEntity(entity, 
updatedClassifications);
+            if (isActive(entity)) {
+                entityChangeNotifier.onClassificationUpdatedToEntity(entity, 
updatedClassifications);
+            }
         }
 
         if (removedPropagations != null) {
@@ -1689,7 +1693,9 @@ public class EntityGraphMapper {
                 AtlasEntityWithExtInfo    entityWithExtInfo      = 
instanceConverter.getAndCacheEntity(entityGuid);
                 AtlasEntity               entity                 = 
(entityWithExtInfo != null) ? entityWithExtInfo.getEntity() : null;
 
-                entityChangeNotifier.onClassificationDeletedFromEntity(entity, 
removedClassifications);
+                if (isActive(entity)) {
+                    
entityChangeNotifier.onClassificationDeletedFromEntity(entity, 
removedClassifications);
+                }
             }
         }
     }

Reply via email to