Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix events behaviour #2663

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,47 +193,25 @@ public void setClassifications(Map<String, AtlasEntityHeader> map) throws AtlasB

AtlasPerfMetrics.MetricRecorder recorder = RequestContext.get().startMetricRecord("commitChanges.notify");
Map<AtlasClassification, Collection<Object>> deleted = RequestContext.get().getDeletedClassificationAndVertices();
Set<AtlasVertex> allVertices = new HashSet<>();

if (MapUtils.isNotEmpty(deleted)) {
for (AtlasClassification deletedClassification: deleted.keySet()) {
Collection<Object> vertices = deleted.get(deletedClassification);
List<AtlasEntity> propagatedEntities = new ArrayList<>();
Map<AtlasEntity, List<AtlasClassification>> 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<AtlasEntity, List<AtlasClassification>> atlasEntityListEntry : entityClassification.entrySet()) {
entityChangeNotifier.onClassificationDeletedFromEntity(atlasEntityListEntry.getKey(), atlasEntityListEntry.getValue());
}
}

Map<AtlasClassification, Collection<Object>> added = RequestContext.get().getAddedClassificationAndVertices();
if (MapUtils.isNotEmpty(added)) {
for (AtlasClassification addedClassification: added.keySet()) {
Collection<Object> vertices = added.get(addedClassification);
List<AtlasEntity> 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<AtlasEntity, List<AtlasClassification>> entityClassification = getEntityClassificationsMapping(added);

entityChangeNotifier.onClassificationsAddedToEntities(propagatedEntities, Collections.singletonList(addedClassification), false);
for (Map.Entry<AtlasEntity, List<AtlasClassification>> atlasEntityListEntry : entityClassification.entrySet()) {
entityChangeNotifier.onClassificationAddedToEntity(atlasEntityListEntry.getKey(), atlasEntityListEntry.getValue());
}
}

entityGraphMapper.updateClassificationText(null, allVertices);
transactionInterceptHelper.intercept();

RequestContext.get().endMetricRecord(recorder);
RequestContext.get().setDelayTagNotifications(false);
}
Expand Down Expand Up @@ -383,6 +361,19 @@ private void summarize(String s) {
private String getJsonArray(StringBuilder actionSummary) {
return "[" + StringUtils.removeEnd(actionSummary.toString(), ",") + "]";
}
private Map<AtlasEntity, List<AtlasClassification>> getEntityClassificationsMapping(Map<AtlasClassification, Collection<Object>> classificationVertices) throws AtlasBaseException {
Map<AtlasEntity, List<AtlasClassification>> entityClassifications = new HashMap<>();
Set<AtlasVertex> vertices = new HashSet<>();
for (AtlasClassification classification : classificationVertices.keySet()) {
for (Object obj : classificationVertices.get(classification)) {
AtlasVertex vertex = (AtlasVertex) obj;
vertices.add(vertex);
}
List<AtlasEntity> propagatedEntities = entityGraphMapper.updateClassificationText(null, vertices);
propagatedEntities.forEach(entity -> entityClassifications.computeIfAbsent(entity, key -> new ArrayList<>()).add(classification));
}
return entityClassifications;
}
}

private static class ListOps<V extends AtlasClassification> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2771,10 +2771,11 @@ public void addClassifications(final EntityMutationContext context, String guid,
Set<AtlasVertex> 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<AtlasEntity, List<AtlasClassification>> entityClassification = new HashMap<>();

for (AtlasClassification classification : addedClassifications.keySet()) {
Set<AtlasVertex> vertices = addedClassifications.get(classification);
List<AtlasEntity> propagatedEntities = updateClassificationText(classification, vertices);
Expand Down Expand Up @@ -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<AtlasEntity, List<AtlasClassification>> entityClassification = new HashMap<>();
if (CollectionUtils.isNotEmpty(entityVertices)) {
Expand Down
Loading