From 187730dd745f5f558e00393e28b919963c24bf08 Mon Sep 17 00:00:00 2001 From: apoorvnaik Date: Tue, 26 Sep 2017 12:13:02 -0700 Subject: [PATCH] ATLAS-2179: Split Atlas client library to avoid unnecessary dependencies --- addons/falcon-bridge/pom.xml | 4 +- addons/hdfs-model/pom.xml | 2 +- addons/hive-bridge/pom.xml | 4 +- addons/sqoop-bridge/pom.xml | 4 +- addons/storm-bridge/pom.xml | 4 +- authorization/pom.xml | 5 - .../simple/AtlasAuthorizationUtils.java | 10 +- .../atlas/authorize/simple/PolicyParser.java | 3 +- client/client-v1/pom.xml | 48 +++ .../org/apache/atlas/AtlasAdminClient.java | 0 .../java/org/apache/atlas/AtlasClient.java | 336 ++++++++-------- .../atlas/CreateUpdateEntitiesResult.java | 0 .../org/apache/atlas/EntityAuditEvent.java | 0 .../src/main/java/org/apache/atlas/SerDe.java | 0 .../org/apache/atlas/AtlasClientTest.java | 60 +-- client/client-v2/pom.xml | 42 ++ .../java/org/apache/atlas/AtlasClientV2.java | 268 +++++++------ client/common/pom.xml | 48 +++ .../org/apache/atlas/AtlasBaseClient.java | 361 +++++++++--------- .../org/apache/atlas/AtlasServerEnsemble.java | 0 .../apache/atlas/AtlasServiceException.java | 29 +- .../org/apache/atlas/ResourceCreator.java | 0 .../atlas/security/SecureClientUtils.java | 0 client/pom.xml | 58 +-- client/src/main/assembly/all-jar.xml | 35 ++ common/pom.xml | 5 + .../atlas/groovy/ArithmeticExpression.java | 4 +- .../apache/atlas/ApplicationProperties.java | 0 .../java/org/apache/atlas/AtlasException.java | 0 .../security/InMemoryJAASConfiguration.java | 0 .../atlas/security/SecurityProperties.java | 0 .../atlas/utils/AuthenticationUtil.java | 0 .../atlas/ApplicationPropertiesTest.java | 0 .../InMemoryJAASConfigurationTest.java | 0 ...nfigurationTicketBasedKafkaClientTest.java | 0 intg/src/test/resources/atlas-jaas.properties | 62 +++ intg/src/test/resources/test.properties | 19 + notification/pom.xml | 2 +- pom.xml | 12 + repository/pom.xml | 2 +- .../converters/AtlasInstanceConverter.java | 4 +- .../graph/GraphBackedMetadataRepository.java | 13 +- .../store/graph/v1/EntityGraphRetriever.java | 53 +-- .../test/java/org/apache/atlas/TestUtils.java | 6 +- ...ackedMetadataRepositoryDeleteTestBase.java | 6 +- .../GraphBackedMetadataRepositoryTest.java | 2 +- .../graph/ReverseReferenceUpdateTestBase.java | 8 +- .../service/DefaultMetadataServiceTest.java | 4 +- server-api/pom.xml | 2 +- .../atlas/services/MetadataService.java | 2 +- .../resources/atlas-application.properties | 6 +- webapp/pom.xml | 7 +- .../NotificationHookConsumer.java | 22 +- .../atlas/web/resources/EntityResource.java | 4 +- .../integration/AdminJerseyResourceIT.java | 2 +- .../DataSetLineageJerseyResourceIT.java | 10 +- .../integration/EntityJerseyResourceIT.java | 20 +- .../EntityLineageJerseyResourceIT.java | 17 +- .../MetadataDiscoveryJerseyResourceIT.java | 14 +- .../integration/TypesJerseyResourceIT.java | 10 +- 60 files changed, 932 insertions(+), 707 deletions(-) create mode 100644 client/client-v1/pom.xml rename client/{ => client-v1}/src/main/java/org/apache/atlas/AtlasAdminClient.java (100%) rename client/{ => client-v1}/src/main/java/org/apache/atlas/AtlasClient.java (70%) mode change 100755 => 100644 rename client/{ => client-v1}/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java (100%) rename client/{ => client-v1}/src/main/java/org/apache/atlas/EntityAuditEvent.java (100%) rename client/{ => client-v1}/src/main/java/org/apache/atlas/SerDe.java (100%) rename client/{ => client-v1}/src/test/java/org/apache/atlas/AtlasClientTest.java (90%) create mode 100644 client/client-v2/pom.xml rename client/{ => client-v2}/src/main/java/org/apache/atlas/AtlasClientV2.java (65%) create mode 100644 client/common/pom.xml rename client/{ => common}/src/main/java/org/apache/atlas/AtlasBaseClient.java (86%) rename client/{ => common}/src/main/java/org/apache/atlas/AtlasServerEnsemble.java (100%) rename client/{ => common}/src/main/java/org/apache/atlas/AtlasServiceException.java (56%) rename client/{ => common}/src/main/java/org/apache/atlas/ResourceCreator.java (100%) rename client/{ => common}/src/main/java/org/apache/atlas/security/SecureClientUtils.java (100%) create mode 100644 client/src/main/assembly/all-jar.xml rename {common => intg}/src/main/java/org/apache/atlas/ApplicationProperties.java (100%) rename {common => intg}/src/main/java/org/apache/atlas/AtlasException.java (100%) rename {common => intg}/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java (100%) rename {common => intg}/src/main/java/org/apache/atlas/security/SecurityProperties.java (100%) rename {common => intg}/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java (100%) rename {common => intg}/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java (100%) rename {common => intg}/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java (100%) rename {common => intg}/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java (100%) create mode 100644 intg/src/test/resources/atlas-jaas.properties create mode 100644 intg/src/test/resources/test.properties diff --git a/addons/falcon-bridge/pom.xml b/addons/falcon-bridge/pom.xml index f0e668fbf..442be4871 100644 --- a/addons/falcon-bridge/pom.xml +++ b/addons/falcon-bridge/pom.xml @@ -53,7 +53,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 @@ -157,7 +157,7 @@ ${project.groupId} - atlas-client + atlas-client-v1 ${project.version} diff --git a/addons/hdfs-model/pom.xml b/addons/hdfs-model/pom.xml index fe784422d..6ed444a3d 100644 --- a/addons/hdfs-model/pom.xml +++ b/addons/hdfs-model/pom.xml @@ -50,7 +50,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 diff --git a/addons/hive-bridge/pom.xml b/addons/hive-bridge/pom.xml index d16fde765..0909dc2a1 100755 --- a/addons/hive-bridge/pom.xml +++ b/addons/hive-bridge/pom.xml @@ -100,7 +100,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 @@ -205,7 +205,7 @@ ${project.groupId} - atlas-client + atlas-client-v1 ${project.version} diff --git a/addons/sqoop-bridge/pom.xml b/addons/sqoop-bridge/pom.xml index c866f16ac..7afc80667 100644 --- a/addons/sqoop-bridge/pom.xml +++ b/addons/sqoop-bridge/pom.xml @@ -101,7 +101,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 @@ -222,7 +222,7 @@ ${project.groupId} - atlas-client + atlas-client-v1 ${project.version} diff --git a/addons/storm-bridge/pom.xml b/addons/storm-bridge/pom.xml index 872668156..279dd6e70 100644 --- a/addons/storm-bridge/pom.xml +++ b/addons/storm-bridge/pom.xml @@ -43,7 +43,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 @@ -171,7 +171,7 @@ ${project.groupId} - atlas-client + atlas-client-v1 ${project.version} diff --git a/authorization/pom.xml b/authorization/pom.xml index bc0882b2c..143c4e4c6 100644 --- a/authorization/pom.xml +++ b/authorization/pom.xml @@ -35,11 +35,6 @@ atlas-common - - org.apache.atlas - atlas-client - - 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} + + + org.apache.atlas + atlas-intg + diff --git a/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java b/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java index a6e1689c5..fff104b7c 100644 --- a/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java +++ b/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java @@ -17,10 +17,10 @@ */ package org.apache.atlas.groovy; -import java.util.List; - import org.apache.atlas.AtlasException; +import java.util.List; + /** * Represents an arithmetic expression such as a+b. */ diff --git a/common/src/main/java/org/apache/atlas/ApplicationProperties.java b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java similarity index 100% rename from common/src/main/java/org/apache/atlas/ApplicationProperties.java rename to intg/src/main/java/org/apache/atlas/ApplicationProperties.java diff --git a/common/src/main/java/org/apache/atlas/AtlasException.java b/intg/src/main/java/org/apache/atlas/AtlasException.java similarity index 100% rename from common/src/main/java/org/apache/atlas/AtlasException.java rename to intg/src/main/java/org/apache/atlas/AtlasException.java diff --git a/common/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java b/intg/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java similarity index 100% rename from common/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java rename to intg/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java diff --git a/common/src/main/java/org/apache/atlas/security/SecurityProperties.java b/intg/src/main/java/org/apache/atlas/security/SecurityProperties.java similarity index 100% rename from common/src/main/java/org/apache/atlas/security/SecurityProperties.java rename to intg/src/main/java/org/apache/atlas/security/SecurityProperties.java diff --git a/common/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java b/intg/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java similarity index 100% rename from common/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java rename to intg/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java diff --git a/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java similarity index 100% rename from common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java rename to intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java diff --git a/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java b/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java similarity index 100% rename from common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java rename to intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java diff --git a/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java b/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java similarity index 100% rename from common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java rename to intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java diff --git a/intg/src/test/resources/atlas-jaas.properties b/intg/src/test/resources/atlas-jaas.properties new file mode 100644 index 000000000..9412fae11 --- /dev/null +++ b/intg/src/test/resources/atlas-jaas.properties @@ -0,0 +1,62 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +######### Notification Configs ######### +atlas.notification.embedded=true + +atlas.kafka.zookeeper.connect=localhost:19026 +atlas.kafka.bootstrap.servers=localhost:19027 +atlas.kafka.data=${sys:atlas.data}/kafka +atlas.kafka.zookeeper.session.timeout.ms=4000 +atlas.kafka.zookeeper.sync.time.ms=20 +atlas.kafka.consumer.timeout.ms=100 +atlas.kafka.auto.commit.interval.ms=100 +atlas.kafka.hook.group.id=atlas +atlas.kafka.entities.group.id=atlas_entities +atlas.kafka.auto.commit.enable=false + +######## JAAS configs ################## + +atlas.jaas.KafkaClient.loginModuleName = com.sun.security.auth.module.Krb5LoginModule +atlas.jaas.KafkaClient.loginModuleControlFlag = required +atlas.jaas.KafkaClient.option.useKeyTab = true +atlas.jaas.KafkaClient.option.storeKey = true +atlas.jaas.KafkaClient.option.serviceName = kafka +atlas.jaas.KafkaClient.option.keyTab = /etc/security/keytabs/kafka_client.keytab +atlas.jaas.KafkaClient.option.principal = kafka-client-1/_HOST@EXAMPLE.COM + +atlas.jaas.myClient.0.loginModuleName = com.sun.security.auth.module.Krb5LoginModule +atlas.jaas.myClient.0.loginModuleControlFlag = required +atlas.jaas.myClient.0.option.useKeyTab = true +atlas.jaas.myClient.0.option.storeKey = true +atlas.jaas.myClient.0.option.serviceName = kafka +atlas.jaas.myClient.0.option.keyTab = /etc/security/keytabs/kafka_client.keytab +atlas.jaas.myClient.0.option.principal = kafka-client-1/abcd@EXAMPLE.COM + +atlas.jaas.myClient.1.loginModuleName = com.sun.security.auth.module.Krb5LoginModule +atlas.jaas.myClient.1.loginModuleControlFlag = optional +atlas.jaas.myClient.1.option.useKeyTab = true +atlas.jaas.myClient.1.option.storeKey = true +atlas.jaas.myClient.1.option.serviceName = kafka +atlas.jaas.myClient.1.option.keyTab = /etc/security/keytabs/kafka_client.keytab +atlas.jaas.myClient.1.option.principal = kafka-client-1@EXAMPLE.COM + + +atlas.jaas.ticketBased-KafkaClient.loginModuleControlFlag=required +atlas.jaas.ticketBased-KafkaClient.loginModuleName=com.sun.security.auth.module.Krb5LoginModule +atlas.jaas.ticketBased-KafkaClient.option.useTicketCache=true \ No newline at end of file diff --git a/intg/src/test/resources/test.properties b/intg/src/test/resources/test.properties new file mode 100644 index 000000000..395537f30 --- /dev/null +++ b/intg/src/test/resources/test.properties @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +jaas.properties.file=atlas-jaas.properties diff --git a/notification/pom.xml b/notification/pom.xml index 192a3fc7a..9b3694030 100644 --- a/notification/pom.xml +++ b/notification/pom.xml @@ -32,7 +32,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 diff --git a/pom.xml b/pom.xml index 684535a69..f793321c2 100644 --- a/pom.xml +++ b/pom.xml @@ -1383,6 +1383,18 @@ ${project.version} + + org.apache.atlas + atlas-client-v1 + ${project.version} + + + + org.apache.atlas + atlas-client-v2 + ${project.version} + + org.apache.atlas atlas-common diff --git a/repository/pom.xml b/repository/pom.xml index 4252751d2..b7eedde0a 100755 --- a/repository/pom.xml +++ b/repository/pom.xml @@ -49,7 +49,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java index 3426ae515..9bde5db69 100644 --- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java +++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java @@ -17,7 +17,6 @@ */ package org.apache.atlas.repository.converters; -import org.apache.atlas.model.legacy.EntityResult; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasException; import org.apache.atlas.CreateUpdateEntitiesResult; @@ -31,6 +30,8 @@ import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutations; import org.apache.atlas.model.instance.EntityMutations.EntityOperation; import org.apache.atlas.model.instance.GuidMapping; +import org.apache.atlas.model.legacy.EntityResult; +import org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext; import org.apache.atlas.services.MetadataService; import org.apache.atlas.type.AtlasClassificationType; import org.apache.atlas.type.AtlasEntityType; @@ -46,7 +47,6 @@ import org.apache.atlas.typesystem.exception.EntityExistsException; import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.TraitNotFoundException; import org.apache.atlas.typesystem.exception.TypeNotFoundException; -import org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext; import org.apache.atlas.typesystem.types.ValueConversionException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java index 50b71167f..568f6b05e 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java @@ -50,16 +50,7 @@ import org.springframework.stereotype.Component; import javax.inject.Inject; import javax.inject.Singleton; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * An implementation backed by a Graph database provided @@ -145,7 +136,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, - EntityExistsException { + EntityExistsException { if (LOG.isDebugEnabled()) { LOG.debug("adding entities={}", entities); } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java index ad88c1b37..36cd980fb 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java @@ -17,8 +17,6 @@ */ package org.apache.atlas.repository.store.graph.v1; -import com.sun.istack.Nullable; -import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasClassification; @@ -40,8 +38,15 @@ import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; import org.apache.atlas.repository.graphdb.AtlasElement; import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.type.*; +import org.apache.atlas.type.AtlasArrayType; +import org.apache.atlas.type.AtlasEntityType; +import org.apache.atlas.type.AtlasMapType; +import org.apache.atlas.type.AtlasRelationshipType; +import org.apache.atlas.type.AtlasStructType; import org.apache.atlas.type.AtlasStructType.AtlasAttribute; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.type.AtlasTypeUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -58,17 +63,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BYTE; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_DATE; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_FLOAT; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_INT; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_LONG; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_SHORT; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_STRING; +import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*; import static org.apache.atlas.repository.graph.GraphHelper.EDGE_LABEL_PREFIX; import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromVertex; import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection; @@ -80,6 +75,12 @@ import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelation public final class EntityGraphRetriever { private static final Logger LOG = LoggerFactory.getLogger(EntityGraphRetriever.class); + private final String NAME = "name"; + private final String DESCRIPTION = "description"; + private final String OWNER = "owner"; + private final String CREATE_TIME = "createTime"; + private final String QUALIFIED_NAME = "qualifiedName"; + private static final GraphHelper graphHelper = GraphHelper.getInstance(); private final AtlasTypeRegistry typeRegistry; @@ -232,16 +233,16 @@ public final class EntityGraphRetriever { } } - Object name = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.NAME)); - Object description = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.DESCRIPTION)); - Object owner = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.OWNER)); - Object createTime = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.CREATE_TIME)); - Object displayText = name != null ? name : ret.getAttribute(AtlasClient.QUALIFIED_NAME); + Object name = getVertexAttribute(entityVertex, entityType.getAttribute(NAME)); + Object description = getVertexAttribute(entityVertex, entityType.getAttribute(DESCRIPTION)); + Object owner = getVertexAttribute(entityVertex, entityType.getAttribute(OWNER)); + Object createTime = getVertexAttribute(entityVertex, entityType.getAttribute(CREATE_TIME)); + Object displayText = name != null ? name : ret.getAttribute(QUALIFIED_NAME); - ret.setAttribute(AtlasClient.NAME, name); - ret.setAttribute(AtlasClient.DESCRIPTION, description); - ret.setAttribute(AtlasClient.OWNER, owner); - ret.setAttribute(AtlasClient.CREATE_TIME, createTime); + ret.setAttribute(NAME, name); + ret.setAttribute(DESCRIPTION, description); + ret.setAttribute(OWNER, owner); + ret.setAttribute(CREATE_TIME, createTime); if (displayText != null) { ret.setDisplayText(displayText.toString()); @@ -339,7 +340,7 @@ public final class EntityGraphRetriever { } - private List getClassifications(AtlasVertex instanceVertex, @Nullable String classificationNameFilter) throws AtlasBaseException { + private List getClassifications(AtlasVertex instanceVertex, String classificationNameFilter) throws AtlasBaseException { List classifications = new ArrayList<>(); List classificationNames = GraphHelper.getTraitNames(instanceVertex); @@ -741,10 +742,10 @@ public final class EntityGraphRetriever { Object ret = null; if (entityType != null) { - ret = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.NAME)); + ret = getVertexAttribute(entityVertex, entityType.getAttribute(NAME)); if (ret == null) { - ret = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.QUALIFIED_NAME)); + ret = getVertexAttribute(entityVertex, entityType.getAttribute(QUALIFIED_NAME)); } } diff --git a/repository/src/test/java/org/apache/atlas/TestUtils.java b/repository/src/test/java/org/apache/atlas/TestUtils.java index 489127931..56bfb824e 100755 --- a/repository/src/test/java/org/apache/atlas/TestUtils.java +++ b/repository/src/test/java/org/apache/atlas/TestUtils.java @@ -528,9 +528,9 @@ public final class TestUtils { String entityjson = InstanceSerialization.toJson(entity, true); JSONArray entitiesJson = new JSONArray(); entitiesJson.put(entityjson); - CreateUpdateEntitiesResult creationResult = metadataService.createEntities(entitiesJson.toString()); - Map guidMap = creationResult.getGuidMapping().getGuidAssignments(); - Map referencedObjects = findReferencedObjects(entity); + CreateUpdateEntitiesResult creationResult = metadataService.createEntities(entitiesJson.toString()); + Map guidMap = creationResult.getGuidMapping().getGuidAssignments(); + Map referencedObjects = findReferencedObjects(entity); for(Map.Entry entry : referencedObjects.entrySet()) { Id foundId = entry.getKey(); diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java index 0e2208035..0834601f7 100644 --- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java +++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java @@ -237,10 +237,10 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase { } private String createInstance(Referenceable entity) throws Exception { - ClassType dataType = typeSystem.getDataType(ClassType.class, entity.getTypeName()); + ClassType dataType = typeSystem.getDataType(ClassType.class, entity.getTypeName()); ITypedReferenceableInstance instance = dataType.convert(entity, Multiplicity.REQUIRED); - CreateUpdateEntitiesResult result = repositoryService.createEntities(instance); - List results = result.getCreatedEntities(); + CreateUpdateEntitiesResult result = repositoryService.createEntities(instance); + List results = result.getCreatedEntities(); return results.get(results.size() - 1); } diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java index d4c250cc0..64443286c 100755 --- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java +++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java @@ -22,8 +22,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.apache.atlas.AtlasException; import org.apache.atlas.CreateUpdateEntitiesResult; -import org.apache.atlas.TestModules; import org.apache.atlas.RequestContext; +import org.apache.atlas.TestModules; import org.apache.atlas.TestUtils; import org.apache.atlas.annotation.GraphTransaction; import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService; diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java index 26dc6a826..8518f9310 100644 --- a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java +++ b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java @@ -255,10 +255,10 @@ public abstract class ReverseReferenceUpdateTestBase { a.set("oneB", b1); b1.set("manyA", Collections.singletonList(a)); - CreateUpdateEntitiesResult result = repositoryService.createEntities(a); - Map guidAssignments = result.getGuidMapping().getGuidAssignments(); - String aGuid = a.getId()._getId(); - String b1Guid = guidAssignments.get(b1.getId()._getId()); + CreateUpdateEntitiesResult result = repositoryService.createEntities(a); + Map guidAssignments = result.getGuidMapping().getGuidAssignments(); + String aGuid = a.getId()._getId(); + String b1Guid = guidAssignments.get(b1.getId()._getId()); a = repositoryService.getEntityDefinition(aGuid); Object object = a.get("oneB"); diff --git a/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java b/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java index e93f08d6e..e885b8c94 100644 --- a/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java +++ b/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java @@ -1304,8 +1304,8 @@ public class DefaultMetadataServiceTest { } private String createBasicEntity(final HierarchicalTypeDefinition refType) throws AtlasException { - String json = InstanceSerialization.toJson(new Referenceable(refType.typeName), false); - CreateUpdateEntitiesResult entities = metadataService.createEntities("[" + json + "]"); + String json = InstanceSerialization.toJson(new Referenceable(refType.typeName), false); + CreateUpdateEntitiesResult entities = metadataService.createEntities("[" + json + "]"); return entities.getCreatedEntities().get(0); } diff --git a/server-api/pom.xml b/server-api/pom.xml index 05e5eec7c..6e99ca351 100644 --- a/server-api/pom.xml +++ b/server-api/pom.xml @@ -53,7 +53,7 @@ org.apache.atlas - atlas-client + atlas-client-v1 diff --git a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java index 7fb3d3f6f..d2aa457b1 100644 --- a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java +++ b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java @@ -24,11 +24,11 @@ import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.model.legacy.EntityResult; import org.apache.atlas.typesystem.IReferenceableInstance; +import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Struct; -import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.types.cache.TypeCache; import org.codehaus.jettison.json.JSONObject; diff --git a/typesystem/src/test/resources/atlas-application.properties b/typesystem/src/test/resources/atlas-application.properties index 65dd9a31f..d7537a516 100644 --- a/typesystem/src/test/resources/atlas-application.properties +++ b/typesystem/src/test/resources/atlas-application.properties @@ -35,7 +35,7 @@ atlas.TypeSystem.impl=org.apache.atlas.typesystem.types.TypeSystem ######### Atlas Server Configs ######### -atlas.rest.address=http://localhost:31000 +atlas.rest.address=http://localhost:21000 ######### Graph Database Configs ######### @@ -82,8 +82,8 @@ atlas.lineage.schema.query.hive_table_v1=hive_table_v1 where __guid='%s'\, colum ######### Notification Configs ######### atlas.notification.embedded=true -atlas.kafka.zookeeper.connect=localhost:19026 -atlas.kafka.bootstrap.servers=localhost:19027 +atlas.kafka.zookeeper.connect=localhost:9026 +atlas.kafka.bootstrap.servers=localhost:9027 atlas.kafka.data=${sys:atlas.data}/kafka atlas.kafka.zookeeper.session.timeout.ms=4000 atlas.kafka.zookeeper.sync.time.ms=20 diff --git a/webapp/pom.xml b/webapp/pom.xml index 8d03af7a6..bfa79e810 100755 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -134,7 +134,12 @@ org.apache.atlas - atlas-client + atlas-client-v1 + + + + org.apache.atlas + atlas-client-v2 diff --git a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java index 858b32009..5fd5087e6 100644 --- a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java +++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java @@ -21,6 +21,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; import kafka.utils.ShutdownableThread; import org.apache.atlas.ApplicationProperties; +import org.apache.atlas.AtlasBaseClient; +import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasServiceException; import org.apache.atlas.RequestContext; @@ -64,7 +66,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import static org.apache.atlas.AtlasClientV2.*; +import static org.apache.atlas.AtlasClientV2.API_V2.DELETE_ENTITY_BY_ATTRIBUTE; +import static org.apache.atlas.AtlasClientV2.API_V2.UPDATE_ENTITY; +import static org.apache.atlas.AtlasClientV2.API_V2.UPDATE_ENTITY_BY_ATTRIBUTE; /** * Consumer of notifications from hooks e.g., hive hook etc. @@ -350,7 +354,8 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl EntityCreateRequest createRequest = (EntityCreateRequest) message; if (numRetries == 0) { // audit only on the first attempt - audit(messageUser, CREATE_ENTITY.getMethod(), CREATE_ENTITY.getPath()); + AtlasBaseClient.API api = AtlasClient.API_V1.CREATE_ENTITY; + audit(messageUser, api.getMethod(), api.getPath()); } entities = instanceConverter.toAtlasEntities(createRequest.getEntities()); @@ -362,8 +367,9 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl final EntityPartialUpdateRequest partialUpdateRequest = (EntityPartialUpdateRequest) message; if (numRetries == 0) { // audit only on the first attempt - audit(messageUser, UPDATE_ENTITY_BY_ATTRIBUTE.getMethod(), - String.format(UPDATE_ENTITY_BY_ATTRIBUTE.getPath(), partialUpdateRequest.getTypeName())); + AtlasBaseClient.API api = UPDATE_ENTITY_BY_ATTRIBUTE; + audit(messageUser, api.getMethod(), + String.format(api.getPath(), partialUpdateRequest.getTypeName())); } Referenceable referenceable = partialUpdateRequest.getEntity(); @@ -386,8 +392,9 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl final EntityDeleteRequest deleteRequest = (EntityDeleteRequest) message; if (numRetries == 0) { // audit only on the first attempt - audit(messageUser, DELETE_ENTITY_BY_ATTRIBUTE.getMethod(), - String.format(DELETE_ENTITY_BY_ATTRIBUTE.getPath(), deleteRequest.getTypeName())); + AtlasBaseClient.API api = DELETE_ENTITY_BY_ATTRIBUTE; + audit(messageUser, api.getMethod(), + String.format(api.getPath(), deleteRequest.getTypeName())); } try { @@ -405,7 +412,8 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl EntityUpdateRequest updateRequest = (EntityUpdateRequest) message; if (numRetries == 0) { // audit only on the first attempt - audit(messageUser, UPDATE_ENTITY.getMethod(), UPDATE_ENTITY.getPath()); + AtlasBaseClient.API api = UPDATE_ENTITY; + audit(messageUser, api.getMethod(), api.getPath()); } entities = instanceConverter.toAtlasEntities(updateRequest.getEntities()); diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java index 711cc04d5..67c9b279e 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java @@ -22,7 +22,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.sun.jersey.api.core.ResourceContext; import org.apache.atlas.AtlasClient; -import org.apache.atlas.model.legacy.EntityResult; import org.apache.atlas.AtlasConstants; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasException; @@ -35,6 +34,7 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.GuidMapping; +import org.apache.atlas.model.legacy.EntityResult; import org.apache.atlas.repository.converters.AtlasInstanceConverter; import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream; @@ -215,7 +215,7 @@ public class EntityResource { UriBuilder ub = uriInfo.getAbsolutePathBuilder(); locationURI = CollectionUtils.isEmpty(guids) ? null : ub.path(guids.get(0)).build(); } else { - String uriPath = AtlasClient.API.GET_ENTITY.getPath(); + String uriPath = AtlasClient.API_V1.GET_ENTITY.getPath(); locationURI = guids.isEmpty() ? null : UriBuilder .fromPath(AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS) .path(uriPath).path(guids.get(0)).build(); diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java index cfe09d6f6..7d045f3ed 100755 --- a/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java @@ -37,7 +37,7 @@ public class AdminJerseyResourceIT extends BaseResourceIT { @Test public void testGetVersion() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null); Assert.assertNotNull(response); PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties"); diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java index 8c6ba7757..1a65daba9 100644 --- a/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java @@ -59,7 +59,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { @Test public void testInputsGraph() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph"); Assert.assertNotNull(response); System.out.println("inputs graph = " + response); @@ -95,7 +95,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { @Test public void testOutputsGraph() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph"); Assert.assertNotNull(response); System.out.println("outputs graph= " + response); @@ -131,7 +131,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { @Test public void testSchema() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema"); Assert.assertNotNull(response); System.out.println("schema = " + response); @@ -173,12 +173,12 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { @Test(expectedExceptions = AtlasServiceException.class) public void testSchemaForInvalidTable() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, "blah", "schema"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema"); } @Test(expectedExceptions = AtlasServiceException.class) public void testSchemaForDB() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema"); } private void setupInstances() throws Exception { diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java index ba5465d30..cf44d4af6 100755 --- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java @@ -27,9 +27,7 @@ import org.apache.atlas.AtlasServiceException; import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.kafka.NotificationProvider; import org.apache.atlas.model.legacy.EntityResult; -import org.apache.atlas.notification.NotificationConsumer; import org.apache.atlas.notification.NotificationInterface; -import org.apache.atlas.notification.entity.EntityNotification; import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.TypesDef; @@ -195,7 +193,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { databaseInstance.set("location", "/tmp"); JSONObject response = atlasClientV1 - .callAPIWithBody(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true)); + .callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true)); assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -345,7 +343,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { String description = "bar table - new desc"; addProperty(guid, "description", description); - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid); Assert.assertNotNull(response); referenceable.set("description", description); @@ -363,7 +361,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { // updating date attribute as string not supported in v2 // addProperty(guid, "createTime", currentTime); - response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid); + response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid); Assert.assertNotNull(response); referenceable.set("createTime", currentTime); @@ -483,7 +481,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { @Test(expectedExceptions = AtlasServiceException.class) public void testGetInvalidEntityDefinition() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, "blah"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah"); Assert.assertNotNull(response); @@ -516,7 +514,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("type", "blah"); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams); assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.ERROR)); } @@ -529,7 +527,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("type", typeName); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams); assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -716,7 +714,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { String traitInstanceAsJSON = InstanceSerialization$.MODULE$.toJson(traitInstance, true); LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON); - atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS); + atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS); } @Test @@ -835,7 +833,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { instance.set(attrName, attrValue); Id guid = createInstance(instance); - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid._getId()); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId()); Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true); Assert.assertEquals(getReferenceable.get(attrName), attrValue); } @@ -1029,7 +1027,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId()); queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId()); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.DELETE_ENTITIES, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams); List deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities(); Assert.assertTrue(deletedGuidsList.contains(db1Id._getId())); Assert.assertTrue(deletedGuidsList.contains(db2Id._getId())); diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java index 55c56c216..381139088 100644 --- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java @@ -21,6 +21,7 @@ package org.apache.atlas.web.integration; import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.sun.jersey.core.util.MultivaluedMapImpl; +import org.apache.atlas.AtlasBaseClient; import org.apache.atlas.AtlasClient; import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.lineage.AtlasLineageInfo; @@ -37,19 +38,17 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.apache.atlas.AtlasBaseClient.APIInfo; - /** * Entity Lineage v2 Integration Tests. */ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceIT { - private static final String BASE_URI = "api/atlas/v2/lineage"; - private static final APIInfo LINEAGE_V2_API = new APIInfo(BASE_URI, "GET", Response.Status.OK); - private static final String INPUT_DIRECTION = "INPUT"; - private static final String OUTPUT_DIRECTION = "OUTPUT"; - private static final String BOTH_DIRECTION = "BOTH"; - private static final String DIRECTION_PARAM = "direction"; - private static final String DEPTH_PARAM = "depth"; + private static final String BASE_URI = "api/atlas/v2/lineage"; + private static final AtlasBaseClient.API LINEAGE_V2_API = new AtlasBaseClient.API(BASE_URI, "GET", Response.Status.OK); + private static final String INPUT_DIRECTION = "INPUT"; + private static final String OUTPUT_DIRECTION = "OUTPUT"; + private static final String BOTH_DIRECTION = "BOTH"; + private static final String DIRECTION_PARAM = "direction"; + private static final String DEPTH_PARAM = "depth"; private String salesFactTable; private String salesMonthlyTable; diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java index 3fa85b18f..a13f0696f 100755 --- a/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java @@ -69,7 +69,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\""; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", dslQuery); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -92,7 +92,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\""; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", dslQuery); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams); assertNotNull(response); //higher limit, all results returned @@ -141,7 +141,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { String dslQuery = "from blah"; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", dslQuery); - atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams); + atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams); } @Test @@ -150,7 +150,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", query); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GREMLIN_SEARCH, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams); assertNotNull(response); assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -165,7 +165,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { String query = "from "+ DATABASE_TYPE + " name=\"" + dbName +"\""; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", query); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -179,7 +179,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { String query = "*"; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", query); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -211,7 +211,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { String query = dbName; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", query); - response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_FULL_TEXT, queryParams); + response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_FULL_TEXT, queryParams); results = response.getJSONArray(AtlasClient.RESULTS); assertEquals(results.length(), 1); diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java index 54db3c0c2..351e5ae77 100755 --- a/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java @@ -81,7 +81,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { String typesAsJSON = TypesSerialization.toJson(typeDefinition, false); System.out.println("typesAsJSON = " + typesAsJSON); - JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_TYPE, typesAsJSON); + JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON); Assert.assertNotNull(response); @@ -142,7 +142,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { System.out.println("typeName = " + typeDefinition.typeName); - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.typeName); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.DEFINITION)); @@ -164,12 +164,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT { @Test(expectedExceptions = AtlasServiceException.class) public void testGetDefinitionForNonexistentType() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, "blah"); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah"); } @Test(dependsOnMethods = "testSubmit") public void testGetTypeNames() throws Exception { - JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, (String[]) null); + JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); @@ -190,7 +190,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("type", DataTypes.TypeCategory.TRAIT.name()); - JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.LIST_TYPES, queryParams); + JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams); Assert.assertNotNull(response); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));