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 2018/01/11 22:48:06 UTC

atlas git commit: ATLAS-2355: Fix IT failures in webapp module

Repository: atlas
Updated Branches:
  refs/heads/master 8253653bc -> ecf8095ff


ATLAS-2355: Fix IT failures in webapp module


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

Branch: refs/heads/master
Commit: ecf8095ff92252f252e14292bb5d82d7b6aa1951
Parents: 8253653
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Thu Jan 11 14:47:50 2018 -0800
Committer: Sarath Subramanian <ss...@hortonworks.com>
Committed: Thu Jan 11 14:47:50 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/atlas/hive/HiveITBase.java  |   2 +-
 .../org/apache/atlas/hive/hook/HiveHookIT.java  |   4 +-
 .../main/java/org/apache/atlas/AtlasClient.java |   7 +-
 .../java/org/apache/atlas/utils/AtlasJson.java  |  14 ++-
 webapp/pom.xml                                  |  13 ---
 .../atlas/web/resources/EntityResource.java     |  25 +++--
 .../atlas/web/integration/BaseResourceIT.java   |   7 --
 .../web/integration/EntityJerseyResourceIT.java |   8 +-
 .../atlas/web/resources/AdminResourceTest.java  |  12 +-
 .../json/search-parameters/entity-filters.json  | 112 +++++++++++++++----
 10 files changed, 138 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/addons/hive-bridge/src/test/java/org/apache/atlas/hive/HiveITBase.java
