Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9D9E8200C2A for ; Wed, 1 Mar 2017 20:45:14 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9C0B1160B70; Wed, 1 Mar 2017 19:45:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1B57E160B56 for ; Wed, 1 Mar 2017 20:45:11 +0100 (CET) Received: (qmail 67541 invoked by uid 500); 1 Mar 2017 19:45:11 -0000 Mailing-List: contact commits-help@atlas.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.incubator.apache.org Delivered-To: mailing list commits@atlas.incubator.apache.org Received: (qmail 67532 invoked by uid 99); 1 Mar 2017 19:45:11 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2017 19:45:11 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B4C111819E4 for ; Wed, 1 Mar 2017 19:45:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.567 X-Spam-Level: X-Spam-Status: No, score=-6.567 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id QpENRrVCzDzX for ; Wed, 1 Mar 2017 19:44:58 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id B33755F1A1 for ; Wed, 1 Mar 2017 19:44:55 +0000 (UTC) Received: (qmail 66502 invoked by uid 99); 1 Mar 2017 19:44:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2017 19:44:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EC87ADF9AF; Wed, 1 Mar 2017 19:44:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: madhan@apache.org To: commits@atlas.incubator.apache.org Date: Wed, 01 Mar 2017 19:44:39 -0000 Message-Id: In-Reply-To: <2904441201534e08a416690970b47046@git.apache.org> References: <2904441201534e08a416690970b47046@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-atlas git commit: ATLAS-1616: consolidated all V2 clients archived-at: Wed, 01 Mar 2017 19:45:14 -0000 ATLAS-1616: consolidated all V2 clients Signed-off-by: Madhan Neethiraj Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/46b1b36e Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/46b1b36e Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/46b1b36e Branch: refs/heads/master Commit: 46b1b36e97b7d405d023b7594e679b65b0226c8a Parents: 84f6923 Author: apoorvnaik Authored: Wed Mar 1 10:17:14 2017 -0800 Committer: Madhan Neethiraj Committed: Wed Mar 1 11:12:40 2017 -0800 ---------------------------------------------------------------------- .../java/org/apache/atlas/AtlasBaseClient.java | 28 +- .../main/java/org/apache/atlas/AtlasClient.java | 4 +- .../java/org/apache/atlas/AtlasClientV2.java | 403 +++++++++++++++++++ .../apache/atlas/AtlasDiscoveryClientV2.java | 96 ----- .../org/apache/atlas/AtlasEntitiesClientV2.java | 188 --------- .../org/apache/atlas/AtlasLineageClientV2.java | 65 --- .../org/apache/atlas/AtlasTypedefClientV2.java | 218 ---------- .../org/apache/atlas/examples/QuickStartV2.java | 47 +-- .../notification/NotificationHookConsumer.java | 8 +- .../apache/atlas/examples/QuickStartV2IT.java | 14 +- .../atlas/web/resources/BaseResourceIT.java | 85 ++-- .../EntityDiscoveryJerseyResourceIT.java | 36 +- .../web/resources/EntityV2JerseyResourceIT.java | 50 +-- .../web/resources/TypedefsJerseyResourceIT.java | 40 +- 14 files changed, 545 insertions(+), 737 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasBaseClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java b/client/src/main/java/org/apache/atlas/AtlasBaseClient.java index 6a34f83..38bf233 100644 --- a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java +++ b/client/src/main/java/org/apache/atlas/AtlasBaseClient.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 - * + *

