Commit 1f8e2146 by Madhan Neethiraj

ATLAS-2292: remove older version jackson libraries from packaging

parent d1aa36c4
...@@ -31,7 +31,6 @@ import org.apache.hadoop.hive.ql.metadata.HiveException; ...@@ -31,7 +31,6 @@ import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.metadata.Partition; import org.apache.hadoop.hive.ql.metadata.Partition;
import org.apache.hadoop.hive.ql.metadata.Table; import org.apache.hadoop.hive.ql.metadata.Table;
import org.apache.hadoop.mapred.TextInputFormat; import org.apache.hadoop.mapred.TextInputFormat;
import org.codehaus.jettison.json.JSONException;
import org.mockito.ArgumentMatcher; import org.mockito.ArgumentMatcher;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
...@@ -113,7 +112,7 @@ public class HiveMetaStoreBridgeTest { ...@@ -113,7 +112,7 @@ public class HiveMetaStoreBridgeTest {
} }
private void returnExistingDatabase(String databaseName, AtlasClient atlasClient, String clusterName) private void returnExistingDatabase(String databaseName, AtlasClient atlasClient, String clusterName)
throws AtlasServiceException, JSONException { throws AtlasServiceException {
when(atlasClient.getEntity( when(atlasClient.getEntity(
HiveDataTypes.HIVE_DB.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, HiveDataTypes.HIVE_DB.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
HiveMetaStoreBridge.getDBQualifiedName(clusterName, databaseName))).thenReturn( HiveMetaStoreBridge.getDBQualifiedName(clusterName, databaseName))).thenReturn(
...@@ -219,7 +218,7 @@ public class HiveMetaStoreBridgeTest { ...@@ -219,7 +218,7 @@ public class HiveMetaStoreBridgeTest {
} }
} }
private Referenceable getEntityReference(String typeName, String id) throws JSONException { private Referenceable getEntityReference(String typeName, String id) {
return new Referenceable(id, typeName, null); return new Referenceable(id, typeName, null);
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.hive.hook; package org.apache.atlas.hive.hook;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -41,8 +43,6 @@ import org.apache.hadoop.hive.ql.metadata.Table; ...@@ -41,8 +43,6 @@ import org.apache.hadoop.hive.ql.metadata.Table;
import org.apache.hadoop.hive.ql.plan.HiveOperation; import org.apache.hadoop.hive.ql.plan.HiveOperation;
import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
...@@ -381,8 +381,8 @@ public class HiveHookIT extends HiveITBase { ...@@ -381,8 +381,8 @@ public class HiveHookIT extends HiveITBase {
//Check lineage which includes table1 //Check lineage which includes table1
String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, viewName); String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, viewName);
JSONObject response = atlasClient.getInputGraph(datasetName); ObjectNode response = atlasClient.getInputGraph(datasetName);
JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices"); JsonNode vertices = response.get("values").get("vertices");
assertTrue(vertices.has(viewId)); assertTrue(vertices.has(viewId));
assertTrue(vertices.has(table1Id)); assertTrue(vertices.has(table1Id));
...@@ -398,7 +398,7 @@ public class HiveHookIT extends HiveITBase { ...@@ -398,7 +398,7 @@ public class HiveHookIT extends HiveITBase {
datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, viewName); datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, viewName);
response = atlasClient.getInputGraph(datasetName); response = atlasClient.getInputGraph(datasetName);
vertices = response.getJSONObject("values").getJSONObject("vertices"); vertices = response.get("values").get("vertices");
assertTrue(vertices.has(viewId)); assertTrue(vertices.has(viewId));
//This is through the alter view process //This is through the alter view process
...@@ -409,8 +409,8 @@ public class HiveHookIT extends HiveITBase { ...@@ -409,8 +409,8 @@ public class HiveHookIT extends HiveITBase {
//Outputs dont exist //Outputs dont exist
response = atlasClient.getOutputGraph(datasetName); response = atlasClient.getOutputGraph(datasetName);
vertices = response.getJSONObject("values").getJSONObject("vertices"); vertices = response.get("values").get("vertices");
Assert.assertEquals(vertices.length(), 0); Assert.assertEquals(vertices.size(), 0);
} }
private String createTestDFSFile(String path) throws Exception { private String createTestDFSFile(String path) throws Exception {
...@@ -938,7 +938,7 @@ public class HiveHookIT extends HiveITBase { ...@@ -938,7 +938,7 @@ public class HiveHookIT extends HiveITBase {
} }
private String createTrait(String guid) throws AtlasServiceException, JSONException { private String createTrait(String guid) throws AtlasServiceException {
//add trait //add trait
//valid type names in v2 must consist of a letter followed by a sequence of letter, number, or _ characters //valid type names in v2 must consist of a letter followed by a sequence of letter, number, or _ characters
String traitName = "PII_Trait" + random(); String traitName = "PII_Trait" + random();
...@@ -949,7 +949,7 @@ public class HiveHookIT extends HiveITBase { ...@@ -949,7 +949,7 @@ public class HiveHookIT extends HiveITBase {
return traitName; return traitName;
} }
private void assertTrait(String guid, String traitName) throws AtlasServiceException, JSONException { private void assertTrait(String guid, String traitName) throws AtlasServiceException {
List<String> traits = atlasClient.listTraits(guid); List<String> traits = atlasClient.listTraits(guid);
Assert.assertEquals(traits.get(0), traitName); Assert.assertEquals(traits.get(0), traitName);
} }
...@@ -1166,20 +1166,20 @@ public class HiveHookIT extends HiveITBase { ...@@ -1166,20 +1166,20 @@ public class HiveHookIT extends HiveITBase {
Assert.assertEquals(bProcessInputsAsString, bLineageInputs); Assert.assertEquals(bProcessInputsAsString, bLineageInputs);
//Test lineage API response //Test lineage API response
JSONObject response = atlasClient.getInputGraphForEntity(dest_a_guid); ObjectNode response = atlasClient.getInputGraphForEntity(dest_a_guid);
JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices"); JsonNode vertices = response.get("values").get("vertices");
JSONObject dest_a_val = (JSONObject) vertices.get(dest_a_guid); JsonNode dest_a_val = vertices.get(dest_a_guid);
JSONObject src_a_val = (JSONObject) vertices.get(a_guid); JsonNode src_a_val = vertices.get(a_guid);
JSONObject src_b_val = (JSONObject) vertices.get(b_guid); JsonNode src_b_val = vertices.get(b_guid);
Assert.assertNotNull(dest_a_val); Assert.assertNotNull(dest_a_val);
Assert.assertNotNull(src_a_val); Assert.assertNotNull(src_a_val);
Assert.assertNotNull(src_b_val); Assert.assertNotNull(src_b_val);
JSONObject b_response = atlasClient.getInputGraphForEntity(dest_b_guid); ObjectNode b_response = atlasClient.getInputGraphForEntity(dest_b_guid);
JSONObject b_vertices = b_response.getJSONObject("values").getJSONObject("vertices"); JsonNode b_vertices = b_response.get("values").get("vertices");
JSONObject b_val = (JSONObject) b_vertices.get(dest_b_guid); JsonNode b_val = b_vertices.get(dest_b_guid);
JSONObject src_tbl_val = (JSONObject) b_vertices.get(sourceTableGUID); JsonNode src_tbl_val = b_vertices.get(sourceTableGUID);
Assert.assertNotNull(b_val); Assert.assertNotNull(b_val);
Assert.assertNotNull(src_tbl_val); Assert.assertNotNull(src_tbl_val);
} }
...@@ -1197,8 +1197,8 @@ public class HiveHookIT extends HiveITBase { ...@@ -1197,8 +1197,8 @@ public class HiveHookIT extends HiveITBase {
//Check lineage //Check lineage
String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName); String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, tableName);
JSONObject response = atlasClient.getInputGraph(datasetName); ObjectNode response = atlasClient.getInputGraph(datasetName);
JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices"); JsonNode vertices = response.get("values").get("vertices");
//Below should be assertTrue - Fix https://issues.apache.org/jira/browse/ATLAS-653 //Below should be assertTrue - Fix https://issues.apache.org/jira/browse/ATLAS-653
Assert.assertFalse(vertices.has(tableId)); Assert.assertFalse(vertices.has(tableId));
} }
...@@ -1841,14 +1841,14 @@ public class HiveHookIT extends HiveITBase { ...@@ -1841,14 +1841,14 @@ public class HiveHookIT extends HiveITBase {
String table2Id = assertTableIsRegistered(db2, table2); String table2Id = assertTableIsRegistered(db2, table2);
String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, db2, table2); String datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, db2, table2);
JSONObject response = atlasClient.getInputGraph(datasetName); ObjectNode response = atlasClient.getInputGraph(datasetName);
JSONObject vertices = response.getJSONObject("values").getJSONObject("vertices"); JsonNode vertices = response.get("values").get("vertices");
assertTrue(vertices.has(table1Id)); assertTrue(vertices.has(table1Id));
assertTrue(vertices.has(table2Id)); assertTrue(vertices.has(table2Id));
datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, table1); datasetName = HiveMetaStoreBridge.getTableQualifiedName(CLUSTER_NAME, DEFAULT_DB, table1);
response = atlasClient.getOutputGraph(datasetName); response = atlasClient.getOutputGraph(datasetName);
vertices = response.getJSONObject("values").getJSONObject("vertices"); vertices = response.get("values").get("vertices");
assertTrue(vertices.has(table1Id)); assertTrue(vertices.has(table1Id));
assertTrue(vertices.has(table2Id)); assertTrue(vertices.has(table2Id));
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.sqoop.hook; package org.apache.atlas.sqoop.hook;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.hive.bridge.HiveMetaStoreBridge; import org.apache.atlas.hive.bridge.HiveMetaStoreBridge;
...@@ -26,8 +28,6 @@ import org.apache.atlas.sqoop.model.SqoopDataTypes; ...@@ -26,8 +28,6 @@ import org.apache.atlas.sqoop.model.SqoopDataTypes;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.sqoop.SqoopJobDataPublisher; import org.apache.sqoop.SqoopJobDataPublisher;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -110,15 +110,15 @@ public class SqoopHookIT { ...@@ -110,15 +110,15 @@ public class SqoopHookIT {
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = atlasClient.search(query, 10, 0); ArrayNode results = atlasClient.search(query, 10, 0);
return results.length() > 0; return results.size() > 0;
} }
}); });
JSONArray results = atlasClient.search(query, 10, 0); ArrayNode results = atlasClient.search(query, 10, 0);
JSONObject row = results.getJSONObject(0).getJSONObject("t"); JsonNode row = results.get(0).get("t");
return row.getString("id"); return row.get("id").asText();
} }
protected void waitFor(int timeout, Predicate predicate) throws Exception { protected void waitFor(int timeout, Predicate predicate) throws Exception {
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.storm.hook; package org.apache.atlas.storm.hook;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.hive.bridge.HiveMetaStoreBridge; import org.apache.atlas.hive.bridge.HiveMetaStoreBridge;
...@@ -27,8 +29,6 @@ import org.apache.atlas.utils.AuthenticationUtil; ...@@ -27,8 +29,6 @@ import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.storm.ILocalCluster; import org.apache.storm.ILocalCluster;
import org.apache.storm.generated.StormTopology; import org.apache.storm.generated.StormTopology;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
...@@ -89,9 +89,9 @@ public class StormAtlasHookIT { ...@@ -89,9 +89,9 @@ public class StormAtlasHookIT {
String query = String.format("from %s where name = \"%s\"", String query = String.format("from %s where name = \"%s\"",
StormDataTypes.STORM_TOPOLOGY.getName(), TOPOLOGY_NAME); StormDataTypes.STORM_TOPOLOGY.getName(), TOPOLOGY_NAME);
JSONArray results = atlasClient.search(query, 10, 0); ArrayNode results = atlasClient.search(query, 10, 0);
JSONObject row = results.getJSONObject(0); JsonNode row = results.get(0);
return row.has("$id$") ? row.getJSONObject("$id$").getString("id"): null; return row.has("$id$") ? row.get("$id$").get("id").asText() : null;
} }
} }
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
package org.apache.atlas; package org.apache.atlas;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
...@@ -26,7 +28,6 @@ import org.apache.atlas.v1.model.instance.Referenceable; ...@@ -26,7 +28,6 @@ import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.codehaus.jettison.json.JSONObject;
import org.mockito.Matchers; import org.mockito.Matchers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
...@@ -96,9 +97,6 @@ public class AtlasClientTest { ...@@ -96,9 +97,6 @@ public class AtlasClientTest {
ClientResponse response = mock(ClientResponse.class); ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode()); when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
JSONObject jsonResponse = new JSONObject(new EntityResult(Arrays.asList("id"), null, null).toString());
when(response.getEntity(String.class)).thenReturn(jsonResponse.toString());
when(response.getLength()).thenReturn(jsonResponse.length());
String entityJson = AtlasType.toV1Json(new Referenceable("type")); String entityJson = AtlasType.toV1Json(new Referenceable("type"));
when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response); when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response);
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
*/ */
package org.apache.atlas; package org.apache.atlas;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientHandlerException;
...@@ -35,12 +37,11 @@ import org.apache.atlas.model.impexp.AtlasImportResult; ...@@ -35,12 +37,11 @@ import org.apache.atlas.model.impexp.AtlasImportResult;
import org.apache.atlas.model.metrics.AtlasMetrics; import org.apache.atlas.model.metrics.AtlasMetrics;
import org.apache.atlas.security.SecureClientUtils; import org.apache.atlas.security.SecureClientUtils;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -163,7 +164,7 @@ public abstract class AtlasBaseClient { ...@@ -163,7 +164,7 @@ public abstract class AtlasBaseClient {
public boolean isServerReady() throws AtlasServiceException { public boolean isServerReady() throws AtlasServiceException {
WebResource resource = getResource(API_VERSION.getNormalizedPath()); WebResource resource = getResource(API_VERSION.getNormalizedPath());
try { try {
callAPIWithResource(API_VERSION, resource, null, JSONObject.class); callAPIWithResource(API_VERSION, resource, null, ObjectNode.class);
return true; return true;
} catch (ClientHandlerException che) { } catch (ClientHandlerException che) {
return false; return false;
...@@ -186,12 +187,10 @@ public abstract class AtlasBaseClient { ...@@ -186,12 +187,10 @@ public abstract class AtlasBaseClient {
public String getAdminStatus() throws AtlasServiceException { public String getAdminStatus() throws AtlasServiceException {
String result = AtlasBaseClient.UNKNOWN_STATUS; String result = AtlasBaseClient.UNKNOWN_STATUS;
WebResource resource = getResource(service, API_STATUS.getNormalizedPath()); WebResource resource = getResource(service, API_STATUS.getNormalizedPath());
JSONObject response = callAPIWithResource(API_STATUS, resource, null, JSONObject.class); ObjectNode response = callAPIWithResource(API_STATUS, resource, null, ObjectNode.class);
try {
result = response.getString("Status"); result = response.get("Status").asText();
} catch (JSONException e) {
LOG.error("Exception while parsing admin status response. Returned response {}", response.toString(), e);
}
return result; return result;
} }
...@@ -355,14 +354,14 @@ public abstract class AtlasBaseClient { ...@@ -355,14 +354,14 @@ public abstract class AtlasBaseClient {
return null; return null;
} }
try { try {
if (responseType.getRawClass().equals(JSONObject.class)) { if (responseType.getRawClass().equals(ObjectNode.class)) {
String stringEntity = clientResponse.getEntity(String.class); String stringEntity = clientResponse.getEntity(String.class);
try { try {
JSONObject jsonObject = new JSONObject(stringEntity); JsonNode jsonObject = AtlasJson.parseToV1JsonNode(stringEntity);
LOG.debug("Response = {}", jsonObject); LOG.debug("Response = {}", jsonObject);
LOG.info("------------------------------------------------------"); LOG.info("------------------------------------------------------");
return (T) jsonObject; return (T) jsonObject;
} catch (JSONException e) { } catch (IOException e) {
throw new AtlasServiceException(api, e); throw new AtlasServiceException(api, e);
} }
} else { } else {
...@@ -462,13 +461,13 @@ public abstract class AtlasBaseClient { ...@@ -462,13 +461,13 @@ public abstract class AtlasBaseClient {
} }
@VisibleForTesting @VisibleForTesting
JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) ObjectNode callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator)
throws AtlasServiceException { throws AtlasServiceException {
for (int i = 0; i < getNumberOfRetries(); i++) { for (int i = 0; i < getNumberOfRetries(); i++) {
WebResource resource = resourceCreator.createResource(); WebResource resource = resourceCreator.createResource();
try { try {
LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1); LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1);
return callAPIWithResource(api, resource, requestObject, JSONObject.class); return callAPIWithResource(api, resource, requestObject, ObjectNode.class);
} catch (ClientHandlerException che) { } catch (ClientHandlerException che) {
if (i == (getNumberOfRetries() - 1)) { if (i == (getNumberOfRetries() - 1)) {
throw che; throw che;
......
...@@ -19,10 +19,6 @@ ...@@ -19,10 +19,6 @@
package org.apache.atlas; package org.apache.atlas;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import javax.ws.rs.WebApplicationException;
public class AtlasServiceException extends Exception { public class AtlasServiceException extends Exception {
private ClientResponse.Status status; private ClientResponse.Status status;
...@@ -31,11 +27,6 @@ public class AtlasServiceException extends Exception { ...@@ -31,11 +27,6 @@ public class AtlasServiceException extends Exception {
super("Metadata service API " + api.getMethod() + " : " + api.getNormalizedPath() + " failed", e); super("Metadata service API " + api.getMethod() + " : " + api.getNormalizedPath() + " failed", e);
} }
public AtlasServiceException(AtlasBaseClient.API api, WebApplicationException e) throws JSONException {
this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
}
private AtlasServiceException(AtlasBaseClient.API api, ClientResponse.Status status, String response) { private AtlasServiceException(AtlasBaseClient.API api, ClientResponse.Status status, String response) {
super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1) super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1)
+ " (" + status + ") Response Body (" + response + ")"); + " (" + status + ") Response Body (" + response + ")");
......
...@@ -98,6 +98,10 @@ ...@@ -98,6 +98,10 @@
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>info.ganglia.gmetric4j</groupId> <groupId>info.ganglia.gmetric4j</groupId>
<artifactId>gmetric4j</artifactId> <artifactId>gmetric4j</artifactId>
</exclusion> </exclusion>
......
...@@ -18,30 +18,15 @@ ...@@ -18,30 +18,15 @@
package org.apache.atlas.type; package org.apache.atlas.type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.notification.EntityNotification;
import org.apache.atlas.model.notification.EntityNotification.EntityNotificationType;
import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.HookNotificationType;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.v1.model.instance.Struct; import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.v1.model.notification.EntityNotificationV1;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityDeleteRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUpdateRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.TypeRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.List; import java.util.List;
...@@ -50,24 +35,7 @@ import java.util.List; ...@@ -50,24 +35,7 @@ import java.util.List;
*/ */
public abstract class AtlasType { public abstract class AtlasType {
private static final Logger LOG = LoggerFactory.getLogger(AtlasStructType.class); private static final Logger LOG = LoggerFactory.getLogger(AtlasType.class);
private static final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
private static final ObjectMapper mapperV1 = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
static {
SimpleModule atlasSerDeModule = new SimpleModule("AtlasSerDe", new Version(1, 0, 0, null));
atlasSerDeModule.addSerializer(Date.class, new DateSerializer());
atlasSerDeModule.addDeserializer(Date.class, new DateDeserializer());
atlasSerDeModule.addDeserializer(HookNotification.class, new HookNotificationDeserializer());
atlasSerDeModule.addDeserializer(EntityNotification.class, new EntityNotificationDeserializer());
mapperV1.registerModule(atlasSerDeModule);
}
private final String typeName; private final String typeName;
...@@ -135,155 +103,24 @@ public abstract class AtlasType { ...@@ -135,155 +103,24 @@ public abstract class AtlasType {
return this; return this;
} }
public static String toJson(Object obj) {
String ret;
try {
ret = mapper.writeValueAsString(obj);
}catch (IOException e){
LOG.error("AtlasType.toJson()", e);
ret = null; public static String toJson(Object obj) {
} return AtlasJson.toJson(obj);
return ret;
} }
public static <T> T fromJson(String jsonStr, Class<T> type) { public static <T> T fromJson(String jsonStr, Class<T> type) {
T ret; return AtlasJson.fromJson(jsonStr, type);
try {
ret = mapper.readValue(jsonStr, type);
}catch (IOException e){
LOG.error("AtlasType.fromJson()", e);
ret = null;
}
return ret;
} }
public static String toV1Json(Object obj) { public static String toV1Json(Object obj) {
String ret; return AtlasJson.toV1Json(obj);
try {
ret = mapperV1.writeValueAsString(obj);
}catch (IOException e){
LOG.error("AtlasType.toV1Json()", e);
ret = null;
}
return ret;
} }
public static <T> T fromV1Json(String jsonStr, Class<T> type) { public static <T> T fromV1Json(String jsonStr, Class<T> type) {
T ret; return AtlasJson.fromV1Json(jsonStr, type);
try {
ret = mapperV1.readValue(jsonStr, type);
if (ret instanceof Struct) {
((Struct) ret).normalize();
}
}catch (IOException e){
LOG.error("AtlasType.fromV1Json()", e);
ret = null;
}
return ret;
} }
public static <T> T fromV1Json(String jsonStr, TypeReference<T> type) { public static <T> T fromV1Json(String jsonStr, TypeReference<T> type) {
T ret; return AtlasJson.fromV1Json(jsonStr, type);
try {
ret = mapperV1.readValue(jsonStr, type);
}catch (IOException e){
LOG.error("AtlasType.toV1Json()", e);
ret = null;
}
return ret;
}
static class DateSerializer extends JsonSerializer<Date> {
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (value != null) {
jgen.writeString(AtlasBaseTypeDef.DATE_FORMATTER.format(value));
}
}
}
static class DateDeserializer extends JsonDeserializer<Date> {
@Override
public Date deserialize(JsonParser parser, DeserializationContext context) throws IOException {
Date ret = null;
String value = parser.readValueAs(String.class);
if (value != null) {
try {
ret = AtlasBaseTypeDef.DATE_FORMATTER.parse(value);
} catch (ParseException excp) {
}
}
return ret;
}
}
static class HookNotificationDeserializer extends JsonDeserializer<HookNotification> {
@Override
public HookNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
HookNotification ret = null;
ObjectCodec mapper = parser.getCodec();
TreeNode root = mapper.readTree(parser);
JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
String strType = typeNode != null ? typeNode.asText() : null;
HookNotificationType notificationType = strType != null ? HookNotificationType.valueOf(strType) : null;
if (notificationType != null) {
switch (notificationType) {
case TYPE_CREATE:
case TYPE_UPDATE:
ret = mapper.treeToValue(root, TypeRequest.class);
break;
case ENTITY_CREATE:
ret = mapper.treeToValue(root, EntityCreateRequest.class);
break;
case ENTITY_PARTIAL_UPDATE:
ret = mapper.treeToValue(root, EntityPartialUpdateRequest.class);
break;
case ENTITY_FULL_UPDATE:
ret = mapper.treeToValue(root, EntityUpdateRequest.class);
break;
case ENTITY_DELETE:
ret = mapper.treeToValue(root, EntityDeleteRequest.class);
break;
}
}
return ret;
}
}
static class EntityNotificationDeserializer extends JsonDeserializer<EntityNotification> {
@Override
public EntityNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
EntityNotification ret = null;
ObjectCodec mapper = parser.getCodec();
TreeNode root = mapper.readTree(parser);
JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
String strType = typeNode != null ? typeNode.asText() : null;
EntityNotificationType notificationType = strType != null ? EntityNotificationType.valueOf(strType) : EntityNotificationType.ENTITY_NOTIFICATION_V1;
if (root != null) {
switch (notificationType) {
case ENTITY_NOTIFICATION_V1:
ret = mapper.treeToValue(root, EntityNotificationV1.class);
break;
}
}
return ret;
}
} }
} }
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.utils;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.model.notification.EntityNotification;
import org.apache.atlas.model.notification.EntityNotification.EntityNotificationType;
import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.HookNotificationType;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.notification.EntityNotificationV1;
import org.apache.atlas.v1.model.notification.HookNotificationV1.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class AtlasJson {
private static final Logger LOG = LoggerFactory.getLogger(AtlasJson.class);
private static final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
private static final ObjectMapper mapperV1 = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
static {
SimpleModule atlasSerDeModule = new SimpleModule("AtlasSerDe", new Version(1, 0, 0, null));
atlasSerDeModule.addSerializer(Date.class, new DateSerializer());
atlasSerDeModule.addDeserializer(Date.class, new DateDeserializer());
atlasSerDeModule.addDeserializer(HookNotification.class, new HookNotificationDeserializer());
atlasSerDeModule.addDeserializer(EntityNotification.class, new EntityNotificationDeserializer());
mapperV1.registerModule(atlasSerDeModule);
}
public static String toJson(Object obj) {
String ret;
try {
ret = mapper.writeValueAsString(obj);
}catch (IOException e){
LOG.error("AtlasJson.toJson()", e);
ret = null;
}
return ret;
}
public static <T> T fromJson(String jsonStr, Class<T> type) {
T ret;
try {
ret = mapper.readValue(jsonStr, type);
}catch (IOException e){
LOG.error("AtlasType.fromJson()", e);
ret = null;
}
return ret;
}
public static String toV1Json(Object obj) {
String ret;
try {
ret = mapperV1.writeValueAsString(obj);
}catch (IOException e){
LOG.error("AtlasType.toV1Json()", e);
ret = null;
}
return ret;
}
public static <T> T fromV1Json(String jsonStr, Class<T> type) {
T ret;
try {
ret = mapperV1.readValue(jsonStr, type);
if (ret instanceof Struct) {
((Struct) ret).normalize();
}
}catch (IOException e){
LOG.error("AtlasType.fromV1Json()", e);
ret = null;
}
return ret;
}
public static <T> T fromV1Json(String jsonStr, TypeReference<T> type) {
T ret;
try {
ret = mapperV1.readValue(jsonStr, type);
}catch (IOException e){
LOG.error("AtlasType.toV1Json()", e);
ret = null;
}
return ret;
}
public static ObjectNode createV1ObjectNode() {
return mapperV1.createObjectNode();
}
public static ObjectNode createV1ObjectNode(String key, Object value) {
ObjectNode ret = mapperV1.createObjectNode();
ret.putPOJO(key, value);
return ret;
}
public static ArrayNode createV1ArrayNode() {
return mapperV1.createArrayNode();
}
public static ArrayNode createV1ArrayNode(Collection<?> array) {
ArrayNode ret = mapperV1.createArrayNode();
for (Object elem : array) {
ret.addPOJO(elem);
}
return ret;
}
public static JsonNode parseToV1JsonNode(String json) throws IOException {
JsonNode jsonNode = mapperV1.readTree(json);
return jsonNode;
}
public static ArrayNode parseToV1ArrayNode(String json) throws IOException {
JsonNode jsonNode = mapperV1.readTree(json);
if (jsonNode instanceof ArrayNode) {
return (ArrayNode)jsonNode;
}
throw new IOException("not an array");
}
public static ArrayNode parseToV1ArrayNode(Collection<String> jsonStrings) throws IOException {
ArrayNode ret = createV1ArrayNode();
for (String json : jsonStrings) {
JsonNode jsonNode = mapperV1.readTree(json);
ret.add(jsonNode);
}
return ret;
}
static class DateSerializer extends JsonSerializer<Date> {
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (value != null) {
jgen.writeString(AtlasBaseTypeDef.DATE_FORMATTER.format(value));
}
}
}
static class DateDeserializer extends JsonDeserializer<Date> {
@Override
public Date deserialize(JsonParser parser, DeserializationContext context) throws IOException {
Date ret = null;
String value = parser.readValueAs(String.class);
if (value != null) {
try {
ret = AtlasBaseTypeDef.DATE_FORMATTER.parse(value);
} catch (ParseException excp) {
}
}
return ret;
}
}
static class HookNotificationDeserializer extends JsonDeserializer<HookNotification> {
@Override
public HookNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
HookNotification ret = null;
ObjectCodec mapper = parser.getCodec();
TreeNode root = mapper.readTree(parser);
JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
String strType = typeNode != null ? typeNode.asText() : null;
HookNotificationType notificationType = strType != null ? HookNotificationType.valueOf(strType) : null;
if (notificationType != null) {
switch (notificationType) {
case TYPE_CREATE:
case TYPE_UPDATE:
ret = mapper.treeToValue(root, TypeRequest.class);
break;
case ENTITY_CREATE:
ret = mapper.treeToValue(root, EntityCreateRequest.class);
break;
case ENTITY_PARTIAL_UPDATE:
ret = mapper.treeToValue(root, EntityPartialUpdateRequest.class);
break;
case ENTITY_FULL_UPDATE:
ret = mapper.treeToValue(root, EntityUpdateRequest.class);
break;
case ENTITY_DELETE:
ret = mapper.treeToValue(root, EntityDeleteRequest.class);
break;
}
}
return ret;
}
}
static class EntityNotificationDeserializer extends JsonDeserializer<EntityNotification> {
@Override
public EntityNotification deserialize(JsonParser parser, DeserializationContext context) throws IOException {
EntityNotification ret = null;
ObjectCodec mapper = parser.getCodec();
TreeNode root = mapper.readTree(parser);
JsonNode typeNode = root != null ? (JsonNode) root.get("type") : null;
String strType = typeNode != null ? typeNode.asText() : null;
EntityNotificationType notificationType = strType != null ? EntityNotificationType.valueOf(strType) : EntityNotificationType.ENTITY_NOTIFICATION_V1;
if (root != null) {
switch (notificationType) {
case ENTITY_NOTIFICATION_V1:
ret = mapper.treeToValue(root, EntityNotificationV1.class);
break;
}
}
return ret;
}
}
}
...@@ -1057,18 +1057,6 @@ ...@@ -1057,18 +1057,6 @@
<dependency> <dependency>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId> <artifactId>jersey-server</artifactId>
<version>${jersey.version}</version> <version>${jersey.version}</version>
</dependency> </dependency>
...@@ -1160,6 +1148,10 @@ ...@@ -1160,6 +1148,10 @@
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>*</artifactId> <artifactId>*</artifactId>
<groupId>org.codehaus.jackson</groupId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.mortbay.jetty</groupId> <groupId>org.mortbay.jetty</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
......
...@@ -22,10 +22,10 @@ import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; ...@@ -22,10 +22,10 @@ import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.runner.LocalSolrRunner; import org.apache.atlas.runner.LocalSolrRunner;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.junit.Assert;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.testng.Assert;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -64,4 +64,4 @@ public class LocalSolrTest { ...@@ -64,4 +64,4 @@ public class LocalSolrTest {
System.out.println("Stopping Local Solr..."); System.out.println("Stopping Local Solr...");
LocalSolrRunner.stop(); LocalSolrRunner.stop();
} }
} }
\ No newline at end of file
...@@ -232,11 +232,6 @@ ...@@ -232,11 +232,6 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId> <groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId> <artifactId>jersey-multipart</artifactId>
</dependency> </dependency>
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.examples; package org.apache.atlas.examples;
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;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
...@@ -33,7 +34,6 @@ import org.apache.atlas.type.AtlasType; ...@@ -33,7 +34,6 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.codehaus.jettison.json.JSONArray;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
...@@ -478,9 +478,9 @@ public class QuickStart { ...@@ -478,9 +478,9 @@ public class QuickStart {
private void search() throws AtlasBaseException { private void search() throws AtlasBaseException {
try { try {
for (String dslQuery : getDSLQueries()) { for (String dslQuery : getDSLQueries()) {
JSONArray results = metadataServiceClient.search(dslQuery, 10, 0); ArrayNode results = metadataServiceClient.search(dslQuery, 10, 0);
if (results != null) { if (results != null) {
System.out.println("query [" + dslQuery + "] returned [" + results.length() + "] rows"); System.out.println("query [" + dslQuery + "] returned [" + results.size() + "] rows");
} else { } else {
System.out.println("query [" + dslQuery + "] failed, results:" + results); System.out.println("query [" + dslQuery + "] failed, results:" + results);
} }
......
...@@ -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.node.ObjectNode;
import com.sun.jersey.multipart.FormDataParam; import com.sun.jersey.multipart.FormDataParam;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -39,6 +40,7 @@ import org.apache.atlas.repository.impexp.ZipSource; ...@@ -39,6 +40,7 @@ import org.apache.atlas.repository.impexp.ZipSource;
import org.apache.atlas.services.MetricsService; import org.apache.atlas.services.MetricsService;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.util.SearchTracker; import org.apache.atlas.util.SearchTracker;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.web.filters.AtlasCSRFPreventionFilter; import org.apache.atlas.web.filters.AtlasCSRFPreventionFilter;
import org.apache.atlas.web.service.ServiceState; import org.apache.atlas.web.service.ServiceState;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
...@@ -46,8 +48,6 @@ import org.apache.commons.configuration.Configuration; ...@@ -46,8 +48,6 @@ import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
...@@ -186,7 +186,7 @@ public class AdminResource { ...@@ -186,7 +186,7 @@ public class AdminResource {
try { try {
PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-buildinfo.properties"); PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-buildinfo.properties");
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
response.put("Version", configProperties.getString("build.version", "UNKNOWN")); response.put("Version", configProperties.getString("build.version", "UNKNOWN"));
response.put("Name", configProperties.getString("project.name", "apache-atlas")); response.put("Name", configProperties.getString("project.name", "apache-atlas"));
response.put("Description", configProperties.getString("project.description", response.put("Description", configProperties.getString("project.description",
...@@ -195,7 +195,7 @@ public class AdminResource { ...@@ -195,7 +195,7 @@ public class AdminResource {
// todo: add hadoop version? // todo: add hadoop version?
// response.put("Hadoop", VersionInfo.getVersion() + "-r" + VersionInfo.getRevision()); // response.put("Hadoop", VersionInfo.getVersion() + "-r" + VersionInfo.getRevision());
version = Response.ok(response).build(); version = Response.ok(response).build();
} catch (JSONException | ConfigurationException e) { } catch (ConfigurationException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
} }
...@@ -215,15 +215,8 @@ public class AdminResource { ...@@ -215,15 +215,8 @@ public class AdminResource {
LOG.debug("==> AdminResource.getStatus()"); LOG.debug("==> AdminResource.getStatus()");
} }
Response response; ObjectNode responseData = AtlasJson.createV1ObjectNode(AtlasClient.STATUS, serviceState.getState().toString());
Response response = Response.ok(responseData).build();
try {
JSONObject responseData = new JSONObject();
responseData.put(AtlasClient.STATUS, serviceState.getState().toString());
response = Response.ok(responseData).build();
} catch (JSONException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AdminResource.getStatus()"); LOG.debug("<== AdminResource.getStatus()");
...@@ -241,42 +234,39 @@ public class AdminResource { ...@@ -241,42 +234,39 @@ public class AdminResource {
} }
Response response; Response response;
try {
boolean isEntityUpdateAccessAllowed = false;
boolean isEntityCreateAccessAllowed = false;
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String userName = null;
Set<String> groups = new HashSet<>();
if (auth != null) {
userName = auth.getName();
Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
for (GrantedAuthority c : authorities) {
groups.add(c.getAuthority());
}
isEntityUpdateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY, boolean isEntityUpdateAccessAllowed = false;
AtlasActionTypes.UPDATE, userName, groups, httpServletRequest); boolean isEntityCreateAccessAllowed = false;
isEntityCreateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY, Authentication auth = SecurityContextHolder.getContext().getAuthentication();
AtlasActionTypes.CREATE, userName, groups, httpServletRequest); String userName = null;
Set<String> groups = new HashSet<>();
if (auth != null) {
userName = auth.getName();
Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
for (GrantedAuthority c : authorities) {
groups.add(c.getAuthority());
} }
JSONObject responseData = new JSONObject(); isEntityUpdateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY,
AtlasActionTypes.UPDATE, userName, groups, httpServletRequest);
responseData.put(isCSRF_ENABLED, AtlasCSRFPreventionFilter.isCSRF_ENABLED); isEntityCreateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(AtlasResourceTypes.ENTITY,
responseData.put(BROWSER_USER_AGENT_PARAM, AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT); AtlasActionTypes.CREATE, userName, groups, httpServletRequest);
responseData.put(CUSTOM_METHODS_TO_IGNORE_PARAM, AtlasCSRFPreventionFilter.METHODS_TO_IGNORE_DEFAULT);
responseData.put(CUSTOM_HEADER_PARAM, AtlasCSRFPreventionFilter.HEADER_DEFAULT);
responseData.put(isEntityUpdateAllowed, isEntityUpdateAccessAllowed);
responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed);
responseData.put(editableEntityTypes, getEditableEntityTypes(atlasProperties));
responseData.put("userName", userName);
responseData.put("groups", groups);
response = Response.ok(responseData).build();
} catch (JSONException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
ObjectNode responseData = AtlasJson.createV1ObjectNode();
responseData.put(isCSRF_ENABLED, AtlasCSRFPreventionFilter.isCSRF_ENABLED);
responseData.put(BROWSER_USER_AGENT_PARAM, AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT);
responseData.put(CUSTOM_METHODS_TO_IGNORE_PARAM, AtlasCSRFPreventionFilter.METHODS_TO_IGNORE_DEFAULT);
responseData.put(CUSTOM_HEADER_PARAM, AtlasCSRFPreventionFilter.HEADER_DEFAULT);
responseData.put(isEntityUpdateAllowed, isEntityUpdateAccessAllowed);
responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed);
responseData.put(editableEntityTypes, getEditableEntityTypes(atlasProperties));
responseData.put("userName", userName);
responseData.put("groups", AtlasJson.createV1ArrayNode(groups));
response = Response.ok(responseData).build();
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AdminResource.getUserProfile()"); LOG.debug("<== AdminResource.getUserProfile()");
} }
......
...@@ -18,18 +18,18 @@ ...@@ -18,18 +18,18 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration; import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.classification.InterfaceAudience; import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.query.QueryParams; import org.apache.atlas.query.QueryParams;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -44,6 +44,7 @@ import javax.ws.rs.Produces; ...@@ -44,6 +44,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -150,7 +151,7 @@ public class MetadataDiscoveryResource { ...@@ -150,7 +151,7 @@ public class MetadataDiscoveryResource {
QueryParams queryParams = validateQueryParams(limit, offset); QueryParams queryParams = validateQueryParams(limit, offset);
final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByDSL(dslQuery, queryParams); final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByDSL(dslQuery, queryParams);
JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build(); ObjectNode response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
return Response.ok(response).build(); return Response.ok(response).build();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
...@@ -222,17 +223,13 @@ public class MetadataDiscoveryResource { ...@@ -222,17 +223,13 @@ public class MetadataDiscoveryResource {
gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty"); gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
final List<Map<String, String>> results = new ArrayList<>(); // TODO-typeSystem-removal: discoveryService.searchByGremlin(gremlinQuery); final List<Map<String, String>> results = new ArrayList<>(); // TODO-typeSystem-removal: discoveryService.searchByGremlin(gremlinQuery);
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.QUERY, gremlinQuery); response.put(AtlasClient.QUERY, gremlinQuery);
response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN); response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN);
JSONArray list = new JSONArray(); response.putPOJO(AtlasClient.RESULTS, results);
for (Map<String, String> result : results) { response.put(AtlasClient.COUNT, results.size());
list.put(new JSONObject(result));
}
response.put(AtlasClient.RESULTS, list);
response.put(AtlasClient.COUNT, list.length());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
...@@ -281,9 +278,9 @@ public class MetadataDiscoveryResource { ...@@ -281,9 +278,9 @@ public class MetadataDiscoveryResource {
query = ParamChecker.notEmpty(query, "query cannot be null or empty"); query = ParamChecker.notEmpty(query, "query cannot be null or empty");
QueryParams queryParams = validateQueryParams(limit, offset); QueryParams queryParams = validateQueryParams(limit, offset);
final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByFullText(query, queryParams); final String jsonResultStr = ""; // TODO-typeSystem-removal: discoveryService.searchByFullText(query, queryParams);
JSONArray rowsJsonArr = new JSONArray(jsonResultStr); ArrayNode rowsJsonArr = AtlasJson.parseToV1ArrayNode(jsonResultStr);
JSONObject response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build(); ObjectNode response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
return Response.ok(response).build(); return Response.ok(response).build();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
LOG.error("Unable to get entity list for query {}", query, e); LOG.error("Unable to get entity list for query {}", query, e);
...@@ -308,10 +305,10 @@ public class MetadataDiscoveryResource { ...@@ -308,10 +305,10 @@ public class MetadataDiscoveryResource {
protected int count = 0; protected int count = 0;
protected String query; protected String query;
protected String queryType; protected String queryType;
protected JSONObject response; protected ObjectNode response;
JsonResponseBuilder() { JsonResponseBuilder() {
this.response = new JSONObject(); this.response = AtlasJson.createV1ObjectNode();
} }
protected JsonResponseBuilder count(int count) { protected JsonResponseBuilder count(int count) {
...@@ -329,7 +326,7 @@ public class MetadataDiscoveryResource { ...@@ -329,7 +326,7 @@ public class MetadataDiscoveryResource {
return this; return this;
} }
protected JSONObject build() throws JSONException { protected ObjectNode build() {
Preconditions.checkNotNull(query, "Query cannot be null"); Preconditions.checkNotNull(query, "Query cannot be null");
Preconditions.checkNotNull(queryType, "Query Type must be specified"); Preconditions.checkNotNull(queryType, "Query Type must be specified");
...@@ -349,25 +346,24 @@ public class MetadataDiscoveryResource { ...@@ -349,25 +346,24 @@ public class MetadataDiscoveryResource {
super(); super();
} }
private JSONObject dslResults; private ArrayNode dslResults;
public DSLJSONResponseBuilder results(JSONObject dslResults) { public DSLJSONResponseBuilder results(ArrayNode dslResults) {
this.dslResults = dslResults; this.dslResults = dslResults;
return this; return this;
} }
public DSLJSONResponseBuilder results(String dslResults) throws JSONException { public DSLJSONResponseBuilder results(String dslResults) throws IOException {
return results(new JSONObject(dslResults)); return results(AtlasJson.parseToV1ArrayNode(dslResults));
} }
@Override @Override
public JSONObject build() throws JSONException { public ObjectNode build() {
Preconditions.checkNotNull(dslResults); Preconditions.checkNotNull(dslResults);
JSONArray rowsJsonArr = dslResults.getJSONArray(AtlasClient.ROWS); count(dslResults.size());
count(rowsJsonArr.length());
queryType(QUERY_TYPE_DSL); queryType(QUERY_TYPE_DSL);
JSONObject response = super.build(); ObjectNode response = super.build();
response.put(AtlasClient.RESULTS, rowsJsonArr); response.putPOJO(AtlasClient.RESULTS, dslResults);
response.put(AtlasClient.DATATYPE, dslResults.get(AtlasClient.DATATYPE)); response.put(AtlasClient.DATATYPE, dslResults.get(AtlasClient.DATATYPE));
return response; return response;
} }
...@@ -376,15 +372,15 @@ public class MetadataDiscoveryResource { ...@@ -376,15 +372,15 @@ public class MetadataDiscoveryResource {
private class FullTextJSonResponseBuilder extends JsonResponseBuilder { private class FullTextJSonResponseBuilder extends JsonResponseBuilder {
private JSONArray fullTextResults; private ArrayNode fullTextResults;
public FullTextJSonResponseBuilder results(JSONArray fullTextResults) { public FullTextJSonResponseBuilder results(ArrayNode fullTextResults) {
this.fullTextResults = fullTextResults; this.fullTextResults = fullTextResults;
return this; return this;
} }
public FullTextJSonResponseBuilder results(String dslResults) throws JSONException { public FullTextJSonResponseBuilder results(String dslResults) throws IOException {
return results(new JSONArray(dslResults)); return results(AtlasJson.parseToV1ArrayNode(dslResults));
} }
public FullTextJSonResponseBuilder() { public FullTextJSonResponseBuilder() {
...@@ -392,12 +388,12 @@ public class MetadataDiscoveryResource { ...@@ -392,12 +388,12 @@ public class MetadataDiscoveryResource {
} }
@Override @Override
public JSONObject build() throws JSONException { public ObjectNode build() {
Preconditions.checkNotNull(fullTextResults); Preconditions.checkNotNull(fullTextResults);
count(fullTextResults.length()); count(fullTextResults.size());
queryType(QUERY_TYPE_FULLTEXT); queryType(QUERY_TYPE_FULLTEXT);
JSONObject response = super.build(); ObjectNode response = super.build();
response.put(AtlasClient.RESULTS, fullTextResults); response.put(AtlasClient.RESULTS, fullTextResults);
return response; return response;
} }
......
...@@ -18,22 +18,21 @@ ...@@ -18,22 +18,21 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.core.ResourceContext; import com.sun.jersey.api.core.ResourceContext;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.v1.model.typedef.TypesDef; import org.apache.atlas.v1.model.typedef.TypesDef;
import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.repository.converters.TypeConverterUtil; import org.apache.atlas.repository.converters.TypeConverterUtil;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.rest.TypesREST; import org.apache.atlas.web.rest.TypesREST;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -102,7 +101,7 @@ public class TypesResource { ...@@ -102,7 +101,7 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
} }
JSONArray typesResponse = new JSONArray(); ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
try { try {
final String typeDefinition = Servlets.getRequestPayload(request); final String typeDefinition = Servlets.getRequestPayload(request);
...@@ -116,13 +115,12 @@ public class TypesResource { ...@@ -116,13 +115,12 @@ public class TypesResource {
List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef); List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef);
for (int i = 0; i < typeNames.size(); i++) { for (int i = 0; i < typeNames.size(); i++) {
final String name = typeNames.get(i); ObjectNode typeNode = AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
typesResponse.put(new JSONObject() {{
put(AtlasClient.NAME, name); typesResponse.add(typeNode);
}});
} }
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse); response.put(AtlasClient.TYPES, typesResponse);
return Response.status(ClientResponse.Status.CREATED).entity(response).build(); return Response.status(ClientResponse.Status.CREATED).entity(response).build();
...@@ -170,7 +168,7 @@ public class TypesResource { ...@@ -170,7 +168,7 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
} }
JSONArray typesResponse = new JSONArray(); ArrayNode typesResponse = AtlasJson.createV1ArrayNode();
try { try {
final String typeDefinition = Servlets.getRequestPayload(request); final String typeDefinition = Servlets.getRequestPayload(request);
...@@ -183,13 +181,12 @@ public class TypesResource { ...@@ -183,13 +181,12 @@ public class TypesResource {
List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef); List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
for (int i = 0; i < typeNames.size(); i++) { for (int i = 0; i < typeNames.size(); i++) {
final String name = typeNames.get(i); ObjectNode typeNode = AtlasJson.createV1ObjectNode(AtlasClient.NAME, typeNames.get(i));
typesResponse.put(new JSONObject() {{
put(AtlasClient.NAME, name); typesResponse.add(typeNode);
}});
} }
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse); response.put(AtlasClient.TYPES, typesResponse);
return Response.ok().entity(response).build(); return Response.ok().entity(response).build();
...@@ -233,21 +230,20 @@ public class TypesResource { ...@@ -233,21 +230,20 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
} }
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
try { try {
TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);; TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);;
String typeDefinition = AtlasType.toV1Json(typesDef);
response.put(AtlasClient.TYPENAME, typeName); response.put(AtlasClient.TYPENAME, typeName);
response.put(AtlasClient.DEFINITION, new JSONObject(typeDefinition)); response.putPOJO(AtlasClient.DEFINITION, typesDef);
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("Unable to get type definition for type {}", typeName, e); LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e)); throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (JSONException | IllegalArgumentException e) { } catch (IllegalArgumentException e) {
LOG.error("Unable to get type definition for type {}", typeName, e); LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) { } catch (WebApplicationException e) {
...@@ -292,11 +288,11 @@ public class TypesResource { ...@@ -292,11 +288,11 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")");
} }
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
try { try {
List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request)); List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
response.put(AtlasClient.RESULTS, new JSONArray(result)); response.putPOJO(AtlasClient.RESULTS, result);
response.put(AtlasClient.COUNT, result.size()); response.put(AtlasClient.COUNT, result.size());
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.web.util;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
@Provider
@Produces(MediaType.APPLICATION_JSON)
@Component
public class AtlasJsonProvider extends JacksonJaxbJsonProvider {
private static final Logger LOG = LoggerFactory.getLogger(AtlasJsonProvider.class);
private static final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
public AtlasJsonProvider() {
super(mapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
LOG.info("AtlasJsonProvider() instantiated");
}
}
...@@ -18,11 +18,13 @@ ...@@ -18,11 +18,13 @@
package org.apache.atlas.web.util; package org.apache.atlas.web.util;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration; import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.LocalServletRequest; import org.apache.atlas.LocalServletRequest;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
...@@ -30,8 +32,6 @@ import org.apache.commons.lang3.StringEscapeUtils; ...@@ -30,8 +32,6 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.client.utils.URLEncodedUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -153,15 +153,10 @@ public final class Servlets { ...@@ -153,15 +153,10 @@ public final class Servlets {
} }
public static Response getErrorResponse(String message, Response.Status status) { public static Response getErrorResponse(String message, Response.Status status) {
JSONObject errorJson = new JSONObject(); Object errorEntity = escapeJsonString(message);
Object errorEntity = escapeJsonString(message); ObjectNode errorJson = AtlasJson.createV1ObjectNode(AtlasClient.ERROR, errorEntity);
try {
errorJson.put(AtlasClient.ERROR, errorEntity); return Response.status(status).entity(errorJson).type(JSON_MEDIA_TYPE).build();
errorEntity = errorJson;
} catch (JSONException jsonE) {
LOG.warn("Could not construct error Json rensponse", jsonE);
}
return Response.status(status).entity(errorEntity).type(JSON_MEDIA_TYPE).build();
} }
public static String getRequestPayload(HttpServletRequest request) throws IOException { public static String getRequestPayload(HttpServletRequest request) throws IOException {
......
...@@ -18,14 +18,13 @@ ...@@ -18,14 +18,13 @@
package org.apache.atlas.examples; package org.apache.atlas.examples;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.v1.model.instance.Id; import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable; import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.web.integration.BaseResourceIT; import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -51,12 +50,12 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -51,12 +50,12 @@ public class QuickStartIT extends BaseResourceIT {
assertEquals(QuickStart.SALES_DB_DESCRIPTION, db.get("description")); assertEquals(QuickStart.SALES_DB_DESCRIPTION, db.get("description"));
} }
private Referenceable getDB(String dbName) throws AtlasServiceException, JSONException { private Referenceable getDB(String dbName) throws AtlasServiceException {
return atlasClientV1.getEntity(QuickStart.DATABASE_TYPE, "name", dbName); return atlasClientV1.getEntity(QuickStart.DATABASE_TYPE, "name", dbName);
} }
@Test @Test
public void testTablesAreAdded() throws AtlasServiceException, JSONException { public void testTablesAreAdded() throws AtlasServiceException {
Referenceable table = getTable(QuickStart.SALES_FACT_TABLE); Referenceable table = getTable(QuickStart.SALES_FACT_TABLE);
verifySimpleTableAttributes(table); verifySimpleTableAttributes(table);
...@@ -71,11 +70,11 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -71,11 +70,11 @@ public class QuickStartIT extends BaseResourceIT {
return atlasClientV1.getEntity(QuickStart.TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName); return atlasClientV1.getEntity(QuickStart.TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
} }
private void verifyTrait(Referenceable table) throws JSONException { private void verifyTrait(Referenceable table) {
assertNotNull(table.getTrait(QuickStart.FACT_TRAIT)); assertNotNull(table.getTrait(QuickStart.FACT_TRAIT));
} }
private void verifyColumnsAreAddedToTable(Referenceable table) throws JSONException { private void verifyColumnsAreAddedToTable(Referenceable table) {
List<Referenceable> columns = (List<Referenceable>) table.get(QuickStart.COLUMNS_ATTRIBUTE); List<Referenceable> columns = (List<Referenceable>) table.get(QuickStart.COLUMNS_ATTRIBUTE);
assertEquals(4, columns.size()); assertEquals(4, columns.size());
Referenceable column = columns.get(0); Referenceable column = columns.get(0);
...@@ -83,18 +82,18 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -83,18 +82,18 @@ public class QuickStartIT extends BaseResourceIT {
assertEquals("int", column.get("dataType")); assertEquals("int", column.get("dataType"));
} }
private void verifyDBIsLinkedToTable(Referenceable table) throws AtlasServiceException, JSONException { private void verifyDBIsLinkedToTable(Referenceable table) throws AtlasServiceException {
Referenceable db = getDB(QuickStart.SALES_DB); Referenceable db = getDB(QuickStart.SALES_DB);
assertEquals(db.getId(), table.get(QuickStart.DB_ATTRIBUTE)); assertEquals(db.getId(), table.get(QuickStart.DB_ATTRIBUTE));
} }
private void verifySimpleTableAttributes(Referenceable table) throws JSONException { private void verifySimpleTableAttributes(Referenceable table) {
assertEquals(QuickStart.SALES_FACT_TABLE, table.get("name")); assertEquals(QuickStart.SALES_FACT_TABLE, table.get("name"));
assertEquals(QuickStart.SALES_FACT_TABLE_DESCRIPTION, table.get("description")); assertEquals(QuickStart.SALES_FACT_TABLE_DESCRIPTION, table.get("description"));
} }
@Test @Test
public void testProcessIsAdded() throws AtlasServiceException, JSONException { public void testProcessIsAdded() throws AtlasServiceException {
Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
QuickStart.LOAD_SALES_DAILY_PROCESS); QuickStart.LOAD_SALES_DAILY_PROCESS);
...@@ -118,29 +117,29 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -118,29 +117,29 @@ public class QuickStartIT extends BaseResourceIT {
} }
@Test @Test
public void testLineageIsMaintained() throws AtlasServiceException, JSONException { public void testLineageIsMaintained() throws AtlasServiceException {
String salesFactTableId = getTableId(QuickStart.SALES_FACT_TABLE); String salesFactTableId = getTableId(QuickStart.SALES_FACT_TABLE);
String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE); String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE); String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE);
JSONObject inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE); ObjectNode inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE);
JSONObject vertices = (JSONObject) ((JSONObject) inputGraph.get("values")).get("vertices"); ArrayNode vertices = (ArrayNode) inputGraph.get("values").get("vertices");
JSONObject edges = (JSONObject) ((JSONObject) inputGraph.get("values")).get("edges"); ArrayNode edges = (ArrayNode) inputGraph.get("values").get("edges");
assertTrue(vertices.has(salesFactTableId)); assertTrue(vertices.has(salesFactTableId));
assertTrue(vertices.has(timeDimTableId)); assertTrue(vertices.has(timeDimTableId));
assertTrue(vertices.has(salesFactDailyMVId)); assertTrue(vertices.has(salesFactDailyMVId));
assertTrue(edges.has(salesFactDailyMVId)); assertTrue(edges.has(salesFactDailyMVId));
JSONArray inputs = (JSONArray)edges.get((String) ((JSONArray) edges.get(salesFactDailyMVId)).get(0)); ArrayNode inputs = (ArrayNode)edges.get((edges.get(salesFactDailyMVId)).get(0).asText());
String i1 = inputs.getString(0); String i1 = inputs.get(0).asText();
String i2 = inputs.getString(1); String i2 = inputs.get(1).asText();
assertTrue(salesFactTableId.equals(i1) || salesFactTableId.equals(i2)); assertTrue(salesFactTableId.equals(i1) || salesFactTableId.equals(i2));
assertTrue(timeDimTableId.equals(i1) || timeDimTableId.equals(i2)); assertTrue(timeDimTableId.equals(i1) || timeDimTableId.equals(i2));
} }
@Test @Test
public void testViewIsAdded() throws AtlasServiceException, JSONException { public void testViewIsAdded() throws AtlasServiceException {
Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW); Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW);
......
...@@ -27,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo; ...@@ -27,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection; import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation; import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.web.integration.BaseResourceIT; import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONException;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -57,7 +56,7 @@ public class QuickStartV2IT extends BaseResourceIT { ...@@ -57,7 +56,7 @@ public class QuickStartV2IT extends BaseResourceIT {
assertEquals("sales database", dbAttributes.get("description")); assertEquals("sales database", dbAttributes.get("description"));
} }
private AtlasEntity getDB(String dbName) throws AtlasServiceException, JSONException { private AtlasEntity getDB(String dbName) throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
attributes.put("name", dbName); attributes.put("name", dbName);
AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity(); AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity();
...@@ -65,7 +64,7 @@ public class QuickStartV2IT extends BaseResourceIT { ...@@ -65,7 +64,7 @@ public class QuickStartV2IT extends BaseResourceIT {
} }
@Test @Test
public void testTablesAreAdded() throws AtlasServiceException, JSONException { public void testTablesAreAdded() throws AtlasServiceException {
AtlasEntity table = getTable(QuickStart.SALES_FACT_TABLE); AtlasEntity table = getTable(QuickStart.SALES_FACT_TABLE);
verifySimpleTableAttributes(table); verifySimpleTableAttributes(table);
...@@ -97,7 +96,7 @@ public class QuickStartV2IT extends BaseResourceIT { ...@@ -97,7 +96,7 @@ public class QuickStartV2IT extends BaseResourceIT {
assertNotNull(traits.get(0).getTypeName()); assertNotNull(traits.get(0).getTypeName());
} }
private void verifyColumnsAreAddedToTable(AtlasEntity table) throws JSONException { private void verifyColumnsAreAddedToTable(AtlasEntity table) {
Map<String, Object> tableAttributes = table.getAttributes(); Map<String, Object> tableAttributes = table.getAttributes();
List<Map> columns = (List<Map>) tableAttributes.get("columns"); List<Map> columns = (List<Map>) tableAttributes.get("columns");
assertEquals(4, columns.size()); assertEquals(4, columns.size());
...@@ -108,21 +107,21 @@ public class QuickStartV2IT extends BaseResourceIT { ...@@ -108,21 +107,21 @@ public class QuickStartV2IT extends BaseResourceIT {
} }
} }
private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException, JSONException { private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException {
AtlasEntity db = getDB(QuickStartV2.SALES_DB); AtlasEntity db = getDB(QuickStartV2.SALES_DB);
Map<String, Object> tableAttributes = table.getAttributes(); Map<String, Object> tableAttributes = table.getAttributes();
Map dbFromTable = (Map) tableAttributes.get("db"); Map dbFromTable = (Map) tableAttributes.get("db");
assertEquals(db.getGuid(), dbFromTable.get("guid")); assertEquals(db.getGuid(), dbFromTable.get("guid"));
} }
private void verifySimpleTableAttributes(AtlasEntity table) throws JSONException { private void verifySimpleTableAttributes(AtlasEntity table) {
Map<String, Object> tableAttributes = table.getAttributes(); Map<String, Object> tableAttributes = table.getAttributes();
assertEquals(QuickStartV2.SALES_FACT_TABLE, tableAttributes.get("name")); assertEquals(QuickStartV2.SALES_FACT_TABLE, tableAttributes.get("name"));
assertEquals("sales fact table", tableAttributes.get("description")); assertEquals("sales fact table", tableAttributes.get("description"));
} }
@Test @Test
public void testProcessIsAdded() throws AtlasServiceException, JSONException { public void testProcessIsAdded() throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.LOAD_SALES_DAILY_PROCESS); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.LOAD_SALES_DAILY_PROCESS);
AtlasEntity loadProcess = atlasClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity(); AtlasEntity loadProcess = atlasClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity();
...@@ -153,7 +152,7 @@ public class QuickStartV2IT extends BaseResourceIT { ...@@ -153,7 +152,7 @@ public class QuickStartV2IT extends BaseResourceIT {
} }
@Test @Test
public void testLineageIsMaintained() throws AtlasServiceException, JSONException { public void testLineageIsMaintained() throws AtlasServiceException {
String salesFactTableId = getTableId(QuickStartV2.SALES_FACT_TABLE); String salesFactTableId = getTableId(QuickStartV2.SALES_FACT_TABLE);
String timeDimTableId = getTableId(QuickStartV2.TIME_DIM_TABLE); String timeDimTableId = getTableId(QuickStartV2.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStartV2.SALES_FACT_DAILY_MV_TABLE); String salesFactDailyMVId = getTableId(QuickStartV2.SALES_FACT_DAILY_MV_TABLE);
...@@ -177,7 +176,7 @@ public class QuickStartV2IT extends BaseResourceIT { ...@@ -177,7 +176,7 @@ public class QuickStartV2IT extends BaseResourceIT {
} }
@Test @Test
public void testViewIsAdded() throws AtlasServiceException, JSONException { public void testViewIsAdded() throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.PRODUCT_DIM_VIEW); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.PRODUCT_DIM_VIEW);
AtlasEntity view = atlasClientV2.getEntityByAttribute(QuickStartV2.VIEW_TYPE, attributes).getEntity(); AtlasEntity view = atlasClientV2.getEntityByAttribute(QuickStartV2.VIEW_TYPE, attributes).getEntity();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.notification; package org.apache.atlas.notification;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.model.notification.HookNotification; import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.v1.model.instance.Id; import org.apache.atlas.v1.model.instance.Id;
...@@ -27,7 +28,6 @@ import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUp ...@@ -27,7 +28,6 @@ import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityPartialUp
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest; import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest;
import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest; import org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest;
import org.apache.atlas.web.integration.BaseResourceIT; import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONArray;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -84,9 +84,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -84,9 +84,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME))); ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_BUILTIN, entity.get(NAME)));
return results.length() == 1; return results.size() == 1;
} }
}); });
} }
...@@ -106,9 +106,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -106,9 +106,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME))); ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, entity.get(QUALIFIED_NAME)));
return results.length() == 1; return results.size() == 1;
} }
}); });
...@@ -175,16 +175,16 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -175,16 +175,16 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newName)); ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newName));
return results.length() == 1; return results.size() == 1;
} }
}); });
//no entity with the old qualified name //no entity with the old qualified name
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName)); ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
assertEquals(results.length(), 0); assertEquals(results.size(), 0);
} }
@Test @Test
...@@ -237,9 +237,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT { ...@@ -237,9 +237,9 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
waitFor(MAX_WAIT_TIME, new Predicate() { waitFor(MAX_WAIT_TIME, new Predicate() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME))); ArrayNode results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, newEntity.get(QUALIFIED_NAME)));
return results.length() == 1; return results.size() == 1;
} }
}); });
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.PropertiesConfiguration;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -37,13 +37,13 @@ public class AdminJerseyResourceIT extends BaseResourceIT { ...@@ -37,13 +37,13 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetVersion() throws Exception { public void testGetVersion() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null);
Assert.assertNotNull(response); Assert.assertNotNull(response);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties"); PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version")); Assert.assertEquals(response.get("Version").asText(), buildConfiguration.getString("build.version"));
Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name")); Assert.assertEquals(response.get("Name").asText(), buildConfiguration.getString("project.name"));
Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description")); Assert.assertEquals(response.get("Description").asText(), buildConfiguration.getString("project.description"));
} }
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -50,7 +51,6 @@ import org.apache.atlas.utils.AuthenticationUtil; ...@@ -50,7 +51,6 @@ import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
...@@ -678,7 +678,7 @@ public abstract class BaseResourceIT { ...@@ -678,7 +678,7 @@ public abstract class BaseResourceIT {
}; };
} }
protected JSONArray searchByDSL(String dslQuery) throws AtlasServiceException { protected ArrayNode searchByDSL(String dslQuery) throws AtlasServiceException {
return atlasClientV1.searchByDSL(dslQuery, 10, 0); return atlasClientV1.searchByDSL(dslQuery, 10, 0);
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.v1.model.instance.Id; import org.apache.atlas.v1.model.instance.Id;
...@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.instance.Struct; ...@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition; import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -64,14 +64,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -64,14 +64,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testInputsGraph() throws Exception { public void testInputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId(); String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph"); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph");
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("inputs graph = " + response); System.out.println("inputs graph = " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS); JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results); Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class); Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
...@@ -86,7 +86,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -86,7 +86,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
public void testInputsGraphForEntity() throws Exception { public void testInputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
salesMonthlyTable).getId()._getId(); salesMonthlyTable).getId()._getId();
JSONObject results = atlasClientV1.getInputGraphForEntity(tableId); ObjectNode results = atlasClientV1.getInputGraphForEntity(tableId);
Assert.assertNotNull(results); Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class); Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
...@@ -113,14 +113,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -113,14 +113,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testOutputsGraph() throws Exception { public void testOutputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph"); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("outputs graph= " + response); System.out.println("outputs graph= " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS); JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results); Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class); Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
...@@ -134,7 +134,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -134,7 +134,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testOutputsGraphForEntity() throws Exception { public void testOutputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId); ObjectNode results = atlasClientV1.getOutputGraphForEntity(tableId);
Assert.assertNotNull(results); Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class); Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
...@@ -159,23 +159,23 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -159,23 +159,23 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSchema() throws Exception { public void testSchema() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject response = atlasClientV1.getSchemaForEntity(tableId); ObjectNode response = atlasClientV1.getSchemaForEntity(tableId);
} }
@Test @Test
public void testSchemaForEntity() throws Exception { public void testSchemaForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject results = atlasClientV1.getSchemaForEntity(tableId); ObjectNode results = atlasClientV1.getSchemaForEntity(tableId);
} }
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForInvalidTable() throws Exception { public void testSchemaForInvalidTable() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema"); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
} }
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForDB() throws Exception { public void testSchemaForDB() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema"); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
} }
private void setupInstances() throws Exception { private void setupInstances() throws Exception {
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl; import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -35,8 +37,6 @@ import org.apache.atlas.type.AtlasType; ...@@ -35,8 +37,6 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -173,7 +173,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -173,7 +173,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("parameters", Collections.EMPTY_MAP); databaseInstance.set("parameters", Collections.EMPTY_MAP);
databaseInstance.set("location", "/tmp"); databaseInstance.set("location", "/tmp");
JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance)); ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance));
assertNotNull(response); assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
...@@ -322,7 +322,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -322,7 +322,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String description = "bar table - new desc"; String description = "bar table - new desc";
addProperty(guid, "description", description); addProperty(guid, "description", description);
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response); Assert.assertNotNull(response);
referenceable.set("description", description); referenceable.set("description", description);
...@@ -460,7 +460,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -460,7 +460,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testGetInvalidEntityDefinition() throws Exception { public void testGetInvalidEntityDefinition() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah"); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah");
Assert.assertNotNull(response); Assert.assertNotNull(response);
...@@ -493,7 +493,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -493,7 +493,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", "blah"); queryParams.add("type", "blah");
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response); assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.ERROR));
} }
...@@ -506,12 +506,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -506,12 +506,12 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", typeName); queryParams.add("type", typeName);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response); assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertEquals(list.length(), 0); Assert.assertEquals(list.size(), 0);
} }
private String addNewType() throws Exception { private String addNewType() throws Exception {
...@@ -827,8 +827,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -827,8 +827,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
instance.set(attrName, attrValue); instance.set(attrName, attrValue);
Id guid = createInstance(instance); Id guid = createInstance(instance);
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId()); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
Referenceable getReferenceable = AtlasType.fromV1Json(response.getString(AtlasClient.DEFINITION), Referenceable.class); Referenceable getReferenceable = AtlasType.fromV1Json(response.get(AtlasClient.DEFINITION).asText(), Referenceable.class);
Assert.assertEquals(getReferenceable.get(attrName), attrValue); Assert.assertEquals(getReferenceable.get(attrName), attrValue);
} }
...@@ -1026,7 +1026,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -1026,7 +1026,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId()); queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId()); queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams);
List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities(); List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities();
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.core.util.MultivaluedMapImpl; import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasBaseClient; import org.apache.atlas.AtlasBaseClient;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -26,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo; ...@@ -26,7 +27,6 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.v1.model.instance.Id; import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable; import org.apache.atlas.v1.model.instance.Referenceable;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -67,7 +67,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -67,7 +67,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION); queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5"); queryParams.add(DEPTH_PARAM, "5");
JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId); ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("input lineage info = " + response System.out.println("input lineage info = " + response
); );
...@@ -95,7 +95,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -95,7 +95,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION); queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5"); queryParams.add(DEPTH_PARAM, "5");
JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId); ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("output lineage info = " + response); System.out.println("output lineage info = " + response);
...@@ -123,7 +123,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -123,7 +123,7 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION); queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
queryParams.add(DEPTH_PARAM, "5"); queryParams.add(DEPTH_PARAM, "5");
JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId); ObjectNode response = atlasClientV1.callAPI(LINEAGE_V2_API, ObjectNode.class, queryParams, tableId);
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("both lineage info = " + response); System.out.println("both lineage info = " + response);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -37,7 +38,6 @@ import org.apache.atlas.model.typedef.AtlasTypesDef; ...@@ -37,7 +38,6 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -147,13 +147,13 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT { ...@@ -147,13 +147,13 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testEntityDeduping() throws Exception { public void testEntityDeduping() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME)); ArrayNode results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
final AtlasEntity hiveDBInstanceV2 = createHiveDB(); final AtlasEntity hiveDBInstanceV2 = createHiveDB();
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME)); results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//Test the same across references //Test the same across references
final String tableName = randomString(); final String tableName = randomString();
...@@ -164,7 +164,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT { ...@@ -164,7 +164,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
assertNotNull(entity); assertNotNull(entity);
assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE)); assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME)); results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
} }
private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction) private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl; import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -28,8 +31,6 @@ import org.apache.atlas.v1.model.instance.Referenceable; ...@@ -28,8 +31,6 @@ import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.v1.model.instance.Struct; import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.*; import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -64,19 +65,19 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -64,19 +65,19 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\""; String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery); queryParams.add("query", dslQuery);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), dslQuery); assertEquals(response.get("query").asText(), dslQuery);
assertEquals(response.getString("queryType"), "dsl"); assertEquals(response.get("queryType").asText(), "dsl");
JSONArray results = response.getJSONArray(AtlasClient.RESULTS); ArrayNode results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertNotNull(results); assertNotNull(results);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
int numRows = response.getInt(AtlasClient.COUNT); int numRows = response.get(AtlasClient.COUNT).asInt();
assertEquals(numRows, 1); assertEquals(numRows, 1);
} }
...@@ -88,24 +89,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -88,24 +89,24 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\""; String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery); queryParams.add("query", dslQuery);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
assertNotNull(response); assertNotNull(response);
//higher limit, all results returned //higher limit, all results returned
JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0); ArrayNode results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//default limit and offset -1, all results returned //default limit and offset -1, all results returned
results = atlasClientV1.searchByDSL(dslQuery, -1, -1); results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//uses the limit parameter passed //uses the limit parameter passed
results = atlasClientV1.searchByDSL(dslQuery, 1, 0); results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//uses the offset parameter passed //uses the offset parameter passed
results = atlasClientV1.searchByDSL(dslQuery, 10, 1); results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
assertEquals(results.length(), 0); assertEquals(results.size(), 0);
//limit > 0 //limit > 0
try { try {
...@@ -146,13 +147,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -146,13 +147,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query); queryParams.add("query", query);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams);
assertNotNull(response); assertNotNull(response);
assertNotNull(response.get(AtlasClient.REQUEST_ID)); assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query); assertEquals(response.get("query").asText(), query);
assertEquals(response.getString("queryType"), "gremlin"); assertEquals(response.get("queryType").asText(), "gremlin");
} }
// Disabling DSL tests // Disabling DSL tests
...@@ -162,13 +163,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -162,13 +163,13 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "from "+ DATABASE_TYPE + " name=\"" + dbName +"\""; String query = "from "+ DATABASE_TYPE + " name=\"" + dbName +"\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query); queryParams.add("query", query);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query); assertEquals(response.get("query").asText(), query);
assertEquals(response.getString("queryType"), "dsl"); assertEquals(response.get("queryType").asText(), "dsl");
} }
// Disabling DSL tests // Disabling DSL tests
...@@ -177,32 +178,32 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -177,32 +178,32 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "*"; String query = "*";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query); queryParams.add("query", query);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), query); assertEquals(response.get("query").asText(), query);
assertEquals(response.getString("queryType"), "full-text"); assertEquals(response.get("queryType").asText(), "full-text");
} }
@Test(enabled = false, dependsOnMethods = "testSearchDSLLimits") @Test(enabled = false, dependsOnMethods = "testSearchDSLLimits")
public void testSearchUsingFullText() throws Exception { public void testSearchUsingFullText() throws Exception {
JSONObject response = atlasClientV1.searchByFullText(dbName, 10, 0); ObjectNode response = atlasClientV1.searchByFullText(dbName, 10, 0);
assertNotNull(response.get(AtlasClient.REQUEST_ID)); assertNotNull(response.get(AtlasClient.REQUEST_ID));
assertEquals(response.getString("query"), dbName); assertEquals(response.get("query").asText(), dbName);
assertEquals(response.getString("queryType"), "full-text"); assertEquals(response.get("queryType").asText(), "full-text");
JSONArray results = response.getJSONArray(AtlasClient.RESULTS); ArrayNode results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertEquals(results.length(), 1, "Results: " + results); assertEquals(results.size(), 1, "Results: " + results);
JSONObject row = results.getJSONObject(0); JsonNode row = results.get(0);
assertNotNull(row.get("guid")); assertNotNull(row.get("guid"));
assertEquals(row.getString("typeName"), DATABASE_TYPE); assertEquals(row.get("typeName").asText(), DATABASE_TYPE);
assertNotNull(row.get("score")); assertNotNull(row.get("score"));
int numRows = response.getInt(AtlasClient.COUNT); int numRows = response.get(AtlasClient.COUNT).asInt();
assertEquals(numRows, 1); assertEquals(numRows, 1);
//API works without limit and offset //API works without limit and offset
...@@ -210,25 +211,25 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -210,25 +211,25 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query); queryParams.add("query", query);
response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_FULL_TEXT, queryParams); response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_FULL_TEXT, queryParams);
results = response.getJSONArray(AtlasClient.RESULTS); results = (ArrayNode) response.get(AtlasClient.RESULTS);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//verify passed in limits and offsets are used //verify passed in limits and offsets are used
//higher limit and 0 offset returns all results //higher limit and 0 offset returns all results
results = atlasClientV1.searchByFullText(query, 10, 0).getJSONArray(AtlasClient.RESULTS); results = (ArrayNode) atlasClientV1.searchByFullText(query, 10, 0).get(AtlasClient.RESULTS);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//offset is used //offset is used
results = atlasClientV1.searchByFullText(query, 10, 1).getJSONArray(AtlasClient.RESULTS); results = (ArrayNode) atlasClientV1.searchByFullText(query, 10, 1).get(AtlasClient.RESULTS);
assertEquals(results.length(), 0); assertEquals(results.size(), 0);
//limit is used //limit is used
results = atlasClientV1.searchByFullText(query, 1, 0).getJSONArray(AtlasClient.RESULTS); results = (ArrayNode) atlasClientV1.searchByFullText(query, 1, 0).get(AtlasClient.RESULTS);
assertEquals(results.length(), 1); assertEquals(results.size(), 1);
//higher offset returns 0 results //higher offset returns 0 results
results = atlasClientV1.searchByFullText(query, 1, 2).getJSONArray(AtlasClient.RESULTS); results = (ArrayNode) atlasClientV1.searchByFullText(query, 1, 2).get(AtlasClient.RESULTS);
assertEquals(results.length(), 0); assertEquals(results.size(), 0);
} }
private void createTypes() throws Exception { private void createTypes() throws Exception {
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.web.integration; package org.apache.atlas.web.integration;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.core.util.MultivaluedMapImpl; import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
...@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.typedef.*; ...@@ -26,8 +28,6 @@ import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
...@@ -81,13 +81,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -81,13 +81,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
System.out.println("typesAsJSON = " + typesAsJSON); System.out.println("typesAsJSON = " + typesAsJSON);
JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON); ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON);
Assert.assertNotNull(response); Assert.assertNotNull(response);
JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES); ArrayNode typesAdded = (ArrayNode) response.get(AtlasClient.TYPES);
assertEquals(typesAdded.length(), 1); assertEquals(typesAdded.size(), 1);
assertEquals(typesAdded.getJSONObject(0).getString(NAME), typeDefinition.getTypeName()); assertEquals(typesAdded.get(0).get(NAME).asText(), typeDefinition.getTypeName());
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));} Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
} }
} }
...@@ -143,13 +143,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -143,13 +143,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
System.out.println("typeName = " + typeDefinition.getTypeName()); System.out.println("typeName = " + typeDefinition.getTypeName());
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.getTypeName()); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.getTypeName());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.DEFINITION)); Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
TypesDef typesDef = AtlasType.fromV1Json(response.getString(AtlasClient.DEFINITION), TypesDef.class); TypesDef typesDef = AtlasType.fromV1Json(response.get(AtlasClient.DEFINITION).asText(), TypesDef.class);
List<? extends HierarchicalTypeDefinition> hierarchicalTypeDefs = Collections.emptyList(); List<? extends HierarchicalTypeDefinition> hierarchicalTypeDefs = Collections.emptyList();
...@@ -172,21 +172,21 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -172,21 +172,21 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testGetDefinitionForNonexistentType() throws Exception { public void testGetDefinitionForNonexistentType() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah"); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah");
} }
@Test(dependsOnMethods = "testSubmit") @Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception { public void testGetTypeNames() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertNotNull(list); Assert.assertNotNull(list);
//Verify that primitive and core types are not returned //Verify that primitive and core types are not returned
String typesString = list.join(" "); String typesString = list.toString();
Assert.assertFalse(typesString.contains(" \"__IdType\" ")); Assert.assertFalse(typesString.contains(" \"__IdType\" "));
Assert.assertFalse(typesString.contains(" \"string\" ")); Assert.assertFalse(typesString.contains(" \"string\" "));
} }
...@@ -198,14 +198,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -198,14 +198,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", DataTypes.TypeCategory.TRAIT.name()); queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams); ObjectNode response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); final ArrayNode list = (ArrayNode) response.get(AtlasClient.RESULTS);
Assert.assertNotNull(list); Assert.assertNotNull(list);
Assert.assertTrue(list.length() >= traitsAdded.length); Assert.assertTrue(list.size() >= traitsAdded.length);
} }
@Test @Test
......
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.web.service.ServiceState; import org.apache.atlas.web.service.ServiceState;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
...@@ -44,27 +43,27 @@ public class AdminResourceTest { ...@@ -44,27 +43,27 @@ public class AdminResourceTest {
} }
@Test @Test
public void testStatusOfActiveServerIsReturned() throws JSONException { public void testStatusOfActiveServerIsReturned() {
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);
JSONObject entity = (JSONObject) response.getEntity(); ObjectNode entity = (ObjectNode) response.getEntity();
assertEquals(entity.get("Status"), "ACTIVE"); assertEquals(entity.get("Status").asText(), "ACTIVE");
} }
@Test @Test
public void testResourceGetsValueFromServiceState() throws JSONException { public void testResourceGetsValueFromServiceState() {
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();
JSONObject entity = (JSONObject) response.getEntity(); ObjectNode entity = (ObjectNode) response.getEntity();
assertEquals(entity.get("Status"), "PASSIVE"); assertEquals(entity.get("Status").asText(), "PASSIVE");
} }
} }
\ No newline at end of file
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
package org.apache.atlas.web.util; package org.apache.atlas.web.util;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.codehaus.jettison.json.JSONObject;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
...@@ -33,8 +33,8 @@ public class ServletsTest { ...@@ -33,8 +33,8 @@ public class ServletsTest {
Response response = Response response =
Servlets.getErrorResponse(new NullPointerException(), Response.Status.INTERNAL_SERVER_ERROR); Servlets.getErrorResponse(new NullPointerException(), Response.Status.INTERNAL_SERVER_ERROR);
assertNotNull(response); assertNotNull(response);
JSONObject responseEntity = (JSONObject) response.getEntity(); ObjectNode responseEntity = (ObjectNode) response.getEntity();
assertNotNull(responseEntity); assertNotNull(responseEntity);
assertNotNull(responseEntity.getString(AtlasClient.ERROR)); assertNotNull(responseEntity.get(AtlasClient.ERROR));
} }
} }
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