Commit e4cc16ac by Sarath Subramaniam Committed by Vimal Sharma

ATLAS-1565 Create EntityREST endpoints for delete operations

parent 69db4a82
......@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1565 Create EntityREST endpoints for delete operations (sarathkumarsubramanian via svimal2106)
ATLAS-1547 Added tests for hard delete (mneethiraj)
ATLAS-1546 (ATLAS-1546.3.patch)Hive hook should choose appropriate JAAS config if host uses kerberos ticket-cache (nixonrodrigues via kevalbhat)
ATLAS-1503 Export/import support to copy data between Atlas instances (ashutoshm via mneethiraj)
......
......@@ -87,7 +87,7 @@ public interface AtlasEntityStore {
EntityMutationResponse deleteById(String guid) throws AtlasBaseException;
/**
* @deprecated
* Deletes an entity using its type and unique attributes
* @param entityType type of the entity
* @param uniqAttributes Attributes that uniquely identify the entity
* @return EntityMutationResponse details of the updates performed by this call
......
......@@ -17,10 +17,8 @@
*/
package org.apache.atlas.web.rest;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasClassification;
......@@ -39,15 +37,11 @@ import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedStruct;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.web.adapters.AtlasFormatConverter;
import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
......@@ -61,7 +55,6 @@ import java.util.List;
import java.util.Map;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toAtlasBaseException;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toEntityMutationResponse;
/**
* REST for a single entity
......@@ -70,8 +63,6 @@ import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toEntityMu
@Singleton
public class EntityREST {
private static final Logger LOG = LoggerFactory.getLogger(EntityREST.class);
public static final String PREFIX_ATTR = "attr:";
private final AtlasTypeRegistry typeRegistry;
......@@ -88,8 +79,7 @@ public class EntityREST {
}
/**
* Fetch the complete definition of an entity given its GUID.
*
* Fetch complete definition of an entity given its GUID.
* @param guid GUID for the entity
* @return AtlasEntity
* @throws AtlasBaseException
......@@ -103,9 +93,9 @@ public class EntityREST {
}
/**
* Get entity information using entity type and unique attribute.
* Fetch complete definition of an entity given its type and unique attribute.
* @param typeName
* @return
* @return AtlasEntityWithExtInfo
* @throws AtlasBaseException
*/
@GET
......@@ -136,29 +126,6 @@ public class EntityREST {
return entitiesStore.createOrUpdate(new AtlasEntityStream(entity), false);
}
/**
* Delete an entity identified by its GUID
*
* @param guid
* @return
*/
@DELETE
@Path("guid/{guid}")
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse deleteByGuid(@PathParam("guid") final String guid) throws AtlasBaseException {
if (StringUtils.isEmpty(guid)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
}
try {
AtlasClient.EntityResult result = metadataService.deleteEntities(new ArrayList<String>() {{ add(guid); }});
return toEntityMutationResponse(result);
} catch (AtlasException e) {
throw toAtlasBaseException(e);
}
}
/*******
* Entity Partial Update - Allows a subset of attributes to be updated on
* an entity which is identified by its type and unique attribute eg: Referenceable.qualifiedName.
......@@ -179,76 +146,39 @@ public class EntityREST {
return entitiesStore.updateByUniqueAttributes(entityType, uniqueAttributes, entity);
}
@Deprecated
/**
* Delete an entity identified by its GUID.
* @param guid GUID for the entity
* @return EntityMutationResponse
*/
@DELETE
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse deleteByUniqueAttribute(@PathParam("typeName") String typeName,
@Context HttpServletRequest servletRequest) throws Exception {
AtlasEntityType entityType = ensureEntityType(typeName);
Map<String, Object> attributes = getAttributes(servletRequest);
validateUniqueAttribute(entityType, attributes);
// legacy API supports only one unique attribute
String attribute = attributes.keySet().toArray(new String[1])[0];
String value = (String)attributes.get(attribute);
final AtlasClient.EntityResult result = metadataService.deleteEntityByUniqueAttribute(typeName, attribute, value);
return toEntityMutationResponse(result);
}
@GET
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Path("guid/{guid}")
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids) throws AtlasBaseException {
if (CollectionUtils.isEmpty(guids)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
}
AtlasEntitiesWithExtInfo entities = entitiesStore.getByIds(guids);
return entities;
public EntityMutationResponse deleteByGuid(@PathParam("guid") final String guid) throws AtlasBaseException {
return entitiesStore.deleteById(guid);
}
/**
* Create new entity or update existing entity in Atlas.
* Existing entity is matched using its unique guid if supplied or by its unique attributes eg: qualifiedName
* @param entities
* Delete an entity identified by its type and unique attributes.
* @param typeName - entity type to be deleted
* @param servletRequest - request containing unique attributes/values
* @return EntityMutationResponse
* @throws AtlasBaseException
*/
@POST
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities) throws AtlasBaseException {
EntityStream entityStream = new AtlasEntityStream(entities);
return entitiesStore.createOrUpdate(entityStream, false);
}
/*******
* Entity Delete
*******/
@DELETE
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse deleteByGuids(@QueryParam("guid") final List<String> guids) throws AtlasBaseException {
EntityMutationResponse ret = entitiesStore.deleteByIds(guids);
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse deleteByUniqueAttribute(@PathParam("typeName") String typeName,
@Context HttpServletRequest servletRequest) throws AtlasBaseException {
AtlasEntityType entityType = ensureEntityType(typeName);
Map<String, Object> attributes = getAttributes(servletRequest);
return ret;
return entitiesStore.deleteByUniqueAttributes(entityType, attributes);
}
/**
* Gets the list of classifications for a given entity represented by a guid.
*
* @param guid globally unique identifier for the entity
* @return a list of classifications for the given entity guid
*/
......@@ -272,10 +202,8 @@ public class EntityREST {
}
}
/**
* Gets the list of classifications for a given entity represented by a guid.
*
* @param guid globally unique identifier for the entity
* @return a list of classifications for the given entity guid
*/
......@@ -307,12 +235,7 @@ public class EntityREST {
}
/**
* Classification management
*/
/**
* Adds classifications to an existing entity represented by a guid.
*
* @param guid globally unique identifier for the entity
*/
@POST
......@@ -340,7 +263,6 @@ public class EntityREST {
/**
* Update classification(s) for an entity represented by a guid.
* Classifications are identified by their guid or name
*
* @param guid globally unique identifier for the entity
*/
@PUT
......@@ -357,7 +279,6 @@ public class EntityREST {
/**
* Deletes a given classification from an existing entity represented by a guid.
*
* @param guid globally unique identifier for the entity
* @param typeName name of the trait
*/
......@@ -381,9 +302,56 @@ public class EntityREST {
}
}
/******************************************************************/
/** Bulk API operations **/
/******************************************************************/
/**
* Bulk API to retrieve list of entities identified by its GUIDs.
*/
@GET
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids) throws AtlasBaseException {
if (CollectionUtils.isEmpty(guids)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
}
AtlasEntitiesWithExtInfo entities = entitiesStore.getByIds(guids);
return entities;
}
/**
* Bulk API to create new entities or update existing entities in Atlas.
* Existing entity is matched using its unique guid if supplied or by its unique attributes eg: qualifiedName
*/
@POST
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities) throws AtlasBaseException {
EntityStream entityStream = new AtlasEntityStream(entities);
return entitiesStore.createOrUpdate(entityStream, false);
}
/**
* Bulk API to delete list of entities identified by its GUIDs
*/
@DELETE
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse deleteByGuids(@QueryParam("guid") final List<String> guids) throws AtlasBaseException {
return entitiesStore.deleteByIds(guids);
}
/**
* Bulk API to associate a tag to multiple entities
*
*/
@POST
@Path("/bulk/classification")
......@@ -412,7 +380,6 @@ public class EntityREST {
}
}
private AtlasEntityType ensureEntityType(String typeName) throws AtlasBaseException {
AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName);
......
......@@ -20,10 +20,8 @@ package org.apache.atlas.web.rest;
import com.google.inject.Inject;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment