You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/03/31 21:00:36 UTC

[atlas] branch branch-1.0 updated: ATLAS-3109: added option to ignore relationshipAttributes in AtlasEntityStore.getByUniqueAttributes

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch branch-1.0
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-1.0 by this push:
     new 3e29960  ATLAS-3109: added option to ignore relationshipAttributes in AtlasEntityStore.getByUniqueAttributes
3e29960 is described below

commit 3e29960210eaed32a66ce930b76ac32972081d36
Author: shanjiaqi <sh...@qiyi.com>
AuthorDate: Sun Mar 31 22:21:57 2019 +0800

    ATLAS-3109: added option to ignore relationshipAttributes in AtlasEntityStore.getByUniqueAttributes
    
    Signed-off-by: Madhan Neethiraj <ma...@apache.org>
    (cherry picked from commit 2b29e4a4460eb6de86904ff2517ee572cd88d3ee)
---
 .../main/java/org/apache/atlas/AtlasClientV2.java  | 24 +++++++++++++++++++++-
 .../repository/impexp/AtlasServerService.java      |  2 +-
 .../repository/store/graph/AtlasEntityStore.java   |  7 ++++---
 .../store/graph/v2/AtlasEntityStoreV2.java         | 21 +++++++++----------
 .../java/org/apache/atlas/web/rest/EntityREST.java | 12 +++++------
 .../atlas/web/adapters/TestEntitiesREST.java       |  2 +-
 .../apache/atlas/web/adapters/TestEntityREST.java  |  8 ++++----
 .../atlas/web/adapters/TestEntityRESTDelete.java   |  4 ++--
 8 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java b/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
index f81a7d5..a5ef34b 100644
--- a/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
+++ b/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
@@ -259,12 +259,28 @@ public class AtlasClientV2 extends AtlasBaseClient {
     }
 
     public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException {
-        return callAPI(API_V2.GET_ENTITY_BY_GUID, AtlasEntityWithExtInfo.class, null, guid);
+        return getEntityByGuid(guid, false, false);
+    }
+
+    public AtlasEntityWithExtInfo getEntityByGuid(String guid, boolean minExtInfo, boolean ignoreRelationships) throws AtlasServiceException {
+        MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+
+        queryParams.add("minExtInfo", String.valueOf(minExtInfo));
+        queryParams.add("ignoreRelationships", String.valueOf(ignoreRelationships));
+
+        return callAPI(API_V2.GET_ENTITY_BY_GUID, AtlasEntityWithExtInfo.class, queryParams, guid);
     }
 
     public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException {
+        return getEntityByAttribute(type, attributes, false, false);
+    }
+
+    public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map<String, String> attributes, boolean minExtInfo, boolean ignoreRelationship) throws AtlasServiceException {
         MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
 
+        queryParams.add("minExtInfo", String.valueOf(minExtInfo));
+        queryParams.add("ignoreRelationships", String.valueOf(ignoreRelationship));
+
         return callAPI(API_V2.GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type);
     }
 
@@ -298,9 +314,15 @@ public class AtlasClientV2 extends AtlasBaseClient {
     }
 
     public AtlasEntitiesWithExtInfo getEntitiesByGuids(List<String> guids) throws AtlasServiceException {
+        return getEntitiesByGuids(guids, false, false);
+    }
+
+    public AtlasEntitiesWithExtInfo getEntitiesByGuids(List<String> guids, boolean minExtInfo, boolean ignoreRelationships) throws AtlasServiceException {
         MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
 
         queryParams.put("guid", guids);
+        queryParams.add("minExtInfo", String.valueOf(minExtInfo));
+        queryParams.add("ignoreRelationships", String.valueOf(ignoreRelationships));
 
         return callAPI(API_V2.GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams);
     }
diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java
index 3e0d580..542106f 100644
--- a/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java
+++ b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java
@@ -105,7 +105,7 @@ public class AtlasServerService {
 
         AtlasObjectId objectId = getObjectId(server);
         for (String guid : entityGuids) {
-            AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(guid, false);
+            AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(guid, false, true);
             updateAttribute(entityWithExtInfo, attributeName, objectId);
         }
     }
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 1da1138..74c19e2 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
@@ -61,7 +61,7 @@ public interface AtlasEntityStore {
      * @param isMinExtInfo
      * @return AtlasEntity
      */
-    AtlasEntityWithExtInfo getById(String guid, boolean isMinExtInfo) throws AtlasBaseException;
+    AtlasEntityWithExtInfo getById(String guid, boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException;
 
     /**
      * Get entity header for the given GUID
@@ -86,7 +86,7 @@ public interface AtlasEntityStore {
      * @return
      * @throws AtlasBaseException
      */
-    AtlasEntitiesWithExtInfo getByIds(List<String> guid, boolean isMinExtInfo) throws AtlasBaseException;
+    AtlasEntitiesWithExtInfo getByIds(List<String> guid, boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException;
 
     /**
      *
@@ -104,9 +104,10 @@ public interface AtlasEntityStore {
      * @param entityType     type of the entity
      * @param uniqAttributes Attributes that uniquely identify the entity
      * @param isMinExtInfo
+     * @param ignoreRelationships ignore relationship attributes
      * @return EntityMutationResponse details of the updates performed by this call
      */
-    AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo)
+    AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo, boolean ignoreRelationships)
             throws AtlasBaseException;
 
     /**
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
index a5a6291..a74eded 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
@@ -104,17 +104,17 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
     @Override
     @GraphTransaction
     public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException {
-        return getById(guid, false);
+        return getById(guid, false, false);
     }
 
     @Override
     @GraphTransaction
-    public AtlasEntityWithExtInfo getById(final String guid, final boolean isMinExtInfo) throws AtlasBaseException {
+    public AtlasEntityWithExtInfo getById(final String guid, final boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> getById({}, {})", guid, isMinExtInfo);
         }
 
-        EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry);
+        EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry, ignoreRelationships);
 
         AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(guid, isMinExtInfo);
 
@@ -158,17 +158,17 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
     @Override
     @GraphTransaction
     public AtlasEntitiesWithExtInfo getByIds(List<String> guids) throws AtlasBaseException {
-        return getByIds(guids, false);
+        return getByIds(guids, false, false);
     }
 
     @Override
     @GraphTransaction
-    public AtlasEntitiesWithExtInfo getByIds(List<String> guids, boolean isMinExtInfo) throws AtlasBaseException {
+    public AtlasEntitiesWithExtInfo getByIds(List<String> guids, boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> getByIds({}, {})", guids, isMinExtInfo);
         }
 
-        EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry);
+        EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry, ignoreRelationships);
 
         AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo);
 
@@ -191,26 +191,25 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
     @GraphTransaction
     public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes)
             throws AtlasBaseException {
-        return getByUniqueAttributes(entityType, uniqAttributes, false);
+        return getByUniqueAttributes(entityType, uniqAttributes, false, false);
     }
 
     @Override
     @GraphTransaction
-    public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo)
-            throws AtlasBaseException {
+    public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes);
         }
 
         AtlasVertex entityVertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(entityType, uniqAttributes);
 
-        EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry);
+        EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry, ignoreRelationships);
 
         AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex, isMinExtInfo);
 
         if (ret == null) {
             throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(),
-                                         uniqAttributes.toString());
+                    uniqAttributes.toString());
         }
 
         AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes);
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 713338e..2c21773 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
@@ -105,7 +105,7 @@ public class EntityREST {
      */
     @GET
     @Path("/guid/{guid}")
-    public AtlasEntityWithExtInfo getById(@PathParam("guid") String guid, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo) throws AtlasBaseException {
+    public AtlasEntityWithExtInfo getById(@PathParam("guid") String guid, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo, @QueryParam("ignoreRelationships") @DefaultValue("false") boolean ignoreRelationships) throws AtlasBaseException {
         Servlets.validateQueryParamLength("guid", guid);
 
         AtlasPerfTracer perf = null;
@@ -115,7 +115,7 @@ public class EntityREST {
                 perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getById(" + guid + ", " + minExtInfo + " )");
             }
 
-            return entitiesStore.getById(guid, minExtInfo);
+            return entitiesStore.getById(guid, minExtInfo, ignoreRelationships);
         } finally {
             AtlasPerfTracer.log(perf);
         }
@@ -165,7 +165,7 @@ public class EntityREST {
     @GET
     @Path("/uniqueAttribute/type/{typeName}")
     public AtlasEntityWithExtInfo getByUniqueAttributes(@PathParam("typeName") String typeName, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo,
-                                                        @Context HttpServletRequest servletRequest) throws AtlasBaseException {
+                                                        @QueryParam("ignoreRelationships") @DefaultValue("false") boolean ignoreRelationships, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
         Servlets.validateQueryParamLength("typeName", typeName);
 
         AtlasPerfTracer perf = null;
@@ -181,7 +181,7 @@ public class EntityREST {
 
             validateUniqueAttribute(entityType, attributes);
 
-            return entitiesStore.getByUniqueAttributes(entityType, attributes, minExtInfo);
+            return entitiesStore.getByUniqueAttributes(entityType, attributes, minExtInfo, ignoreRelationships);
         } finally {
             AtlasPerfTracer.log(perf);
         }
@@ -586,7 +586,7 @@ public class EntityREST {
      */
     @GET
     @Path("/bulk")
-    public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo) throws AtlasBaseException {
+    public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo, @QueryParam("ignoreRelationships") @DefaultValue("false") boolean ignoreRelationships) throws AtlasBaseException {
         if (CollectionUtils.isNotEmpty(guids)) {
             for (String guid : guids) {
                 Servlets.validateQueryParamLength("guid", guid);
@@ -604,7 +604,7 @@ public class EntityREST {
                 throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
             }
 
-            return entitiesStore.getByIds(guids, minExtInfo);
+            return entitiesStore.getByIds(guids, minExtInfo, ignoreRelationships);
         } finally {
             AtlasPerfTracer.log(perf);
         }
diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
index ae9c34d..b62938f 100644
--- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
+++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
@@ -165,7 +165,7 @@ public class TestEntitiesREST {
     @Test(dependsOnMethods = "testCreateOrUpdateEntities")
     public void testGetEntities() throws Exception {
 
-        final AtlasEntitiesWithExtInfo response = entityREST.getByGuids(createdGuids, false);
+        final AtlasEntitiesWithExtInfo response = entityREST.getByGuids(createdGuids, false, false);
         final List<AtlasEntity> entities = response.getEntities();
 
         Assert.assertNotNull(entities);
diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
index 6739364..c8015ec 100644
--- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
+++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
@@ -100,7 +100,7 @@ public class TestEntityREST {
     @Test
     public void testGetEntityById() throws Exception {
         createTestEntity();
-        AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid(), false);
+        AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid(), false, false);
 
         Assert.assertNotNull(response);
         Assert.assertNotNull(response.getEntity());
@@ -184,7 +184,7 @@ public class TestEntityREST {
     @Test(dependsOnMethods = "testAddAndGetClassification")
     public void  testGetEntityWithAssociations() throws Exception {
 
-        AtlasEntityWithExtInfo entity = entityREST.getById(dbEntity.getGuid(), false);
+        AtlasEntityWithExtInfo entity = entityREST.getById(dbEntity.getGuid(), false, false);
         final List<AtlasClassification> retrievedClassifications = entity.getEntity().getClassifications();
 
         Assert.assertNotNull(retrievedClassifications);
@@ -316,7 +316,7 @@ public class TestEntityREST {
         Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
 
         //Get By unique attribute
-        AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, false, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
+        AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, false, false, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
         Assert.assertNotNull(entity);
         Assert.assertNotNull(entity.getEntity().getGuid());
         Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
@@ -341,7 +341,7 @@ public class TestEntityREST {
         Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
 
         //Get By unique attribute
-        AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, false, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
+        AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, false, false, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
         Assert.assertNotNull(entity);
         Assert.assertNotNull(entity.getEntity().getGuid());
         Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java
index 02e78f4..6e604f5 100644
--- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java
+++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java
@@ -71,13 +71,13 @@ public class TestEntityRESTDelete {
     }
 
     private void assertSoftDelete(String guid) throws AtlasBaseException {
-        AtlasEntity.AtlasEntityWithExtInfo entity = entityREST.getById(guid, false);
+        AtlasEntity.AtlasEntityWithExtInfo entity = entityREST.getById(guid, false, false);
         assertTrue(entity != null && entity.getEntity().getStatus() == AtlasEntity.Status.DELETED);
     }
 
     private void assertHardDelete(String guid) {
         try {
-            entityREST.getById(guid, false);
+            entityREST.getById(guid, false, false);
             fail("Entity should have been deleted. Exception should have been thrown.");
         } catch (AtlasBaseException e) {
             assertTrue(true);