javax.servlet
javax.servlet-api
diff --git a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java b/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
index d67376fa4..cc42a7304 100644
--- a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
+++ b/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
@@ -19,16 +19,16 @@
package org.apache.atlas.authorize.simple;
-import javax.servlet.http.HttpServletRequest;
-import org.apache.atlas.AtlasClient;
+import org.apache.atlas.authorize.AtlasAccessRequest;
import org.apache.atlas.authorize.AtlasActionTypes;
-import org.apache.atlas.authorize.AtlasResourceTypes;
import org.apache.atlas.authorize.AtlasAuthorizationException;
import org.apache.atlas.authorize.AtlasAuthorizer;
-import org.apache.atlas.authorize.AtlasAccessRequest;
import org.apache.atlas.authorize.AtlasAuthorizerFactory;
+import org.apache.atlas.authorize.AtlasResourceTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashSet;
@@ -38,7 +38,7 @@ import java.util.regex.Pattern;
public class AtlasAuthorizationUtils {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationUtils.class);
private static boolean isDebugEnabled = LOG.isDebugEnabled();
- private static final String BASE_URL = "/" + AtlasClient.BASE_URI;
+ private static final String BASE_URL = "/api/atlas/";
public static String getApi(String contextPath) {
if (isDebugEnabled) {
diff --git a/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java b/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
index fc611c8ac..aabac9018 100644
--- a/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
+++ b/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
@@ -21,7 +21,6 @@ import org.apache.atlas.authorize.AtlasActionTypes;
import org.apache.atlas.authorize.AtlasResourceTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import scala.tools.jline_embedded.internal.Log;
import java.util.ArrayList;
import java.util.HashMap;
@@ -234,7 +233,7 @@ public class PolicyParser {
} else if (type.equalsIgnoreCase("RELATIONSHIP")) {
resourceType = AtlasResourceTypes.RELATIONSHIP;
} else {
- Log.warn(type + " is invalid resource please check PolicyStore file");
+ LOG.warn(type + " is invalid resource please check PolicyStore file");
continue;
}
diff --git a/client/client-v1/pom.xml b/client/client-v1/pom.xml
new file mode 100644
index 000000000..2b492bb85
--- /dev/null
+++ b/client/client-v1/pom.xml
@@ -0,0 +1,48 @@
+
+
+
+
+ atlas-client
+ org.apache.atlas
+ 1.0.0-SNAPSHOT
+
+ 4.0.0
+
+ atlas-client-v1
+
+
+
+ org.apache.atlas
+ atlas-typesystem
+
+
+ org.apache.atlas
+ atlas-client-common
+ ${project.version}
+
+
+ org.apache.atlas
+ atlas-typesystem
+ tests
+ test
+
+
+
diff --git a/client/src/main/java/org/apache/atlas/AtlasAdminClient.java b/client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/AtlasAdminClient.java
rename to client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java
diff --git a/client/src/main/java/org/apache/atlas/AtlasClient.java b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
old mode 100755
new mode 100644
similarity index 70%
rename from client/src/main/java/org/apache/atlas/AtlasClient.java
rename to client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
index 5fa5df793..6d0b83db2
--- a/client/src/main/java/org/apache/atlas/AtlasClient.java
+++ b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
@@ -6,9 +6,9 @@
* 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
- *
+ *
+ * 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.
@@ -57,60 +57,57 @@ import java.util.List;
public class AtlasClient extends AtlasBaseClient {
private static final Logger LOG = LoggerFactory.getLogger(AtlasClient.class);
- public static final String TYPE = "type";
- public static final String TYPENAME = "typeName";
- public static final String GUID = "GUID";
- public static final String ENTITIES = "entities";
+ public static final String TYPE = "type";
+ public static final String TYPENAME = "typeName";
+ public static final String GUID = "GUID";
+ public static final String ENTITIES = "entities";
public static final String GUID_ASSIGNMENTS = "guidAssignments";
public static final String DEFINITION = "definition";
- public static final String ERROR = "error";
+ public static final String ERROR = "error";
public static final String STACKTRACE = "stackTrace";
public static final String REQUEST_ID = "requestId";
- public static final String RESULTS = "results";
- public static final String COUNT = "count";
- public static final String ROWS = "rows";
- public static final String DATATYPE = "dataType";
- public static final String STATUS = "Status";
+ public static final String RESULTS = "results";
+ public static final String COUNT = "count";
+ public static final String ROWS = "rows";
+ public static final String DATATYPE = "dataType";
+ public static final String STATUS = "Status";
- public static final String EVENTS = "events";
- public static final String START_KEY = "startKey";
+ public static final String EVENTS = "events";
+ public static final String START_KEY = "startKey";
public static final String NUM_RESULTS = "count";
- public static final String URI_ENTITY = "entities";
- public static final String URI_ENTITY_AUDIT = "audit";
- public static final String URI_SEARCH = "discovery/search";
- public static final String URI_NAME_LINEAGE = "lineage/hive/table";
- public static final String URI_LINEAGE = "lineage/";
- public static final String URI_TRAITS = "traits";
- public static final String TRAITS = "traits";
+ public static final String URI_ENTITY = "entities";
+ public static final String URI_ENTITY_AUDIT = "audit";
+ public static final String URI_SEARCH = "discovery/search";
+ public static final String URI_NAME_LINEAGE = "lineage/hive/table";
+ public static final String URI_LINEAGE = "lineage/";
+ public static final String URI_TRAITS = "traits";
+ public static final String TRAITS = "traits";
public static final String TRAIT_DEFINITIONS = "traitDefinitions";
- public static final String QUERY = "query";
- public static final String LIMIT = "limit";
- public static final String OFFSET = "offset";
- public static final String QUERY_TYPE = "queryType";
- public static final String ATTRIBUTE_NAME = "property";
+ public static final String QUERY_TYPE = "queryType";
+ public static final String ATTRIBUTE_NAME = "property";
public static final String ATTRIBUTE_VALUE = "value";
- public static final String SUPERTYPE = "supertype";
+ public static final String SUPERTYPE = "supertype";
public static final String NOT_SUPERTYPE = "notsupertype";
- public static final String ASSET_TYPE = "Asset";
- public static final String NAME = "name";
+ public static final String ASSET_TYPE = "Asset";
+ public static final String NAME = "name";
public static final String DESCRIPTION = "description";
- public static final String OWNER = "owner";
+ public static final String OWNER = "owner";
public static final String CREATE_TIME = "createTime";
public static final String INFRASTRUCTURE_SUPER_TYPE = "Infrastructure";
- public static final String DATA_SET_SUPER_TYPE = "DataSet";
- public static final String PROCESS_SUPER_TYPE = "Process";
- public static final String PROCESS_ATTRIBUTE_INPUTS = "inputs";
+ public static final String DATA_SET_SUPER_TYPE = "DataSet";
+ public static final String PROCESS_SUPER_TYPE = "Process";
+ public static final String PROCESS_ATTRIBUTE_INPUTS = "inputs";
public static final String PROCESS_ATTRIBUTE_OUTPUTS = "outputs";
- public static final String REFERENCEABLE_SUPER_TYPE = "Referenceable";
- public static final String QUALIFIED_NAME = "qualifiedName";
+ public static final String REFERENCEABLE_SUPER_TYPE = "Referenceable";
+ public static final String QUALIFIED_NAME = "qualifiedName";
public static final String REFERENCEABLE_ATTRIBUTE_NAME = QUALIFIED_NAME;
public static final String UNKNOWN_STATUS = "Unknown status";
@@ -125,7 +122,7 @@ public class AtlasClient extends AtlasBaseClient {
*/
public AtlasClient(String[] baseUrl, String cookieName, String value, String path, String domain) {
- super(baseUrl, new Cookie( cookieName, value, path, domain));
+ super(baseUrl, new Cookie(cookieName, value, path, domain));
}
/**
@@ -182,6 +179,11 @@ public class AtlasClient extends AtlasBaseClient {
super(configuration, baseUrl, basicAuthUserNamePassword);
}
+ @Override
+ protected API formatPathParameters(final API api, final String... params) {
+ return new API(String.format(api.getPath(), params), api.getMethod(), api.getExpectedStatus());
+ }
+
@VisibleForTesting
public AtlasClient(Configuration configuration, String... baseUrls) throws AtlasException {
initializeState(configuration, baseUrls, getCurrentUGI(), getCurrentUGI().getShortUserName());
@@ -196,75 +198,55 @@ public class AtlasClient extends AtlasBaseClient {
return service;
}
- public enum API {
-
+ public static class API_V1 extends API {
//Admin operations
- VERSION(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK),
- STATUS(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK),
+ public static final API_V1 VERSION = new API_V1(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 STATUS = new API_V1(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK);
//Type operations
- CREATE_TYPE(BASE_URI + TYPES, HttpMethod.POST, Response.Status.CREATED),
- UPDATE_TYPE(BASE_URI + TYPES, HttpMethod.PUT, Response.Status.OK),
- GET_TYPE(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK),
- LIST_TYPES(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK),
- LIST_TRAIT_TYPES(BASE_URI + TYPES + "?type=trait", HttpMethod.GET, Response.Status.OK),
+ public static final API_V1 CREATE_TYPE = new API_V1(BASE_URI + TYPES, HttpMethod.POST, Response.Status.CREATED);
+ public static final API_V1 UPDATE_TYPE = new API_V1(BASE_URI + TYPES, HttpMethod.PUT, Response.Status.OK);
+ public static final API_V1 GET_TYPE = new API_V1(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LIST_TYPES = new API_V1(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LIST_TRAIT_TYPES = new API_V1(BASE_URI + TYPES + "?type=trait", HttpMethod.GET, Response.Status.OK);
//Entity operations
- CREATE_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED),
- GET_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- UPDATE_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.PUT, Response.Status.OK),
- UPDATE_ENTITY_PARTIAL(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.OK),
- LIST_ENTITIES(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- DELETE_ENTITIES(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK),
- DELETE_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK),
+ public static final API_V1 CREATE_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED);
+ public static final API_V1 GET_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 UPDATE_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.PUT, Response.Status.OK);
+ public static final API_V1 UPDATE_ENTITY_PARTIAL = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.OK);
+ public static final API_V1 LIST_ENTITIES = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 DELETE_ENTITIES = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V1 DELETE_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK);
//audit operation
- LIST_ENTITY_AUDIT(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
+ public static final API_V1 LIST_ENTITY_AUDIT = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
//Trait operations
- ADD_TRAITS(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED),
- DELETE_TRAITS(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK),
- LIST_TRAITS(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- GET_ALL_TRAIT_DEFINITIONS(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- GET_TRAIT_DEFINITION(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
+ public static final API_V1 ADD_TRAITS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED);
+ public static final API_V1 DELETE_TRAITS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V1 LIST_TRAITS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 GET_ALL_TRAIT_DEFINITIONS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 GET_TRAIT_DEFINITION = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
//Search operations
- SEARCH(BASE_URI + URI_SEARCH, HttpMethod.GET, Response.Status.OK),
- SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET, Response.Status.OK),
- SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET, Response.Status.OK),
-
- GREMLIN_SEARCH(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET, Response.Status.OK),
+ public static final API_V1 SEARCH = new API_V1(BASE_URI + URI_SEARCH, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 SEARCH_DSL = new API_V1(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 SEARCH_FULL_TEXT = new API_V1(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 GREMLIN_SEARCH = new API_V1(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET, Response.Status.OK);
//Lineage operations based on dataset name
- NAME_LINEAGE_INPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
- NAME_LINEAGE_OUTPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
- NAME_LINEAGE_SCHEMA(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
+ public static final API_V1 NAME_LINEAGE_INPUTS_GRAPH = new API_V1(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 NAME_LINEAGE_OUTPUTS_GRAPH = new API_V1(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 NAME_LINEAGE_SCHEMA = new API_V1(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK);
//Lineage operations based on entity id of the dataset
- LINEAGE_INPUTS_GRAPH(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK),
- LINEAGE_OUTPUTS_GRAPH(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK),
- LINEAGE_SCHEMA(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LINEAGE_INPUTS_GRAPH = new API_V1(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LINEAGE_OUTPUTS_GRAPH = new API_V1(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LINEAGE_SCHEMA = new API_V1(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
- private final String method;
- private final String path;
- private final Response.Status status;
-
- API(String path, String method, Response.Status status) {
- this.path = path;
- this.method = method;
- this.status = status;
- }
-
- public String getMethod() {
- return method;
- }
-
- public String getPath() {
- return path;
- }
-
- public Response.Status getExpectedStatus() {
- return status;
+ private API_V1(String path, String method, Response.Status status) {
+ super(path, method, status);
}
}
@@ -276,7 +258,7 @@ public class AtlasClient extends AtlasBaseClient {
*/
public List createType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Creating type definition: {}", typeAsJson);
- JSONObject response = callAPIWithBody(API.CREATE_TYPE, typeAsJson);
+ JSONObject response = callAPIWithBody(API_V1.CREATE_TYPE, typeAsJson);
List results = extractResults(response, AtlasClient.TYPES, new ExtractOperation() {
@Override
String extractElement(JSONObject element) throws JSONException {
@@ -307,10 +289,10 @@ public class AtlasClient extends AtlasBaseClient {
*/
public List createTraitType(String traitName, ImmutableSet superTraits, AttributeDefinition... attributeDefinitions) throws AtlasServiceException {
HierarchicalTypeDefinition piiTrait =
- TypesUtil.createTraitTypeDef(traitName, superTraits, attributeDefinitions);
+ TypesUtil.createTraitTypeDef(traitName, superTraits, attributeDefinitions);
String traitDefinitionAsJSON = TypesSerialization.toJson(piiTrait, true);
- LOG.debug("Creating trait type {} {}" , traitName, traitDefinitionAsJSON);
+ LOG.debug("Creating trait type {} {}", traitName, traitDefinitionAsJSON);
return createType(traitDefinitionAsJSON);
}
@@ -332,7 +314,7 @@ public class AtlasClient extends AtlasBaseClient {
*/
public List updateType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Updating type definition: {}", typeAsJson);
- JSONObject response = callAPIWithBody(API.UPDATE_TYPE, typeAsJson);
+ JSONObject response = callAPIWithBody(API_V1.UPDATE_TYPE, typeAsJson);
List results = extractResults(response, AtlasClient.TYPES, new ExtractOperation() {
@Override
String extractElement(JSONObject element) throws JSONException {
@@ -359,7 +341,7 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public List listTypes() throws AtlasServiceException {
- final JSONObject jsonObject = callAPIWithQueryParams(API.LIST_TYPES, null);
+ final JSONObject jsonObject = callAPIWithQueryParams(API_V1.LIST_TYPES, null);
return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation());
}
@@ -370,10 +352,11 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public List listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException {
- JSONObject response = callAPIWithRetries(API.LIST_TYPES, null, new ResourceCreator() {
+ final API api = API_V1.LIST_TYPES;
+ JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.LIST_TYPES.getPath());
+ WebResource resource = getResource(api.getPath());
resource = resource.queryParam(TYPE, category.name());
return resource;
}
@@ -395,10 +378,11 @@ public class AtlasClient extends AtlasBaseClient {
*/
public List listTypes(final DataTypes.TypeCategory category, final String superType,
final String notSupertype) throws AtlasServiceException {
- JSONObject response = callAPIWithRetries(API.LIST_TYPES, null, new ResourceCreator() {
+ final API api = API_V1.LIST_TYPES;
+ JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.LIST_TYPES);
+ WebResource resource = getResource(api);
resource = resource.queryParam(TYPE, category.name());
resource = resource.queryParam(SUPERTYPE, superType);
resource = resource.queryParam(NOT_SUPERTYPE, notSupertype);
@@ -410,8 +394,8 @@ public class AtlasClient extends AtlasBaseClient {
public TypesDef getType(String typeName) throws AtlasServiceException {
try {
- JSONObject response = callAPIWithBodyAndParams(API.GET_TYPE, null, typeName);
- String typeJson = response.getString(DEFINITION);
+ JSONObject response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName);
+ String typeJson = response.getString(DEFINITION);
return TypesSerialization.fromJson(typeJson);
} catch (JSONException e) {
throw new AtlasServiceException(e);
@@ -426,8 +410,8 @@ public class AtlasClient extends AtlasBaseClient {
*/
protected List createEntity(JSONArray entities) throws AtlasServiceException {
LOG.debug("Creating entities: {}", entities);
- JSONObject response = callAPIWithBody(API.CREATE_ENTITY, entities.toString());
- List results = extractEntityResult(response).getCreatedEntities();
+ JSONObject response = callAPIWithBody(API_V1.CREATE_ENTITY, entities.toString());
+ List results = extractEntityResult(response).getCreatedEntities();
LOG.debug("Create entities returned results: {}", results);
return results;
}
@@ -476,8 +460,8 @@ public class AtlasClient extends AtlasBaseClient {
protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException {
LOG.debug("Updating entities: {}", entities);
- JSONObject response = callAPIWithBody(API.UPDATE_ENTITY, entities.toString());
- EntityResult results = extractEntityResult(response);
+ JSONObject response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString());
+ EntityResult results = extractEntityResult(response);
LOG.debug("Update entities returned results: {}", results);
return results;
}
@@ -497,10 +481,10 @@ public class AtlasClient extends AtlasBaseClient {
public EntityResult updateEntityAttribute(final String guid, final String attribute, String value)
throws AtlasServiceException {
LOG.debug("Updating entity id: {}, attribute name: {}, attribute value: {}", guid, attribute, value);
- JSONObject response = callAPIWithRetries(API.UPDATE_ENTITY_PARTIAL, value, new ResourceCreator() {
+ final API api = API_V1.UPDATE_ENTITY_PARTIAL;
+ JSONObject response = callAPIWithRetries(api, value, new ResourceCreator() {
@Override
public WebResource createResource() {
- API api = API.UPDATE_ENTITY_PARTIAL;
WebResource resource = getResource(api, guid);
resource = resource.queryParam(ATTRIBUTE_NAME, attribute);
return resource;
@@ -518,7 +502,7 @@ public class AtlasClient extends AtlasBaseClient {
public EntityResult updateEntity(String guid, Referenceable entity) throws AtlasServiceException {
String entityJson = InstanceSerialization.toJson(entity, true);
LOG.debug("Updating entity id {} with {}", guid, entityJson);
- JSONObject response = callAPIWithBodyAndParams(API.UPDATE_ENTITY_PARTIAL, entityJson, guid);
+ JSONObject response = callAPIWithBodyAndParams(API_V1.UPDATE_ENTITY_PARTIAL, entityJson, guid);
return extractEntityResult(response);
}
@@ -531,7 +515,7 @@ public class AtlasClient extends AtlasBaseClient {
public void addTrait(String guid, Struct traitDefinition) throws AtlasServiceException {
String traitJson = InstanceSerialization.toJson(traitDefinition, true);
LOG.debug("Adding trait to entity with id {} {}", guid, traitJson);
- callAPIWithBodyAndParams(API.ADD_TRAITS, traitJson, guid, URI_TRAITS);
+ callAPIWithBodyAndParams(API_V1.ADD_TRAITS, traitJson, guid, URI_TRAITS);
}
/**
@@ -541,7 +525,7 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public void deleteTrait(String guid, String traitName) throws AtlasServiceException {
- callAPIWithBodyAndParams(API.DELETE_TRAITS, null, guid, TRAITS, traitName);
+ callAPIWithBodyAndParams(API_V1.DELETE_TRAITS, null, guid, TRAITS, traitName);
}
/**
@@ -555,10 +539,10 @@ public class AtlasClient extends AtlasBaseClient {
public EntityResult updateEntity(final String entityType, final String uniqueAttributeName,
final String uniqueAttributeValue,
Referenceable entity) throws AtlasServiceException {
- final API api = API.UPDATE_ENTITY_PARTIAL;
- String entityJson = InstanceSerialization.toJson(entity, true);
+ final API api = API_V1.UPDATE_ENTITY_PARTIAL;
+ String entityJson = InstanceSerialization.toJson(entity, true);
LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType,
- uniqueAttributeName, uniqueAttributeValue, entityJson);
+ uniqueAttributeName, uniqueAttributeValue, entityJson);
JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
@Override
public WebResource createResource() {
@@ -589,12 +573,12 @@ public class AtlasClient extends AtlasBaseClient {
* @return List of entity ids updated/deleted
* @throws AtlasServiceException
*/
- public EntityResult deleteEntities(final String ... guids) throws AtlasServiceException {
+ public EntityResult deleteEntities(final String... guids) throws AtlasServiceException {
LOG.debug("Deleting entities: {}", guids);
- JSONObject jsonResponse = callAPIWithRetries(API.DELETE_ENTITIES, null, new ResourceCreator() {
+ final API api = API_V1.DELETE_ENTITIES;
+ JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- API api = API.DELETE_ENTITIES;
WebResource resource = getResource(api);
for (String guid : guids) {
resource = resource.queryParam(GUID.toLowerCase(), guid);
@@ -617,14 +601,14 @@ public class AtlasClient extends AtlasBaseClient {
public EntityResult deleteEntity(String entityType, String uniqueAttributeName, String uniqueAttributeValue)
throws AtlasServiceException {
LOG.debug("Deleting entity type: {}, attributeName: {}, attributeValue: {}", entityType, uniqueAttributeName,
- uniqueAttributeValue);
- API api = API.DELETE_ENTITY;
+ uniqueAttributeValue);
+ API api = API_V1.DELETE_ENTITIES;
WebResource resource = getResource(api);
resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
- JSONObject jsonResponse = callAPIWithResource(API.DELETE_ENTITIES, resource);
- EntityResult results = extractEntityResult(jsonResponse);
+ JSONObject jsonResponse = callAPIWithResource(api, resource);
+ EntityResult results = extractEntityResult(jsonResponse);
LOG.debug("Delete entities returned results: {}", results);
return results;
}
@@ -636,12 +620,12 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public Referenceable getEntity(String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ENTITY, null, guid);
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid);
try {
String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
} catch (JSONException e) {
- throw new AtlasServiceException(API.GET_ENTITY, e);
+ throw new AtlasServiceException(API_V1.GET_ENTITY, e);
}
}
@@ -663,10 +647,11 @@ public class AtlasClient extends AtlasBaseClient {
*/
public Referenceable getEntity(final String entityType, final String attribute, final String value)
throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithRetries(API.GET_ENTITY, null, new ResourceCreator() {
+ final API api = API_V1.GET_ENTITY;
+ JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.GET_ENTITY);
+ WebResource resource = getResource(api);
resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, attribute);
resource = resource.queryParam(ATTRIBUTE_VALUE, value);
@@ -677,7 +662,7 @@ public class AtlasClient extends AtlasBaseClient {
String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
} catch (JSONException e) {
- throw new AtlasServiceException(API.GET_ENTITY, e);
+ throw new AtlasServiceException(api, e);
}
}
@@ -688,10 +673,10 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public List listEntities(final String entityType) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithRetries(API.LIST_ENTITIES, null, new ResourceCreator() {
+ JSONObject jsonResponse = callAPIWithRetries(API_V1.LIST_ENTITIES, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.LIST_ENTITIES);
+ WebResource resource = getResource(API_V1.LIST_ENTITIES);
resource = resource.queryParam(TYPE, entityType);
return resource;
}
@@ -706,7 +691,7 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public List listTraits(final String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.LIST_TRAITS, null, guid, URI_TRAITS);
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.LIST_TRAITS, null, guid, URI_TRAITS);
return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation());
}
@@ -716,11 +701,11 @@ public class AtlasClient extends AtlasBaseClient {
* @return List trait definitions of the traits associated to the entity
* @throws AtlasServiceException
*/
- public List listTraitDefinitions(final String guid) throws AtlasServiceException{
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
- List traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation());
+ public List listTraitDefinitions(final String guid) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
+ List traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation());
ArrayList traitStructList = new ArrayList<>();
- for(JSONObject traitDef:traitDefList){
+ for (JSONObject traitDef : traitDefList) {
Struct traitStruct = InstanceSerialization.fromJsonStruct(traitDef.toString(), true);
traitStructList.add(traitStruct);
}
@@ -734,13 +719,13 @@ public class AtlasClient extends AtlasBaseClient {
* @return trait definition
* @throws AtlasServiceException
*/
- public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException{
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
+ public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
try {
return InstanceSerialization.fromJsonStruct(jsonResponse.getString(AtlasClient.RESULTS), false);
- }catch (JSONException e){
- throw new AtlasServiceException(API.GET_TRAIT_DEFINITION, e);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(API_V1.GET_TRAIT_DEFINITION, e);
}
}
@@ -753,7 +738,7 @@ public class AtlasClient extends AtlasBaseClient {
protected List extractResults(JSONObject jsonResponse, String key, ExtractOperation extractInterafce)
throws AtlasServiceException {
try {
- JSONArray results = jsonResponse.getJSONArray(key);
+ JSONArray results = jsonResponse.getJSONArray(key);
ArrayList resultsList = new ArrayList<>();
for (int index = 0; index < results.length(); index++) {
Object element = results.get(index);
@@ -787,13 +772,13 @@ public class AtlasClient extends AtlasBaseClient {
*/
public List getEntityAuditEvents(String entityId, String startKey, short numResults)
throws AtlasServiceException {
- WebResource resource = getResource(API.LIST_ENTITY_AUDIT, entityId, URI_ENTITY_AUDIT);
+ WebResource resource = getResource(API_V1.LIST_ENTITY_AUDIT, entityId, URI_ENTITY_AUDIT);
if (StringUtils.isNotEmpty(startKey)) {
resource = resource.queryParam(START_KEY, startKey);
}
resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults));
- JSONObject jsonResponse = callAPIWithResource(API.LIST_ENTITY_AUDIT, resource);
+ JSONObject jsonResponse = callAPIWithResource(API_V1.LIST_ENTITY_AUDIT, resource);
return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation() {
@Override
EntityAuditEvent extractElement(JSONObject element) throws JSONException {
@@ -812,10 +797,11 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public JSONArray search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException {
- JSONObject result = callAPIWithRetries(API.SEARCH, null, new ResourceCreator() {
+ final API api = API_V1.SEARCH;
+ JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.SEARCH);
+ WebResource resource = getResource(api);
resource = resource.queryParam(QUERY, searchQuery);
resource = resource.queryParam(LIMIT, String.valueOf(limit));
resource = resource.queryParam(OFFSET, String.valueOf(offset));
@@ -840,10 +826,11 @@ public class AtlasClient extends AtlasBaseClient {
*/
public JSONArray searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
LOG.debug("DSL query: {}", query);
- JSONObject result = callAPIWithRetries(API.SEARCH_DSL, null, new ResourceCreator() {
+ final API api = API_V1.SEARCH_DSL;
+ JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.SEARCH_DSL);
+ WebResource resource = getResource(api);
resource = resource.queryParam(QUERY, query);
resource = resource.queryParam(LIMIT, String.valueOf(limit));
resource = resource.queryParam(OFFSET, String.valueOf(offset));
@@ -866,10 +853,11 @@ public class AtlasClient extends AtlasBaseClient {
* @throws AtlasServiceException
*/
public JSONObject searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException {
- return callAPIWithRetries(API.SEARCH_FULL_TEXT, null, new ResourceCreator() {
+ final API api = API_V1.SEARCH_FULL_TEXT;
+ return callAPIWithRetries(api, null, new ResourceCreator() {
@Override
public WebResource createResource() {
- WebResource resource = getResource(API.SEARCH_FULL_TEXT);
+ WebResource resource = getResource(api);
resource = resource.queryParam(QUERY, query);
resource = resource.queryParam(LIMIT, String.valueOf(limit));
resource = resource.queryParam(OFFSET, String.valueOf(offset));
@@ -879,7 +867,7 @@ public class AtlasClient extends AtlasBaseClient {
}
public JSONObject getInputGraph(String datasetName) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
+ JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
try {
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
@@ -888,7 +876,7 @@ public class AtlasClient extends AtlasBaseClient {
}
public JSONObject getOutputGraph(String datasetName) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
+ JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
try {
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
@@ -897,7 +885,7 @@ public class AtlasClient extends AtlasBaseClient {
}
public JSONObject getInputGraphForEntity(String entityId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
+ JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
try {
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
@@ -906,7 +894,7 @@ public class AtlasClient extends AtlasBaseClient {
}
public JSONObject getOutputGraphForEntity(String datasetId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
+ JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
try {
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
@@ -915,7 +903,7 @@ public class AtlasClient extends AtlasBaseClient {
}
public JSONObject getSchemaForEntity(String datasetId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
+ JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
try {
return response.getJSONObject(AtlasClient.RESULTS);
} catch (JSONException e) {
@@ -926,37 +914,61 @@ public class AtlasClient extends AtlasBaseClient {
// Wrapper methods for compatibility
@VisibleForTesting
public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
- return callAPIWithResource(toAPIInfo(api), resource, null, JSONObject.class);
+ return callAPIWithResource(api, resource, null, JSONObject.class);
}
@VisibleForTesting
- public WebResource getResource(API api, String ... params) {
- return getResource(toAPIInfo(api), params);
+ public JSONObject callAPIWithResource(API_V1 apiV1, WebResource resource) throws AtlasServiceException {
+ return callAPIWithResource(apiV1, resource, null, JSONObject.class);
+ }
+
+ @VisibleForTesting
+ public WebResource getResource(API api, String... params) {
+ return getResource(api.getPath(), params);
+ }
+
+ @VisibleForTesting
+ public WebResource getResource(API_V1 apiV1, String... params) {
+ return getResource(apiV1.getPath(), params);
}
@VisibleForTesting
public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException {
- return callAPI(toAPIInfo(api), JSONObject.class, requestObject, (String[]) null);
+ return callAPI(api, JSONObject.class, requestObject, (String[]) null);
}
@VisibleForTesting
- public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String ... params) throws AtlasServiceException {
- return callAPI(toAPIInfo(api), JSONObject.class, requestObject, params);
+ public JSONObject callAPIWithBody(API_V1 apiV1, Object requestObject) throws AtlasServiceException {
+ return callAPI(apiV1, JSONObject.class, requestObject, (String[]) null);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String... params) throws AtlasServiceException {
+ return callAPI(api, JSONObject.class, requestObject, params);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithBodyAndParams(API_V1 apiV1, Object requestObject, String... params) throws AtlasServiceException {
+ return callAPI(apiV1, JSONObject.class, requestObject, params);
}
@VisibleForTesting
public JSONObject callAPIWithQueryParams(API api, MultivaluedMap queryParams) throws AtlasServiceException {
- return callAPI(toAPIInfo(api), JSONObject.class, queryParams);
+ return callAPI(api, JSONObject.class, queryParams);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithQueryParams(API_V1 apiV1, MultivaluedMap queryParams) throws AtlasServiceException {
+ return callAPI(apiV1, JSONObject.class, queryParams);
}
@VisibleForTesting
JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
- return super.callAPIWithRetries(toAPIInfo(api), requestObject, resourceCreator);
+ return super.callAPIWithRetries(api, requestObject, resourceCreator);
}
- private APIInfo toAPIInfo(API api){
- return new APIInfo(api.getPath(), api.getMethod(), api.getExpectedStatus());
+ @VisibleForTesting
+ JSONObject callAPIWithRetries(API_V1 apiV1, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
+ return super.callAPIWithRetries(apiV1, requestObject, resourceCreator);
}
-
-
}
diff --git a/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java b/client/client-v1/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
rename to client/client-v1/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
diff --git a/client/src/main/java/org/apache/atlas/EntityAuditEvent.java b/client/client-v1/src/main/java/org/apache/atlas/EntityAuditEvent.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/EntityAuditEvent.java
rename to client/client-v1/src/main/java/org/apache/atlas/EntityAuditEvent.java
diff --git a/client/src/main/java/org/apache/atlas/SerDe.java b/client/client-v1/src/main/java/org/apache/atlas/SerDe.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/SerDe.java
rename to client/client-v1/src/main/java/org/apache/atlas/SerDe.java
diff --git a/client/src/test/java/org/apache/atlas/AtlasClientTest.java b/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
similarity index 90%
rename from client/src/test/java/org/apache/atlas/AtlasClientTest.java
rename to client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
index c33906acf..1da6b4500 100644
--- a/client/src/test/java/org/apache/atlas/AtlasClientTest.java
+++ b/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
@@ -76,12 +76,12 @@ public class AtlasClientTest {
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(response.getEntity(String.class)).thenReturn("{\"Version\":\"version-rrelease\",\"Name\":\"apache-atlas\"," +
"\"Description\":\"Metadata Management and Data Governance Platform over Hadoop\"}");
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
assertTrue(atlasClient.isServerReady());
}
@@ -91,7 +91,7 @@ public class AtlasClientTest {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.CREATE_ENTITY, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.CREATE_ENTITY, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
@@ -106,7 +106,7 @@ public class AtlasClientTest {
assertEquals(ids.get(0), "id");
}
- private WebResource.Builder setupBuilder(AtlasClient.API api, WebResource webResource) {
+ private WebResource.Builder setupBuilder(AtlasClient.API_V1 api, WebResource webResource) {
when(webResource.path(api.getPath())).thenReturn(service);
return getBuilder(service);
}
@@ -115,8 +115,8 @@ public class AtlasClientTest {
public void shouldReturnFalseIfServerIsNotReady() throws AtlasServiceException {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenThrow(
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenThrow(
new ClientHandlerException());
assertFalse(atlasClient.isServerReady());
}
@@ -125,12 +125,12 @@ public class AtlasClientTest {
public void shouldReturnFalseIfServiceIsUnavailable() throws AtlasServiceException {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE);
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
assertFalse(atlasClient.isServerReady());
}
@@ -140,12 +140,12 @@ public class AtlasClientTest {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.INTERNAL_SERVER_ERROR);
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
atlasClient.isServerReady();
fail("Should throw exception");
@@ -157,13 +157,13 @@ public class AtlasClientTest {
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
String activeStatus = "{\"Status\":\"Active\"}";
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
// Fix after AtlasBaseClient
// atlasClient.setService();
@@ -179,11 +179,11 @@ public class AtlasClientTest {
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.INTERNAL_SERVER_ERROR);
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
String status = atlasClient.getAdminStatus();
fail("Should fail with AtlasServiceException");
@@ -194,11 +194,11 @@ public class AtlasClientTest {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(response.getEntity(String.class)).thenReturn("{\"status\":\"Active\"}");
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
String status = atlasClient.getAdminStatus();
assertEquals(status, AtlasClient.UNKNOWN_STATUS);
@@ -218,7 +218,7 @@ public class AtlasClientTest {
when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
when(client.resource(UriBuilder.fromUri("http://localhost:41000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse firstResponse = mock(ClientResponse.class);
when(firstResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
String passiveStatus = "{\"Status\":\"PASSIVE\"}";
@@ -229,7 +229,7 @@ public class AtlasClientTest {
String activeStatus = "{\"Status\":\"ACTIVE\"}";
when(secondResponse.getEntity(String.class)).thenReturn(activeStatus);
when(secondResponse.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
thenReturn(firstResponse).thenReturn(firstResponse).thenReturn(firstResponse).
thenReturn(secondResponse);
@@ -246,7 +246,7 @@ public class AtlasClientTest {
setupRetryParams();
when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
@@ -255,7 +255,7 @@ public class AtlasClientTest {
String activeStatus = "{\"Status\":\"ACTIVE\"}";
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
thenReturn(response).thenReturn(response).thenReturn(nextResponse);
AtlasClient atlasClient = new AtlasClient(service, configuration);
@@ -271,7 +271,7 @@ public class AtlasClientTest {
setupRetryParams();
when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
@@ -280,7 +280,7 @@ public class AtlasClientTest {
String activeStatus = "{\"Status\":\"ACTIVE\"}";
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
thenThrow(new ClientHandlerException("Simulating connection exception")).
thenReturn(response).
thenReturn(nextResponse);
@@ -300,11 +300,11 @@ public class AtlasClientTest {
setupRetryParams();
when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
thenThrow(new ClientHandlerException("Simulating connection exception")).
thenReturn(response).
thenReturn(response);
@@ -336,7 +336,7 @@ public class AtlasClientTest {
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.LIST_TYPES.getMethod(), ClientResponse.class, null)).
thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
thenReturn(response);
@@ -347,7 +347,7 @@ public class AtlasClientTest {
atlasClient.setService(service);
atlasClient.setConfiguration(configuration);
- atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
+ atlasClient.callAPIWithRetries(AtlasClient.API_V1.LIST_TYPES, null, resourceCreator);
verify(client).destroy();
verify(client).resource(UriBuilder.fromUri("http://localhost:31000").build());
@@ -371,7 +371,7 @@ public class AtlasClientTest {
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.LIST_TYPES.getMethod(), ClientResponse.class, null)).
thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
thenReturn(response);
@@ -383,7 +383,7 @@ public class AtlasClientTest {
atlasClient.setService(resourceObject);
atlasClient.setConfiguration(configuration);
- atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
+ atlasClient.callAPIWithRetries(AtlasClient.API_V1.LIST_TYPES, null, resourceCreator);
verify(client).destroy();
verify(client, times(2)).resource(UriBuilder.fromUri("http://localhost:31000").build());
@@ -412,7 +412,7 @@ public class AtlasClientTest {
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).
+ when(builder.method(AtlasClient.API_V1.LIST_TYPES.getMethod(), ClientResponse.class, null)).
thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
thenReturn(firstResponse).
thenReturn(response);
@@ -423,7 +423,7 @@ public class AtlasClientTest {
atlasClient.setService(resourceObject);
atlasClient.setConfiguration(configuration);
- atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
+ atlasClient.callAPIWithRetries(AtlasClient.API_V1.LIST_TYPES, null, resourceCreator);
verify(client).destroy();
diff --git a/client/client-v2/pom.xml b/client/client-v2/pom.xml
new file mode 100644
index 000000000..66013f591
--- /dev/null
+++ b/client/client-v2/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+
+ atlas-client
+ org.apache.atlas
+ 1.0.0-SNAPSHOT
+
+ 4.0.0
+
+ atlas-client-v2
+
+
+
+ org.apache.atlas
+ atlas-intg
+
+
+ org.apache.atlas
+ atlas-client-common
+ ${project.version}
+
+
+
diff --git a/client/src/main/java/org/apache/atlas/AtlasClientV2.java b/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
similarity index 65%
rename from client/src/main/java/org/apache/atlas/AtlasClientV2.java
rename to client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
index 2cb9e84b4..24a3ef63a 100644
--- a/client/src/main/java/org/apache/atlas/AtlasClientV2.java
+++ b/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
@@ -47,70 +47,28 @@ import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
-import static org.apache.atlas.AtlasClient.LIMIT;
-import static org.apache.atlas.AtlasClient.OFFSET;
-import static org.apache.atlas.AtlasClient.QUERY;
-
public class AtlasClientV2 extends AtlasBaseClient {
-
// Type APIs
- public static final String TYPES_API = BASE_URI + "v2/types/";
- private static final String TYPEDEFS_API = TYPES_API + "typedefs/";
- private static final String TYPEDEF_BY_NAME = TYPES_API + "typedef/name/";
- private static final String TYPEDEF_BY_GUID = TYPES_API + "typedef/guid/";
-
+ public static final String TYPES_API = BASE_URI + "v2/types/";
+ // Entity APIs
+ public static final String ENTITY_API = BASE_URI + "v2/entity/";
+ private static final String PREFIX_ATTR = "attr:";
+ private static final String TYPEDEFS_API = TYPES_API + "typedefs/";
+ private static final String TYPEDEF_BY_NAME = TYPES_API + "typedef/name/";
+ private static final String TYPEDEF_BY_GUID = TYPES_API + "typedef/guid/";
private static final String GET_BY_NAME_TEMPLATE = TYPES_API + "%s/name/%s";
private static final String GET_BY_GUID_TEMPLATE = TYPES_API + "%s/guid/%s";
-
- private static final APIInfo GET_TYPEDEF_BY_NAME = new APIInfo(TYPEDEF_BY_NAME, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo GET_TYPEDEF_BY_GUID = new APIInfo(TYPEDEF_BY_GUID, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo GET_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo CREATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.POST, Response.Status.OK);
- private static final APIInfo UPDATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.PUT, Response.Status.OK);
- private static final APIInfo DELETE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.DELETE, Response.Status.NO_CONTENT);
-
- // Entity APIs
- public static final String ENTITY_API = BASE_URI + "v2/entity/";
- private static final String ENTITY_BULK_API = ENTITY_API + "bulk/";
-
- private static final APIInfo GET_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.GET, Response.Status.OK);
- private static final APIInfo GET_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/", HttpMethod.GET, Response.Status.OK);
- public static final APIInfo CREATE_ENTITY = new APIInfo(ENTITY_API, HttpMethod.POST, Response.Status.OK);
- public static final APIInfo UPDATE_ENTITY = CREATE_ENTITY;
- public static final APIInfo UPDATE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/", HttpMethod.PUT, Response.Status.OK);
- private static final APIInfo DELETE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.DELETE, Response.Status.OK);
- public static final APIInfo DELETE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/", HttpMethod.DELETE, Response.Status.OK);
-
- private static final APIInfo GET_ENTITIES_BY_GUIDS = new APIInfo(ENTITY_BULK_API, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo CREATE_ENTITIES = new APIInfo(ENTITY_BULK_API, HttpMethod.POST, Response.Status.OK);
- private static final APIInfo UPDATE_ENTITIES = CREATE_ENTITIES;
- private static final APIInfo DELETE_ENTITIES_BY_GUIDS = new APIInfo(ENTITY_BULK_API, HttpMethod.DELETE, Response.Status.OK);
-
- private static final APIInfo GET_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.GET, Response.Status.OK);
- private static final APIInfo ADD_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.POST, Response.Status.NO_CONTENT);
- private static final APIInfo UPDATE_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.PUT, Response.Status.OK);
- private static final APIInfo DELETE_CLASSIFICATION = new APIInfo(ENTITY_API + "guid/%s/classification/%s", HttpMethod.DELETE, Response.Status.NO_CONTENT);
-
- public static final String PREFIX_ATTR = "attr:";
-
+ private static final String ENTITY_BULK_API = ENTITY_API + "bulk/";
// Lineage APIs
- private static final String LINEAGE_URI = BASE_URI + "v2/lineage/";
- private static final APIInfo LINEAGE_INFO = new APIInfo(LINEAGE_URI, HttpMethod.GET, Response.Status.OK);
-
+ private static final String LINEAGE_URI = BASE_URI + "v2/lineage/";
// Discovery APIs
- private static final String DISCOVERY_URI = BASE_URI + "v2/search";
- private static final String DSL_URI = DISCOVERY_URI + "/dsl";
- private static final String FULL_TEXT_URI = DISCOVERY_URI + "/fulltext";
- private static final String BASIC_SEARCH_URI = DISCOVERY_URI + "/basic";
+ private static final String DISCOVERY_URI = BASE_URI + "v2/search";
+ private static final String DSL_URI = DISCOVERY_URI + "/dsl";
+ private static final String FULL_TEXT_URI = DISCOVERY_URI + "/fulltext";
+ private static final String BASIC_SEARCH_URI = DISCOVERY_URI + "/basic";
private static final String FACETED_SEARCH_URI = BASIC_SEARCH_URI;
- private static final APIInfo DSL_SEARCH = new APIInfo(DSL_URI, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo FULL_TEXT_SEARCH = new APIInfo(FULL_TEXT_URI, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo BASIC_SEARCH = new APIInfo(BASIC_SEARCH_URI, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo FACETED_SEARCH = new APIInfo(FACETED_SEARCH_URI, HttpMethod.POST, Response.Status.OK);
-
-
public AtlasClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) {
super(baseUrl, basicAuthUserNamePassword);
}
@@ -155,12 +113,12 @@ public class AtlasClientV2 extends AtlasBaseClient {
* @return A composite wrapper object with lists of all type definitions
*/
public AtlasTypesDef getAllTypeDefs(SearchFilter searchFilter) throws AtlasServiceException {
- return callAPI(GET_ALL_TYPE_DEFS, AtlasTypesDef.class, searchFilter.getParams());
+ return callAPI(API_V2.GET_ALL_TYPE_DEFS, AtlasTypesDef.class, searchFilter.getParams());
}
public boolean typeWithGuidExists(String guid) {
try {
- callAPI(GET_TYPEDEF_BY_GUID, String.class, null, guid);
+ callAPI(API_V2.GET_TYPEDEF_BY_GUID, String.class, null, guid);
} catch (AtlasServiceException e) {
return false;
}
@@ -169,7 +127,7 @@ public class AtlasClientV2 extends AtlasBaseClient {
public boolean typeWithNameExists(String name) {
try {
- callAPI(GET_TYPEDEF_BY_NAME, String.class, null, name);
+ callAPI(API_V2.GET_TYPEDEF_BY_NAME, String.class, null, name);
} catch (AtlasServiceException e) {
return false;
}
@@ -249,7 +207,6 @@ public class AtlasClientV2 extends AtlasBaseClient {
return created.getClassificationDefs().get(0);
}
-
/**
* Bulk create APIs for all atlas type definitions, only new definitions will be created.
* Any changes to the existing definitions will be discarded
@@ -259,7 +216,7 @@ public class AtlasClientV2 extends AtlasBaseClient {
* created
*/
public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
- return callAPI(CREATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
+ return callAPI(API_V2.CREATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
}
/**
@@ -269,7 +226,7 @@ public class AtlasClientV2 extends AtlasBaseClient {
* @return A composite object with lists of type definitions that were updated
*/
public AtlasTypesDef updateAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
- return callAPI(UPDATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
+ return callAPI(API_V2.UPDATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
}
/**
@@ -278,54 +235,54 @@ public class AtlasClientV2 extends AtlasBaseClient {
* @param typesDef A composite object that captures all types to be deleted
*/
public void deleteAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
- callAPI(DELETE_ALL_TYPE_DEFS, (Class>)null, AtlasType.toJson(typesDef));
+ callAPI(API_V2.DELETE_ALL_TYPE_DEFS, (Class>)null, AtlasType.toJson(typesDef));
}
- /* Lineage Calls */
-
public AtlasLineageInfo getLineageInfo(final String guid, final LineageDirection direction, final int depth) throws AtlasServiceException {
MultivaluedMap queryParams = new MultivaluedMapImpl();
queryParams.add("direction", direction.toString());
queryParams.add("depth", String.valueOf(depth));
- return callAPI(LINEAGE_INFO, AtlasLineageInfo.class, queryParams, guid);
+ return callAPI(API_V2.LINEAGE_INFO, AtlasLineageInfo.class, queryParams, guid);
}
- /* Entity Calls */
-
public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException {
- return callAPI(GET_ENTITY_BY_GUID, AtlasEntityWithExtInfo.class, (MultivaluedMap) null, guid);
+ return callAPI(API_V2.GET_ENTITY_BY_GUID, AtlasEntityWithExtInfo.class, (MultivaluedMap) null, guid);
}
public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map attributes) throws AtlasServiceException {
MultivaluedMap queryParams = attributesToQueryParams(attributes);
- return callAPI(GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type);
+ return callAPI(API_V2.GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type);
}
public EntityMutationResponse updateEntityByAttribute(String type, Map attributes, AtlasEntityWithExtInfo entityInfo)
throws AtlasServiceException {
MultivaluedMap queryParams = attributesToQueryParams(attributes);
- return callAPI(UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type);
+ return callAPI(API_V2.UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type);
}
+ /* Lineage Calls */
+
public EntityMutationResponse deleteEntityByAttribute(String type, Map attributes) throws AtlasServiceException {
MultivaluedMap queryParams = attributesToQueryParams(attributes);
- return callAPI(DELETE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, queryParams, type);
+ return callAPI(API_V2.DELETE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, queryParams, type);
}
+ /* Entity Calls */
+
public EntityMutationResponse createEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException {
- return callAPI(CREATE_ENTITY, EntityMutationResponse.class, entity);
+ return callAPI(API_V2.CREATE_ENTITY, EntityMutationResponse.class, entity);
}
public EntityMutationResponse updateEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException {
- return callAPI(UPDATE_ENTITY, EntityMutationResponse.class, entity);
+ return callAPI(API_V2.UPDATE_ENTITY, EntityMutationResponse.class, entity);
}
public EntityMutationResponse deleteEntityByGuid(String guid) throws AtlasServiceException {
- return callAPI(DELETE_ENTITY_BY_GUID, EntityMutationResponse.class, null, guid);
+ return callAPI(API_V2.DELETE_ENTITY_BY_GUID, EntityMutationResponse.class, null, guid);
}
public AtlasEntitiesWithExtInfo getEntitiesByGuids(List guids) throws AtlasServiceException {
@@ -333,41 +290,95 @@ public class AtlasClientV2 extends AtlasBaseClient {
queryParams.put("guid", guids);
- return callAPI(GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams);
+ return callAPI(API_V2.GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams);
}
public EntityMutationResponse createEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException {
- return callAPI(CREATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
+ return callAPI(API_V2.CREATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
}
public EntityMutationResponse updateEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException {
- return callAPI(UPDATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
+ return callAPI(API_V2.UPDATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
}
public EntityMutationResponse deleteEntitiesByGuids(List guids) throws AtlasServiceException {
- return callAPI(DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse.class, "guid", guids);
+ return callAPI(API_V2.DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse.class, "guid", guids);
}
public AtlasClassifications getClassifications(String guid) throws AtlasServiceException {
- return callAPI(updatePathParameters(GET_CLASSIFICATIONS, guid), AtlasClassifications.class, null);
+ return callAPI(formatPathParameters(API_V2.GET_CLASSIFICATIONS, guid), AtlasClassifications.class, null);
}
public void addClassifications(String guid, List classifications) throws AtlasServiceException {
- callAPI(updatePathParameters(ADD_CLASSIFICATIONS, guid), (Class>)null, classifications, (String[]) null);
+ callAPI(formatPathParameters(API_V2.ADD_CLASSIFICATIONS, guid), (Class>)null, classifications, (String[]) null);
}
public void updateClassifications(String guid, List classifications) throws AtlasServiceException {
- callAPI(updatePathParameters(UPDATE_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
+ callAPI(formatPathParameters(API_V2.UPDATE_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
}
public void deleteClassifications(String guid, List classifications) throws AtlasServiceException {
- callAPI(updatePathParameters(GET_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
+ callAPI(formatPathParameters(API_V2.GET_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
}
public void deleteClassification(String guid, String classificationName) throws AtlasServiceException {
- callAPI(updatePathParameters(DELETE_CLASSIFICATION, guid, classificationName), null, null);
+ callAPI(formatPathParameters(API_V2.DELETE_CLASSIFICATION, guid, classificationName), null, null);
}
+ /* Discovery calls */
+ public AtlasSearchResult dslSearch(final String query) throws AtlasServiceException {
+ MultivaluedMap queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+
+ return callAPI(API_V2.DSL_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult dslSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
+ MultivaluedMap queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+ queryParams.add(LIMIT, String.valueOf(limit));
+ queryParams.add(OFFSET, String.valueOf(offset));
+
+ return callAPI(API_V2.DSL_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult fullTextSearch(final String query) throws AtlasServiceException {
+ MultivaluedMap queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+
+ return callAPI(API_V2.FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult fullTextSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
+ MultivaluedMap queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+ queryParams.add(LIMIT, String.valueOf(limit));
+ queryParams.add(OFFSET, String.valueOf(offset));
+
+ return callAPI(API_V2.FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult basicSearch(final String typeName, final String classification, final String query,
+ final boolean excludeDeletedEntities, final int limit, final int offset) throws AtlasServiceException {
+ MultivaluedMap queryParams = new MultivaluedMapImpl();
+ queryParams.add("typeName", typeName);
+ queryParams.add("classification", classification);
+ queryParams.add(QUERY, query);
+ queryParams.add("excludeDeletedEntities", String.valueOf(excludeDeletedEntities));
+ queryParams.add(LIMIT, String.valueOf(limit));
+ queryParams.add(OFFSET, String.valueOf(offset));
+
+ return callAPI(API_V2.BASIC_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult facetedSearch(SearchParameters searchParameters) throws AtlasServiceException {
+ return callAPI(API_V2.FACETED_SEARCH, AtlasSearchResult.class, searchParameters);
+ }
+
+ @Override
+ protected API formatPathParameters(final API api, final String... params) {
+ return new API(String.format(api.getPath(), params), api.getMethod(), api.getExpectedStatus());
+ }
private MultivaluedMap attributesToQueryParams(Map attributes) {
return attributesToQueryParams(attributes, null);
@@ -388,66 +399,16 @@ public class AtlasClientV2 extends AtlasBaseClient {
return queryParams;
}
- /* Discovery calls */
- public AtlasSearchResult dslSearch(final String query) throws AtlasServiceException {
- MultivaluedMap queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
-
- return callAPI(DSL_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult dslSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
- MultivaluedMap queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
- queryParams.add(LIMIT, String.valueOf(limit));
- queryParams.add(OFFSET, String.valueOf(offset));
-
- return callAPI(DSL_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult fullTextSearch(final String query) throws AtlasServiceException {
- MultivaluedMap queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
-
- return callAPI(FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult fullTextSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
- MultivaluedMap queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
- queryParams.add(LIMIT, String.valueOf(limit));
- queryParams.add(OFFSET, String.valueOf(offset));
-
- return callAPI(FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult basicSearch(final String typeName, final String classification, final String query,
- final boolean excludeDeletedEntities, final int limit, final int offset) throws AtlasServiceException {
- MultivaluedMap queryParams = new MultivaluedMapImpl();
- queryParams.add("typeName", typeName);
- queryParams.add("classification", classification);
- queryParams.add(QUERY, query);
- queryParams.add("excludeDeletedEntities", String.valueOf(excludeDeletedEntities));
- queryParams.add(LIMIT, String.valueOf(limit));
- queryParams.add(OFFSET, String.valueOf(offset));
-
- return callAPI(BASIC_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult facetedSearch(SearchParameters searchParameters) throws AtlasServiceException {
- return callAPI(FACETED_SEARCH, AtlasSearchResult.class, searchParameters);
- }
-
private T getTypeDefByName(final String name, Class typeDefClass) throws AtlasServiceException {
String atlasPath = getAtlasPath(typeDefClass);
- APIInfo apiInfo = new APIInfo(String.format(GET_BY_NAME_TEMPLATE, atlasPath, name), HttpMethod.GET, Response.Status.OK);
- return callAPI(apiInfo, typeDefClass, null);
+ API api = new API(String.format(GET_BY_NAME_TEMPLATE, atlasPath, name), HttpMethod.GET, Response.Status.OK);
+ return callAPI(api, typeDefClass, null);
}
private T getTypeDefByGuid(final String guid, Class typeDefClass) throws AtlasServiceException {
String atlasPath = getAtlasPath(typeDefClass);
- APIInfo apiInfo = new APIInfo(String.format(GET_BY_GUID_TEMPLATE, atlasPath, guid), HttpMethod.GET, Response.Status.OK);
- return callAPI(apiInfo, typeDefClass, null);
+ API api = new API(String.format(GET_BY_GUID_TEMPLATE, atlasPath, guid), HttpMethod.GET, Response.Status.OK);
+ return callAPI(api, typeDefClass, null);
}
private String getAtlasPath(Class typeDefClass) {
@@ -463,4 +424,37 @@ public class AtlasClientV2 extends AtlasBaseClient {
// Code should never reach this point
return "";
}
+
+ public static class API_V2 extends API {
+ public static final API_V2 GET_TYPEDEF_BY_NAME = new API_V2(TYPEDEF_BY_NAME, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 GET_TYPEDEF_BY_GUID = new API_V2(TYPEDEF_BY_GUID, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 GET_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 CREATE_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.PUT, Response.Status.OK);
+ public static final API_V2 DELETE_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.DELETE, Response.Status.NO_CONTENT);
+ public static final API_V2 GET_ENTITY_BY_GUID = new API_V2(ENTITY_API + "guid/", HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 GET_ENTITY_BY_ATTRIBUTE = new API_V2(ENTITY_API + "uniqueAttribute/type/", HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 CREATE_ENTITY = new API_V2(ENTITY_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ENTITY = new API_V2(ENTITY_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ENTITY_BY_ATTRIBUTE = new API_V2(ENTITY_API + "uniqueAttribute/type/", HttpMethod.PUT, Response.Status.OK);
+ public static final API_V2 DELETE_ENTITY_BY_GUID = new API_V2(ENTITY_API + "guid/", HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V2 DELETE_ENTITY_BY_ATTRIBUTE = new API_V2(ENTITY_API + "uniqueAttribute/type/", HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V2 GET_ENTITIES_BY_GUIDS = new API_V2(ENTITY_BULK_API, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 CREATE_ENTITIES = new API_V2(ENTITY_BULK_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ENTITIES = new API_V2(ENTITY_BULK_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 DELETE_ENTITIES_BY_GUIDS = new API_V2(ENTITY_BULK_API, HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V2 GET_CLASSIFICATIONS = new API_V2(ENTITY_API + "guid/%s/classifications", HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 ADD_CLASSIFICATIONS = new API_V2(ENTITY_API + "guid/%s/classifications", HttpMethod.POST, Response.Status.NO_CONTENT);
+ public static final API_V2 UPDATE_CLASSIFICATIONS = new API_V2(ENTITY_API + "guid/%s/classifications", HttpMethod.PUT, Response.Status.OK);
+ public static final API_V2 DELETE_CLASSIFICATION = new API_V2(ENTITY_API + "guid/%s/classification/%s", HttpMethod.DELETE, Response.Status.NO_CONTENT);
+ public static final API_V2 LINEAGE_INFO = new API_V2(LINEAGE_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 DSL_SEARCH = new API_V2(DSL_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 FULL_TEXT_SEARCH = new API_V2(FULL_TEXT_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 BASIC_SEARCH = new API_V2(BASIC_SEARCH_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 FACETED_SEARCH = new API_V2(FACETED_SEARCH_URI, HttpMethod.POST, Response.Status.OK);
+
+ private API_V2(String path, String method, Response.Status status) {
+ super(path, method, status);
+ }
+ }
}
diff --git a/client/common/pom.xml b/client/common/pom.xml
new file mode 100644
index 000000000..c6ef0b8aa
--- /dev/null
+++ b/client/common/pom.xml
@@ -0,0 +1,48 @@
+
+
+
+
+ atlas-client
+ org.apache.atlas
+ 1.0.0-SNAPSHOT
+
+ 4.0.0
+
+ atlas-client-common
+
+
+
+
+ org.apache.httpcomponents
+ httpclient
+
+
+
+ com.sun.jersey
+ jersey-client
+
+
+
+ org.apache.atlas
+ atlas-intg
+
+
+
\ No newline at end of file
diff --git a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
similarity index 86%
rename from client/src/main/java/org/apache/atlas/AtlasBaseClient.java
rename to client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
index 602831a2d..5e1d10180 100644
--- a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
@@ -58,16 +58,21 @@ public abstract class AtlasBaseClient {
public static final String ADMIN_STATUS = "admin/status";
public static final String ADMIN_METRICS = "admin/metrics";
public static final String HTTP_AUTHENTICATION_ENABLED = "atlas.http.authentication.enabled";
- //Admin operations
- public static final APIInfo VERSION = new APIInfo(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK);
- public static final APIInfo STATUS = new APIInfo(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK);
- public static final APIInfo METRICS = new APIInfo(BASE_URI + ADMIN_METRICS, HttpMethod.GET, Response.Status.OK);
- static final String JSON_MEDIA_TYPE = MediaType.APPLICATION_JSON + "; charset=UTF-8";
- static final String UNKNOWN_STATUS = "Unknown status";
- static final String ATLAS_CLIENT_HA_RETRIES_KEY = "atlas.client.ha.retries";
+
+ public static final String QUERY = "query";
+ public static final String LIMIT = "limit";
+ public static final String OFFSET = "offset";
+
+ public static final API API_STATUS = new API(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK);;
+ public static final API API_VERSION = new API(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK);;
+ public static final API API_METRICS = new API(BASE_URI + ADMIN_METRICS, HttpMethod.GET, Response.Status.OK);;
+
+ static final String JSON_MEDIA_TYPE = MediaType.APPLICATION_JSON + "; charset=UTF-8";
+ static final String UNKNOWN_STATUS = "Unknown status";
+ static final String ATLAS_CLIENT_HA_RETRIES_KEY = "atlas.client.ha.retries";
// Setting the default value based on testing failovers while client code like quickstart is running.
- static final int DEFAULT_NUM_RETRIES = 4;
- static final String ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY = "atlas.client.ha.sleep.interval.ms";
+ static final int DEFAULT_NUM_RETRIES = 4;
+ static final String ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY = "atlas.client.ha.sleep.interval.ms";
// Setting the default value based on testing failovers while client code like quickstart is running.
// With number of retries, this gives a total time of about 20s for the server to start.
static final int DEFAULT_SLEEP_BETWEEN_RETRIES_MS = 5000;
@@ -133,10 +138,6 @@ public abstract class AtlasBaseClient {
initializeState(configuration, baseUrl, null, null);
}
- public void setCookie(Cookie cookie) {
- this.cookie = cookie;
- }
-
protected static UserGroupInformation getCurrentUGI() throws AtlasException {
try {
return UserGroupInformation.getCurrentUser();
@@ -145,22 +146,89 @@ public abstract class AtlasBaseClient {
}
}
- void initializeState(String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
- initializeState(getClientProperties(), baseUrls, ugi, doAsUser);
+ public void setCookie(Cookie cookie) {
+ this.cookie = cookie;
}
- void initializeState(Configuration configuration, String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
- this.configuration = configuration;
- Client client = getClient(configuration, ugi, doAsUser);
-
- if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
- final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(basicAuthUser, basicAuthPassword);
- client.addFilter(authFilter);
+ public boolean isServerReady() throws AtlasServiceException {
+ WebResource resource = getResource(API_VERSION.getPath());
+ try {
+ callAPIWithResource(API_VERSION, resource, null, JSONObject.class);
+ return true;
+ } catch (ClientHandlerException che) {
+ return false;
+ } catch (AtlasServiceException ase) {
+ if (ase.getStatus() != null && ase.getStatus().equals(ClientResponse.Status.SERVICE_UNAVAILABLE)) {
+ LOG.warn("Received SERVICE_UNAVAILABLE, server is not yet ready");
+ return false;
+ }
+ throw ase;
}
+ }
- String activeServiceUrl = determineActiveServiceURL(baseUrls, client);
- atlasClientContext = new AtlasClientContext(baseUrls, client, ugi, doAsUser);
- service = client.resource(UriBuilder.fromUri(activeServiceUrl).build());
+ /**
+ * Return status of the service instance the client is pointing to.
+ *
+ * @return One of the values in ServiceState.ServiceStateValue or {@link #UNKNOWN_STATUS} if
+ * there is a JSON parse exception
+ * @throws AtlasServiceException if there is a HTTP error.
+ */
+ public String getAdminStatus() throws AtlasServiceException {
+ String result = AtlasBaseClient.UNKNOWN_STATUS;
+ WebResource resource = getResource(service, API_STATUS.getPath());
+ JSONObject response = callAPIWithResource(API_STATUS, resource, null, JSONObject.class);
+ try {
+ result = response.getString("Status");
+ } catch (JSONException e) {
+ LOG.error("Exception while parsing admin status response. Returned response {}", response.toString(), e);
+ }
+ return result;
+ }
+
+ /**
+ * @return Return metrics of the service instance the client is pointing to
+ * @throws AtlasServiceException
+ */
+ public AtlasMetrics getAtlasMetrics() throws AtlasServiceException {
+ return callAPI(API_METRICS, AtlasMetrics.class, null);
+ }
+
+ public T callAPI(API api, Class responseType, Object requestObject, String... params)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
+ }
+
+ public T callAPI(API api, GenericType responseType, Object requestObject, String... params)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
+ }
+
+ public T callAPI(API api, Class responseType, Object requestBody,
+ MultivaluedMap queryParams, String... params) throws AtlasServiceException {
+ WebResource resource = getResource(api, queryParams, params);
+ return callAPIWithResource(api, resource, requestBody, responseType);
+ }
+
+ public T callAPI(API api, Class responseType, MultivaluedMap queryParams, String... params)
+ throws AtlasServiceException {
+ WebResource resource = getResource(api, queryParams, params);
+ return callAPIWithResource(api, resource, null, responseType);
+ }
+
+ public T callAPI(API api, GenericType responseType, MultivaluedMap queryParams, String... params)
+ throws AtlasServiceException {
+ WebResource resource = getResource(api, queryParams, params);
+ return callAPIWithResource(api, resource, null, responseType);
+ }
+
+ public T callAPI(API api, Class responseType, MultivaluedMap queryParams)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, queryParams), null, responseType);
+ }
+
+ public T callAPI(API api, Class responseType, String queryParamKey, List queryParamValues)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, queryParamKey, queryParamValues), null, responseType);
}
@VisibleForTesting
@@ -219,44 +287,6 @@ public abstract class AtlasBaseClient {
return baseUrl;
}
- private String selectActiveServerAddress(Client client, AtlasServerEnsemble serverEnsemble)
- throws AtlasServiceException {
- List serverInstances = serverEnsemble.getMembers();
- String activeServerAddress = null;
- for (String serverInstance : serverInstances) {
- LOG.info("Trying with address {}", serverInstance);
- activeServerAddress = getAddressIfActive(client, serverInstance);
- if (activeServerAddress != null) {
- LOG.info("Found service {} as active service.", serverInstance);
- break;
- }
- }
- if (activeServerAddress != null)
- return activeServerAddress;
- else
- throw new AtlasServiceException(STATUS, new RuntimeException("Could not find any active instance"));
- }
-
- private String getAddressIfActive(Client client, String serverInstance) {
- String activeServerAddress = null;
- for (int i = 0; i < getNumberOfRetries(); i++) {
- try {
- service = client.resource(UriBuilder.fromUri(serverInstance).build());
- String adminStatus = getAdminStatus();
- if (StringUtils.equals(adminStatus, "ACTIVE")) {
- activeServerAddress = serverInstance;
- break;
- } else {
- LOG.info("attempt #{}: Service {} - is not active. status={}", (i + 1), serverInstance, adminStatus);
- }
- } catch (Exception e) {
- LOG.error("attempt #{}: Service {} - could not get status", (i + 1), serverInstance, e);
- }
- sleepBetweenRetries();
- }
- return activeServerAddress;
- }
-
protected Configuration getClientProperties() {
try {
if (configuration == null) {
@@ -268,27 +298,11 @@ public abstract class AtlasBaseClient {
return configuration;
}
- public boolean isServerReady() throws AtlasServiceException {
- WebResource resource = getResource(VERSION.getPath());
- try {
- callAPIWithResource(VERSION, resource, null, JSONObject.class);
- return true;
- } catch (ClientHandlerException che) {
- return false;
- } catch (AtlasServiceException ase) {
- if (ase.getStatus() != null && ase.getStatus().equals(ClientResponse.Status.SERVICE_UNAVAILABLE)) {
- LOG.warn("Received SERVICE_UNAVAILABLE, server is not yet ready");
- return false;
- }
- throw ase;
- }
- }
-
protected WebResource getResource(String path, String... pathParams) {
return getResource(service, path, pathParams);
}
- protected T callAPIWithResource(APIInfo api, WebResource resource, Object requestObject, Class responseType) throws AtlasServiceException {
+ protected T callAPIWithResource(API api, WebResource resource, Object requestObject, Class responseType) throws AtlasServiceException {
GenericType genericType = null;
if (responseType != null) {
genericType = new GenericType<>(responseType);
@@ -296,7 +310,7 @@ public abstract class AtlasBaseClient {
return callAPIWithResource(api, resource, requestObject, genericType);
}
- protected T callAPIWithResource(APIInfo api, WebResource resource, Object requestObject, GenericType responseType) throws AtlasServiceException {
+ protected T callAPIWithResource(API api, WebResource resource, Object requestObject, GenericType responseType) throws AtlasServiceException {
ClientResponse clientResponse = null;
int i = 0;
do {
@@ -356,12 +370,41 @@ public abstract class AtlasBaseClient {
throw new AtlasServiceException(api, clientResponse);
}
- private WebResource getResource(WebResource service, String path, String... pathParams) {
- WebResource resource = service.path(path);
+ protected WebResource getResource(API api, String... pathParams) {
+ return getResource(service, api, pathParams);
+ }
+
+ protected WebResource getResource(API api, MultivaluedMap queryParams, String... pathParams) {
+ WebResource resource = service.path(api.getPath());
resource = appendPathParams(resource, pathParams);
+ resource = appendQueryParams(queryParams, resource);
return resource;
}
+ protected WebResource getResource(API api, MultivaluedMap queryParams) {
+ return getResource(service, api, queryParams);
+ }
+
+ protected abstract API formatPathParameters(API api, String ... params);
+
+ void initializeState(String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
+ initializeState(getClientProperties(), baseUrls, ugi, doAsUser);
+ }
+
+ void initializeState(Configuration configuration, String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
+ this.configuration = configuration;
+ Client client = getClient(configuration, ugi, doAsUser);
+
+ if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
+ final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(basicAuthUser, basicAuthPassword);
+ client.addFilter(authFilter);
+ }
+
+ String activeServiceUrl = determineActiveServiceURL(baseUrls, client);
+ atlasClientContext = new AtlasClientContext(baseUrls, client, ugi, doAsUser);
+ service = client.resource(UriBuilder.fromUri(activeServiceUrl).build());
+ }
+
void sleepBetweenRetries() {
try {
Thread.sleep(getSleepBetweenRetriesMs());
@@ -374,37 +417,6 @@ public abstract class AtlasBaseClient {
return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_RETRIES_KEY, AtlasBaseClient.DEFAULT_NUM_RETRIES);
}
- private int getSleepBetweenRetriesMs() {
- return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY, AtlasBaseClient.DEFAULT_SLEEP_BETWEEN_RETRIES_MS);
- }
-
- /**
- * Return status of the service instance the client is pointing to.
- *
- * @return One of the values in ServiceState.ServiceStateValue or {@link #UNKNOWN_STATUS} if
- * there is a JSON parse exception
- * @throws AtlasServiceException if there is a HTTP error.
- */
- public String getAdminStatus() throws AtlasServiceException {
- String result = AtlasBaseClient.UNKNOWN_STATUS;
- WebResource resource = getResource(service, STATUS.getPath());
- JSONObject response = callAPIWithResource(STATUS, resource, null, JSONObject.class);
- try {
- result = response.getString("Status");
- } catch (JSONException e) {
- LOG.error("Exception while parsing admin status response. Returned response {}", response.toString(), e);
- }
- return result;
- }
-
- /**
- * @return Return metrics of the service instance the client is pointing to
- * @throws AtlasServiceException
- */
- public AtlasMetrics getAtlasMetrics() throws AtlasServiceException {
- return callAPI(METRICS, AtlasMetrics.class, null);
- }
-
boolean isRetryableException(ClientHandlerException che) {
return che.getCause().getClass().equals(IOException.class)
|| che.getCause().getClass().equals(ConnectException.class);
@@ -424,7 +436,7 @@ public abstract class AtlasBaseClient {
}
@VisibleForTesting
- JSONObject callAPIWithRetries(APIInfo api, Object requestObject, ResourceCreator resourceCreator)
+ JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator)
throws AtlasServiceException {
for (int i = 0; i < getNumberOfRetries(); i++) {
WebResource resource = resourceCreator.createResource();
@@ -443,57 +455,72 @@ public abstract class AtlasBaseClient {
throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries."));
}
- public T callAPI(APIInfo api, Class responseType, Object requestObject, String... params)
+ @VisibleForTesting
+ void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ @VisibleForTesting
+ void setService(WebResource resource) {
+ this.service = resource;
+ }
+
+ private String selectActiveServerAddress(Client client, AtlasServerEnsemble serverEnsemble)
throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
+ List serverInstances = serverEnsemble.getMembers();
+ String activeServerAddress = null;
+ for (String serverInstance : serverInstances) {
+ LOG.info("Trying with address {}", serverInstance);
+ activeServerAddress = getAddressIfActive(client, serverInstance);
+ if (activeServerAddress != null) {
+ LOG.info("Found service {} as active service.", serverInstance);
+ break;
+ }
+ }
+ if (activeServerAddress != null)
+ return activeServerAddress;
+ else
+ throw new AtlasServiceException(API_STATUS, new RuntimeException("Could not find any active instance"));
}
- public T callAPI(APIInfo api, GenericType responseType, Object requestObject, String... params)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
+ private String getAddressIfActive(Client client, String serverInstance) {
+ String activeServerAddress = null;
+ for (int i = 0; i < getNumberOfRetries(); i++) {
+ try {
+ service = client.resource(UriBuilder.fromUri(serverInstance).build());
+ String adminStatus = getAdminStatus();
+ if (StringUtils.equals(adminStatus, "ACTIVE")) {
+ activeServerAddress = serverInstance;
+ break;
+ } else {
+ LOG.info("attempt #{}: Service {} - is not active. status={}", (i + 1), serverInstance, adminStatus);
+ }
+ } catch (Exception e) {
+ LOG.error("attempt #{}: Service {} - could not get status", (i + 1), serverInstance, e);
+ }
+ sleepBetweenRetries();
+ }
+ return activeServerAddress;
}
-
- public T callAPI(APIInfo api, Class responseType, Object requestBody,
- MultivaluedMap queryParams, String... params) throws AtlasServiceException {
- WebResource resource = getResource(api, queryParams, params);
- return callAPIWithResource(api, resource, requestBody, responseType);
+ private WebResource getResource(WebResource service, String path, String... pathParams) {
+ WebResource resource = service.path(path);
+ resource = appendPathParams(resource, pathParams);
+ return resource;
}
- public T callAPI(APIInfo api, Class responseType, MultivaluedMap queryParams, String... params)
- throws AtlasServiceException {
- WebResource resource = getResource(api, queryParams, params);
- return callAPIWithResource(api, resource, null, responseType);
- }
-
- public T callAPI(APIInfo api, GenericType responseType, MultivaluedMap queryParams, String... params)
- throws AtlasServiceException {
- WebResource resource = getResource(api, queryParams, params);
- return callAPIWithResource(api, resource, null, responseType);
- }
-
- protected WebResource getResource(APIInfo api, String... pathParams) {
- return getResource(service, api, pathParams);
+ private int getSleepBetweenRetriesMs() {
+ return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY, AtlasBaseClient.DEFAULT_SLEEP_BETWEEN_RETRIES_MS);
}
// Modify URL to include the path params
- private WebResource getResource(WebResource service, APIInfo api, String... pathParams) {
+ private WebResource getResource(WebResource service, API api, String... pathParams) {
WebResource resource = service.path(api.getPath());
resource = appendPathParams(resource, pathParams);
return resource;
}
- public T callAPI(APIInfo api, Class responseType, MultivaluedMap queryParams)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, queryParams), null, responseType);
- }
-
- public T callAPI(APIInfo api, Class responseType, String queryParamKey, List queryParamValues)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, queryParamKey, queryParamValues), null, responseType);
- }
-
- private WebResource getResource(APIInfo api, String queryParamKey, List queryParamValues) {
+ private WebResource getResource(API api, String queryParamKey, List queryParamValues) {
WebResource resource = service.path(api.getPath());
for (String queryParamValue : queryParamValues) {
if (StringUtils.isNotBlank(queryParamKey) && StringUtils.isNotBlank(queryParamValue)) {
@@ -503,13 +530,6 @@ public abstract class AtlasBaseClient {
return resource;
}
- protected WebResource getResource(APIInfo api, MultivaluedMap queryParams, String... pathParams) {
- WebResource resource = service.path(api.getPath());
- resource = appendPathParams(resource, pathParams);
- resource = appendQueryParams(queryParams, resource);
- return resource;
- }
-
private WebResource appendPathParams(WebResource resource, String[] pathParams) {
if (pathParams != null) {
for (String pathParam : pathParams) {
@@ -519,12 +539,8 @@ public abstract class AtlasBaseClient {
return resource;
}
- protected WebResource getResource(APIInfo api, MultivaluedMap queryParams) {
- return getResource(service, api, queryParams);
- }
-
// Modify URL to include the query params
- private WebResource getResource(WebResource service, APIInfo api, MultivaluedMap queryParams) {
+ private WebResource getResource(WebResource service, API api, MultivaluedMap queryParams) {
WebResource resource = service.path(api.getPath());
resource = appendQueryParams(queryParams, resource);
return resource;
@@ -543,27 +559,12 @@ public abstract class AtlasBaseClient {
return resource;
}
- protected APIInfo updatePathParameters(APIInfo apiInfo, String... params) {
- return new APIInfo(String.format(apiInfo.getPath(), params), apiInfo.getMethod(), apiInfo.getExpectedStatus());
- }
-
- @VisibleForTesting
- void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- }
-
- @VisibleForTesting
- void setService(WebResource resource) {
- this.service = resource;
- }
-
-
- public static class APIInfo {
+ public static class API {
private final String method;
private final String path;
private final Response.Status status;
- public APIInfo(String path, String method, Response.Status status) {
+ public API(String path, String method, Response.Status status) {
this.path = path;
this.method = method;
this.status = status;
diff --git a/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java b/client/common/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
rename to client/common/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
diff --git a/client/src/main/java/org/apache/atlas/AtlasServiceException.java b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
similarity index 56%
rename from client/src/main/java/org/apache/atlas/AtlasServiceException.java
rename to client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
index b128f9825..83f4f8d27 100755
--- a/client/src/main/java/org/apache/atlas/AtlasServiceException.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
@@ -27,41 +27,22 @@ import javax.ws.rs.WebApplicationException;
public class AtlasServiceException extends Exception {
private ClientResponse.Status status;
- public AtlasServiceException(AtlasClient.API api, Exception e) {
- super("Metadata service API " + api + " failed", e);
- }
-
- public AtlasServiceException(AtlasBaseClient.APIInfo api, Exception e) {
+ public AtlasServiceException(AtlasBaseClient.API api, Exception e) {
super("Metadata service API " + api.getMethod() + " : " + api.getPath() + " failed", e);
}
- public AtlasServiceException(AtlasClient.API api, WebApplicationException e) throws JSONException {
+ public AtlasServiceException(AtlasBaseClient.API api, WebApplicationException e) throws JSONException {
this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
- ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
+ ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
}
- public AtlasServiceException(AtlasBaseClient.APIInfo api, WebApplicationException e) throws JSONException {
- this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
- ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
- }
-
- private AtlasServiceException(AtlasClient.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)
+ " (" + status + ") Response Body (" + response + ")");
this.status = status;
}
- private AtlasServiceException(AtlasBaseClient.APIInfo api, ClientResponse.Status status, String response) {
- super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1)
- + " (" + status + ") Response Body (" + response + ")");
- this.status = status;
- }
-
- public AtlasServiceException(AtlasClient.API api, ClientResponse response) {
- this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class));
- }
-
- public AtlasServiceException(AtlasBaseClient.APIInfo api, ClientResponse response) {
+ public AtlasServiceException(AtlasBaseClient.API api, ClientResponse response) {
this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class));
}
diff --git a/client/src/main/java/org/apache/atlas/ResourceCreator.java b/client/common/src/main/java/org/apache/atlas/ResourceCreator.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/ResourceCreator.java
rename to client/common/src/main/java/org/apache/atlas/ResourceCreator.java
diff --git a/client/src/main/java/org/apache/atlas/security/SecureClientUtils.java b/client/common/src/main/java/org/apache/atlas/security/SecureClientUtils.java
similarity index 100%
rename from client/src/main/java/org/apache/atlas/security/SecureClientUtils.java
rename to client/common/src/main/java/org/apache/atlas/security/SecureClientUtils.java
diff --git a/client/pom.xml b/client/pom.xml
index 9d411760c..b065833e2 100755
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -24,59 +24,29 @@
org.apache.atlas
1.0.0-SNAPSHOT
+
+
+
+ common
+ client-v1
+ client-v2
+
+
atlas-client
Apache Atlas Client
Apache Atlas Client
- jar
+ pom
-
- org.apache.atlas
- atlas-typesystem
-
-
-
-
- org.apache.httpcomponents
- httpclient
-
-
-
- org.apache.hadoop
- hadoop-common
-
-
-
- org.apache.hadoop
- hadoop-annotations
-
-
-
- org.apache.hadoop
- hadoop-minikdc
-
-
-
- com.sun.jersey
- jersey-client
-
-
-
- org.testng
- testng
-
-
-
- org.apache.atlas
- atlas-typesystem
- tests
- test
-
-
org.mockito
mockito-all
test
+
+ org.testng
+ testng
+ test
+
diff --git a/client/src/main/assembly/all-jar.xml b/client/src/main/assembly/all-jar.xml
new file mode 100644
index 000000000..8bc9eee65
--- /dev/null
+++ b/client/src/main/assembly/all-jar.xml
@@ -0,0 +1,35 @@
+
+
+ all-jar
+
+ jar
+
+
+ false
+
+
+
+ true
+ false
+
+
+
\ No newline at end of file
diff --git a/common/pom.xml b/common/pom.xml
index 7178bfa6c..c2e5da659 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -77,5 +77,10 @@
guava
${guava.version}
+
+