* 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. @@ -80,7 +80,8 @@ public abstract class AtlasBaseClient { private AtlasClientContext atlasClientContext; private boolean retryEnabled = false; - protected AtlasBaseClient() {} + protected AtlasBaseClient() { + } protected AtlasBaseClient(String[] baseUrl, String[] basicAuthUserNamePassword) { if (basicAuthUserNamePassword != null) { @@ -158,7 +159,8 @@ public abstract class AtlasBaseClient { DefaultClientConfig config = new DefaultClientConfig(); // Enable POJO mapping feature config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000);; + int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000); + ; int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000); if (configuration.getBoolean(TLS_ENABLED, false)) { // create an SSL properties configuration if one doesn't exist. SSLFactory expects a file, so forced @@ -237,10 +239,10 @@ public abstract class AtlasBaseClient { activeServerAddress = serverInstance; break; } else { - LOG.info("attempt #{}: Service {} - is not active. status={}", (i+1), serverInstance, adminStatus); + 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); + LOG.error("attempt #{}: Service {} - could not get status", (i + 1), serverInstance, e); } sleepBetweenRetries(); } @@ -280,7 +282,7 @@ public abstract class AtlasBaseClient { protected T callAPIWithResource(APIInfo api, WebResource resource, Object requestObject, Class responseType) throws AtlasServiceException { GenericType genericType = null; - if(responseType != null) { + if (responseType != null) { genericType = new GenericType<>(responseType); } return callAPIWithResource(api, resource, requestObject, genericType); @@ -381,7 +383,7 @@ public abstract class AtlasBaseClient { * @return Return metrics of the service instance the client is pointing to * @throws AtlasServiceException */ - public AtlasMetrics getAtlasMetrics () throws AtlasServiceException { + public AtlasMetrics getAtlasMetrics() throws AtlasServiceException { return callAPI(METRICS, AtlasMetrics.class, null); } @@ -423,18 +425,18 @@ public abstract class AtlasBaseClient { throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries.")); } - public T callAPI(APIInfo api, Object requestObject, Class responseType, String... params) + public T callAPI(APIInfo api, Class responseType, Object requestObject, String... params) throws AtlasServiceException { return callAPIWithResource(api, getResource(api, params), requestObject, responseType); } - public T callAPI(APIInfo api, Object requestObject, GenericType responseType, String... params) + public T callAPI(APIInfo api, GenericType responseType, Object requestObject, String... params) throws AtlasServiceException { return callAPIWithResource(api, getResource(api, params), requestObject, responseType); } - public T callAPI(APIInfo api, Object requestBody, Class responseType, + 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); @@ -483,7 +485,7 @@ public abstract class AtlasBaseClient { return resource; } - protected WebResource getResource(APIInfo api, MultivaluedMap queryParams, String ... pathParams) { + protected WebResource getResource(APIInfo api, MultivaluedMap queryParams, String... pathParams) { WebResource resource = service.path(api.getPath()); resource = appendPathParams(resource, pathParams); resource = appendQueryParams(queryParams, resource); @@ -523,7 +525,7 @@ public abstract class AtlasBaseClient { return resource; } - protected APIInfo formatPathForPathParams(APIInfo apiInfo, String ... params) { + protected APIInfo updatePathParameters(APIInfo apiInfo, String... params) { return new APIInfo(String.format(apiInfo.getPath(), params), apiInfo.getMethod(), apiInfo.getExpectedStatus()); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasClient.java b/client/src/main/java/org/apache/atlas/AtlasClient.java index d0e6ed4..1c6b8d1 100755 --- a/client/src/main/java/org/apache/atlas/AtlasClient.java +++ b/client/src/main/java/org/apache/atlas/AtlasClient.java @@ -997,12 +997,12 @@ public class AtlasClient extends AtlasBaseClient { @VisibleForTesting public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException { - return callAPI(toAPIInfo(api), requestObject, JSONObject.class, (String[]) null); + return callAPI(toAPIInfo(api), JSONObject.class, requestObject, (String[]) null); } @VisibleForTesting public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String ... params) throws AtlasServiceException { - return callAPI(toAPIInfo(api), requestObject, JSONObject.class, params); + return callAPI(toAPIInfo(api), JSONObject.class, requestObject, params); } @VisibleForTesting http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasClientV2.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasClientV2.java b/client/src/main/java/org/apache/atlas/AtlasClientV2.java new file mode 100644 index 0000000..af7dbbf --- /dev/null +++ b/client/src/main/java/org/apache/atlas/AtlasClientV2.java @@ -0,0 +1,403 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas; + +import com.google.common.annotations.VisibleForTesting; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.core.util.MultivaluedMapImpl; +import org.apache.atlas.model.SearchFilter; +import org.apache.atlas.model.discovery.AtlasSearchResult; +import org.apache.atlas.model.instance.AtlasClassification; +import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications; +import org.apache.atlas.model.instance.AtlasEntity; +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.lineage.AtlasLineageInfo; +import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection; +import org.apache.atlas.model.typedef.AtlasClassificationDef; +import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.apache.atlas.model.typedef.AtlasEnumDef; +import org.apache.atlas.model.typedef.AtlasStructDef; +import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.type.AtlasType; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.configuration.Configuration; +import org.apache.hadoop.security.UserGroupInformation; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MultivaluedMap; +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 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_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.OK); + + // 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:"; + + // 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); + + + // 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 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); + + + public AtlasClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) { + super(baseUrl, basicAuthUserNamePassword); + } + + public AtlasClientV2(String... baseUrls) throws AtlasException { + super(baseUrls); + } + + public AtlasClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) { + super(ugi, doAsUser, baseUrls); + } + + protected AtlasClientV2() { + super(); + } + + @VisibleForTesting + AtlasClientV2(WebResource service, Configuration configuration) { + super(service, configuration); + } + + /** + * Bulk retrieval API for retrieving all type definitions in Atlas + * + * @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()); + } + + public AtlasEnumDef getEnumDefByName(final String name) throws AtlasServiceException { + return getTypeDefByName(name, AtlasEnumDef.class); + } + + public AtlasEnumDef getEnumDefByGuid(final String guid) throws AtlasServiceException { + return getTypeDefByGuid(guid, AtlasEnumDef.class); + } + + public AtlasStructDef getStructDefByName(final String name) throws AtlasServiceException { + return getTypeDefByName(name, AtlasStructDef.class); + } + + public AtlasStructDef getStructDefByGuid(final String guid) throws AtlasServiceException { + return getTypeDefByGuid(guid, AtlasStructDef.class); + } + + public AtlasClassificationDef getClassificationDefByName(final String name) throws AtlasServiceException { + return getTypeDefByName(name, AtlasClassificationDef.class); + } + + public AtlasClassificationDef getClassificationDefByGuid(final String guid) throws AtlasServiceException { + return getTypeDefByGuid(guid, AtlasClassificationDef.class); + } + + public AtlasEntityDef getEntityDefByName(final String name) throws AtlasServiceException { + return getTypeDefByName(name, AtlasEntityDef.class); + } + + public AtlasEntityDef getEntityDefByGuid(final String guid) throws AtlasServiceException { + return getTypeDefByGuid(guid, AtlasEntityDef.class); + } + + @Deprecated + public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasServiceException { + AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); + atlasTypesDef.getEnumDefs().add(enumDef); + AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); + assert created != null; + assert created.getEnumDefs() != null; + return created.getEnumDefs().get(0); + } + + @Deprecated + public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException { + AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); + atlasTypesDef.getStructDefs().add(structDef); + AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); + assert created != null; + assert created.getStructDefs() != null; + return created.getStructDefs().get(0); + } + + @Deprecated + public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException { + AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); + atlasTypesDef.getEntityDefs().add(entityDef); + AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); + assert created != null; + assert created.getEntityDefs() != null; + return created.getEntityDefs().get(0); + } + + @Deprecated + public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) + throws AtlasServiceException { + AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); + atlasTypesDef.getClassificationDefs().add(classificationDef); + AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); + assert created != null; + assert created.getClassificationDefs() != null; + 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 + * + * @param typesDef A composite wrapper object with corresponding lists of the type definition + * @return A composite wrapper object with lists of type definitions that were successfully + * created + */ + public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException { + return callAPI(CREATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef)); + } + + /** + * Bulk update API for all types, changes detected in the type definitions would be persisted + * + * @param typesDef A composite object that captures all type definition changes + * @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)); + } + + /** + * Bulk delete API for all types + * + * @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, AtlasTypesDef.class, 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); + } + + /* Entity Calls */ + + public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException { + return callAPI(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); + } + + public EntityMutationResponse updateEntityByAttribute(String type, Map attributes, AtlasEntity entity) throws AtlasServiceException { + MultivaluedMap queryParams = attributesToQueryParams(attributes); + + return callAPI(UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entity, queryParams, type); + } + + public EntityMutationResponse deleteEntityByAttribute(String type, Map attributes) throws AtlasServiceException { + MultivaluedMap queryParams = attributesToQueryParams(attributes); + + return callAPI(DELETE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, queryParams, type); + } + + public EntityMutationResponse createEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException { + return callAPI(CREATE_ENTITY, EntityMutationResponse.class, entity); + } + + public EntityMutationResponse updateEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException { + return callAPI(UPDATE_ENTITY, EntityMutationResponse.class, entity); + } + + public EntityMutationResponse deleteEntityByGuid(String guid) throws AtlasServiceException { + return callAPI(DELETE_ENTITY_BY_GUID, EntityMutationResponse.class, null, guid); + } + + public AtlasEntitiesWithExtInfo getEntitiesByGuids(List guids) throws AtlasServiceException { + MultivaluedMap queryParams = new MultivaluedMapImpl(); + + queryParams.put("guid", guids); + + return callAPI(GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams); + } + + public EntityMutationResponse createEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException { + return callAPI(CREATE_ENTITIES, EntityMutationResponse.class, atlasEntities); + } + + public EntityMutationResponse updateEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException { + return callAPI(UPDATE_ENTITIES, EntityMutationResponse.class, atlasEntities); + } + + public EntityMutationResponse deleteEntitiesByGuids(List guids) throws AtlasServiceException { + return callAPI(DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse.class, "guid", guids); + } + + public AtlasClassifications getClassifications(String guid) throws AtlasServiceException { + return callAPI(updatePathParameters(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); + } + + public void updateClassifications(String guid, List classifications) throws AtlasServiceException { + callAPI(updatePathParameters(UPDATE_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications); + } + + public void deleteClassifications(String guid, List classifications) throws AtlasServiceException { + callAPI(updatePathParameters(GET_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications); + } + + public void deleteClassification(String guid, String classificationName) throws AtlasServiceException { + callAPI(updatePathParameters(DELETE_CLASSIFICATION, guid, classificationName), null, null); + } + + + private MultivaluedMap attributesToQueryParams(Map attributes) { + return attributesToQueryParams(attributes, null); + } + + private MultivaluedMap attributesToQueryParams(Map attributes, + MultivaluedMap queryParams) { + if (queryParams == null) { + queryParams = new MultivaluedMapImpl(); + } + + if (MapUtils.isNotEmpty(attributes)) { + for (Map.Entry e : attributes.entrySet()) { + queryParams.putSingle(PREFIX_ATTR + e.getKey(), e.getValue()); + } + } + + 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); + } + + 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); + } + + 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); + } + + private String getAtlasPath(Class typeDefClass) { + if (typeDefClass.isAssignableFrom(AtlasEnumDef.class)) { + return "enumdef"; + } else if (typeDefClass.isAssignableFrom(AtlasEntityDef.class)) { + return "entitydef"; + } else if (typeDefClass.isAssignableFrom(AtlasClassificationDef.class)) { + return "classificationdef"; + } else if (typeDefClass.isAssignableFrom(AtlasStructDef.class)) { + return "structdef"; + } + // Code should never reach this point + return ""; + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasDiscoveryClientV2.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasDiscoveryClientV2.java b/client/src/main/java/org/apache/atlas/AtlasDiscoveryClientV2.java deleted file mode 100644 index f653111..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasDiscoveryClientV2.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas; - -import com.google.common.annotations.VisibleForTesting; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; -import org.apache.atlas.model.discovery.AtlasSearchResult; -import org.apache.commons.configuration.Configuration; -import org.apache.hadoop.security.UserGroupInformation; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - -import static org.apache.atlas.AtlasClient.LIMIT; -import static org.apache.atlas.AtlasClient.OFFSET; -import static org.apache.atlas.AtlasClient.QUERY; - -public class AtlasDiscoveryClientV2 extends AtlasBaseClient { - - 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 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); - - public AtlasDiscoveryClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) { - super(baseUrl, basicAuthUserNamePassword); - } - - public AtlasDiscoveryClientV2(String... baseUrls) throws AtlasException { - super(baseUrls); - } - - public AtlasDiscoveryClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) { - super(ugi, doAsUser, baseUrls); - } - - protected AtlasDiscoveryClientV2() { - super(); - } - - @VisibleForTesting - AtlasDiscoveryClientV2(WebResource service, Configuration configuration) { - super(service, configuration); - } - - 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); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasEntitiesClientV2.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasEntitiesClientV2.java b/client/src/main/java/org/apache/atlas/AtlasEntitiesClientV2.java deleted file mode 100644 index b16bb58..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasEntitiesClientV2.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas; - -import java.util.List; -import java.util.Map; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - -import org.apache.atlas.model.instance.AtlasClassification; -import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications; -import org.apache.atlas.model.instance.AtlasEntity; -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.commons.collections.MapUtils; -import org.apache.commons.configuration.Configuration; -import org.apache.hadoop.security.UserGroupInformation; - -import com.google.common.annotations.VisibleForTesting; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -public class AtlasEntitiesClientV2 extends AtlasBaseClient { - public static final String ENTITY_API = BASE_URI + "v2/entity/"; - - private static final APIInfo GET_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/%s", HttpMethod.GET, Response.Status.OK); - private static final APIInfo GET_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/%s", 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/%s", HttpMethod.PUT, Response.Status.OK); - private static final APIInfo DELETE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/%s", HttpMethod.DELETE, Response.Status.OK); - public static final APIInfo DELETE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/%s", HttpMethod.DELETE, Response.Status.OK); - - private static final APIInfo GET_ENTITIES_BY_GUIDS = new APIInfo(ENTITY_API + "bulk/", HttpMethod.GET, Response.Status.OK); - private static final APIInfo CREATE_ENTITIES = new APIInfo(ENTITY_API + "bulk/", HttpMethod.POST, Response.Status.OK); - private static final APIInfo UPDATE_ENTITIES = CREATE_ENTITIES; - private static final APIInfo DELETE_ENTITIES_BY_GUIDS = new APIInfo(ENTITY_API + "bulk/", 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:"; - - - public AtlasEntitiesClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) { - super(baseUrl, basicAuthUserNamePassword); - } - - public AtlasEntitiesClientV2(String... baseUrls) throws AtlasException { - super(baseUrls); - } - - public AtlasEntitiesClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) { - super(ugi, doAsUser, baseUrls); - } - - protected AtlasEntitiesClientV2() { - super(); - } - - @VisibleForTesting - AtlasEntitiesClientV2(WebResource service, Configuration configuration) { - super(service, configuration); - } - - public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException { - return callAPI(formatPathForPathParams(GET_ENTITY_BY_GUID, guid), AtlasEntityWithExtInfo.class, null); - } - - public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map attributes) throws AtlasServiceException { - MultivaluedMap queryParams = attributesToQueryParams(attributes); - - return callAPI(formatPathForPathParams(GET_ENTITY_BY_ATTRIBUTE, type), AtlasEntityWithExtInfo.class, queryParams); - } - - public EntityMutationResponse updateEntityByAttribute(String type, Map attributes, AtlasEntity entity) throws AtlasServiceException { - MultivaluedMap queryParams = attributesToQueryParams(attributes); - - return callAPI(formatPathForPathParams(UPDATE_ENTITY_BY_ATTRIBUTE, type), entity, EntityMutationResponse.class, queryParams); - } - - public EntityMutationResponse deleteEntityByAttribute(String type, Map attributes) throws AtlasServiceException { - MultivaluedMap queryParams = attributesToQueryParams(attributes); - - return callAPI(formatPathForPathParams(DELETE_ENTITY_BY_ATTRIBUTE, type), null, EntityMutationResponse.class, queryParams); - } - - public EntityMutationResponse createEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException { - return callAPI(CREATE_ENTITY, entity, EntityMutationResponse.class); - } - - public EntityMutationResponse updateEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException { - return callAPI(UPDATE_ENTITY, entity, EntityMutationResponse.class); - } - - public EntityMutationResponse deleteEntityByGuid(String guid) throws AtlasServiceException { - return callAPI(formatPathForPathParams(DELETE_ENTITY_BY_GUID, guid), EntityMutationResponse.class, null); - } - - - public AtlasEntitiesWithExtInfo getEntitiesByGuids(List guids) throws AtlasServiceException { - MultivaluedMap queryParams = new MultivaluedMapImpl(); - - queryParams.put("guid", guids); - - return callAPI(GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams); - } - - public EntityMutationResponse createEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException { - return callAPI(CREATE_ENTITIES, atlasEntities, EntityMutationResponse.class); - } - - public EntityMutationResponse updateEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException { - return callAPI(UPDATE_ENTITIES, atlasEntities, EntityMutationResponse.class); - } - - public EntityMutationResponse deleteEntitiesByGuids(List guids) throws AtlasServiceException { - return callAPI(DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse.class, "guid", guids); - } - - - public AtlasClassifications getClassifications(String guid) throws AtlasServiceException { - return callAPI(formatPathForPathParams(GET_CLASSIFICATIONS, guid), null, AtlasClassifications.class); - } - - public void addClassifications(String guid, List classifications) throws AtlasServiceException { - callAPI(formatPathForPathParams(ADD_CLASSIFICATIONS, guid), classifications, (Class)null, (String[]) null); - } - - public void updateClassifications(String guid, List classifications) throws AtlasServiceException { - callAPI(formatPathForPathParams(UPDATE_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class); - } - - public void deleteClassifications(String guid, List classifications) throws AtlasServiceException { - callAPI(formatPathForPathParams(GET_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class); - } - - public void deleteClassification(String guid, String classificationName) throws AtlasServiceException { - callAPI(formatPathForPathParams(DELETE_CLASSIFICATION, guid, classificationName), null, null); - } - - // Entities operations - public List getEntities(List entityIds) { - // TODO Map the query params correctly - return null; - } - - - private MultivaluedMap attributesToQueryParams(Map attributes) { - return attributesToQueryParams(attributes, null); - } - - private MultivaluedMap attributesToQueryParams(Map attributes, - MultivaluedMap queryParams) { - if (queryParams == null) { - queryParams = new MultivaluedMapImpl(); - } - - if (MapUtils.isNotEmpty(attributes)) { - for (Map.Entry e : attributes.entrySet()) { - queryParams.putSingle(PREFIX_ATTR + e.getKey(), e.getValue()); - } - } - - return queryParams; - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasLineageClientV2.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasLineageClientV2.java b/client/src/main/java/org/apache/atlas/AtlasLineageClientV2.java deleted file mode 100644 index ac870d4..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasLineageClientV2.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas; - -import com.google.common.annotations.VisibleForTesting; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; -import org.apache.atlas.model.lineage.AtlasLineageInfo; -import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection; -import org.apache.commons.configuration.Configuration; -import org.apache.hadoop.security.UserGroupInformation; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - -public class AtlasLineageClientV2 extends AtlasBaseClient { - - private static final String LINEAGE_URI = BASE_URI + "v2/lineage/%s/"; - private static final APIInfo LINEAGE_INFO = new APIInfo(LINEAGE_URI, HttpMethod.GET, Response.Status.OK); - - public AtlasLineageClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) { - super(baseUrl, basicAuthUserNamePassword); - } - - public AtlasLineageClientV2(String... baseUrls) throws AtlasException { - super(baseUrls); - } - - public AtlasLineageClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) { - super(ugi, doAsUser, baseUrls); - } - - protected AtlasLineageClientV2() { - super(); - } - - @VisibleForTesting - AtlasLineageClientV2(WebResource service, Configuration configuration) { - super(service, configuration); - } - - 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(formatPathForPathParams(LINEAGE_INFO, guid), AtlasLineageInfo.class, queryParams); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/client/src/main/java/org/apache/atlas/AtlasTypedefClientV2.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasTypedefClientV2.java b/client/src/main/java/org/apache/atlas/AtlasTypedefClientV2.java deleted file mode 100644 index a48b6fb..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasTypedefClientV2.java +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas; - -import com.google.common.annotations.VisibleForTesting; - -import com.sun.jersey.api.client.WebResource; - -import org.apache.atlas.model.SearchFilter; -import org.apache.atlas.model.typedef.AtlasClassificationDef; -import org.apache.atlas.model.typedef.AtlasEntityDef; -import org.apache.atlas.model.typedef.AtlasEnumDef; -import org.apache.atlas.model.typedef.AtlasStructDef; -import org.apache.atlas.model.typedef.AtlasTypesDef; -import org.apache.atlas.type.AtlasType; -import org.apache.commons.configuration.Configuration; -import org.apache.hadoop.security.UserGroupInformation; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.Response; - -public class AtlasTypedefClientV2 extends AtlasBaseClient { - - private static final String BASE_URI = "api/atlas/v2/types/"; - private static final String ENUMDEF_URI = BASE_URI + "enumdef/"; - private static final String STRUCTDEF_URI = BASE_URI + "structdef/"; - private static final String ENTITYDEF_URI = BASE_URI + "entitydef/"; - private static final String CLASSIFICATIONDEF_URI = BASE_URI + "classificationdef/"; - private static final String TYPEDEFS_PATH = BASE_URI + "typedefs/"; - private static final String GET_BY_NAME_TEMPLATE = BASE_URI + "%s/name/%s"; - private static final String GET_BY_GUID_TEMPLATE = BASE_URI + "%s/guid/%s"; - - private static final APIInfo CREATE_ENUM_DEF = new APIInfo(ENUMDEF_URI, HttpMethod.POST, Response.Status.OK); - private static final APIInfo CREATE_STRUCT_DEF = new APIInfo(STRUCTDEF_URI, HttpMethod.POST, Response.Status.OK); - private static final APIInfo CREATE_ENTITY_DEF = new APIInfo(ENTITYDEF_URI, HttpMethod.POST, Response.Status.OK); - private static final APIInfo CREATE_CLASSIFICATION_DEF = new APIInfo(CLASSIFICATIONDEF_URI, HttpMethod.POST, Response.Status.OK); - - private static final APIInfo GET_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.GET, Response.Status.OK); - private static final APIInfo CREATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.POST, Response.Status.OK); - private static final APIInfo UPDATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.PUT, Response.Status.OK); - private static final APIInfo DELETE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.DELETE, Response.Status.OK); - - public AtlasTypedefClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) { - super(baseUrl, basicAuthUserNamePassword); - } - - public AtlasTypedefClientV2(String... baseUrls) throws AtlasException { - super(baseUrls); - } - - public AtlasTypedefClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) { - super(ugi, doAsUser, baseUrls); - } - - protected AtlasTypedefClientV2() { - super(); - } - - @VisibleForTesting - AtlasTypedefClientV2(WebResource service, Configuration configuration) { - super(service, configuration); - } - - /** - * Bulk retrieval API for retrieving all type definitions in Atlas - * - * @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()); - } - - public AtlasEnumDef getEnumByName(final String name) throws AtlasServiceException { - return getTypeDefByName(name, AtlasEnumDef.class); - } - - public AtlasEnumDef getEnumByGuid(final String guid) throws AtlasServiceException { - return getTypeDefByGuid(guid, AtlasEnumDef.class); - } - - public AtlasStructDef getStructByName(final String name) throws AtlasServiceException { - return getTypeDefByName(name, AtlasStructDef.class); - } - - public AtlasStructDef getStructByGuid(final String guid) throws AtlasServiceException { - return getTypeDefByGuid(guid, AtlasStructDef.class); - } - - public AtlasClassificationDef getClassificationByName(final String name) throws AtlasServiceException { - return getTypeDefByName(name, AtlasClassificationDef.class); - } - - public AtlasClassificationDef getClassificationByGuid(final String guid) throws AtlasServiceException { - return getTypeDefByGuid(guid, AtlasClassificationDef.class); - } - - public AtlasEntityDef getEntityByName(final String name) throws AtlasServiceException { - return getTypeDefByName(name, AtlasEntityDef.class); - } - - public AtlasEntityDef getEntityByGuid(final String guid) throws AtlasServiceException { - return getTypeDefByGuid(guid, AtlasEntityDef.class); - } - - @Deprecated - public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasServiceException { - AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); - atlasTypesDef.getEnumDefs().add(enumDef); - AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); - assert created != null; - assert created.getEnumDefs() != null; - return created.getEnumDefs().get(0); - } - - @Deprecated - public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException { - AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); - atlasTypesDef.getStructDefs().add(structDef); - AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); - assert created != null; - assert created.getStructDefs() != null; - return created.getStructDefs().get(0); - } - - @Deprecated - public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException { - AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); - atlasTypesDef.getEntityDefs().add(entityDef); - AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); - assert created != null; - assert created.getEntityDefs() != null; - return created.getEntityDefs().get(0); - } - - @Deprecated - public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) - throws AtlasServiceException { - AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); - atlasTypesDef.getClassificationDefs().add(classificationDef); - AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); - assert created != null; - assert created.getClassificationDefs() != null; - 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 - * - * @param typesDef A composite wrapper object with corresponding lists of the type definition - * @return A composite wrapper object with lists of type definitions that were successfully - * created - */ - public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException { - return callAPI(CREATE_ALL_TYPE_DEFS, AtlasType.toJson(typesDef), AtlasTypesDef.class); - } - - /** - * Bulk update API for all types, changes detected in the type definitions would be persisted - * - * @param typesDef A composite object that captures all type definition changes - * @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, AtlasType.toJson(typesDef), AtlasTypesDef.class); - } - - /** - * Bulk delete API for all types - * - * @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, AtlasType.toJson(typesDef), AtlasTypesDef.class); - } - - 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, null, typeDefClass); - } - - 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, null, typeDefClass); - } - - private String getAtlasPath(Class typeDefClass) { - if (typeDefClass.isAssignableFrom(AtlasEnumDef.class)) { - return "enumdef"; - } else if (typeDefClass.isAssignableFrom(AtlasEntityDef.class)) { - return "entitydef"; - } else if (typeDefClass.isAssignableFrom(AtlasClassificationDef.class)) { - return "classificationdef"; - } else if (typeDefClass.isAssignableFrom(AtlasStructDef.class)) { - return "structdef"; - } - // Code should never reach this pion - return ""; - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java b/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java index a11351a..a95fac3 100755 --- a/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java +++ b/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java @@ -24,18 +24,18 @@ import com.google.common.collect.ImmutableSet; import com.sun.jersey.core.util.MultivaluedMapImpl; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasDiscoveryClientV2; -import org.apache.atlas.AtlasEntitiesClientV2; +import org.apache.atlas.AtlasClientV2; import org.apache.atlas.AtlasException; -import org.apache.atlas.AtlasLineageClientV2; import org.apache.atlas.AtlasServiceException; -import org.apache.atlas.AtlasTypedefClientV2; import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.discovery.AtlasSearchResult; import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult; import org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult; -import org.apache.atlas.model.instance.*; +import org.apache.atlas.model.instance.AtlasClassification; +import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.instance.AtlasEntityHeader; +import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutations.EntityOperation; import org.apache.atlas.model.lineage.AtlasLineageInfo; import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection; @@ -53,11 +53,15 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.ArrayUtils; import javax.ws.rs.core.MultivaluedMap; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; /** * A driver that sets up sample types and entities using v2 types and entity model for testing purposes. @@ -169,23 +173,14 @@ public class QuickStartV2 { return urls; } - private final AtlasTypedefClientV2 typesClient; - private final AtlasEntitiesClientV2 entitiesClient; - private final AtlasDiscoveryClientV2 discoveryClient; - private final AtlasLineageClientV2 lineageClient; + private final AtlasClientV2 atlasClientV2; QuickStartV2(String[] urls, String[] basicAuthUsernamePassword) { - typesClient = new AtlasTypedefClientV2(urls,basicAuthUsernamePassword); - entitiesClient = new AtlasEntitiesClientV2(urls,basicAuthUsernamePassword); - discoveryClient = new AtlasDiscoveryClientV2(urls,basicAuthUsernamePassword); - lineageClient = new AtlasLineageClientV2(urls,basicAuthUsernamePassword); + atlasClientV2 = new AtlasClientV2(urls,basicAuthUsernamePassword); } QuickStartV2(String[] urls) throws AtlasException { - typesClient = new AtlasTypedefClientV2(urls); - entitiesClient = new AtlasEntitiesClientV2(urls); - discoveryClient = new AtlasDiscoveryClientV2(urls); - lineageClient = new AtlasLineageClientV2(urls); + atlasClientV2 = new AtlasClientV2(urls); } @@ -193,7 +188,7 @@ public class QuickStartV2 { AtlasTypesDef atlasTypesDef = createTypeDefinitions(); System.out.println("\nCreating sample types: "); - typesClient.createAtlasTypeDefs(atlasTypesDef); + atlasClientV2.createAtlasTypeDefs(atlasTypesDef); verifyTypesCreated(); } @@ -341,11 +336,11 @@ public class QuickStartV2 { private AtlasEntity createInstance(AtlasEntity entity, String[] traitNames) throws Exception { AtlasEntity ret = null; - EntityMutationResponse response = entitiesClient.createEntity(new AtlasEntityWithExtInfo(entity)); + EntityMutationResponse response = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(entity)); List entities = response.getEntitiesByOperation(EntityOperation.CREATE); if (CollectionUtils.isNotEmpty(entities)) { - AtlasEntityWithExtInfo getByGuidResponse = entitiesClient.getEntityByGuid(entities.get(0).getGuid()); + AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid()); ret = getByGuidResponse.getEntity(); System.out.println("Created entity of type [" + ret.getTypeName() + "], guid: " + ret.getGuid()); } @@ -463,7 +458,7 @@ public class QuickStartV2 { searchParams.clear(); searchParams.add(SearchFilter.PARAM_NAME, typeName); SearchFilter searchFilter = new SearchFilter(searchParams); - AtlasTypesDef searchDefs = typesClient.getAllTypeDefs(searchFilter); + AtlasTypesDef searchDefs = atlasClientV2.getAllTypeDefs(searchFilter); assert (!searchDefs.isEmpty()); System.out.println("Created type [" + typeName + "]"); @@ -516,7 +511,7 @@ public class QuickStartV2 { System.out.println("\nSample DSL Queries: "); for (String dslQuery : getDSLQueries()) { - AtlasSearchResult results = discoveryClient.dslSearchWithParams(dslQuery, 10, 0); + AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0); if (results != null) { List entitiesResult = results.getEntities(); @@ -539,7 +534,7 @@ public class QuickStartV2 { private void lineage() throws AtlasServiceException { System.out.println("\nSample Lineage Info: "); - AtlasLineageInfo lineageInfo = lineageClient.getLineageInfo(getTableId(SALES_FACT_DAILY_MV_TABLE), LineageDirection.BOTH, 0); + AtlasLineageInfo lineageInfo = atlasClientV2.getLineageInfo(getTableId(SALES_FACT_DAILY_MV_TABLE), LineageDirection.BOTH, 0); Set relations = lineageInfo.getRelations(); Map guidEntityMap = lineageInfo.getGuidEntityMap(); @@ -556,7 +551,7 @@ public class QuickStartV2 { Map attributes = new HashMap<>(); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName); - AtlasEntity tableEntity = entitiesClient.getEntityByAttribute(TABLE_TYPE, attributes).getEntity(); + AtlasEntity tableEntity = atlasClientV2.getEntityByAttribute(TABLE_TYPE, attributes).getEntity(); return tableEntity.getGuid(); } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java ---------------------------------------------------------------------- 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 f030140..e6d5697 100644 --- a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java +++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java @@ -56,10 +56,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import static org.apache.atlas.AtlasEntitiesClientV2.CREATE_ENTITY; -import static org.apache.atlas.AtlasEntitiesClientV2.DELETE_ENTITY_BY_ATTRIBUTE; -import static org.apache.atlas.AtlasEntitiesClientV2.UPDATE_ENTITY; -import static org.apache.atlas.AtlasEntitiesClientV2.UPDATE_ENTITY_BY_ATTRIBUTE; +import static org.apache.atlas.AtlasClientV2.CREATE_ENTITY; +import static org.apache.atlas.AtlasClientV2.DELETE_ENTITY_BY_ATTRIBUTE; +import static org.apache.atlas.AtlasClientV2.UPDATE_ENTITY; +import static org.apache.atlas.AtlasClientV2.UPDATE_ENTITY_BY_ATTRIBUTE; import static org.apache.atlas.notification.hook.HookNotification.EntityCreateRequest; import static org.apache.atlas.notification.hook.HookNotification.EntityDeleteRequest; import static org.apache.atlas.notification.hook.HookNotification.EntityUpdateRequest; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java b/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java index 1449812..7f3192a 100644 --- a/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java +++ b/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java @@ -61,7 +61,7 @@ public class QuickStartV2IT extends BaseResourceIT { private AtlasEntity getDB(String dbName) throws AtlasServiceException, JSONException { Map attributes = new HashMap<>(); attributes.put("name", dbName); - AtlasEntity dbEntity = entitiesClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity(); + AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity(); return dbEntity; } @@ -80,20 +80,20 @@ public class QuickStartV2IT extends BaseResourceIT { private AtlasEntity getTable(String tableName) throws AtlasServiceException { Map attributes = new HashMap<>(); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName); - AtlasEntity tableEntity = entitiesClientV2.getEntityByAttribute(QuickStartV2.TABLE_TYPE, attributes).getEntity(); + AtlasEntity tableEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.TABLE_TYPE, attributes).getEntity(); return tableEntity; } private AtlasEntity getProcess(String processName) throws AtlasServiceException { Map attributes = new HashMap<>(); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, processName); - AtlasEntity processEntity = entitiesClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity(); + AtlasEntity processEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity(); return processEntity; } private void verifyTrait(AtlasEntity table) throws AtlasServiceException { - AtlasClassification.AtlasClassifications classfications = entitiesClientV2.getClassifications(table.getGuid()); + AtlasClassification.AtlasClassifications classfications = atlasClientV2.getClassifications(table.getGuid()); List traits = classfications.getList(); assertNotNull(traits.get(0).getTypeName()); } @@ -126,7 +126,7 @@ public class QuickStartV2IT extends BaseResourceIT { public void testProcessIsAdded() throws AtlasServiceException, JSONException { Map attributes = new HashMap<>(); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.LOAD_SALES_DAILY_PROCESS); - AtlasEntity loadProcess = entitiesClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity(); + AtlasEntity loadProcess = atlasClientV2.getEntityByAttribute(QuickStartV2.LOAD_PROCESS_TYPE, attributes).getEntity(); Map loadProcessAttribs = loadProcess.getAttributes(); assertEquals(QuickStartV2.LOAD_SALES_DAILY_PROCESS, loadProcessAttribs.get(AtlasClient.NAME)); @@ -162,7 +162,7 @@ public class QuickStartV2IT extends BaseResourceIT { String salesDailyProcessId = getProcessId(QuickStartV2.LOAD_SALES_DAILY_PROCESS); String salesMonthlyProcessId = getProcessId(QuickStartV2.LOAD_SALES_MONTHLY_PROCESS); - AtlasLineageInfo inputLineage = lineageClientV2.getLineageInfo(salesFactDailyMVId, LineageDirection.BOTH, 0); + AtlasLineageInfo inputLineage = atlasClientV2.getLineageInfo(salesFactDailyMVId, LineageDirection.BOTH, 0); List relations = new ArrayList<>(inputLineage.getRelations()); Map entityMap = inputLineage.getGuidEntityMap(); @@ -181,7 +181,7 @@ public class QuickStartV2IT extends BaseResourceIT { public void testViewIsAdded() throws AtlasServiceException, JSONException { Map attributes = new HashMap<>(); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStartV2.PRODUCT_DIM_VIEW); - AtlasEntity view = entitiesClientV2.getEntityByAttribute(QuickStartV2.VIEW_TYPE, attributes).getEntity(); + AtlasEntity view = atlasClientV2.getEntityByAttribute(QuickStartV2.VIEW_TYPE, attributes).getEntity(); Map viewAttributes = view.getAttributes(); assertEquals(QuickStartV2.PRODUCT_DIM_VIEW, viewAttributes.get(AtlasClient.NAME)); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java index 134c798..0bcabb7 100755 --- a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java @@ -18,32 +18,21 @@ package org.apache.atlas.web.resources; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import kafka.consumer.ConsumerTimeoutException; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasDiscoveryClientV2; -import org.apache.atlas.AtlasEntitiesClientV2; -import org.apache.atlas.AtlasLineageClientV2; +import org.apache.atlas.AtlasClientV2; import org.apache.atlas.AtlasServiceException; -import org.apache.atlas.AtlasTypedefClientV2; import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutations; -import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEnumDef; @@ -61,21 +50,10 @@ import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.json.InstanceSerialization; import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.EnumTypeDefinition; -import org.apache.atlas.typesystem.types.EnumValue; -import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.IDataType; -import org.apache.atlas.typesystem.types.Multiplicity; -import org.apache.atlas.typesystem.types.StructTypeDefinition; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.TypeUtils; +import org.apache.atlas.typesystem.types.*; import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.ParamChecker; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.RandomStringUtils; import org.codehaus.jettison.json.JSONArray; @@ -84,11 +62,17 @@ import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.BeforeClass; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -import kafka.consumer.ConsumerTimeoutException; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; /** * Base class for integration tests. @@ -104,10 +88,7 @@ public abstract class BaseResourceIT { // All service clients protected AtlasClient atlasClientV1; - protected AtlasTypedefClientV2 typedefClientV2; - protected AtlasEntitiesClientV2 entitiesClientV2; - protected AtlasDiscoveryClientV2 discoveryClientV2; - protected AtlasLineageClientV2 lineageClientV2; + protected AtlasClientV2 atlasClientV2; public static final Logger LOG = LoggerFactory.getLogger(BaseResourceIT.class); protected static final int MAX_WAIT_TIME = 60000; @@ -131,30 +112,24 @@ public abstract class BaseResourceIT { if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) { atlasClientV1 = new AtlasClient(atlasUrls, new String[]{"admin", "admin"}); - typedefClientV2 = new AtlasTypedefClientV2(atlasUrls, new String[]{"admin", "admin"}); - entitiesClientV2 = new AtlasEntitiesClientV2(atlasUrls, new String[]{"admin", "admin"}); - discoveryClientV2 = new AtlasDiscoveryClientV2(atlasUrls, new String[]{"admin", "admin"}); - lineageClientV2 = new AtlasLineageClientV2(atlasUrls, new String[]{"admin", "admin"}); + atlasClientV2 = new AtlasClientV2(atlasUrls, new String[]{"admin", "admin"}); } else { atlasClientV1 = new AtlasClient(atlasUrls); - typedefClientV2 = new AtlasTypedefClientV2(atlasUrls); - entitiesClientV2 = new AtlasEntitiesClientV2(atlasUrls); - discoveryClientV2 = new AtlasDiscoveryClientV2(atlasUrls); - lineageClientV2 = new AtlasLineageClientV2(atlasUrls); + atlasClientV2 = new AtlasClientV2(atlasUrls); } } protected void batchCreateTypes(AtlasTypesDef typesDef) throws AtlasServiceException { for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { try { - typedefClientV2.createEnumDef(enumDef); + atlasClientV2.createEnumDef(enumDef); } catch (AtlasServiceException ex) { LOG.warn("EnumDef creation failed for {}", enumDef.getName()); } } for (AtlasStructDef structDef : typesDef.getStructDefs()) { try { - typedefClientV2.createStructDef(structDef); + atlasClientV2.createStructDef(structDef); } catch (AtlasServiceException ex) { LOG.warn("StructDef creation failed for {}", structDef.getName()); } @@ -166,7 +141,7 @@ public abstract class BaseResourceIT { Collections.emptyList(), typesDef.getEntityDefs()); try { - typedefClientV2.createAtlasTypeDefs(entityDefs); + atlasClientV2.createAtlasTypeDefs(entityDefs); } catch(AtlasServiceException e) { LOG.warn("Type creation failed for {}", typesDef.toString()); @@ -175,7 +150,7 @@ public abstract class BaseResourceIT { for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { try { - typedefClientV2.createClassificationDef(classificationDef); + atlasClientV2.createClassificationDef(classificationDef); } catch (AtlasServiceException ex) { LOG.warn("ClassificationDef creation failed for {}", classificationDef.getName()); } @@ -187,28 +162,28 @@ public abstract class BaseResourceIT { // Since the bulk create bails out on a single failure, this has to be done as a workaround for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { try { - typedefClientV2.createEnumDef(enumDef); + atlasClientV2.createEnumDef(enumDef); } catch (AtlasServiceException ex) { LOG.warn("EnumDef creation failed for {}", enumDef.getName()); } } for (AtlasStructDef structDef : typesDef.getStructDefs()) { try { - typedefClientV2.createStructDef(structDef); + atlasClientV2.createStructDef(structDef); } catch (AtlasServiceException ex) { LOG.warn("StructDef creation failed for {}", structDef.getName()); } } for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { try { - typedefClientV2.createEntityDef(entityDef); + atlasClientV2.createEntityDef(entityDef); } catch (AtlasServiceException ex) { LOG.warn("EntityDef creation failed for {}", entityDef.getName()); } } for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { try { - typedefClientV2.createClassificationDef(classificationDef); + atlasClientV2.createClassificationDef(classificationDef); } catch (AtlasServiceException ex) { LOG.warn("ClassificationDef creation failed for {}", classificationDef.getName()); } @@ -288,13 +263,13 @@ public abstract class BaseResourceIT { EntityMutationResponse entity = null; try { if (!update) { - entity = entitiesClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity)); + entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity)); assertNotNull(entity); assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE)); assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size() > 0); return entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0); } else { - entity = entitiesClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity)); + entity = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity)); assertNotNull(entity); assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE)); assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/46b1b36e/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java index c99ff57..db3a7c3 100755 --- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java @@ -63,7 +63,7 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { public void testSearchByDSL() throws Exception { String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\""; - AtlasSearchResult searchResult = discoveryClientV2.dslSearch(dslQuery); + AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery); assertNotNull(searchResult); assertEquals(searchResult.getQueryText(), dslQuery); assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL); @@ -84,48 +84,48 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { @Test public void testSearchDSLLimits() throws Exception { String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\""; - AtlasSearchResult searchResult = discoveryClientV2.dslSearch(dslQuery); + AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery); assertNotNull(searchResult); //higher limit, all results returned - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, 10, 0); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0); assertEquals(searchResult.getEntities().size(), 1); //default limit and offset -1, all results returned - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, -1, -1); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, -1, -1); assertEquals(searchResult.getEntities().size(), 1); //uses the limit parameter passed - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, 1, 0); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 1, 0); assertEquals(searchResult.getEntities().size(), 1); //uses the offset parameter passed - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, 10, 1); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 1); assertNull(searchResult.getEntities()); //limit > 0 - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, 0, 10); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 0, 10); assertNull(searchResult.getEntities()); //limit > maxlimit - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, Integer.MAX_VALUE, 10); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, Integer.MAX_VALUE, 10); assertNull(searchResult.getEntities()); //offset >= 0 - searchResult = discoveryClientV2.dslSearchWithParams(dslQuery, 10, -2); + searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, -2); assertEquals(searchResult.getEntities().size(), 1); } @Test(expectedExceptions = AtlasServiceException.class) public void testSearchByDSLForUnknownType() throws Exception { String dslQuery = "from blah"; - discoveryClientV2.dslSearch(dslQuery); + atlasClientV2.dslSearch(dslQuery); } @Test public void testSearchUsingDSL() throws Exception { String query = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\""; - AtlasSearchResult searchResult = discoveryClientV2.dslSearch(query); + AtlasSearchResult searchResult = atlasClientV2.dslSearch(query); assertNotNull(searchResult); assertEquals(searchResult.getQueryText(), query); @@ -147,7 +147,7 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { @Test public void testSearchFullTextOnDSLFailure() throws Exception { String query = "*"; - AtlasSearchResult searchResult = discoveryClientV2.fullTextSearch(query); + AtlasSearchResult searchResult = atlasClientV2.fullTextSearch(query); assertNotNull(searchResult); assertEquals(searchResult.getQueryText(), query); assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT); @@ -155,7 +155,7 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { @Test(dependsOnMethods = "testSearchDSLLimits") public void testSearchUsingFullText() throws Exception { - AtlasSearchResult searchResult = discoveryClientV2.fullTextSearchWithParams(dbName, 10, 0); + AtlasSearchResult searchResult = atlasClientV2.fullTextSearchWithParams(dbName, 10, 0); assertNotNull(searchResult); assertEquals(searchResult.getQueryText(), dbName); @@ -173,25 +173,25 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { String query = dbName; MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("query", query); - searchResult = discoveryClientV2.fullTextSearch(query); + searchResult = atlasClientV2.fullTextSearch(query); assertNotNull(searchResult); assertEquals(searchResult.getFullTextResult().size(), 1); //verify passed in limits and offsets are used //higher limit and 0 offset returns all results - searchResult = discoveryClientV2.fullTextSearchWithParams(query, 10, 0); + searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 0); assertEquals(searchResult.getFullTextResult().size(), 1); //offset is used - searchResult = discoveryClientV2.fullTextSearchWithParams(query, 10, 1); + searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 1); assertEquals(searchResult.getFullTextResult().size(), 1); //limit is used - searchResult = discoveryClientV2.fullTextSearchWithParams(query, 1, 0); + searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 0); assertEquals(searchResult.getFullTextResult().size(), 1); //higher offset returns 0 results - searchResult = discoveryClientV2.fullTextSearchWithParams(query, 1, 2); + searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 2); assertEquals(searchResult.getFullTextResult().size(), 1); }