You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2019/03/12 18:21:13 UTC

[atlas] branch master updated: ATLAS-3073: Investigate and fix IT failures in EntityJerseyResourceIT

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

sarath 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 df44a5c  ATLAS-3073: Investigate and fix IT failures in EntityJerseyResourceIT
df44a5c is described below

commit df44a5cb2a48eae7bdb79d27f45f10aeb8c97d0c
Author: Sarath Subramanian <ss...@hortonworks.com>
AuthorDate: Tue Mar 12 11:15:12 2019 -0700

    ATLAS-3073: Investigate and fix IT failures in EntityJerseyResourceIT
---
 .../converters/AtlasEntityFormatConverter.java     | 45 +++-------------------
 .../store/graph/v2/EntityGraphRetriever.java       | 31 ++++++++++++++-
 2 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEntityFormatConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEntityFormatConverter.java
index 6c82b93..3084e70 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEntityFormatConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEntityFormatConverter.java
@@ -24,6 +24,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
 import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasEntity.Status;
 import org.apache.atlas.model.instance.AtlasObjectId;
+import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.v1.model.instance.AtlasSystemAttributes;
 import org.apache.atlas.v1.model.instance.Id;
 import org.apache.atlas.v1.model.instance.Referenceable;
@@ -128,30 +129,12 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter {
                     throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
                 }
 
-                final Map v2Attribs             = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
-                final Map v2RelationshipAttribs = (Map) v2Map.get(RELATIONSHIP_ATTRIBUTES_PROPERTY_KEY);
-                final Map attributes;
-
-                if (MapUtils.isNotEmpty(v2RelationshipAttribs)) {
-                    if (MapUtils.isNotEmpty(v2Attribs)) {
-                        attributes = new HashMap(v2RelationshipAttribs);
-
-                        for (Object key : v2Attribs.keySet()) {
-                            if (!attributes.containsKey(key)) {
-                                attributes.put(key, v2Attribs.get(key));
-                            }
-                        }
-                    } else {
-                        attributes = v2RelationshipAttribs;
-                    }
-                } else {
-                    attributes = v2Attribs;
-                }
+                final Map v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
 
                 if (MapUtils.isEmpty(v2Attribs)) {
                     ret = new Id(idStr, 0, typeName);
                 } else {
-                    ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, attributes, context));
+                    ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, v2Attribs, context));
                 }
             } else if (v2Obj instanceof AtlasEntity) {
                 AtlasEntity entity = (AtlasEntity) v2Obj;
@@ -161,28 +144,10 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter {
                     status = Status.ACTIVE;
                 }
 
-                final Map<String, Object> v2Attribs             = entity.getAttributes();
-                final Map<String, Object> v2RelationshipAttribs = entity.getRelationshipAttributes();
-                final Map<String, Object> attributes;
-
-                if (MapUtils.isNotEmpty(v2RelationshipAttribs)) {
-                    if (MapUtils.isNotEmpty(v2Attribs)) {
-                        attributes = new HashMap(v2RelationshipAttribs);
-
-                        for (String key : v2Attribs.keySet()) {
-                            if (!attributes.containsKey(key)) {
-                                attributes.put(key, v2Attribs.get(key));
-                            }
-                        }
-                    } else {
-                        attributes = v2RelationshipAttribs;
-                    }
-                } else {
-                    attributes = v2Attribs;
-                }
+                final Map<String, Object> v2Attribs = entity.getAttributes();
 
                 Referenceable referenceable = new Referenceable(entity.getGuid(), entity.getTypeName(), status.name(),
-                                                                fromV2ToV1(entityType, attributes, context),
+                                                                fromV2ToV1(entityType, v2Attribs, context),
                                                                 new AtlasSystemAttributes(entity.getCreatedBy(), entity.getUpdatedBy(), entity.getCreateTime(), entity.getUpdateTime()));
 
                 if (CollectionUtils.isNotEmpty(entity.getClassifications())) {
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
index c727a4f..cae74d1 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
@@ -65,6 +65,7 @@ import javax.inject.Inject;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -1044,13 +1045,41 @@ public class EntityGraphRetriever {
             entity.setRelationshipAttribute(attributeName, ret);
 
             if (attributeEndDef.getIsLegacyAttribute() && !entity.hasAttribute(attributeName)) {
-                entity.setAttribute(attributeName, ret);
+                entity.setAttribute(attributeName, toAtlasObjectId(ret));
             }
         }
 
         return ret;
     }
 
+    private Object toAtlasObjectId(Object obj) {
+        final Object ret;
+
+        if (obj instanceof AtlasObjectId) {
+            ret = new AtlasObjectId((AtlasObjectId) obj);
+        } else if (obj instanceof Collection) {
+            List list = new ArrayList();
+
+            for (Object elem : (Collection) obj) {
+                list.add(toAtlasObjectId(elem));
+            }
+
+            ret = list;
+        } else if (obj instanceof Map) {
+            Map map = new HashMap();
+
+            for (Object key : ((Map) obj).keySet()) {
+                map.put(key, toAtlasObjectId(((Map) obj).get(key)));
+            }
+
+            ret = map;
+        } else {
+            ret = obj;
+        }
+
+        return ret;
+    }
+
     private AtlasObjectId mapRelatedVertexToObjectId(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) throws AtlasBaseException {
         AtlasEdge edge = graphHelper.getEdgeForLabel(entityVertex, attribute.getRelationshipEdgeLabel(), attribute.getRelationshipEdgeDirection());