From 2680919f2ec3d0e25cecdc4a7bce46a664ff6a24 Mon Sep 17 00:00:00 2001 From: aarshi Date: Mon, 18 Dec 2023 15:10:05 +0530 Subject: [PATCH 1/2] Fix events behaviour --- .../graph/v2/ClassificationAssociator.java | 48 ++++++++----------- .../store/graph/v2/EntityGraphMapper.java | 8 +++- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java index bb2f3c329f..fd9d1eef49 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java @@ -18,6 +18,7 @@ package org.apache.atlas.repository.store.graph.v2; +import com.google.gson.Gson; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.RequestContext; import org.apache.atlas.exception.AtlasBaseException; @@ -193,47 +194,25 @@ public void setClassifications(Map map) throws AtlasB AtlasPerfMetrics.MetricRecorder recorder = RequestContext.get().startMetricRecord("commitChanges.notify"); Map> deleted = RequestContext.get().getDeletedClassificationAndVertices(); - Set allVertices = new HashSet<>(); if (MapUtils.isNotEmpty(deleted)) { - for (AtlasClassification deletedClassification: deleted.keySet()) { - Collection vertices = deleted.get(deletedClassification); - List propagatedEntities = new ArrayList<>(); + Map> entityClassification = getEntityClassificationsMapping(deleted); - for (Object obj: vertices) { - AtlasVertex vertex = (AtlasVertex) obj; - AtlasEntity entity = instanceConverter.getAndCacheEntity(GraphHelper.getGuid(vertex), IGNORE_REL); - - allVertices.add(vertex); - propagatedEntities.add(entity); - } - - entityChangeNotifier.onClassificationsDeletedFromEntities(propagatedEntities, Collections.singletonList(deletedClassification)); + for (Map.Entry> atlasEntityListEntry : entityClassification.entrySet()) { + entityChangeNotifier.onClassificationDeletedFromEntity(atlasEntityListEntry.getKey(), atlasEntityListEntry.getValue()); } } Map> added = RequestContext.get().getAddedClassificationAndVertices(); if (MapUtils.isNotEmpty(added)) { - for (AtlasClassification addedClassification: added.keySet()) { - Collection vertices = added.get(addedClassification); - List propagatedEntities = new ArrayList<>(); - - for (Object obj: vertices) { - AtlasVertex vertex = (AtlasVertex) obj; - AtlasEntity entity = instanceConverter.getAndCacheEntity(GraphHelper.getGuid(vertex), IGNORE_REL); - - allVertices.add(vertex); - - propagatedEntities.add(entity); - } + Map> entityClassification = getEntityClassificationsMapping(added); - entityChangeNotifier.onClassificationsAddedToEntities(propagatedEntities, Collections.singletonList(addedClassification), false); + for (Map.Entry> atlasEntityListEntry : entityClassification.entrySet()) { + entityChangeNotifier.onClassificationAddedToEntity(atlasEntityListEntry.getKey(), atlasEntityListEntry.getValue()); } } - entityGraphMapper.updateClassificationText(null, allVertices); transactionInterceptHelper.intercept(); - RequestContext.get().endMetricRecord(recorder); RequestContext.get().setDelayTagNotifications(false); } @@ -383,6 +362,19 @@ private void summarize(String s) { private String getJsonArray(StringBuilder actionSummary) { return "[" + StringUtils.removeEnd(actionSummary.toString(), ",") + "]"; } + private Map> getEntityClassificationsMapping(Map> classificationVertices) throws AtlasBaseException { + Map> entityClassifications = new HashMap<>(); + Set vertices = new HashSet<>(); + for (AtlasClassification classification : classificationVertices.keySet()) { + for (Object obj : classificationVertices.get(classification)) { + AtlasVertex vertex = (AtlasVertex) obj; + vertices.add(vertex); + } + List propagatedEntities = entityGraphMapper.updateClassificationText(null, vertices); + propagatedEntities.forEach(entity -> entityClassifications.computeIfAbsent(entity, key -> new ArrayList<>()).add(classification)); + } + return entityClassifications; + } } private static class ListOps { 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 4b815e5f1e..ee88c6c8d2 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 @@ -2771,10 +2771,11 @@ public void addClassifications(final EntityMutationContext context, String guid, Set vertices = addedClassifications.get(classification); RequestContext.get().addAddedClassificationAndVertices(classification, new ArrayList<>(vertices)); } - } else { + /** ToDO : @aarshi: remove this after testing : + * this is dead code it will never be executed as isDelayTagNotifications() always true + **/ Map> entityClassification = new HashMap<>(); - for (AtlasClassification classification : addedClassifications.keySet()) { Set vertices = addedClassifications.get(classification); List propagatedEntities = updateClassificationText(classification, vertices); @@ -3037,6 +3038,9 @@ public void deleteClassification(String entityGuid, String classificationName) t if (RequestContext.get().isDelayTagNotifications()) { RequestContext.get().addDeletedClassificationAndVertices(classification, new ArrayList<>(entityVertices)); } else if (CollectionUtils.isNotEmpty(entityVertices)) { + /** ToDO : @aarshi: remove this after testing : + * this is dead code it will never be executed as isDelayTagNotifications() always true + **/ Map> entityClassification = new HashMap<>(); if (CollectionUtils.isNotEmpty(entityVertices)) { From f7af6eda7b1065ae39fda23e43530c5f26edc4ea Mon Sep 17 00:00:00 2001 From: aarshi Date: Mon, 18 Dec 2023 15:11:55 +0530 Subject: [PATCH 2/2] Remove extra libraries --- .../repository/store/graph/v2/ClassificationAssociator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java index fd9d1eef49..6224c1ae8d 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java @@ -18,7 +18,6 @@ package org.apache.atlas.repository.store.graph.v2; -import com.google.gson.Gson; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.RequestContext; import org.apache.atlas.exception.AtlasBaseException;