Commit f8cb6f76 by Madhan Neethiraj

ATLAS-3492: updated object-id attributes in audit logs to replace…

ATLAS-3492: updated object-id attributes in audit logs to replace unassigned-guids with assigned-guids (#2)
parent c6ee2779
...@@ -597,8 +597,6 @@ public class EntityGraphMapper { ...@@ -597,8 +597,6 @@ public class EntityGraphMapper {
true, ctx.getAttribute().getRelationshipEdgeDirection(), ctx.getReferringVertex()); true, ctx.getAttribute().getRelationshipEdgeDirection(), ctx.getReferringVertex());
} }
setAssignedGuid(ctx.getValue(), context.getGuidAssignments());
return newEdge; return newEdge;
} }
...@@ -628,7 +626,7 @@ public class EntityGraphMapper { ...@@ -628,7 +626,7 @@ public class EntityGraphMapper {
} }
} }
setAssignedGuid(ctx.getValue(), context.getGuidAssignments()); setAssignedGuid(ctx.getValue(), context);
return ret; return ret;
} }
...@@ -1021,6 +1019,8 @@ public class EntityGraphMapper { ...@@ -1021,6 +1019,8 @@ public class EntityGraphMapper {
ret = mapObjectIdValue(ctx, context); ret = mapObjectIdValue(ctx, context);
} }
setAssignedGuid(ctx.getValue(), context);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== mapObjectIdValueUsingRelationship({})", ctx); LOG.debug("<== mapObjectIdValueUsingRelationship({})", ctx);
} }
...@@ -1304,34 +1304,54 @@ public class EntityGraphMapper { ...@@ -1304,34 +1304,54 @@ public class EntityGraphMapper {
return null; return null;
} }
private static void setAssignedGuid(Object val, Map<String, String> guidAssignements) { private static void setAssignedGuid(Object val, EntityMutationContext context) {
if (val != null && MapUtils.isNotEmpty(guidAssignements)) { if (val != null) {
Map<String, String> guidAssignements = context.getGuidAssignments();
if (val instanceof AtlasObjectId) { if (val instanceof AtlasObjectId) {
AtlasObjectId objId = (AtlasObjectId) val; AtlasObjectId objId = (AtlasObjectId) val;
String guid = objId.getGuid(); String guid = objId.getGuid();
String assignedGuid = null;
if (StringUtils.isNotEmpty(guid) && !AtlasTypeUtil.isAssignedGuid(guid)) { if (StringUtils.isNotEmpty(guid)) {
String assignedGuid = guidAssignements.get(guid); if (!AtlasTypeUtil.isAssignedGuid(guid) && MapUtils.isNotEmpty(guidAssignements)) {
assignedGuid = guidAssignements.get(guid);
}
} else {
AtlasVertex vertex = context.getDiscoveryContext().getResolvedEntityVertex(objId);
if (vertex != null) {
assignedGuid = GraphHelper.getGuid(vertex);
}
}
if (StringUtils.isNotEmpty(assignedGuid)) { if (StringUtils.isNotEmpty(assignedGuid)) {
RequestContext.get().recordEntityGuidUpdate(objId, guid); RequestContext.get().recordEntityGuidUpdate(objId, guid);
objId.setGuid(assignedGuid); objId.setGuid(assignedGuid);
} }
}
} else if (val instanceof Map) { } else if (val instanceof Map) {
Map objId = (Map) val; Map mapObjId = (Map) val;
Object guidVal = objId.get(AtlasObjectId.KEY_GUID); Object guidVal = mapObjId.get(AtlasObjectId.KEY_GUID);
String guid = objId != null ? guidVal.toString() : null; String guid = guidVal != null ? guidVal.toString() : null;
String assignedGuid = null;
if (StringUtils.isNotEmpty(guid) && !AtlasTypeUtil.isAssignedGuid(guid)) { if (StringUtils.isNotEmpty(guid) ) {
String assignedGuid = guidAssignements.get(guid); if (!AtlasTypeUtil.isAssignedGuid(guid) && MapUtils.isNotEmpty(guidAssignements)) {
assignedGuid = guidAssignements.get(guid);
}
} else {
AtlasVertex vertex = context.getDiscoveryContext().getResolvedEntityVertex(new AtlasObjectId(mapObjId));
if (vertex != null) {
assignedGuid = GraphHelper.getGuid(vertex);
}
}
if (StringUtils.isNotEmpty(assignedGuid)) { if (StringUtils.isNotEmpty(assignedGuid)) {
RequestContext.get().recordEntityGuidUpdate(objId, guid); RequestContext.get().recordEntityGuidUpdate(mapObjId, guid);
objId.put(AtlasObjectId.KEY_GUID, assignedGuid); mapObjId.put(AtlasObjectId.KEY_GUID, assignedGuid);
}
} }
} }
} }
...@@ -2148,6 +2168,7 @@ public class EntityGraphMapper { ...@@ -2148,6 +2168,7 @@ public class EntityGraphMapper {
} }
private void recordEntityUpdate(AtlasVertex vertex) throws AtlasBaseException { private void recordEntityUpdate(AtlasVertex vertex) throws AtlasBaseException {
if (vertex != null) {
RequestContext req = RequestContext.get(); RequestContext req = RequestContext.get();
if (!req.isUpdatedEntity(GraphHelper.getGuid(vertex))) { if (!req.isUpdatedEntity(GraphHelper.getGuid(vertex))) {
...@@ -2156,6 +2177,7 @@ public class EntityGraphMapper { ...@@ -2156,6 +2177,7 @@ public class EntityGraphMapper {
req.recordEntityUpdate(entityRetriever.toAtlasEntityHeader(vertex)); req.recordEntityUpdate(entityRetriever.toAtlasEntityHeader(vertex));
} }
} }
}
private String getIdFromInVertex(AtlasEdge edge) { private String getIdFromInVertex(AtlasEdge edge) {
return getIdFromVertex(edge.getInVertex()); return getIdFromVertex(edge.getInVertex());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment