You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/10/28 17:31:29 UTC

[atlas] branch master updated: ATLAS-3492: updated object-id attributes in audit logs to replace unassigned-guids with assigned-guids (#2)

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new f8cb6f7  ATLAS-3492: updated object-id attributes in audit logs to replace unassigned-guids with assigned-guids (#2)
f8cb6f7 is described below

commit f8cb6f76cc8851848225ea35417bebdbc85ad6f7
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Mon Oct 28 00:06:48 2019 -0700

    ATLAS-3492: updated object-id attributes in audit logs to replace unassigned-guids with assigned-guids (#2)
---
 .../store/graph/v2/EntityGraphMapper.java          | 74 ++++++++++++++--------
 1 file changed, 48 insertions(+), 26 deletions(-)

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 749c307..19d4cef 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
@@ -597,8 +597,6 @@ public class EntityGraphMapper {
                                                       true, ctx.getAttribute().getRelationshipEdgeDirection(), ctx.getReferringVertex());
                 }
 
-                setAssignedGuid(ctx.getValue(), context.getGuidAssignments());
-
                 return newEdge;
             }
 
@@ -628,7 +626,7 @@ public class EntityGraphMapper {
             }
         }
 
-        setAssignedGuid(ctx.getValue(), context.getGuidAssignments());
+        setAssignedGuid(ctx.getValue(), context);
 
         return ret;
     }
@@ -1021,6 +1019,8 @@ public class EntityGraphMapper {
             ret = mapObjectIdValue(ctx, context);
         }
 
+        setAssignedGuid(ctx.getValue(), context);
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== mapObjectIdValueUsingRelationship({})", ctx);
         }
@@ -1304,35 +1304,55 @@ public class EntityGraphMapper {
         return null;
     }
 
-    private static void setAssignedGuid(Object val, Map<String, String> guidAssignements) {
-        if (val != null && MapUtils.isNotEmpty(guidAssignements)) {
-            if (val instanceof AtlasObjectId) {
-                AtlasObjectId objId = (AtlasObjectId) val;
-                String        guid  = objId.getGuid();
+    private static void setAssignedGuid(Object val, EntityMutationContext context) {
+        if (val != null) {
+            Map<String, String> guidAssignements = context.getGuidAssignments();
 
-                if (StringUtils.isNotEmpty(guid) && !AtlasTypeUtil.isAssignedGuid(guid)) {
-                    String assignedGuid = guidAssignements.get(guid);
+            if (val instanceof AtlasObjectId) {
+                AtlasObjectId objId        = (AtlasObjectId) val;
+                String        guid         = objId.getGuid();
+                String        assignedGuid = null;
 
-                    if (StringUtils.isNotEmpty(assignedGuid)) {
-                        RequestContext.get().recordEntityGuidUpdate(objId, guid);
+                if (StringUtils.isNotEmpty(guid)) {
+                    if (!AtlasTypeUtil.isAssignedGuid(guid) && MapUtils.isNotEmpty(guidAssignements)) {
+                        assignedGuid = guidAssignements.get(guid);
+                    }
+                } else {
+                    AtlasVertex vertex = context.getDiscoveryContext().getResolvedEntityVertex(objId);
 
-                        objId.setGuid(assignedGuid);
+                    if (vertex != null) {
+                        assignedGuid = GraphHelper.getGuid(vertex);
                     }
                 }
-            } else if (val instanceof Map) {
-                Map    objId   = (Map) val;
-                Object guidVal = objId.get(AtlasObjectId.KEY_GUID);
-                String guid    = objId != null ? guidVal.toString() : null;
 
-                if (StringUtils.isNotEmpty(guid) && !AtlasTypeUtil.isAssignedGuid(guid)) {
-                    String assignedGuid = guidAssignements.get(guid);
+                if (StringUtils.isNotEmpty(assignedGuid)) {
+                    RequestContext.get().recordEntityGuidUpdate(objId, guid);
 
-                    if (StringUtils.isNotEmpty(assignedGuid)) {
-                        RequestContext.get().recordEntityGuidUpdate(objId, guid);
+                    objId.setGuid(assignedGuid);
+                }
+            } else if (val instanceof Map) {
+                Map    mapObjId     = (Map) val;
+                Object guidVal      = mapObjId.get(AtlasObjectId.KEY_GUID);
+                String guid         = guidVal != null ? guidVal.toString() : null;
+                String assignedGuid = null;
+
+                if (StringUtils.isNotEmpty(guid) ) {
+                    if (!AtlasTypeUtil.isAssignedGuid(guid) && MapUtils.isNotEmpty(guidAssignements)) {
+                        assignedGuid = guidAssignements.get(guid);
+                    }
+                } else {
+                    AtlasVertex vertex = context.getDiscoveryContext().getResolvedEntityVertex(new AtlasObjectId(mapObjId));
 
-                        objId.put(AtlasObjectId.KEY_GUID, assignedGuid);
+                    if (vertex != null) {
+                        assignedGuid = GraphHelper.getGuid(vertex);
                     }
                 }
+
+                if (StringUtils.isNotEmpty(assignedGuid)) {
+                    RequestContext.get().recordEntityGuidUpdate(mapObjId, guid);
+
+                    mapObjId.put(AtlasObjectId.KEY_GUID, assignedGuid);
+                }
             }
         }
     }
@@ -2148,12 +2168,14 @@ public class EntityGraphMapper {
     }
 
     private void recordEntityUpdate(AtlasVertex vertex) throws AtlasBaseException {
-        RequestContext req = RequestContext.get();
+        if (vertex != null) {
+            RequestContext req = RequestContext.get();
 
-        if (!req.isUpdatedEntity(GraphHelper.getGuid(vertex))) {
-            updateModificationMetadata(vertex);
+            if (!req.isUpdatedEntity(GraphHelper.getGuid(vertex))) {
+                updateModificationMetadata(vertex);
 
-            req.recordEntityUpdate(entityRetriever.toAtlasEntityHeader(vertex));
+                req.recordEntityUpdate(entityRetriever.toAtlasEntityHeader(vertex));
+            }
         }
     }