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

Update Classification add/delete behaviour #2723

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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 @@ -133,6 +133,10 @@ public static EntityAuditActionV2 fromString(String strValue) {
private AtlasEntity entity;
private EntityAuditType type;
private Map<String, Object> detail;
private List<Map<String,Object>> classificationDetails;

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
private String classificationDetail;
private AtlasEntityHeader entityDetail;
private Map<String, String> headers;

Expand Down Expand Up @@ -290,12 +294,13 @@ public boolean equals(Object o) {
Objects.equals(created, that.created) &&
Objects.equals(typeName, that.typeName) &&
Objects.equals(entityQualifiedName, that.entityQualifiedName) &&
Objects.equals(headers, that.headers);
Objects.equals(headers, that.headers)&&
Objects.equals(classificationDetails, that.classificationDetails);
}

@Override
public int hashCode() {
return Objects.hash(entityId, timestamp, user, action, details, eventKey, entity, type, detail, created, entityQualifiedName, typeName, headers);
return Objects.hash(entityId, timestamp, user, action, details, eventKey, entity, type, detail, created, entityQualifiedName, typeName, headers, classificationDetails);
}

@Override
Expand All @@ -315,6 +320,7 @@ public String toString() {
sb.append(", detail=").append(detail);
sb.append(", created=").append(created);
sb.append(", headers=").append(headers);
sb.append(", classificationDetails").append(classificationDetails);
sb.append('}');

return sb.toString();
Expand Down Expand Up @@ -346,6 +352,7 @@ public void clear() {
detail = null;
created = 0L;
headers = null;
classificationDetails = null;
}

private String getJsonPartFromDetails() {
Expand Down Expand Up @@ -415,4 +422,20 @@ public static void sortEvents(List<EntityAuditEventV2> events, String sortByColu

events.sort(sortOrderDesc ? comparator.reversed() : comparator);
}

public List<Map<String, Object>> getClassificationDetails() {
return classificationDetails;
}

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

public String getClassificationDetail() {
return classificationDetail;
}

public void setClassificationDetail(String classificationDetail) {
this.classificationDetail = classificationDetail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ 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 @@ -29,6 +29,7 @@
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.audit.EntityAuditEventV2;
import org.apache.atlas.model.audit.EntityAuditSearchResult;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.type.AtlasType;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class ESBasedAuditRepository extends AbstractStorageBasedAuditRepository
private static final String USER = "user";
private static final String DETAIL = "detail";
private static final String ENTITY = "entity";
private static final String CLASSIFICATION_DETAIL= "classificationDetail";
private static final String bulkMetadata = String.format("{ \"index\" : { \"_index\" : \"%s\" } }%n", INDEX_NAME);

/*
Expand Down Expand Up @@ -134,7 +136,8 @@ public void putEventsV2(List<EntityAuditEventV2> events) throws AtlasBaseExcepti
event.getEntityQualifiedName(),
event.getEntity().getTypeName(),
created,
"" + event.getEntity().getUpdateTime().getTime());
"" + event.getEntity().getUpdateTime().getTime(),
event.getClassificationDetail());

bulkRequestBody.append(bulkMetadata);
bulkRequestBody.append(bulkItem);
Expand Down Expand Up @@ -174,7 +177,7 @@ private String getQueryTemplate(Map<String, String> requestContextHeaders) {
StringBuilder template = new StringBuilder();

template.append("'{'\"entityId\":\"{0}\",\"action\":\"{1}\",\"detail\":{2},\"user\":\"{3}\", \"eventKey\":\"{4}\", " +
"\"entityQualifiedName\": {5}, \"typeName\": \"{6}\",\"created\":{7}, \"timestamp\":{8}");
"\"entityQualifiedName\": {5}, \"typeName\": \"{6}\",\"created\":{7}, \"timestamp\":{8}, \"classificationDetail\":{9}");

if (MapUtils.isNotEmpty(requestContextHeaders)) {
template.append(",")
Expand Down Expand Up @@ -226,7 +229,14 @@ 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) {
if (source.get(DETAIL) instanceof Map) {
event.setDetail((Map<String, Object>) source.get(DETAIL));
}
}
if (source.get(CLASSIFICATION_DETAIL) instanceof List) {
event.setClassificationDetails((List<Map<String, Object>>) source.get(CLASSIFICATION_DETAIL));
}
event.setUser((String) source.get(USER));
event.setCreated((long) source.get(CREATED));
if (source.get(TIMESTAMP) != null) {
Expand Down
Loading
Loading