http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/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 deleted file mode 100755 index 5fa5df7..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasClient.java +++ /dev/null @@ -1,962 +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.google.common.collect.ImmutableSet; -import com.sun.jersey.api.client.WebResource; -import org.apache.atlas.model.legacy.EntityResult; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.Struct; -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.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.utils.TypesUtil; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.lang.StringUtils; -import org.apache.hadoop.security.UserGroupInformation; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.Cookie; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * Client for metadata. - */ -@Deprecated -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 GUID_ASSIGNMENTS = "guidAssignments"; - - public static final String DEFINITION = "definition"; - 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 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 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 ATTRIBUTE_VALUE = "value"; - - 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 DESCRIPTION = "description"; - 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 PROCESS_ATTRIBUTE_OUTPUTS = "outputs"; - - 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"; - - /** - * Constructor for AtlasClient with cookie params as header - * @param baseUrl - * @param cookieName - * @param value - * @param path - * @param domain - */ - - public AtlasClient(String[] baseUrl, String cookieName, String value, String path, String domain) { - super(baseUrl, new Cookie( cookieName, value, path, domain)); - } - - /** - * Constructor for AtlasClient with cookie as header - * @param baseUrl - * @param cookie - */ - - public AtlasClient(String[] baseUrl, Cookie cookie) { - super(baseUrl, cookie); - } - - - // New constructor for Basic auth - public AtlasClient(String[] baseUrl, String[] basicAuthUserNamePassword) { - super(baseUrl, basicAuthUserNamePassword); - } - - /** - * Create a new Atlas client. - * @param baseUrls A list of URLs that point to an ensemble of Atlas servers working in - * High Availability mode. The client will automatically determine the - * active instance on startup and also when there is a scenario of - * failover. - */ - public AtlasClient(String... baseUrls) throws AtlasException { - this(getCurrentUGI(), baseUrls); - } - - /** - * Create a new Atlas client. - * @param ugi UserGroupInformation - * @param doAsUser - * @param baseUrls A list of URLs that point to an ensemble of Atlas servers working in - * High Availability mode. The client will automatically determine the - * active instance on startup and also when there is a scenario of - * failover. - */ - public AtlasClient(UserGroupInformation ugi, String doAsUser, String... baseUrls) { - initializeState(baseUrls, ugi, doAsUser); - } - - private AtlasClient(UserGroupInformation ugi, String[] baseUrls) { - this(ugi, ugi.getShortUserName(), baseUrls); - } - - //Used by LocalAtlasClient - protected AtlasClient() { - //Do nothing - } - - @VisibleForTesting - public AtlasClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword) { - super(configuration, baseUrl, basicAuthUserNamePassword); - } - - @VisibleForTesting - public AtlasClient(Configuration configuration, String... baseUrls) throws AtlasException { - initializeState(configuration, baseUrls, getCurrentUGI(), getCurrentUGI().getShortUserName()); - } - - @VisibleForTesting - AtlasClient(WebResource service, Configuration configuration) { - super(service, configuration); - } - - public WebResource getResource() { - return service; - } - - public enum API { - - //Admin operations - VERSION(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK), - STATUS(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), - - //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), - - //audit operation - LIST_ENTITY_AUDIT(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), - - //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), - - //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), - - //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); - - 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; - } - } - - /** - * Register the given type(meta model) - * @param typeAsJson type definition a jaon - * @return result json object - * @throws AtlasServiceException - */ - public List<String> createType(String typeAsJson) throws AtlasServiceException { - LOG.debug("Creating type definition: {}", typeAsJson); - JSONObject response = callAPIWithBody(API.CREATE_TYPE, typeAsJson); - List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() { - @Override - String extractElement(JSONObject element) throws JSONException { - return element.getString(AtlasClient.NAME); - } - }); - LOG.debug("Create type definition returned results: {}", results); - return results; - } - - /** - * Register the given type(meta model) - * @param typeDef type definition - * @return result json object - * @throws AtlasServiceException - */ - public List<String> createType(TypesDef typeDef) throws AtlasServiceException { - return createType(TypesSerialization.toJson(typeDef)); - } - - /** - * Creates trait type with specifiedName, superTraits and attributes - * @param traitName the name of the trait type - * @param superTraits the list of super traits from which this trait type inherits attributes - * @param attributeDefinitions the list of attributes of the trait type - * @return the list of types created - * @throws AtlasServiceException - */ - public List<String> createTraitType(String traitName, ImmutableSet<String> superTraits, AttributeDefinition... attributeDefinitions) throws AtlasServiceException { - HierarchicalTypeDefinition<TraitType> piiTrait = - TypesUtil.createTraitTypeDef(traitName, superTraits, attributeDefinitions); - - String traitDefinitionAsJSON = TypesSerialization.toJson(piiTrait, true); - LOG.debug("Creating trait type {} {}" , traitName, traitDefinitionAsJSON); - return createType(traitDefinitionAsJSON); - } - - /** - * Creates simple trait type with specifiedName with no superTraits or attributes - * @param traitName the name of the trait type - * @return the list of types created - * @throws AtlasServiceException - */ - public List<String> createTraitType(String traitName) throws AtlasServiceException { - return createTraitType(traitName, null); - } - - /** - * Register the given type(meta model) - * @param typeAsJson type definition a jaon - * @return result json object - * @throws AtlasServiceException - */ - public List<String> updateType(String typeAsJson) throws AtlasServiceException { - LOG.debug("Updating type definition: {}", typeAsJson); - JSONObject response = callAPIWithBody(API.UPDATE_TYPE, typeAsJson); - List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() { - @Override - String extractElement(JSONObject element) throws JSONException { - return element.getString(AtlasClient.NAME); - } - }); - LOG.debug("Update type definition returned results: {}", results); - return results; - } - - /** - * Register the given type(meta model) - * @param typeDef type definition - * @return result json object - * @throws AtlasServiceException - */ - public List<String> updateType(TypesDef typeDef) throws AtlasServiceException { - return updateType(TypesSerialization.toJson(typeDef)); - } - - /** - * Returns all type names in the system - * @return list of type names - * @throws AtlasServiceException - */ - public List<String> listTypes() throws AtlasServiceException { - final JSONObject jsonObject = callAPIWithQueryParams(API.LIST_TYPES, null); - return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation<String, String>()); - } - - /** - * Returns all type names with the given category - * @param category - * @return list of type names - * @throws AtlasServiceException - */ - public List<String> listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException { - JSONObject response = callAPIWithRetries(API.LIST_TYPES, null, new ResourceCreator() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.LIST_TYPES.getPath()); - resource = resource.queryParam(TYPE, category.name()); - return resource; - } - }); - return extractResults(response, AtlasClient.RESULTS, new ExtractOperation<String, String>()); - } - - /** - * Return the list of type names in the type system which match the specified filter. - * - * @param category returns types whose category is the given typeCategory - * @param superType returns types which contain the given supertype - * @param notSupertype returns types which do not contain the given supertype - * - * Its possible to specify combination of these filters in one request and the conditions are combined with AND - * For example, typeCategory = TRAIT && supertype contains 'X' && supertype !contains 'Y' - * If there is no filter, all the types are returned - * @return list of type names - */ - public List<String> listTypes(final DataTypes.TypeCategory category, final String superType, - final String notSupertype) throws AtlasServiceException { - JSONObject response = callAPIWithRetries(API.LIST_TYPES, null, new ResourceCreator() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.LIST_TYPES); - resource = resource.queryParam(TYPE, category.name()); - resource = resource.queryParam(SUPERTYPE, superType); - resource = resource.queryParam(NOT_SUPERTYPE, notSupertype); - return resource; - } - }); - return extractResults(response, AtlasClient.RESULTS, new ExtractOperation<String, String>()); - } - - public TypesDef getType(String typeName) throws AtlasServiceException { - try { - JSONObject response = callAPIWithBodyAndParams(API.GET_TYPE, null, typeName); - String typeJson = response.getString(DEFINITION); - return TypesSerialization.fromJson(typeJson); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - /** - * Create the given entity - * @param entities entity(type instance) as json - * @return json array of guids - * @throws AtlasServiceException - */ - protected List<String> createEntity(JSONArray entities) throws AtlasServiceException { - LOG.debug("Creating entities: {}", entities); - JSONObject response = callAPIWithBody(API.CREATE_ENTITY, entities.toString()); - List<String> results = extractEntityResult(response).getCreatedEntities(); - LOG.debug("Create entities returned results: {}", results); - return results; - } - - protected EntityResult extractEntityResult(JSONObject response) throws AtlasServiceException { - return EntityResult.fromString(response.toString()); - } - - /** - * Create the given entity - * @param entitiesAsJson entity(type instance) as json - * @return json array of guids - * @throws AtlasServiceException - */ - public List<String> createEntity(String... entitiesAsJson) throws AtlasServiceException { - return createEntity(new JSONArray(Arrays.asList(entitiesAsJson))); - } - - public List<String> createEntity(Referenceable... entities) throws AtlasServiceException { - return createEntity(Arrays.asList(entities)); - } - - public List<String> createEntity(Collection<Referenceable> entities) throws AtlasServiceException { - JSONArray entityArray = getEntitiesArray(entities); - return createEntity(entityArray); - } - - private JSONArray getEntitiesArray(Collection<Referenceable> entities) { - JSONArray entityArray = new JSONArray(entities.size()); - for (Referenceable entity : entities) { - entityArray.put(InstanceSerialization.toJson(entity, true)); - } - return entityArray; - } - - /** - * Replaces entity definitions identified by their guid or unique attribute - * Updates properties set in the definition for the entity corresponding to guid - * @param entities entities to be updated - * @return json array of guids which were updated/created - * @throws AtlasServiceException - */ - public EntityResult updateEntities(Referenceable... entities) throws AtlasServiceException { - return updateEntities(Arrays.asList(entities)); - } - - protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException { - LOG.debug("Updating entities: {}", entities); - JSONObject response = callAPIWithBody(API.UPDATE_ENTITY, entities.toString()); - EntityResult results = extractEntityResult(response); - LOG.debug("Update entities returned results: {}", results); - return results; - } - - public EntityResult updateEntities(Collection<Referenceable> entities) throws AtlasServiceException { - JSONArray entitiesArray = getEntitiesArray(entities); - return updateEntities(entitiesArray); - } - - /** - * Supports Partial updates - * Updates property for the entity corresponding to guid - * @param guid guid - * @param attribute property key - * @param value property value - */ - 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() { - @Override - public WebResource createResource() { - API api = API.UPDATE_ENTITY_PARTIAL; - WebResource resource = getResource(api, guid); - resource = resource.queryParam(ATTRIBUTE_NAME, attribute); - return resource; - } - }); - return extractEntityResult(response); - } - - /** - * Supports Partial updates - * Updates properties set in the definition for the entity corresponding to guid - * @param guid guid - * @param entity entity definition - */ - 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); - return extractEntityResult(response); - } - - /** - * Associate trait to an entity - * - * @param guid guid - * @param traitDefinition trait definition - */ - 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); - } - - /** - * Delete a trait from the given entity - * @param guid guid of the entity - * @param traitName trait to be deleted - * @throws AtlasServiceException - */ - public void deleteTrait(String guid, String traitName) throws AtlasServiceException { - callAPIWithBodyAndParams(API.DELETE_TRAITS, null, guid, TRAITS, traitName); - } - - /** - * Supports Partial updates - * Updates properties set in the definition for the entity corresponding to guid - * @param entityType Type of the entity being updated - * @param uniqueAttributeName Attribute Name that uniquely identifies the entity - * @param uniqueAttributeValue Attribute Value that uniquely identifies the entity - * @param entity entity definition - */ - 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); - LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType, - uniqueAttributeName, uniqueAttributeValue, entityJson); - JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() { - @Override - public WebResource createResource() { - WebResource resource = getResource(api, QUALIFIED_NAME); - resource = resource.queryParam(TYPE, entityType); - resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName); - resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue); - return resource; - } - }); - EntityResult result = extractEntityResult(response); - LOG.debug("Update entity returned result: {}", result); - return result; - } - - protected String getString(JSONObject jsonObject, String parameter) throws AtlasServiceException { - try { - return jsonObject.getString(parameter); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - /** - * Delete the specified entities from the repository - * - * @param guids guids of entities to delete - * @return List of entity ids updated/deleted - * @throws AtlasServiceException - */ - public EntityResult deleteEntities(final String ... guids) throws AtlasServiceException { - LOG.debug("Deleting entities: {}", guids); - JSONObject jsonResponse = callAPIWithRetries(API.DELETE_ENTITIES, 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); - } - return resource; - } - }); - EntityResult results = extractEntityResult(jsonResponse); - LOG.debug("Delete entities returned results: {}", results); - return results; - } - - /** - * Supports Deletion of an entity identified by its unique attribute value - * @param entityType Type of the entity being deleted - * @param uniqueAttributeName Attribute Name that uniquely identifies the entity - * @param uniqueAttributeValue Attribute Value that uniquely identifies the entity - * @return List of entity ids updated/deleted(including composite references from that entity) - */ - 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; - 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); - LOG.debug("Delete entities returned results: {}", results); - return results; - } - - /** - * Get an entity given the entity id - * @param guid entity id - * @return result object - * @throws AtlasServiceException - */ - public Referenceable getEntity(String guid) throws AtlasServiceException { - JSONObject jsonResponse = callAPIWithBodyAndParams(API.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); - } - } - - public static String toString(JSONArray jsonArray) throws JSONException { - ArrayList<String> resultsList = new ArrayList<>(); - for (int index = 0; index < jsonArray.length(); index++) { - resultsList.add(jsonArray.getString(index)); - } - return StringUtils.join(resultsList, ","); - } - - /** - * Get an entity given the entity id - * @param entityType entity type name - * @param attribute qualified name of the entity - * @param value - * @return result object - * @throws AtlasServiceException - */ - public Referenceable getEntity(final String entityType, final String attribute, final String value) - throws AtlasServiceException { - JSONObject jsonResponse = callAPIWithRetries(API.GET_ENTITY, null, new ResourceCreator() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.GET_ENTITY); - resource = resource.queryParam(TYPE, entityType); - resource = resource.queryParam(ATTRIBUTE_NAME, attribute); - resource = resource.queryParam(ATTRIBUTE_VALUE, value); - return resource; - } - }); - try { - String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION); - return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true); - } catch (JSONException e) { - throw new AtlasServiceException(API.GET_ENTITY, e); - } - } - - /** - * List entities for a given entity type - * @param entityType - * @return - * @throws AtlasServiceException - */ - public List<String> listEntities(final String entityType) throws AtlasServiceException { - JSONObject jsonResponse = callAPIWithRetries(API.LIST_ENTITIES, null, new ResourceCreator() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.LIST_ENTITIES); - resource = resource.queryParam(TYPE, entityType); - return resource; - } - }); - return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>()); - } - - /** - * List traits for a given entity identified by its GUID - * @param guid GUID of the entity - * @return List<String> - traitnames associated with entity - * @throws AtlasServiceException - */ - public List<String> listTraits(final String guid) throws AtlasServiceException { - JSONObject jsonResponse = callAPIWithBodyAndParams(API.LIST_TRAITS, null, guid, URI_TRAITS); - return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>()); - } - - /** - * Get all trait definitions for an entity - * @param guid GUID of the entity - * @return List<String> trait definitions of the traits associated to the entity - * @throws AtlasServiceException - */ - public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException{ - JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS); - List<JSONObject> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<JSONObject, JSONObject>()); - ArrayList<Struct> traitStructList = new ArrayList<>(); - for(JSONObject traitDef:traitDefList){ - Struct traitStruct = InstanceSerialization.fromJsonStruct(traitDef.toString(), true); - traitStructList.add(traitStruct); - } - return traitStructList; - } - - /** - * Get trait definition for a given entity and traitname - * @param guid GUID of the entity - * @param traitName - * @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); - - try { - return InstanceSerialization.fromJsonStruct(jsonResponse.getString(AtlasClient.RESULTS), false); - }catch (JSONException e){ - throw new AtlasServiceException(API.GET_TRAIT_DEFINITION, e); - } - } - - protected class ExtractOperation<T, U> { - T extractElement(U element) throws JSONException { - return (T) element; - } - } - - protected <T, U> List<T> extractResults(JSONObject jsonResponse, String key, ExtractOperation<T, U> extractInterafce) - throws AtlasServiceException { - try { - JSONArray results = jsonResponse.getJSONArray(key); - ArrayList<T> resultsList = new ArrayList<>(); - for (int index = 0; index < results.length(); index++) { - Object element = results.get(index); - resultsList.add(extractInterafce.extractElement((U) element)); - } - return resultsList; - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - /** - * Get the latest numResults entity audit events in decreasing order of timestamp for the given entity id - * @param entityId entity id - * @param numResults number of results to be returned - * @return list of audit events for the entity id - * @throws AtlasServiceException - */ - public List<EntityAuditEvent> getEntityAuditEvents(String entityId, short numResults) - throws AtlasServiceException { - return getEntityAuditEvents(entityId, null, numResults); - } - - /** - * Get the entity audit events in decreasing order of timestamp for the given entity id - * @param entityId entity id - * @param startKey key for the first event to be returned, used for pagination - * @param numResults number of results to be returned - * @return list of audit events for the entity id - * @throws AtlasServiceException - */ - public List<EntityAuditEvent> getEntityAuditEvents(String entityId, String startKey, short numResults) - throws AtlasServiceException { - WebResource resource = getResource(API.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); - return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() { - @Override - EntityAuditEvent extractElement(JSONObject element) throws JSONException { - return SerDe.GSON.fromJson(element.toString(), EntityAuditEvent.class); - } - }); - - } - - /** - * Search using dsl/full text - * @param searchQuery - * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value - * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0 - * @return Query results - * @throws AtlasServiceException - */ - public JSONArray search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException { - JSONObject result = callAPIWithRetries(API.SEARCH, null, new ResourceCreator() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.SEARCH); - resource = resource.queryParam(QUERY, searchQuery); - resource = resource.queryParam(LIMIT, String.valueOf(limit)); - resource = resource.queryParam(OFFSET, String.valueOf(offset)); - return resource; - } - }); - try { - return result.getJSONArray(RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - - } - - /** - * Search given query DSL - * @param query DSL query - * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value - * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0 - * @return result json object - * @throws AtlasServiceException - */ - 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() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.SEARCH_DSL); - resource = resource.queryParam(QUERY, query); - resource = resource.queryParam(LIMIT, String.valueOf(limit)); - resource = resource.queryParam(OFFSET, String.valueOf(offset)); - return resource; - } - }); - try { - return result.getJSONArray(RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - /** - * Search given full text search - * @param query Query - * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value - * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0 - * @return result json object - * @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() { - @Override - public WebResource createResource() { - WebResource resource = getResource(API.SEARCH_FULL_TEXT); - resource = resource.queryParam(QUERY, query); - resource = resource.queryParam(LIMIT, String.valueOf(limit)); - resource = resource.queryParam(OFFSET, String.valueOf(offset)); - return resource; - } - }); - } - - public JSONObject getInputGraph(String datasetName) throws AtlasServiceException { - JSONObject response = callAPIWithBodyAndParams(API.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph"); - try { - return response.getJSONObject(AtlasClient.RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - public JSONObject getOutputGraph(String datasetName) throws AtlasServiceException { - JSONObject response = callAPIWithBodyAndParams(API.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph"); - try { - return response.getJSONObject(AtlasClient.RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - public JSONObject getInputGraphForEntity(String entityId) throws AtlasServiceException { - JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph"); - try { - return response.getJSONObject(AtlasClient.RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - public JSONObject getOutputGraphForEntity(String datasetId) throws AtlasServiceException { - JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph"); - try { - return response.getJSONObject(AtlasClient.RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - public JSONObject getSchemaForEntity(String datasetId) throws AtlasServiceException { - JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema"); - try { - return response.getJSONObject(AtlasClient.RESULTS); - } catch (JSONException e) { - throw new AtlasServiceException(e); - } - } - - // Wrapper methods for compatibility - @VisibleForTesting - public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException { - return callAPIWithResource(toAPIInfo(api), resource, null, JSONObject.class); - } - - @VisibleForTesting - public WebResource getResource(API api, String ... params) { - return getResource(toAPIInfo(api), params); - } - - @VisibleForTesting - public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException { - 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), JSONObject.class, requestObject, params); - } - - @VisibleForTesting - public JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException { - return callAPI(toAPIInfo(api), JSONObject.class, queryParams); - } - - @VisibleForTesting - JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { - return super.callAPIWithRetries(toAPIInfo(api), requestObject, resourceCreator); - } - - private APIInfo toAPIInfo(API api){ - return new APIInfo(api.getPath(), api.getMethod(), api.getExpectedStatus()); - } - - -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/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 deleted file mode 100644 index 2cb9e84..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasClientV2.java +++ /dev/null @@ -1,466 +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.SearchFilter; -import org.apache.atlas.model.discovery.AtlasSearchResult; -import org.apache.atlas.model.discovery.SearchParameters; -import org.apache.atlas.model.instance.AtlasClassification; -import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications; -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.Cookie; -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 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:"; - - // 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 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); - } - - public AtlasClientV2(String... baseUrls) throws AtlasException { - super(baseUrls); - } - - public AtlasClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) { - super(ugi, doAsUser, baseUrls); - } - - /** - * Constructor for AtlasClient with cookie params as header - * @param baseUrl - * @param cookieName - * @param value - * @param path - * @param domain - */ - public AtlasClientV2(String[] baseUrl, String cookieName, String value, String path, String domain) { - super(baseUrl, new Cookie(cookieName, value, path, domain)); - } - - /** - * Constructor for AtlasClient with cookie as header - * @param baseUrl - * @param cookie - */ - public AtlasClientV2(String[] baseUrl, Cookie cookie) { - super(baseUrl, cookie); - } - - @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 boolean typeWithGuidExists(String guid) { - try { - callAPI(GET_TYPEDEF_BY_GUID, String.class, null, guid); - } catch (AtlasServiceException e) { - return false; - } - return true; - } - - public boolean typeWithNameExists(String name) { - try { - callAPI(GET_TYPEDEF_BY_NAME, String.class, null, name); - } catch (AtlasServiceException e) { - return false; - } - return true; - } - - 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, (Class<?>)null, AtlasType.toJson(typesDef)); - } - - /* Lineage Calls */ - - public AtlasLineageInfo getLineageInfo(final String guid, final LineageDirection direction, final int depth) throws AtlasServiceException { - MultivaluedMap<String, String> 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<String, String>) null, guid); - } - - public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException { - MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes); - - return callAPI(GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type); - } - - public EntityMutationResponse updateEntityByAttribute(String type, Map<String, String> attributes, AtlasEntityWithExtInfo entityInfo) - throws AtlasServiceException { - MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes); - - return callAPI(UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type); - } - - public EntityMutationResponse deleteEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException { - MultivaluedMap<String, String> 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<String> guids) throws AtlasServiceException { - MultivaluedMap<String, String> 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<String> 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<AtlasClassification> classifications) throws AtlasServiceException { - callAPI(updatePathParameters(ADD_CLASSIFICATIONS, guid), (Class<?>)null, classifications, (String[]) null); - } - - public void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException { - callAPI(updatePathParameters(UPDATE_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications); - } - - public void deleteClassifications(String guid, List<AtlasClassification> 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<String, String> attributesToQueryParams(Map<String, String> attributes) { - return attributesToQueryParams(attributes, null); - } - - private MultivaluedMap<String, String> attributesToQueryParams(Map<String, String> attributes, - MultivaluedMap<String, String> queryParams) { - if (queryParams == null) { - queryParams = new MultivaluedMapImpl(); - } - - if (MapUtils.isNotEmpty(attributes)) { - for (Map.Entry<String, String> e : attributes.entrySet()) { - queryParams.putSingle(PREFIX_ATTR + e.getKey(), e.getValue()); - } - } - - return queryParams; - } - - /* Discovery calls */ - public AtlasSearchResult dslSearch(final String query) throws AtlasServiceException { - MultivaluedMap<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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> T getTypeDefByName(final String name, Class<T> 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> T getTypeDefByGuid(final String guid, Class<T> 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 <T> String getAtlasPath(Class<T> typeDefClass) { - if (AtlasEnumDef.class.isAssignableFrom(typeDefClass)) { - return "enumdef"; - } else if (AtlasEntityDef.class.isAssignableFrom(typeDefClass)) { - return "entitydef"; - } else if (AtlasClassificationDef.class.isAssignableFrom(typeDefClass)) { - return "classificationdef"; - } else if (AtlasStructDef.class.isAssignableFrom(typeDefClass)) { - return "structdef"; - } - // Code should never reach this point - return ""; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java b/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java deleted file mode 100644 index 01e4e32..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java +++ /dev/null @@ -1,52 +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.base.Preconditions; -import org.apache.commons.lang.StringUtils; -import java.util.Arrays; - -import java.util.List; - -public class AtlasServerEnsemble { - - private final String[] urls; - - public AtlasServerEnsemble(String[] baseUrls) { - Preconditions.checkArgument((baseUrls!=null && baseUrls.length>0), - "List of baseURLs cannot be null or empty."); - for (String baseUrl : baseUrls) { - Preconditions.checkArgument(StringUtils.isNotEmpty(baseUrl), - "Base URL cannot be null or empty."); - } - urls = baseUrls; - } - - public boolean hasSingleInstance() { - return urls.length==1; - } - - public String firstURL() { - return urls[0]; - } - - public List<String> getMembers() { - return Arrays.asList(urls); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasServiceException.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasServiceException.java b/client/src/main/java/org/apache/atlas/AtlasServiceException.java deleted file mode 100755 index b128f98..0000000 --- a/client/src/main/java/org/apache/atlas/AtlasServiceException.java +++ /dev/null @@ -1,75 +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.sun.jersey.api.client.ClientResponse; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; - -import javax.ws.rs.WebApplicationException; - -public class AtlasServiceException extends Exception { - 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) { - super("Metadata service API " + api.getMethod() + " : " + api.getPath() + " failed", e); - } - - public AtlasServiceException(AtlasClient.API api, WebApplicationException e) throws JSONException { - this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()), - ((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) { - 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) { - this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class)); - } - - public AtlasServiceException(Exception e) { - super(e); - } - - public ClientResponse.Status getStatus() { - return status; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java b/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java deleted file mode 100644 index 5e6d6db..0000000 --- a/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java +++ /dev/null @@ -1,124 +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 org.apache.atlas.model.instance.GuidMapping; -import org.apache.atlas.model.legacy.EntityResult; -import org.apache.atlas.type.AtlasType; - -import java.util.Collections; -import java.util.List; - -/** - * Result from creating or updating entities. - */ -@Deprecated -public class CreateUpdateEntitiesResult { - - /** - * Guid mapping for the entities that were created/updated - */ - private GuidMapping guidMapping; - - /** - * Entity result - */ - private EntityResult entityResult; - - /** - * Gets the guid mapping - */ - public GuidMapping getGuidMapping() { - return guidMapping; - } - - /** - * Sets the guid mapping - */ - public void setGuidMapping(GuidMapping guidMapping) { - this.guidMapping = guidMapping; - } - - /** - * Gets the entity result - */ - public EntityResult getEntityResult() { - return entityResult; - } - - /** - * Sets the entity result - */ - public void setEntityResult(EntityResult entityResult) { - this.entityResult = entityResult; - } - - /** - * Deserializes the given json into an instance of - * CreateUpdateEntitiesResult. - * - * @param json - * the (unmodified) json that comes back from Atlas. - * @return - * @throws AtlasServiceException - */ - public static CreateUpdateEntitiesResult fromJson(String json) throws AtlasServiceException { - - GuidMapping guidMapping = AtlasType.fromJson(json, GuidMapping.class); - EntityResult entityResult = EntityResult.fromString(json); - CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult(); - result.setEntityResult(entityResult); - result.setGuidMapping(guidMapping); - return result; - } - - /** - * Convenience method to get the guids of the created entities from - * the EntityResult. - */ - public List<String> getCreatedEntities() { - if(entityResult == null) { - return Collections.emptyList(); - } - return getEntityResult().getCreatedEntities(); - } - - /** - * Convenience method to get the guids of the updated entities from - * the EntityResult. - */ - public List<String> getUpdatedEntities() { - if(entityResult == null) { - return Collections.emptyList(); - } - return getEntityResult().getUpdateEntities(); - } - - - /** - * Convenience method to get the guids of the deleted entities - * from the EntityResult. - */ - public List<String> getDeletedEntities() { - if (entityResult == null) { - return Collections.emptyList(); - } - return getEntityResult().getDeletedEntities(); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/EntityAuditEvent.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/EntityAuditEvent.java b/client/src/main/java/org/apache/atlas/EntityAuditEvent.java deleted file mode 100644 index 904674d..0000000 --- a/client/src/main/java/org/apache/atlas/EntityAuditEvent.java +++ /dev/null @@ -1,146 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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 org.apache.atlas.typesystem.IReferenceableInstance; -import org.apache.atlas.typesystem.json.InstanceSerialization; - -import java.util.Objects; - -/** - * Structure of entity audit event - */ -public class EntityAuditEvent { - public enum EntityAuditAction { - ENTITY_CREATE, ENTITY_UPDATE, ENTITY_DELETE, TAG_ADD, TAG_DELETE, TAG_UPDATE, - ENTITY_IMPORT_CREATE, ENTITY_IMPORT_UPDATE, ENTITY_IMPORT_DELETE, - } - - private String entityId; - private long timestamp; - private String user; - private EntityAuditAction action; - private String details; - private String eventKey; - private IReferenceableInstance entityDefinition; - - public EntityAuditEvent() { - } - - public EntityAuditEvent(String entityId, Long ts, String user, EntityAuditAction action, String details, - IReferenceableInstance entityDefinition) throws AtlasException { - this.entityId = entityId; - this.timestamp = ts; - this.user = user; - this.action = action; - this.details = details; - this.entityDefinition = entityDefinition; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - EntityAuditEvent that = (EntityAuditEvent) o; - return timestamp == that.timestamp && - Objects.equals(entityId, that.entityId) && - Objects.equals(user, that.user) && - action == that.action && - Objects.equals(details, that.details) && - Objects.equals(eventKey, that.eventKey) && - Objects.equals(entityDefinition, that.entityDefinition); - } - - @Override - public int hashCode() { - return Objects.hash(entityId, timestamp, user, action, details, eventKey, entityDefinition); - } - - @Override - public String toString() { - return SerDe.GSON.toJson(this); - } - - public static EntityAuditEvent fromString(String eventString) { - return SerDe.GSON.fromJson(eventString, EntityAuditEvent.class); - } - - public String getEntityId() { - return entityId; - } - - public long getTimestamp() { - return timestamp; - } - - public String getUser() { - return user; - } - - public EntityAuditAction getAction() { - return action; - } - - public String getDetails() { - return details; - } - - public void setEntityId(String entityId) { - this.entityId = entityId; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public void setUser(String user) { - this.user = user; - } - - public void setAction(EntityAuditAction action) { - this.action = action; - } - - public void setDetails(String details) { - this.details = details; - } - - public String getEventKey() { - return eventKey; - } - - public void setEventKey(String eventKey) { - this.eventKey = eventKey; - } - - public IReferenceableInstance getEntityDefinition() { - return entityDefinition; - } - - public String getEntityDefinitionString() { - if (entityDefinition != null) { - return InstanceSerialization.toJson(entityDefinition, true); - } - return null; - } - - public void setEntityDefinition(String entityDefinition) { - this.entityDefinition = InstanceSerialization.fromJsonReferenceable(entityDefinition, true); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/ResourceCreator.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/ResourceCreator.java b/client/src/main/java/org/apache/atlas/ResourceCreator.java deleted file mode 100644 index 2017065..0000000 --- a/client/src/main/java/org/apache/atlas/ResourceCreator.java +++ /dev/null @@ -1,29 +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.sun.jersey.api.client.WebResource; - -/** - * An interface to capture the closure of how a WebResource is created. - */ -@Deprecated -public interface ResourceCreator { - WebResource createResource(); -} http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/SerDe.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/SerDe.java b/client/src/main/java/org/apache/atlas/SerDe.java deleted file mode 100644 index cdc3509..0000000 --- a/client/src/main/java/org/apache/atlas/SerDe.java +++ /dev/null @@ -1,80 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import org.apache.atlas.typesystem.IReferenceableInstance; -import org.apache.atlas.typesystem.IStruct; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.Struct; -import org.apache.atlas.typesystem.json.InstanceSerialization; - -import java.lang.reflect.Type; - -@Deprecated -public class SerDe { - public static final Gson GSON = new GsonBuilder(). - registerTypeAdapter(IStruct.class, new StructDeserializer()). - registerTypeAdapter(IReferenceableInstance.class, new ReferenceableSerializerDeserializer()). - registerTypeAdapter(Referenceable.class, new ReferenceableSerializerDeserializer()). - create(); - - /** - * Serde for Struct used by AbstractNotificationConsumer.GSON. - */ - public static final class StructDeserializer implements JsonDeserializer<IStruct>, JsonSerializer<IStruct> { - @Override - public IStruct deserialize(final JsonElement json, final Type type, - final JsonDeserializationContext context) { - return context.deserialize(json, Struct.class); - } - - @Override - public JsonElement serialize(IStruct src, Type typeOfSrc, JsonSerializationContext context) { - String instanceJson = InstanceSerialization.toJson(src, true); - return new JsonParser().parse(instanceJson).getAsJsonObject(); - } - } - - /** - * Serde for Referenceable used by AbstractNotificationConsumer.GSON. - */ - public static final class ReferenceableSerializerDeserializer implements JsonDeserializer<IStruct>, - JsonSerializer<IReferenceableInstance> { - @Override - public IReferenceableInstance deserialize(final JsonElement json, final Type type, - final JsonDeserializationContext context) { - - return InstanceSerialization.fromJsonReferenceable(json.toString(), true); - } - - @Override - public JsonElement serialize(IReferenceableInstance src, Type typeOfSrc, JsonSerializationContext context) { - String instanceJson = InstanceSerialization.toJson(src, true); - return new JsonParser().parse(instanceJson).getAsJsonObject(); - } - } -}
