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 2017/03/07 22:30:31 UTC

incubator-atlas git commit: ATLAS-1648: Fix HiveHookIT failures

Repository: incubator-atlas
Updated Branches:
  refs/heads/master d0e9d48b1 -> f87f5f22b


ATLAS-1648: Fix HiveHookIT failures

Signed-off-by: Madhan Neethiraj <ma...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/f87f5f22
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/f87f5f22
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/f87f5f22

Branch: refs/heads/master
Commit: f87f5f22b8de37c8b08dfeaf0b2c5ca289675c84
Parents: d0e9d48
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Tue Mar 7 14:07:22 2017 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Tue Mar 7 14:12:19 2017 -0800

----------------------------------------------------------------------
 .../org/apache/atlas/hive/hook/HiveHookIT.java  |  3 +-
 .../atlas/model/typedef/AtlasBaseTypeDef.java   |  5 ++
 .../converters/AtlasObjectIdConverter.java      | 52 +++++++++++++++++---
 .../web/resources/EntityJerseyResourceIT.java   |  2 +-
 4 files changed, 54 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f87f5f22/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
----------------------------------------------------------------------
diff --git a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
index d640a81..979e729 100755
--- a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
+++ b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java
@@ -942,7 +942,8 @@ public class HiveHookIT extends HiveITBase {
 
     private String createTrait(String guid) throws AtlasServiceException, JSONException {
         //add trait
-        String traitName = "PII_Trait" + RandomStringUtils.random(10);
+        //valid type names in v2 must consist of a letter followed by a sequence of letter, number, or _ characters
+        String traitName = "PII_Trait" + random();
         atlasClient.createTraitType(traitName);
 
         Struct traitInstance = new Struct(traitName);

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f87f5f22/intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
index f8083de..7308eb7 100644
--- a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
+++ b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
@@ -35,6 +35,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.TimeZone;
 
 import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
 import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
@@ -110,6 +111,10 @@ public abstract class AtlasBaseTypeDef implements java.io.Serializable {
     public static final String     SERIALIZED_DATE_FORMAT_STR = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
     public static final DateFormat DATE_FORMATTER             = new SimpleDateFormat(SERIALIZED_DATE_FORMAT_STR);
 
+    static {
+        DATE_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC"));
+    }
+
     private final TypeCategory category;
     private String  guid       = null;
     private String  createdBy  = null;

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f87f5f22/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
index a5ab8d7..f8fa4d5 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
@@ -19,6 +19,7 @@ package org.apache.atlas.repository.converters;
 
 
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.AtlasException;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.instance.AtlasEntity;
@@ -27,7 +28,10 @@ import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.typesystem.IReferenceableInstance;
+import org.apache.atlas.typesystem.Referenceable;
 import org.apache.atlas.typesystem.persistence.Id;
+import org.apache.atlas.typesystem.persistence.StructInstance;
+import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.Map;
@@ -50,23 +54,24 @@ AtlasObjectIdConverter extends  AtlasAbstractFormatConverter {
         if (v1Obj != null) {
             if (v1Obj instanceof Id) {
                 Id id = (Id) v1Obj;
+
                 ret = new AtlasObjectId(id._getId(), id.getTypeName());
             } else if (v1Obj instanceof IReferenceableInstance) {
                 IReferenceableInstance refInst = (IReferenceableInstance) v1Obj;
+                String                 guid    = refInst.getId()._getId();
 
-                String guid = refInst.getId()._getId();
                 ret = new AtlasObjectId(guid, refInst.getTypeName());
 
-                if (!converterContext.entityExists(guid)) {
-                    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
-                    AtlasEntityFormatConverter entityFormatConverter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
-
-                    AtlasEntity entity = entityFormatConverter.fromV1ToV2(v1Obj, entityType, converterContext);
+                if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
+                    AtlasEntityType            entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
+                    AtlasEntityFormatConverter converter  = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
+                    AtlasEntity                entity     = converter.fromV1ToV2(v1Obj, entityType, converterContext);
 
                     converterContext.addReferredEntity(entity);
                 }
             }
         }
+
         return ret;
     }
 
@@ -97,4 +102,39 @@ AtlasObjectIdConverter extends  AtlasAbstractFormatConverter {
         }
         return ret;
     }
+
+    private boolean hasAnyAssignedAttribute(IReferenceableInstance rInstance) {
+        boolean ret = false;
+
+        if (rInstance instanceof StructInstance) {
+            StructInstance sInstance = (StructInstance) rInstance;
+
+            Map<String, Object> attributes = null;
+
+            try {
+                attributes = sInstance.getValuesMap();
+            } catch (AtlasException e) {
+                // ignore
+            }
+
+            if (MapUtils.isNotEmpty(attributes)) {
+                for (String attrName : attributes.keySet()) {
+                    try {
+                        if (sInstance.isValueSet(attrName)) {
+                            ret = true;
+                            break;
+                        }
+                    } catch (AtlasException e) {
+                            // ignore
+                    }
+                }
+            }
+        } else if (rInstance instanceof Referenceable) {
+            Referenceable referenceable = (Referenceable) rInstance;
+
+            ret = MapUtils.isNotEmpty(referenceable.getValuesMap());
+        }
+
+        return ret;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f87f5f22/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
index 91e2947..f2af208 100755
--- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
@@ -738,7 +738,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
 
         LOG.debug("Updating entity= {}", tableUpdated);
         AtlasClient.EntityResult entityResult = atlasClientV1.updateEntity(tableId._getId(), tableUpdated);
-        assertEquals(entityResult.getUpdateEntities().size(), 2);
+        assertEquals(entityResult.getUpdateEntities().size(), 1);
         assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
 
         JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, tableId._getId());