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;
} }
} }
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas; package org.apache.atlas;
import com.fasterxml.jackson.databind.node.ArrayNode;
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.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.model.legacy.EntityResult; import org.apache.atlas.model.legacy.EntityResult;
...@@ -27,14 +29,12 @@ import org.apache.atlas.v1.model.typedef.AttributeDefinition; ...@@ -27,14 +29,12 @@ import org.apache.atlas.v1.model.typedef.AttributeDefinition;
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition; import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
import org.apache.atlas.v1.model.typedef.TypesDef; import org.apache.atlas.v1.model.typedef.TypesDef;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AtlasJson;
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.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.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;
...@@ -42,6 +42,7 @@ import javax.ws.rs.HttpMethod; ...@@ -42,6 +42,7 @@ import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Cookie; import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.*; import java.util.*;
/** /**
...@@ -252,11 +253,11 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -252,11 +253,11 @@ public class AtlasClient extends AtlasBaseClient {
*/ */
public List<String> createType(String typeAsJson) throws AtlasServiceException { public List<String> createType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Creating type definition: {}", typeAsJson); LOG.debug("Creating type definition: {}", typeAsJson);
JSONObject response = callAPIWithBody(API_V1.CREATE_TYPE, typeAsJson); ObjectNode response = callAPIWithBody(API_V1.CREATE_TYPE, typeAsJson);
List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() { List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, ObjectNode>() {
@Override @Override
String extractElement(JSONObject element) throws JSONException { String extractElement(ObjectNode element) {
return element.getString(AtlasClient.NAME); return element.get(AtlasClient.NAME).asText();
} }
}); });
LOG.debug("Create type definition returned results: {}", results); LOG.debug("Create type definition returned results: {}", results);
...@@ -309,11 +310,11 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -309,11 +310,11 @@ public class AtlasClient extends AtlasBaseClient {
*/ */
public List<String> updateType(String typeAsJson) throws AtlasServiceException { public List<String> updateType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Updating type definition: {}", typeAsJson); LOG.debug("Updating type definition: {}", typeAsJson);
JSONObject response = callAPIWithBody(API_V1.UPDATE_TYPE, typeAsJson); ObjectNode response = callAPIWithBody(API_V1.UPDATE_TYPE, typeAsJson);
List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() { List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, ObjectNode>() {
@Override @Override
String extractElement(JSONObject element) throws JSONException { String extractElement(ObjectNode element) {
return element.getString(AtlasClient.NAME); return element.get(AtlasClient.NAME).asText();
} }
}); });
LOG.debug("Update type definition returned results: {}", results); LOG.debug("Update type definition returned results: {}", results);
...@@ -336,7 +337,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -336,7 +337,7 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public List<String> listTypes() throws AtlasServiceException { public List<String> listTypes() throws AtlasServiceException {
final JSONObject jsonObject = callAPIWithQueryParams(API_V1.LIST_TYPES, null); final ObjectNode jsonObject = callAPIWithQueryParams(API_V1.LIST_TYPES, null);
return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation<String, String>()); return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation<String, String>());
} }
...@@ -348,7 +349,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -348,7 +349,7 @@ public class AtlasClient extends AtlasBaseClient {
*/ */
public List<String> listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException { public List<String> listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException {
final API api = API_V1.LIST_TYPES; final API api = API_V1.LIST_TYPES;
JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api.getNormalizedPath()); WebResource resource = getResource(api.getNormalizedPath());
...@@ -374,7 +375,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -374,7 +375,7 @@ public class AtlasClient extends AtlasBaseClient {
public List<String> listTypes(final DataTypes.TypeCategory category, final String superType, public List<String> listTypes(final DataTypes.TypeCategory category, final String superType,
final String notSupertype) throws AtlasServiceException { final String notSupertype) throws AtlasServiceException {
final API api = API_V1.LIST_TYPES; final API api = API_V1.LIST_TYPES;
JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api); WebResource resource = getResource(api);
...@@ -388,13 +389,9 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -388,13 +389,9 @@ public class AtlasClient extends AtlasBaseClient {
} }
public TypesDef getType(String typeName) throws AtlasServiceException { public TypesDef getType(String typeName) throws AtlasServiceException {
try { ObjectNode response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName);
JSONObject response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName); String typeJson = response.get(DEFINITION).asText();
String typeJson = response.getString(DEFINITION); return AtlasType.fromV1Json(typeJson, TypesDef.class);
return AtlasType.fromV1Json(typeJson, TypesDef.class);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
/** /**
...@@ -403,15 +400,15 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -403,15 +400,15 @@ public class AtlasClient extends AtlasBaseClient {
* @return json array of guids * @return json array of guids
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
protected List<String> createEntity(JSONArray entities) throws AtlasServiceException { protected List<String> createEntity(ArrayNode entities) throws AtlasServiceException {
LOG.debug("Creating entities: {}", entities); LOG.debug("Creating entities: {}", entities);
JSONObject response = callAPIWithBody(API_V1.CREATE_ENTITY, entities.toString()); ObjectNode response = callAPIWithBody(API_V1.CREATE_ENTITY, entities.toString());
List<String> results = extractEntityResult(response).getCreatedEntities(); List<String> results = extractEntityResult(response).getCreatedEntities();
LOG.debug("Create entities returned results: {}", results); LOG.debug("Create entities returned results: {}", results);
return results; return results;
} }
protected EntityResult extractEntityResult(JSONObject response) throws AtlasServiceException { protected EntityResult extractEntityResult(ObjectNode response) throws AtlasServiceException {
return EntityResult.fromString(response.toString()); return EntityResult.fromString(response.toString());
} }
...@@ -422,7 +419,11 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -422,7 +419,11 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public List<String> createEntity(String... entitiesAsJson) throws AtlasServiceException { public List<String> createEntity(String... entitiesAsJson) throws AtlasServiceException {
return createEntity(new JSONArray(Arrays.asList(entitiesAsJson))); try {
return createEntity(AtlasJson.parseToV1ArrayNode(Arrays.asList(entitiesAsJson)));
} catch (IOException excp) {
throw new AtlasServiceException(excp);
}
} }
public List<String> createEntity(Referenceable... entities) throws AtlasServiceException { public List<String> createEntity(Referenceable... entities) throws AtlasServiceException {
...@@ -430,14 +431,14 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -430,14 +431,14 @@ public class AtlasClient extends AtlasBaseClient {
} }
public List<String> createEntity(Collection<Referenceable> entities) throws AtlasServiceException { public List<String> createEntity(Collection<Referenceable> entities) throws AtlasServiceException {
JSONArray entityArray = getEntitiesArray(entities); ArrayNode entityArray = getEntitiesArray(entities);
return createEntity(entityArray); return createEntity(entityArray);
} }
private JSONArray getEntitiesArray(Collection<Referenceable> entities) { private ArrayNode getEntitiesArray(Collection<Referenceable> entities) {
JSONArray entityArray = new JSONArray(entities.size()); ArrayNode entityArray = AtlasJson.createV1ArrayNode();
for (Referenceable entity : entities) { for (Referenceable entity : entities) {
entityArray.put(AtlasType.toV1Json(entity)); entityArray.add(AtlasType.toV1Json(entity));
} }
return entityArray; return entityArray;
} }
...@@ -453,16 +454,16 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -453,16 +454,16 @@ public class AtlasClient extends AtlasBaseClient {
return updateEntities(Arrays.asList(entities)); return updateEntities(Arrays.asList(entities));
} }
protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException { protected EntityResult updateEntities(ArrayNode entities) throws AtlasServiceException {
LOG.debug("Updating entities: {}", entities); LOG.debug("Updating entities: {}", entities);
JSONObject response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString()); ObjectNode response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString());
EntityResult results = extractEntityResult(response); EntityResult results = extractEntityResult(response);
LOG.debug("Update entities returned results: {}", results); LOG.debug("Update entities returned results: {}", results);
return results; return results;
} }
public EntityResult updateEntities(Collection<Referenceable> entities) throws AtlasServiceException { public EntityResult updateEntities(Collection<Referenceable> entities) throws AtlasServiceException {
JSONArray entitiesArray = getEntitiesArray(entities); ArrayNode entitiesArray = getEntitiesArray(entities);
return updateEntities(entitiesArray); return updateEntities(entitiesArray);
} }
...@@ -477,7 +478,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -477,7 +478,7 @@ public class AtlasClient extends AtlasBaseClient {
throws AtlasServiceException { throws AtlasServiceException {
LOG.debug("Updating entity id: {}, attribute name: {}, attribute value: {}", guid, attribute, value); LOG.debug("Updating entity id: {}, attribute name: {}, attribute value: {}", guid, attribute, value);
final API api = API_V1.UPDATE_ENTITY_PARTIAL; final API api = API_V1.UPDATE_ENTITY_PARTIAL;
JSONObject response = callAPIWithRetries(api, value, new ResourceCreator() { ObjectNode response = callAPIWithRetries(api, value, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api, guid); WebResource resource = getResource(api, guid);
...@@ -497,7 +498,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -497,7 +498,7 @@ public class AtlasClient extends AtlasBaseClient {
public EntityResult updateEntity(String guid, Referenceable entity) throws AtlasServiceException { public EntityResult updateEntity(String guid, Referenceable entity) throws AtlasServiceException {
String entityJson = AtlasType.toV1Json(entity); String entityJson = AtlasType.toV1Json(entity);
LOG.debug("Updating entity id {} with {}", guid, entityJson); LOG.debug("Updating entity id {} with {}", guid, entityJson);
JSONObject response = callAPIWithBodyAndParams(API_V1.UPDATE_ENTITY_PARTIAL, entityJson, guid); ObjectNode response = callAPIWithBodyAndParams(API_V1.UPDATE_ENTITY_PARTIAL, entityJson, guid);
return extractEntityResult(response); return extractEntityResult(response);
} }
...@@ -538,7 +539,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -538,7 +539,7 @@ public class AtlasClient extends AtlasBaseClient {
String entityJson = AtlasType.toV1Json(entity); String entityJson = AtlasType.toV1Json(entity);
LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType, LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType,
uniqueAttributeName, uniqueAttributeValue, entityJson); uniqueAttributeName, uniqueAttributeValue, entityJson);
JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() { ObjectNode response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api, QUALIFIED_NAME); WebResource resource = getResource(api, QUALIFIED_NAME);
...@@ -553,12 +554,8 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -553,12 +554,8 @@ public class AtlasClient extends AtlasBaseClient {
return result; return result;
} }
protected String getString(JSONObject jsonObject, String parameter) throws AtlasServiceException { protected String getString(ObjectNode jsonObject, String parameter) throws AtlasServiceException {
try { return jsonObject.get(parameter).asText();
return jsonObject.getString(parameter);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
/** /**
...@@ -571,7 +568,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -571,7 +568,7 @@ public class AtlasClient extends AtlasBaseClient {
public EntityResult deleteEntities(final String... guids) throws AtlasServiceException { public EntityResult deleteEntities(final String... guids) throws AtlasServiceException {
LOG.debug("Deleting entities: {}", guids); LOG.debug("Deleting entities: {}", guids);
final API api = API_V1.DELETE_ENTITIES; final API api = API_V1.DELETE_ENTITIES;
JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api); WebResource resource = getResource(api);
...@@ -602,7 +599,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -602,7 +599,7 @@ public class AtlasClient extends AtlasBaseClient {
resource = resource.queryParam(TYPE, entityType); resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName); resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue); resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
JSONObject jsonResponse = callAPIWithResource(api, resource); ObjectNode jsonResponse = callAPIWithResource(api, resource);
EntityResult results = extractEntityResult(jsonResponse); EntityResult results = extractEntityResult(jsonResponse);
LOG.debug("Delete entities returned results: {}", results); LOG.debug("Delete entities returned results: {}", results);
return results; return results;
...@@ -615,19 +612,15 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -615,19 +612,15 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public Referenceable getEntity(String guid) throws AtlasServiceException { public Referenceable getEntity(String guid) throws AtlasServiceException {
JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid); ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid);
try { String entityInstanceDefinition = jsonResponse.get(AtlasClient.DEFINITION).asText();
String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION); return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
} catch (JSONException e) {
throw new AtlasServiceException(API_V1.GET_ENTITY, e);
}
} }
public static String toString(JSONArray jsonArray) throws JSONException { public static String toString(ArrayNode jsonArray) {
ArrayList<String> resultsList = new ArrayList<>(); ArrayList<String> resultsList = new ArrayList<>();
for (int index = 0; index < jsonArray.length(); index++) { for (int index = 0; index < jsonArray.size(); index++) {
resultsList.add(jsonArray.getString(index)); resultsList.add(jsonArray.get(index).asText());
} }
return StringUtils.join(resultsList, ","); return StringUtils.join(resultsList, ",");
} }
...@@ -643,7 +636,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -643,7 +636,7 @@ public class AtlasClient extends AtlasBaseClient {
public Referenceable getEntity(final String entityType, final String attribute, final String value) public Referenceable getEntity(final String entityType, final String attribute, final String value)
throws AtlasServiceException { throws AtlasServiceException {
final API api = API_V1.GET_ENTITY; final API api = API_V1.GET_ENTITY;
JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api); WebResource resource = getResource(api);
...@@ -653,12 +646,8 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -653,12 +646,8 @@ public class AtlasClient extends AtlasBaseClient {
return resource; return resource;
} }
}); });
try { String entityInstanceDefinition = jsonResponse.get(AtlasClient.DEFINITION).asText();
String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION); return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
} catch (JSONException e) {
throw new AtlasServiceException(api, e);
}
} }
/** /**
...@@ -668,7 +657,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -668,7 +657,7 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public List<String> listEntities(final String entityType) throws AtlasServiceException { public List<String> listEntities(final String entityType) throws AtlasServiceException {
JSONObject jsonResponse = callAPIWithRetries(API_V1.LIST_ENTITIES, null, new ResourceCreator() { ObjectNode jsonResponse = callAPIWithRetries(API_V1.LIST_ENTITIES, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(API_V1.LIST_ENTITIES); WebResource resource = getResource(API_V1.LIST_ENTITIES);
...@@ -686,7 +675,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -686,7 +675,7 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public List<String> listTraits(final String guid) throws AtlasServiceException { public List<String> listTraits(final String guid) throws AtlasServiceException {
JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.LIST_TRAITS, null, guid, URI_TRAITS); ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.LIST_TRAITS, null, guid, URI_TRAITS);
return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>()); return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
} }
...@@ -697,10 +686,10 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -697,10 +686,10 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException { public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException {
JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS); ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
List<JSONObject> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<JSONObject, JSONObject>()); List<ObjectNode> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<ObjectNode, ObjectNode>());
ArrayList<Struct> traitStructList = new ArrayList<>(); ArrayList<Struct> traitStructList = new ArrayList<>();
for (JSONObject traitDef : traitDefList) { for (ObjectNode traitDef : traitDefList) {
Struct traitStruct = AtlasType.fromV1Json(traitDef.toString(), Struct.class); Struct traitStruct = AtlasType.fromV1Json(traitDef.toString(), Struct.class);
traitStructList.add(traitStruct); traitStructList.add(traitStruct);
} }
...@@ -715,34 +704,26 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -715,34 +704,26 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException { public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException {
JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName); ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
try { return AtlasType.fromV1Json(jsonResponse.get(AtlasClient.RESULTS).asText(), Struct.class);
return AtlasType.fromV1Json(jsonResponse.getString(AtlasClient.RESULTS), Struct.class);
} catch (JSONException e) {
throw new AtlasServiceException(API_V1.GET_TRAIT_DEFINITION, e);
}
} }
protected class ExtractOperation<T, U> { protected class ExtractOperation<T, U> {
T extractElement(U element) throws JSONException { T extractElement(U element) {
return (T) element; return (T) element;
} }
} }
protected <T, U> List<T> extractResults(JSONObject jsonResponse, String key, ExtractOperation<T, U> extractInterafce) protected <T, U> List<T> extractResults(ObjectNode jsonResponse, String key, ExtractOperation<T, U> extractInterafce)
throws AtlasServiceException { throws AtlasServiceException {
try { ArrayNode results = (ArrayNode)jsonResponse.get(key);
JSONArray results = jsonResponse.getJSONArray(key); ArrayList<T> resultsList = new ArrayList<>();
ArrayList<T> resultsList = new ArrayList<>(); for (int index = 0; index < results.size(); index++) {
for (int index = 0; index < results.length(); index++) { Object element = results.get(index);
Object element = results.get(index); resultsList.add(extractInterafce.extractElement((U) element));
resultsList.add(extractInterafce.extractElement((U) element));
}
return resultsList;
} catch (JSONException e) {
throw new AtlasServiceException(e);
} }
return resultsList;
} }
/** /**
...@@ -773,10 +754,10 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -773,10 +754,10 @@ public class AtlasClient extends AtlasBaseClient {
} }
resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults)); resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults));
JSONObject jsonResponse = callAPIWithResource(API_V1.LIST_ENTITY_AUDIT, resource); ObjectNode jsonResponse = callAPIWithResource(API_V1.LIST_ENTITY_AUDIT, resource);
return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() { return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, ObjectNode>() {
@Override @Override
EntityAuditEvent extractElement(JSONObject element) throws JSONException { EntityAuditEvent extractElement(ObjectNode element) {
return AtlasType.fromV1Json(element.toString(), EntityAuditEvent.class); return AtlasType.fromV1Json(element.toString(), EntityAuditEvent.class);
} }
}); });
...@@ -791,9 +772,9 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -791,9 +772,9 @@ public class AtlasClient extends AtlasBaseClient {
* @return Query results * @return Query results
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public JSONArray search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException { public ArrayNode search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException {
final API api = API_V1.SEARCH; final API api = API_V1.SEARCH;
JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode result = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api); WebResource resource = getResource(api);
...@@ -803,12 +784,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -803,12 +784,7 @@ public class AtlasClient extends AtlasBaseClient {
return resource; return resource;
} }
}); });
try { return (ArrayNode)result.get(RESULTS);
return result.getJSONArray(RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
/** /**
...@@ -819,10 +795,10 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -819,10 +795,10 @@ public class AtlasClient extends AtlasBaseClient {
* @return result json object * @return result json object
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public JSONArray searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException { public ArrayNode searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
LOG.debug("DSL query: {}", query); LOG.debug("DSL query: {}", query);
final API api = API_V1.SEARCH_DSL; final API api = API_V1.SEARCH_DSL;
JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() { ObjectNode result = callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api); WebResource resource = getResource(api);
...@@ -832,11 +808,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -832,11 +808,7 @@ public class AtlasClient extends AtlasBaseClient {
return resource; return resource;
} }
}); });
try { return (ArrayNode)result.get(RESULTS);
return result.getJSONArray(RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
/** /**
...@@ -847,7 +819,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -847,7 +819,7 @@ public class AtlasClient extends AtlasBaseClient {
* @return result json object * @return result json object
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public JSONObject searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException { public ObjectNode searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException {
final API api = API_V1.SEARCH_FULL_TEXT; final API api = API_V1.SEARCH_FULL_TEXT;
return callAPIWithRetries(api, null, new ResourceCreator() { return callAPIWithRetries(api, null, new ResourceCreator() {
@Override @Override
...@@ -861,60 +833,40 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -861,60 +833,40 @@ public class AtlasClient extends AtlasBaseClient {
}); });
} }
public JSONObject getInputGraph(String datasetName) throws AtlasServiceException { public ObjectNode getInputGraph(String datasetName) throws AtlasServiceException {
JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph"); ObjectNode response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
try { return (ObjectNode)response.get(AtlasClient.RESULTS);
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
public JSONObject getOutputGraph(String datasetName) throws AtlasServiceException { public ObjectNode getOutputGraph(String datasetName) throws AtlasServiceException {
JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph"); ObjectNode response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
try { return (ObjectNode)response.get(AtlasClient.RESULTS);
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
public JSONObject getInputGraphForEntity(String entityId) throws AtlasServiceException { public ObjectNode getInputGraphForEntity(String entityId) throws AtlasServiceException {
JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph"); ObjectNode response = callAPIWithBodyAndParams(API_V1.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
try { return (ObjectNode)response.get(AtlasClient.RESULTS);
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
public JSONObject getOutputGraphForEntity(String datasetId) throws AtlasServiceException { public ObjectNode getOutputGraphForEntity(String datasetId) throws AtlasServiceException {
JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph"); ObjectNode response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
try { return (ObjectNode) response.get(AtlasClient.RESULTS);
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
public JSONObject getSchemaForEntity(String datasetId) throws AtlasServiceException { public ObjectNode getSchemaForEntity(String datasetId) throws AtlasServiceException {
JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema"); ObjectNode response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
try { return (ObjectNode) response.get(AtlasClient.RESULTS);
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
} }
// Wrapper methods for compatibility // Wrapper methods for compatibility
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException { public ObjectNode callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
return callAPIWithResource(api, resource, null, JSONObject.class); return callAPIWithResource(api, resource, null, ObjectNode.class);
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithResource(API_V1 apiV1, WebResource resource) throws AtlasServiceException { public ObjectNode callAPIWithResource(API_V1 apiV1, WebResource resource) throws AtlasServiceException {
return callAPIWithResource(apiV1, resource, null, JSONObject.class); return callAPIWithResource(apiV1, resource, null, ObjectNode.class);
} }
@VisibleForTesting @VisibleForTesting
...@@ -928,42 +880,42 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -928,42 +880,42 @@ public class AtlasClient extends AtlasBaseClient {
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException { public ObjectNode callAPIWithBody(API api, Object requestObject) throws AtlasServiceException {
return callAPI(api, JSONObject.class, requestObject, (String[]) null); return callAPI(api, ObjectNode.class, requestObject, (String[]) null);
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithBody(API_V1 apiV1, Object requestObject) throws AtlasServiceException { public ObjectNode callAPIWithBody(API_V1 apiV1, Object requestObject) throws AtlasServiceException {
return callAPI(apiV1, JSONObject.class, requestObject, (String[]) null); return callAPI(apiV1, ObjectNode.class, requestObject, (String[]) null);
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String... params) throws AtlasServiceException { public ObjectNode callAPIWithBodyAndParams(API api, Object requestObject, String... params) throws AtlasServiceException {
return callAPI(api, JSONObject.class, requestObject, params); return callAPI(api, ObjectNode.class, requestObject, params);
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithBodyAndParams(API_V1 apiV1, Object requestObject, String... params) throws AtlasServiceException { public ObjectNode callAPIWithBodyAndParams(API_V1 apiV1, Object requestObject, String... params) throws AtlasServiceException {
return callAPI(apiV1, JSONObject.class, requestObject, params); return callAPI(apiV1, ObjectNode.class, requestObject, params);
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException { public ObjectNode callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
return callAPI(api, JSONObject.class, queryParams); return callAPI(api, ObjectNode.class, queryParams);
} }
@VisibleForTesting @VisibleForTesting
public JSONObject callAPIWithQueryParams(API_V1 apiV1, MultivaluedMap<String, String> queryParams) throws AtlasServiceException { public ObjectNode callAPIWithQueryParams(API_V1 apiV1, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
return callAPI(apiV1, JSONObject.class, queryParams); return callAPI(apiV1, ObjectNode.class, queryParams);
} }
@VisibleForTesting @VisibleForTesting
JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { ObjectNode callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
return super.callAPIWithRetries(api, requestObject, resourceCreator); return super.callAPIWithRetries(api, requestObject, resourceCreator);
} }
@VisibleForTesting @VisibleForTesting
JSONObject callAPIWithRetries(API_V1 apiV1, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { ObjectNode callAPIWithRetries(API_V1 apiV1, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
return super.callAPIWithRetries(apiV1, requestObject, resourceCreator); return super.callAPIWithRetries(apiV1, requestObject, resourceCreator);
} }
} }
...@@ -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,6 +18,8 @@ ...@@ -18,6 +18,8 @@
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.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -43,6 +45,7 @@ import org.apache.atlas.type.AtlasEntityType; ...@@ -43,6 +45,7 @@ import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
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.v1.model.instance.Id; import org.apache.atlas.v1.model.instance.Id;
...@@ -52,9 +55,6 @@ import org.apache.atlas.web.rest.EntityREST; ...@@ -52,9 +55,6 @@ import org.apache.atlas.web.rest.EntityREST;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
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;
...@@ -68,9 +68,9 @@ import javax.ws.rs.core.MediaType; ...@@ -68,9 +68,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -141,21 +141,20 @@ public class EntityResource { ...@@ -141,21 +141,20 @@ public class EntityResource {
String entities = Servlets.getRequestPayload(request); String entities = Servlets.getRequestPayload(request);
//Handle backward compatibility - if entities is not JSONArray, convert to JSONArray //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
JSONArray jsonEntities = null; ArrayNode jsonEntities = null;
try { try {
jsonEntities = new JSONArray(entities); jsonEntities = AtlasJson.parseToV1ArrayNode(entities);
} catch (JSONException e) { } catch (IOException e) {
final String finalEntities = entities; jsonEntities = AtlasJson.createV1ArrayNode();
jsonEntities = new JSONArray() {{
put(finalEntities); jsonEntities.add(entities);
}};
} }
String[] jsonStrings = new String[jsonEntities.length()]; String[] jsonStrings = new String[jsonEntities.size()];
for (int i = 0; i < jsonEntities.length(); i++) { for (int i = 0; i < jsonEntities.size(); i++) {
jsonStrings[i] = jsonEntities.getString(i); jsonStrings[i] = jsonEntities.get(i).asText();
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -173,7 +172,7 @@ public class EntityResource { ...@@ -173,7 +172,7 @@ public class EntityResource {
final CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse); final CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
JSONObject response = getResponse(result); ObjectNode response = getResponse(result);
URI locationURI = getLocationURI(guids); URI locationURI = getLocationURI(guids);
return Response.created(locationURI).entity(response).build(); return Response.created(locationURI).entity(response).build();
...@@ -216,27 +215,26 @@ public class EntityResource { ...@@ -216,27 +215,26 @@ public class EntityResource {
return locationURI; return locationURI;
} }
private JSONObject getResponse(EntityResult entityResult) throws AtlasBaseException, AtlasException, JSONException { private ObjectNode getResponse(EntityResult entityResult) throws AtlasBaseException, AtlasException {
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult(); CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
result.setEntityResult(entityResult); result.setEntityResult(entityResult);
return getResponse(result); return getResponse(result);
} }
private JSONObject getResponse(CreateUpdateEntitiesResult result) throws AtlasBaseException, AtlasException, JSONException { private ObjectNode getResponse(CreateUpdateEntitiesResult result) throws AtlasBaseException, AtlasException {
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
EntityResult entityResult = result.getEntityResult(); EntityResult entityResult = result.getEntityResult();
GuidMapping mapping = result.getGuidMapping(); GuidMapping mapping = result.getGuidMapping();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.putPOJO(AtlasClient.REQUEST_ID, Servlets.getRequestId());
if(entityResult != null) { if(entityResult != null) {
response.put(AtlasClient.ENTITIES, new JSONObject(entityResult.toString()).get(AtlasClient.ENTITIES)); response.putPOJO(AtlasClient.ENTITIES, entityResult.getEntities());
String sampleEntityId = getSample(result.getEntityResult()); String sampleEntityId = getSample(result.getEntityResult());
if (sampleEntityId != null) { if (sampleEntityId != null) {
String entityDefinition = getEntityJson(sampleEntityId); response.putPOJO(AtlasClient.DEFINITION, getEntity(sampleEntityId));
response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
} }
} }
if(mapping != null) { if(mapping != null) {
response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(AtlasType.toV1Json(mapping)).get(AtlasClient.GUID_ASSIGNMENTS)); response.putPOJO(AtlasClient.GUID_ASSIGNMENTS, mapping);
} }
return response; return response;
} }
...@@ -261,12 +259,13 @@ public class EntityResource { ...@@ -261,12 +259,13 @@ public class EntityResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntities()"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntities()");
} }
final String entities = Servlets.getRequestPayload(request); entityJson = Servlets.getRequestPayload(request);
JSONArray jsonEntities = new JSONArray(entities);
String[] jsonStrings = new String[jsonEntities.length()]; ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
String[] jsonStrings = new String[jsonEntities.size()];
for (int i = 0; i < jsonEntities.length(); i++) { for (int i = 0; i < jsonEntities.size(); i++) {
jsonStrings[i] = jsonEntities.getString(i); jsonStrings[i] = jsonEntities.get(i).asText();
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -281,7 +280,7 @@ public class EntityResource { ...@@ -281,7 +280,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult()); LOG.debug("Updated entities: {}", result.getEntityResult());
} }
JSONObject response = getResponse(result); ObjectNode response = getResponse(result);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
...@@ -383,7 +382,7 @@ public class EntityResource { ...@@ -383,7 +382,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult()); LOG.debug("Updated entities: {}", result.getEntityResult());
} }
JSONObject response = getResponse(result); ObjectNode response = getResponse(result);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("Unable to partially update entity {} {}:{}.{}", entityJson, entityType, attribute, value, e); LOG.error("Unable to partially update entity {} {}:{}.{}", entityJson, entityType, attribute, value, e);
...@@ -472,7 +471,7 @@ public class EntityResource { ...@@ -472,7 +471,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult()); LOG.debug("Updated entities: {}", result.getEntityResult());
} }
JSONObject response = getResponse(result); ObjectNode response = getResponse(result);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e); LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
...@@ -517,7 +516,7 @@ public class EntityResource { ...@@ -517,7 +516,7 @@ public class EntityResource {
LOG.debug("Updated entities: {}", result.getEntityResult()); LOG.debug("Updated entities: {}", result.getEntityResult());
} }
JSONObject response = getResponse(result); ObjectNode response = getResponse(result);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e); LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e);
...@@ -587,7 +586,7 @@ public class EntityResource { ...@@ -587,7 +586,7 @@ public class EntityResource {
LOG.debug("Deleted entity result: {}", entityResult); LOG.debug("Deleted entity result: {}", entityResult);
} }
JSONObject response = getResponse(entityResult); ObjectNode response = getResponse(entityResult);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e); LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
...@@ -635,14 +634,13 @@ public class EntityResource { ...@@ -635,14 +634,13 @@ public class EntityResource {
guid = ParamChecker.notEmpty(guid, "guid cannot be null"); guid = ParamChecker.notEmpty(guid, "guid cannot be null");
String entityDefinition = getEntityJson(guid); Referenceable entity = getEntity(guid);
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
Response.Status status = Response.Status.NOT_FOUND; Response.Status status = Response.Status.NOT_FOUND;
if (entityDefinition != null) { if (entity != null) {
response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition)); response.putPOJO(AtlasClient.DEFINITION, entity);
status = Response.Status.OK; status = Response.Status.OK;
} else { } else {
response.put(AtlasClient.ERROR, response.put(AtlasClient.ERROR,
...@@ -683,10 +681,10 @@ public class EntityResource { ...@@ -683,10 +681,10 @@ public class EntityResource {
List<String> entityGUIDS = entitiesStore.getEntityGUIDS(entityType); List<String> entityGUIDS = entitiesStore.getEntityGUIDS(entityType);
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.TYPENAME, entityType); response.put(AtlasClient.TYPENAME, entityType);
response.put(AtlasClient.RESULTS, new JSONArray(entityGUIDS)); response.putPOJO(AtlasClient.RESULTS, entityGUIDS);
response.put(AtlasClient.COUNT, entityGUIDS.size()); response.put(AtlasClient.COUNT, entityGUIDS.size());
return Response.ok(response).build(); return Response.ok(response).build();
...@@ -769,20 +767,17 @@ public class EntityResource { ...@@ -769,20 +767,17 @@ public class EntityResource {
throw toWebApplicationException(e); throw toWebApplicationException(e);
} }
String entityDefinition = null; Referenceable entity = null;
if (entityInfo != null) { if (entityInfo != null) {
Referenceable instance = restAdapters.getReferenceable(entityInfo); entity = restAdapters.getReferenceable(entityInfo);
entityDefinition = AtlasType.toV1Json(instance);
} }
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
Response.Status status = Response.Status.NOT_FOUND; Response.Status status = Response.Status.NOT_FOUND;
if (entityDefinition != null) { if (entity != null) {
response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition)); response.putPOJO(AtlasClient.DEFINITION, entity);
status = Response.Status.OK; status = Response.Status.OK;
} else { } else {
response.put(AtlasClient.ERROR, Servlets.escapeJsonString(String.format("An entity with type={%s}, " + response.put(AtlasClient.ERROR, Servlets.escapeJsonString(String.format("An entity with type={%s}, " +
...@@ -840,9 +835,9 @@ public class EntityResource { ...@@ -840,9 +835,9 @@ public class EntityResource {
traitNames.add(classification.getTypeName()); traitNames.add(classification.getTypeName());
} }
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.RESULTS, new JSONArray(traitNames)); response.putPOJO(AtlasClient.RESULTS, traitNames);
response.put(AtlasClient.COUNT, traitNames.size()); response.put(AtlasClient.COUNT, traitNames.size());
return Response.ok(response).build(); return Response.ok(response).build();
...@@ -891,16 +886,16 @@ public class EntityResource { ...@@ -891,16 +886,16 @@ public class EntityResource {
final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid); final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid);
JSONArray traits = new JSONArray(); ArrayNode traits = AtlasJson.createV1ArrayNode();
for (AtlasClassification classification : classifications) { for (AtlasClassification classification : classifications) {
Struct trait = restAdapters.getTrait(classification); Struct trait = restAdapters.getTrait(classification);
traits.put(new JSONObject(AtlasType.toV1Json(trait))); traits.addPOJO(trait);
} }
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.RESULTS, traits); response.put(AtlasClient.RESULTS, traits);
response.put(AtlasClient.COUNT, traits.length()); response.put(AtlasClient.COUNT, traits.size());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
...@@ -953,9 +948,9 @@ public class EntityResource { ...@@ -953,9 +948,9 @@ public class EntityResource {
Struct traitDefinition = restAdapters.getTrait(classification); Struct traitDefinition = restAdapters.getTrait(classification);
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.RESULTS, new JSONObject(AtlasType.toV1Json(traitDefinition))); response.putPOJO(AtlasClient.RESULTS, traitDefinition);
return Response.ok(response).build(); return Response.ok(response).build();
...@@ -1017,8 +1012,7 @@ public class EntityResource { ...@@ -1017,8 +1012,7 @@ public class EntityResource {
add(guid); add(guid);
}}); }});
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
return Response.created(locationURI).entity(response).build(); return Response.created(locationURI).entity(response).build();
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
...@@ -1071,7 +1065,7 @@ public class EntityResource { ...@@ -1071,7 +1065,7 @@ public class EntityResource {
entitiesStore.deleteClassifications(guid, new ArrayList<String>() {{ add(traitName); }}); entitiesStore.deleteClassifications(guid, new ArrayList<String>() {{ add(traitName); }});
JSONObject response = new JSONObject(); ObjectNode response = AtlasJson.createV1ObjectNode();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(TRAIT_NAME, traitName); response.put(TRAIT_NAME, traitName);
...@@ -1129,9 +1123,9 @@ public class EntityResource { ...@@ -1129,9 +1123,9 @@ public class EntityResource {
List<EntityAuditEvent> events = entityAuditRepository.listEvents(guid, startKey, count); List<EntityAuditEvent> events = entityAuditRepository.listEvents(guid, startKey, count);
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.EVENTS, getJSONArray(events)); response.putPOJO(AtlasClient.EVENTS, events);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e); LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
...@@ -1151,14 +1145,6 @@ public class EntityResource { ...@@ -1151,14 +1145,6 @@ public class EntityResource {
} }
} }
private <T> JSONArray getJSONArray(Collection<T> elements) throws JSONException {
JSONArray jsonArray = new JSONArray();
for(T element : elements) {
jsonArray.put(new JSONObject(AtlasType.toV1Json(element)));
}
return jsonArray;
}
private AtlasEntityType getEntityType(String typeName) throws AtlasBaseException { private AtlasEntityType getEntityType(String typeName) throws AtlasBaseException {
AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName); AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName);
...@@ -1184,11 +1170,10 @@ public class EntityResource { ...@@ -1184,11 +1170,10 @@ public class EntityResource {
return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode())); return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
} }
private String getEntityJson(String guid) throws AtlasBaseException { private Referenceable getEntity(String guid) throws AtlasBaseException {
AtlasEntityWithExtInfo entity = entitiesStore.getById(guid); AtlasEntityWithExtInfo entity = entitiesStore.getById(guid);
Referenceable referenceable = restAdapters.getReferenceable(entity); Referenceable referenceable = restAdapters.getReferenceable(entity);
String entityJson = AtlasType.toV1Json(referenceable);
return entityJson; return referenceable;
} }
} }
...@@ -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