atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svimal2...@apache.org
Subject incubator-atlas git commit: ATLAS-1565 Create EntityREST endpoints for delete operations
Date Fri, 17 Feb 2017 10:51:25 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 69db4a828 -> e4cc16ac7


ATLAS-1565 Create EntityREST endpoints for delete operations


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/e4cc16ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/e4cc16ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/e4cc16ac

Branch: refs/heads/master
Commit: e4cc16ac7bd133964bf02eda360fe660d9225484
Parents: 69db4a8
Author: Sarath Subramaniam <sarath.kum4r@gmail.com>
Authored: Fri Feb 17 16:19:33 2017 +0530
Committer: Vimal Sharma <svimal2106@apache.org>
Committed: Fri Feb 17 16:20:19 2017 +0530

----------------------------------------------------------------------
 release-log.txt                                 |   1 +
 .../store/graph/AtlasEntityStore.java           |   2 +-
 .../org/apache/atlas/web/rest/EntityREST.java   | 177 ++++++++-----------
 .../org/apache/atlas/web/rest/TypesREST.java    |   2 -
 4 files changed, 74 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/e4cc16ac/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 8488de7..0f9e0a1 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/e4cc16ac/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
index 260c5a8..1cd4375 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
@@ -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

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/e4cc16ac/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
index 9518f54..8518e12 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
@@ -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.
@@ -169,8 +136,8 @@ public class EntityREST {
     @Produces(Servlets.JSON_MEDIA_TYPE)
     @Path("/uniqueAttribute/type/{typeName}")
     public EntityMutationResponse partialUpdateByUniqueAttributes(@PathParam("typeName")
String typeName,
-                                                                 @Context HttpServletRequest
servletRequest,
-                                                                 AtlasEntity entity) throws
Exception {
+                                                                  @Context HttpServletRequest
servletRequest,
+                                                                  AtlasEntity entity) throws
Exception {
         AtlasEntityType     entityType       = ensureEntityType(typeName);
         Map<String, Object> uniqueAttributes = getAttributes(servletRequest);
 
@@ -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);
 
@@ -470,4 +437,4 @@ public class EntityREST {
             }
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/e4cc16ac/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
index 3203b71..ca7340c 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
@@ -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;


Mime
View raw message