----------------------------------------------------------------------
diff --git a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/HiveITBase.java b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/HiveITBase.java
index febce06..b4ea3f9 100644
--- a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/HiveITBase.java
+++ b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/HiveITBase.java
@@ -155,7 +155,7 @@ public class HiveITBase {
 
     protected String assertEntityIsRegistered(final String typeName, final String property, final String value,
                                             final HiveHookIT.AssertPredicate assertPredicate) throws Exception {
-        waitFor(80000, new HiveHookIT.Predicate() {
+        waitFor(2000, new HiveHookIT.Predicate() {
             @Override
             public void evaluate() throws Exception {
                 Referenceable entity = atlasClient.getEntity(typeName, property, value);

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/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 9176fb9..262f7dc 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
@@ -876,7 +876,7 @@ public class HiveHookIT extends HiveITBase {
 
         String tableId = assertTableIsRegistered(DEFAULT_DB, tableName);
         Referenceable tableEntity = atlasClient.getEntity(tableId);
-        final String createTime = (String)tableEntity.get(HiveMetaStoreBridge.CREATE_TIME);
+        final String createTime = String.valueOf(tableEntity.get(HiveMetaStoreBridge.CREATE_TIME));
         Assert.assertNotNull(createTime);
 
         String columnGuid = assertColumnIsRegistered(HiveMetaStoreBridge.getColumnQualifiedName(HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName), NAME));
@@ -917,7 +917,7 @@ public class HiveHookIT extends HiveITBase {
                 Referenceable sd = ((Referenceable) entity.get(HiveMetaStoreBridge.STORAGE_DESC));
                 String location = (String) sd.get(HiveMetaStoreBridge.LOCATION);
                 assertTrue(location.contains(newTableName));
-                Assert.assertEquals(entity.get(HiveMetaStoreBridge.CREATE_TIME), createTime);
+                Assert.assertEquals(String.valueOf(entity.get(HiveMetaStoreBridge.CREATE_TIME)), createTime);
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
index ab5bdac..c132afc 100644
--- a/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
+++ b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
@@ -799,7 +799,7 @@ public class AtlasClient extends AtlasBaseClient {
     public ArrayNode searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
         LOG.debug("DSL query: {}", query);
         final API api = API_V1.SEARCH_DSL;
-        ObjectNode result = callAPIWithRetries(api, null, new ResourceCreator() {
+        ObjectNode response = callAPIWithRetries(api, null, new ResourceCreator() {
             @Override
             public WebResource createResource() {
                 WebResource resource = getResource(api);
@@ -809,7 +809,10 @@ public class AtlasClient extends AtlasBaseClient {
                 return resource;
             }
         });
-        return (ArrayNode)result.get(RESULTS);
+
+        JsonNode results = response.get(RESULTS);
+
+        return (results.isNull()) ? AtlasJson.createV1ArrayNode(): (ArrayNode) response.get(RESULTS);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java b/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
index d4db756..adf0665 100644
--- a/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
+++ b/intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
@@ -87,7 +87,11 @@ public class AtlasJson {
     public static String toJson(Object obj) {
         String ret;
         try {
-            ret = mapper.writeValueAsString(obj);
+            if (obj instanceof JsonNode && ((JsonNode) obj).isTextual()) {
+                ret = ((JsonNode) obj).textValue();
+            } else {
+                ret = mapperV1.writeValueAsString(obj);
+            }
         }catch (IOException e){
             LOG.error("AtlasJson.toJson()", e);
 
@@ -115,8 +119,12 @@ public class AtlasJson {
     public static String toV1Json(Object obj) {
         String ret;
         try {
-            ret = mapperV1.writeValueAsString(obj);
-        }catch (IOException e){
+            if (obj instanceof JsonNode && ((JsonNode) obj).isTextual()) {
+                ret = ((JsonNode) obj).textValue();
+            } else {
+                ret = mapperV1.writeValueAsString(obj);
+            }
+        } catch (IOException e) {
             LOG.error("AtlasType.toV1Json()", e);
 
             ret = null;

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/webapp/pom.xml
----------------------------------------------------------------------
diff --git a/webapp/pom.xml b/webapp/pom.xml
index 352b8cd..2cf6e10 100755
--- a/webapp/pom.xml
+++ b/webapp/pom.xml
@@ -237,19 +237,6 @@
         </dependency>
 
         <dependency>
-            <groupId>com.sun.jersey</groupId>
-            <artifactId>jersey-json</artifactId>
-            <version>${jersey.version}</version>
-
-        </dependency>
-
-        <dependency>
-            <groupId>javax.ws.rs</groupId>
-            <artifactId>jsr311-api</artifactId>
-            <version>${jsr.version}</version>
-        </dependency>
-
-        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-all</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
index b062093..715a54d 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
@@ -18,6 +18,7 @@
 
 package org.apache.atlas.web.resources;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
@@ -264,19 +265,25 @@ public class EntityResource {
 
             entityJson = Servlets.getRequestPayload(request);
 
-            ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
-            String[]  jsonStrings = new String[jsonEntities.size()];
+            //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
+            String[] jsonStrings;
 
-            for (int i = 0; i < jsonEntities.size(); i++) {
-                jsonStrings[i] = AtlasJson.toV1Json(jsonEntities.get(i));
-            }
+            try {
+                ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
 
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("updateEntities(): count={}, entityJson={} ", jsonEntities.size(), entityJson);
+                jsonStrings = new String[jsonEntities.size()];
 
-                for (int i = 0; i < jsonStrings.length; i++) {
-                    LOG.debug("updateEntities(): entity[{}]={}", i, jsonStrings[i]);
+                for (int i = 0; i < jsonEntities.size(); i++) {
+                    jsonStrings[i] = AtlasJson.toV1Json(jsonEntities.get(i));
                 }
+            } catch (IOException e) {
+                jsonStrings = new String[1];
+
+                jsonStrings[0] = entityJson;
+            }
+
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Updating entities: count={}; entities-json={}", jsonStrings.length, entityJson);
             }
 
             AtlasEntitiesWithExtInfo   entitiesInfo     = restAdapters.toAtlasEntities(jsonStrings);

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
index 64a828b..6a7aece 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
@@ -100,7 +100,6 @@ public abstract class BaseResourceIT {
 
 
     protected NotificationInterface notificationInterface = null;
-    protected EmbeddedKafkaServer   kafkaServer           = null;
     protected KafkaNotification     kafkaNotification     = null;
 
     @BeforeClass
@@ -689,13 +688,10 @@ public abstract class BaseResourceIT {
 
         applicationProperties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));
 
-        kafkaServer           = new EmbeddedKafkaServer(applicationProperties);
         kafkaNotification     = new KafkaNotification(applicationProperties);
         notificationInterface = kafkaNotification;
 
-        kafkaServer.start();
         kafkaNotification.start();
-
         Thread.sleep(2000);
     }
 
@@ -705,8 +701,5 @@ public abstract class BaseResourceIT {
             kafkaNotification.stop();
         }
 
-        if (kafkaServer != null) {
-            kafkaServer.stop();
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
index d49391f..f769431 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
@@ -878,8 +878,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
 
         LOG.debug("Updating entity= {}", tableUpdated);
         EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated);
-        assertEquals(entityResult.getUpdateEntities().size(), 2);
-        assertEquals(entityResult.getUpdateEntities().get(1), guid);
+        assertEquals(entityResult.getUpdateEntities().size(), 1);
+        assertEquals(entityResult.getUpdateEntities().get(0), guid);
 
         Referenceable entity = atlasClientV1.getEntity(guid);
         List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
@@ -935,8 +935,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
         LOG.debug("Updating entity= {}", tableUpdated);
         EntityResult entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
                 (String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated);
-        assertEquals(entityResult.getUpdateEntities().size(), 2);
-        assertEquals(entityResult.getUpdateEntities().get(1), guid);
+        assertEquals(entityResult.getUpdateEntities().size(), 1);
+        assertEquals(entityResult.getUpdateEntities().get(0), guid);
 
         Referenceable entity = atlasClientV1.getEntity(guid);
         List<Referenceable> refs = (List<Referenceable>) entity.get("columns");

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java b/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
index 3c5d031..fd96fc3 100644
--- a/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
@@ -18,7 +18,9 @@
 
 package org.apache.atlas.web.resources;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.atlas.utils.AtlasJson;
 import org.apache.atlas.web.service.ServiceState;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -28,6 +30,8 @@ import org.testng.annotations.Test;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.core.Response;
 
+import java.io.IOException;
+
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.testng.Assert.assertEquals;
@@ -43,26 +47,26 @@ public class AdminResourceTest {
     }
 
     @Test
-    public void testStatusOfActiveServerIsReturned() {
+    public void testStatusOfActiveServerIsReturned() throws IOException {
 
         when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE);
 
         AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
         Response response = adminResource.getStatus();
         assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
-        ObjectNode entity = (ObjectNode) response.getEntity();
+        JsonNode entity = AtlasJson.parseToV1JsonNode((String) response.getEntity());
         assertEquals(entity.get("Status").asText(), "ACTIVE");
     }
 
     @Test
-    public void testResourceGetsValueFromServiceState() {
+    public void testResourceGetsValueFromServiceState() throws IOException {
         when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
 
         AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
         Response response = adminResource.getStatus();
 
         verify(serviceState).getState();
-        ObjectNode entity = (ObjectNode) response.getEntity();
+        JsonNode entity = AtlasJson.parseToV1JsonNode((String) response.getEntity());
         assertEquals(entity.get("Status").asText(), "PASSIVE");
 
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ecf8095f/webapp/src/test/resources/json/search-parameters/entity-filters.json
----------------------------------------------------------------------
diff --git a/webapp/src/test/resources/json/search-parameters/entity-filters.json b/webapp/src/test/resources/json/search-parameters/entity-filters.json
index 0611644..b18311f 100644
--- a/webapp/src/test/resources/json/search-parameters/entity-filters.json
+++ b/webapp/src/test/resources/json/search-parameters/entity-filters.json
@@ -74,9 +74,19 @@
       "limit": 50,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "name",
-        "operator": "neq",
-        "attributeValue": "dummy /Table_1@0"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "name",
+            "operator": "neq",
+            "attributeValue": "dummy /Table_1@0"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [
@@ -96,9 +106,19 @@
       "limit": 25,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "temporary",
-        "operator": "eq",
-        "attributeValue": "false"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "temporary",
+            "operator": "eq",
+            "attributeValue": "false"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [
@@ -118,9 +138,19 @@
       "limit": 50,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "temporary",
-        "operator": "neq",
-        "attributeValue": "true"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "temporary",
+            "operator": "neq",
+            "attributeValue": "true"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [
@@ -162,9 +192,19 @@
       "limit": 25,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "name",
-        "operator": "endsWith",
-        "attributeValue": "0"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "name",
+            "operator": "endsWith",
+            "attributeValue": "0"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [
@@ -184,9 +224,19 @@
       "limit": 25,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "name",
-        "operator": "endsWith",
-        "attributeValue": "8"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "name",
+            "operator": "endsWith",
+            "attributeValue": "8"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [
@@ -206,9 +256,19 @@
       "limit": 25,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "createTime",
-        "operator": "lte",
-        "attributeValue": "1491250084794"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "createTime",
+            "operator": "lte",
+            "attributeValue": "1491250084794"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [
@@ -228,9 +288,19 @@
       "limit": 25,
       "offset": 0,
       "entityFilters": {
-        "attributeName": "lastAccessTime",
-        "operator": "gte",
-        "attributeValue": "1491248907000"
+        "condition": "AND",
+        "criterion": [
+          {
+            "attributeName": "lastAccessTime",
+            "operator": "gte",
+            "attributeValue": "1491248907000"
+          },
+          {
+            "attributeName": "description",
+            "operator": "isNull",
+            "attributeValue": ""
+          }
+        ]
       },
       "tagFilters": null,
       "attributes": [