Commit ecf8095f by Sarath Subramanian

ATLAS-2355: Fix IT failures in webapp module

parent 8253653b
...@@ -155,7 +155,7 @@ public class HiveITBase { ...@@ -155,7 +155,7 @@ public class HiveITBase {
protected String assertEntityIsRegistered(final String typeName, final String property, final String value, protected String assertEntityIsRegistered(final String typeName, final String property, final String value,
final HiveHookIT.AssertPredicate assertPredicate) throws Exception { final HiveHookIT.AssertPredicate assertPredicate) throws Exception {
waitFor(80000, new HiveHookIT.Predicate() { waitFor(2000, new HiveHookIT.Predicate() {
@Override @Override
public void evaluate() throws Exception { public void evaluate() throws Exception {
Referenceable entity = atlasClient.getEntity(typeName, property, value); Referenceable entity = atlasClient.getEntity(typeName, property, value);
......
...@@ -876,7 +876,7 @@ public class HiveHookIT extends HiveITBase { ...@@ -876,7 +876,7 @@ public class HiveHookIT extends HiveITBase {
String tableId = assertTableIsRegistered(DEFAULT_DB, tableName); String tableId = assertTableIsRegistered(DEFAULT_DB, tableName);
Referenceable tableEntity = atlasClient.getEntity(tableId); 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); Assert.assertNotNull(createTime);
String columnGuid = assertColumnIsRegistered(HiveMetaStoreBridge.getColumnQualifiedName(HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName), NAME)); String columnGuid = assertColumnIsRegistered(HiveMetaStoreBridge.getColumnQualifiedName(HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName), NAME));
...@@ -917,7 +917,7 @@ public class HiveHookIT extends HiveITBase { ...@@ -917,7 +917,7 @@ public class HiveHookIT extends HiveITBase {
Referenceable sd = ((Referenceable) entity.get(HiveMetaStoreBridge.STORAGE_DESC)); Referenceable sd = ((Referenceable) entity.get(HiveMetaStoreBridge.STORAGE_DESC));
String location = (String) sd.get(HiveMetaStoreBridge.LOCATION); String location = (String) sd.get(HiveMetaStoreBridge.LOCATION);
assertTrue(location.contains(newTableName)); assertTrue(location.contains(newTableName));
Assert.assertEquals(entity.get(HiveMetaStoreBridge.CREATE_TIME), createTime); Assert.assertEquals(String.valueOf(entity.get(HiveMetaStoreBridge.CREATE_TIME)), createTime);
} }
}); });
} }
......
...@@ -799,7 +799,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -799,7 +799,7 @@ public class AtlasClient extends AtlasBaseClient {
public ArrayNode searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException { public ArrayNode searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
LOG.debug("DSL query: {}", query); LOG.debug("DSL query: {}", query);
final API api = API_V1.SEARCH_DSL; final API api = API_V1.SEARCH_DSL;
ObjectNode result = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api); WebResource resource = getResource(api);
...@@ -809,7 +809,10 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -809,7 +809,10 @@ public class AtlasClient extends AtlasBaseClient {
return resource; return resource;
} }
}); });
return (ArrayNode)result.get(RESULTS);
JsonNode results = response.get(RESULTS);
return (results.isNull()) ? AtlasJson.createV1ArrayNode(): (ArrayNode) response.get(RESULTS);
} }
/** /**
......
...@@ -87,7 +87,11 @@ public class AtlasJson { ...@@ -87,7 +87,11 @@ public class AtlasJson {
public static String toJson(Object obj) { public static String toJson(Object obj) {
String ret; String ret;
try { try {
ret = mapper.writeValueAsString(obj); if (obj instanceof JsonNode && ((JsonNode) obj).isTextual()) {
ret = ((JsonNode) obj).textValue();
} else {
ret = mapperV1.writeValueAsString(obj);
}
}catch (IOException e){ }catch (IOException e){
LOG.error("AtlasJson.toJson()", e); LOG.error("AtlasJson.toJson()", e);
...@@ -115,8 +119,12 @@ public class AtlasJson { ...@@ -115,8 +119,12 @@ public class AtlasJson {
public static String toV1Json(Object obj) { public static String toV1Json(Object obj) {
String ret; String ret;
try { try {
if (obj instanceof JsonNode && ((JsonNode) obj).isTextual()) {
ret = ((JsonNode) obj).textValue();
} else {
ret = mapperV1.writeValueAsString(obj); ret = mapperV1.writeValueAsString(obj);
}catch (IOException e){ }
} catch (IOException e) {
LOG.error("AtlasType.toV1Json()", e); LOG.error("AtlasType.toV1Json()", e);
ret = null; ret = null;
......
...@@ -237,19 +237,6 @@ ...@@ -237,19 +237,6 @@
</dependency> </dependency>
<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> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>
</dependency> </dependency>
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
...@@ -264,19 +265,25 @@ public class EntityResource { ...@@ -264,19 +265,25 @@ public class EntityResource {
entityJson = Servlets.getRequestPayload(request); entityJson = Servlets.getRequestPayload(request);
//Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
String[] jsonStrings;
try {
ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson); ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
String[] jsonStrings = new String[jsonEntities.size()];
jsonStrings = new String[jsonEntities.size()];
for (int i = 0; i < jsonEntities.size(); i++) { for (int i = 0; i < jsonEntities.size(); i++) {
jsonStrings[i] = AtlasJson.toV1Json(jsonEntities.get(i)); jsonStrings[i] = AtlasJson.toV1Json(jsonEntities.get(i));
} }
} catch (IOException e) {
jsonStrings = new String[1];
if (LOG.isDebugEnabled()) { jsonStrings[0] = entityJson;
LOG.debug("updateEntities(): count={}, entityJson={} ", jsonEntities.size(), entityJson);
for (int i = 0; i < jsonStrings.length; i++) {
LOG.debug("updateEntities(): entity[{}]={}", i, jsonStrings[i]);
} }
if (LOG.isDebugEnabled()) {
LOG.debug("Updating entities: count={}; entities-json={}", jsonStrings.length, entityJson);
} }
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings); AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings);
......
...@@ -100,7 +100,6 @@ public abstract class BaseResourceIT { ...@@ -100,7 +100,6 @@ public abstract class BaseResourceIT {
protected NotificationInterface notificationInterface = null; protected NotificationInterface notificationInterface = null;
protected EmbeddedKafkaServer kafkaServer = null;
protected KafkaNotification kafkaNotification = null; protected KafkaNotification kafkaNotification = null;
@BeforeClass @BeforeClass
...@@ -689,13 +688,10 @@ public abstract class BaseResourceIT { ...@@ -689,13 +688,10 @@ public abstract class BaseResourceIT {
applicationProperties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5)); applicationProperties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));
kafkaServer = new EmbeddedKafkaServer(applicationProperties);
kafkaNotification = new KafkaNotification(applicationProperties); kafkaNotification = new KafkaNotification(applicationProperties);
notificationInterface = kafkaNotification; notificationInterface = kafkaNotification;
kafkaServer.start();
kafkaNotification.start(); kafkaNotification.start();
Thread.sleep(2000); Thread.sleep(2000);
} }
...@@ -705,8 +701,5 @@ public abstract class BaseResourceIT { ...@@ -705,8 +701,5 @@ public abstract class BaseResourceIT {
kafkaNotification.stop(); kafkaNotification.stop();
} }
if (kafkaServer != null) {
kafkaServer.stop();
}
} }
} }
...@@ -878,8 +878,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -878,8 +878,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("Updating entity= {}", tableUpdated); LOG.debug("Updating entity= {}", tableUpdated);
EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated); EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated);
assertEquals(entityResult.getUpdateEntities().size(), 2); assertEquals(entityResult.getUpdateEntities().size(), 1);
assertEquals(entityResult.getUpdateEntities().get(1), guid); assertEquals(entityResult.getUpdateEntities().get(0), guid);
Referenceable entity = atlasClientV1.getEntity(guid); Referenceable entity = atlasClientV1.getEntity(guid);
List<Referenceable> refs = (List<Referenceable>) entity.get("columns"); List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
...@@ -935,8 +935,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -935,8 +935,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("Updating entity= {}", tableUpdated); LOG.debug("Updating entity= {}", tableUpdated);
EntityResult entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, EntityResult entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
(String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated); (String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated);
assertEquals(entityResult.getUpdateEntities().size(), 2); assertEquals(entityResult.getUpdateEntities().size(), 1);
assertEquals(entityResult.getUpdateEntities().get(1), guid); assertEquals(entityResult.getUpdateEntities().get(0), guid);
Referenceable entity = atlasClientV1.getEntity(guid); Referenceable entity = atlasClientV1.getEntity(guid);
List<Referenceable> refs = (List<Referenceable>) entity.get("columns"); List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.web.service.ServiceState; import org.apache.atlas.web.service.ServiceState;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
...@@ -28,6 +30,8 @@ import org.testng.annotations.Test; ...@@ -28,6 +30,8 @@ import org.testng.annotations.Test;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
...@@ -43,26 +47,26 @@ public class AdminResourceTest { ...@@ -43,26 +47,26 @@ public class AdminResourceTest {
} }
@Test @Test
public void testStatusOfActiveServerIsReturned() { public void testStatusOfActiveServerIsReturned() throws IOException {
when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE); when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE);
AdminResource adminResource = new AdminResource(serviceState, null, null, null, null); AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
Response response = adminResource.getStatus(); Response response = adminResource.getStatus();
assertEquals(response.getStatus(), HttpServletResponse.SC_OK); assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
ObjectNode entity = (ObjectNode) response.getEntity(); JsonNode entity = AtlasJson.parseToV1JsonNode((String) response.getEntity());
assertEquals(entity.get("Status").asText(), "ACTIVE"); assertEquals(entity.get("Status").asText(), "ACTIVE");
} }
@Test @Test
public void testResourceGetsValueFromServiceState() { public void testResourceGetsValueFromServiceState() throws IOException {
when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE); when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
AdminResource adminResource = new AdminResource(serviceState, null, null, null, null); AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
Response response = adminResource.getStatus(); Response response = adminResource.getStatus();
verify(serviceState).getState(); verify(serviceState).getState();
ObjectNode entity = (ObjectNode) response.getEntity(); JsonNode entity = AtlasJson.parseToV1JsonNode((String) response.getEntity());
assertEquals(entity.get("Status").asText(), "PASSIVE"); assertEquals(entity.get("Status").asText(), "PASSIVE");
} }
......
...@@ -74,10 +74,20 @@ ...@@ -74,10 +74,20 @@
"limit": 50, "limit": 50,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "name", "attributeName": "name",
"operator": "neq", "operator": "neq",
"attributeValue": "dummy /Table_1@0" "attributeValue": "dummy /Table_1@0"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
...@@ -96,10 +106,20 @@ ...@@ -96,10 +106,20 @@
"limit": 25, "limit": 25,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "temporary", "attributeName": "temporary",
"operator": "eq", "operator": "eq",
"attributeValue": "false" "attributeValue": "false"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
...@@ -118,10 +138,20 @@ ...@@ -118,10 +138,20 @@
"limit": 50, "limit": 50,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "temporary", "attributeName": "temporary",
"operator": "neq", "operator": "neq",
"attributeValue": "true" "attributeValue": "true"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
...@@ -162,10 +192,20 @@ ...@@ -162,10 +192,20 @@
"limit": 25, "limit": 25,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "name", "attributeName": "name",
"operator": "endsWith", "operator": "endsWith",
"attributeValue": "0" "attributeValue": "0"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
...@@ -184,10 +224,20 @@ ...@@ -184,10 +224,20 @@
"limit": 25, "limit": 25,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "name", "attributeName": "name",
"operator": "endsWith", "operator": "endsWith",
"attributeValue": "8" "attributeValue": "8"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
...@@ -206,10 +256,20 @@ ...@@ -206,10 +256,20 @@
"limit": 25, "limit": 25,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "createTime", "attributeName": "createTime",
"operator": "lte", "operator": "lte",
"attributeValue": "1491250084794" "attributeValue": "1491250084794"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
...@@ -228,10 +288,20 @@ ...@@ -228,10 +288,20 @@
"limit": 25, "limit": 25,
"offset": 0, "offset": 0,
"entityFilters": { "entityFilters": {
"condition": "AND",
"criterion": [
{
"attributeName": "lastAccessTime", "attributeName": "lastAccessTime",
"operator": "gte", "operator": "gte",
"attributeValue": "1491248907000" "attributeValue": "1491248907000"
}, },
{
"attributeName": "description",
"operator": "isNull",
"attributeValue": ""
}
]
},
"tagFilters": null, "tagFilters": null,
"attributes": [ "attributes": [
"" ""
......
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