Commit ecf8095f by Sarath Subramanian

ATLAS-2355: Fix IT failures in webapp module

parent 8253653b
......@@ -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);
......
......@@ -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);
}
});
}
......
......@@ -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);
}
/**
......
......@@ -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;
......
......@@ -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>
......
......@@ -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);
......
......@@ -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();
}
}
}
......@@ -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");
......
......@@ -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");
}
......
......@@ -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": [
......
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