Repository: atlas Updated Branches: refs/heads/master 27e8b2a40 -> 4b2324f36
ATLAS-2830: Tag Propagation, Entity Delete : Classification update notification not sent to entities down the lineage present after the deleted entity Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/4b2324f3 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/4b2324f3 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/4b2324f3 Branch: refs/heads/master Commit: 4b2324f360b212d7495ce72e1b24075d04d05f6b Parents: 27e8b2a Author: Sarath Subramanian <[email protected]> Authored: Tue Aug 21 12:14:05 2018 -0700 Committer: Sarath Subramanian <[email protected]> Committed: Tue Aug 21 12:14:05 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/4b2324f3/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 78ed74d..a3398ac 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); } @@ -1297,6 +1299,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/4b2324f3/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 7eb3214..1c679c7 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 @@ -1530,6 +1530,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; @@ -1583,8 +1584,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()) { @@ -1644,20 +1657,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); } @@ -1667,7 +1669,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) { @@ -1678,7 +1682,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); + } } } }
