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

Import Classification Delete event changes #2678

Merged
merged 11 commits into from
Dec 19, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static EntityAuditActionV2 fromString(String strValue) {
private String eventKey;
private AtlasEntity entity;
private EntityAuditType type;
private Map<String, Object> detail;
private List<Map<String, Object>> detail;
private AtlasEntityHeader entityDetail;
private Map<String, String> headers;

Expand Down Expand Up @@ -226,11 +226,11 @@ public void setType(EntityAuditType type) {
this.type = type;
}

public Map<String, Object> getDetail() {
public List<Map<String, Object>> getDetail() {
return detail;
}

public void setDetail(Map<String, Object> detail) {
public void setDetail(List<Map<String, Object>> detail) {
this.detail = detail;
}

Expand Down Expand Up @@ -355,7 +355,7 @@ private String getJsonPartFromDetails() {
if(bracketStartPosition != -1) {
ret = details.substring(bracketStartPosition);
}
} else if(MapUtils.isNotEmpty(detail)) {
} else if(!detail.isEmpty()) {
ret = AtlasType.toJson(detail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public AtlasType getType(String typeName) throws AtlasBaseException {
LOG.debug("==> AtlasTypeRegistry.getType({})", typeName);
}

if (typeName == null) {
return null;
}
AtlasType ret = registryData.allTypes.getTypeByName(typeName);

if (ret == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,16 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
EntityAuditEventV2 event = new EntityAuditEventV2();
event.setEntityId(entityGuid);
event.setAction(EntityAuditEventV2.EntityAuditActionV2.fromString((String) source.get(ACTION)));
event.setDetail((Map<String, Object>) source.get(DETAIL));
if (source.get(DETAIL) != null) {
List<Map<String, Object>> classificationMap;
if (source.get(DETAIL) instanceof java.util.ArrayList) {
classificationMap = (List<Map<String, Object>>) source.get(DETAIL);
} else {
classificationMap = new ArrayList<>();
classificationMap.add((Map<String, Object>) source.get(DETAIL));
}
event.setDetail(classificationMap);
}
event.setUser((String) source.get(USER));
event.setCreated((long) source.get(CREATED));
if (source.get(TIMESTAMP) != null) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ EntityMutationResponse deleteByUniqueAttributes(List<AtlasObjectId> objectIds)

void deleteClassification(String guid, String classificationName, String associatedEntityGuid) throws AtlasBaseException;

void deleteClassifications(String guid, List<AtlasClassification> classificationName) throws AtlasBaseException;
public void deleteClassifications(final String guid, final List<AtlasClassification> classifications, final String associatedEntityGuid) throws AtlasBaseException;
List<AtlasClassification> getClassifications(String guid) throws AtlasBaseException;

AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,41 @@ private void repairMeanings(AtlasVertex assetVertex) {
}

}

@Override
@GraphTransaction
public void deleteClassifications(final String guid, final List<AtlasClassification> classifications) throws AtlasBaseException {
deleteClassifications(guid, classifications, null);
}

@Override
@GraphTransaction
public void deleteClassifications(final String guid, final List<AtlasClassification> classifications, final String associatedEntityGuid) throws AtlasBaseException {
if (StringUtils.isEmpty(guid)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
}
if (CollectionUtils.isEmpty(classifications)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications not specified");
}

GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);

AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);

// verify authorization only for removal of directly associated classification and not propagated one.
for (AtlasClassification classification : classifications) {
if (StringUtils.isEmpty(associatedEntityGuid) || guid.equals(associatedEntityGuid)) {
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_REMOVE_CLASSIFICATION,
entityHeader, new AtlasClassification(classification.getTypeName())),
"remove classification: guid=", guid, ", classification=", classification.getDisplayName());
}

if (LOG.isDebugEnabled()) {
LOG.debug("Deleting classification={} from entity={}", classification.getDisplayName(), guid);
}
}
entityGraphMapper.deleteClassifications(guid, classifications, associatedEntityGuid);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -193,43 +193,20 @@ 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<>();

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));
Map<AtlasEntity, List<AtlasClassification>> entityClassification = getEntityClassificationsMapping(deleted);
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);
}

entityChangeNotifier.onClassificationsAddedToEntities(propagatedEntities, Collections.singletonList(addedClassification), false);
Map<AtlasEntity, List<AtlasClassification>> entityClassification = getEntityClassificationsMapping(added);
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);
Expand Down Expand Up @@ -310,14 +287,12 @@ private void deleteClassifications(String entityGuid, String typeName, List<Atla
if (CollectionUtils.isEmpty(list)) {
return;
}

for (AtlasClassification c : list) {
try {
entitiesStore.deleteClassification(entityGuid, c.getTypeName());
} catch (AtlasBaseException e) {
LOG.error("Failed to remove classification association between {}, entity with guid {}", c.getTypeName(), c.getEntityGuid());
throw e;
}
String classificationNames = getClassificationNames(list);
try {
entitiesStore.deleteClassifications(entityGuid, list);
} catch (AtlasBaseException e) {
LOG.error("Failed to remove classification association between {}, entity with guid {}", classificationNames, entityGuid);
throw e;
}
}

Expand Down Expand Up @@ -383,6 +358,20 @@ 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
Loading