Commit 2b29e4a4 by shanjiaqi Committed by Madhan Neethiraj

ATLAS-3109: added option to ignore relationshipAttributes in AtlasEntityStore.getByUniqueAttributes

parent 07192bc8
...@@ -259,12 +259,28 @@ public class AtlasClientV2 extends AtlasBaseClient { ...@@ -259,12 +259,28 @@ public class AtlasClientV2 extends AtlasBaseClient {
} }
public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException { 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 { 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); 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); return callAPI(API_V2.GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type);
} }
...@@ -298,9 +314,15 @@ public class AtlasClientV2 extends AtlasBaseClient { ...@@ -298,9 +314,15 @@ public class AtlasClientV2 extends AtlasBaseClient {
} }
public AtlasEntitiesWithExtInfo getEntitiesByGuids(List<String> guids) throws AtlasServiceException { 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(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.put("guid", guids); 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); return callAPI(API_V2.GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams);
} }
......
...@@ -105,7 +105,7 @@ public class AtlasServerService { ...@@ -105,7 +105,7 @@ public class AtlasServerService {
AtlasObjectId objectId = getObjectId(server); AtlasObjectId objectId = getObjectId(server);
for (String guid : entityGuids) { for (String guid : entityGuids) {
AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(guid, false); AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(guid, false, true);
updateAttribute(entityWithExtInfo, attributeName, objectId); updateAttribute(entityWithExtInfo, attributeName, objectId);
} }
} }
......
...@@ -61,7 +61,7 @@ public interface AtlasEntityStore { ...@@ -61,7 +61,7 @@ public interface AtlasEntityStore {
* @param isMinExtInfo * @param isMinExtInfo
* @return AtlasEntity * @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 * Get entity header for the given GUID
...@@ -86,7 +86,7 @@ public interface AtlasEntityStore { ...@@ -86,7 +86,7 @@ public interface AtlasEntityStore {
* @return * @return
* @throws AtlasBaseException * @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 { ...@@ -104,9 +104,10 @@ public interface AtlasEntityStore {
* @param entityType type of the entity * @param entityType type of the entity
* @param uniqAttributes Attributes that uniquely identify the entity * @param uniqAttributes Attributes that uniquely identify the entity
* @param isMinExtInfo * @param isMinExtInfo
* @param ignoreRelationships ignore relationship attributes
* @return EntityMutationResponse details of the updates performed by this call * @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; throws AtlasBaseException;
/** /**
......
...@@ -104,17 +104,17 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -104,17 +104,17 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException { public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException {
return getById(guid, false); return getById(guid, false, false);
} }
@Override @Override
@GraphTransaction @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()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> getById({}, {})", guid, isMinExtInfo); LOG.debug("==> getById({}, {})", guid, isMinExtInfo);
} }
EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry); EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry, ignoreRelationships);
AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(guid, isMinExtInfo); AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(guid, isMinExtInfo);
...@@ -158,17 +158,17 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -158,17 +158,17 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntitiesWithExtInfo getByIds(List<String> guids) throws AtlasBaseException { public AtlasEntitiesWithExtInfo getByIds(List<String> guids) throws AtlasBaseException {
return getByIds(guids, false); return getByIds(guids, false, false);
} }
@Override @Override
@GraphTransaction @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()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> getByIds({}, {})", guids, isMinExtInfo); LOG.debug("==> getByIds({}, {})", guids, isMinExtInfo);
} }
EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry); EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry, ignoreRelationships);
AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo); AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo);
...@@ -191,26 +191,25 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -191,26 +191,25 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
@GraphTransaction @GraphTransaction
public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes)
throws AtlasBaseException { throws AtlasBaseException {
return getByUniqueAttributes(entityType, uniqAttributes, false); return getByUniqueAttributes(entityType, uniqAttributes, false, false);
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo) public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes, boolean isMinExtInfo, boolean ignoreRelationships) throws AtlasBaseException {
throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes); LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes);
} }
AtlasVertex entityVertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(entityType, uniqAttributes); AtlasVertex entityVertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(entityType, uniqAttributes);
EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry); EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry, ignoreRelationships);
AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex, isMinExtInfo); AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex, isMinExtInfo);
if (ret == null) { if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(), 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); AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes);
......
...@@ -105,7 +105,7 @@ public class EntityREST { ...@@ -105,7 +105,7 @@ public class EntityREST {
*/ */
@GET @GET
@Path("/guid/{guid}") @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); Servlets.validateQueryParamLength("guid", guid);
AtlasPerfTracer perf = null; AtlasPerfTracer perf = null;
...@@ -115,7 +115,7 @@ public class EntityREST { ...@@ -115,7 +115,7 @@ public class EntityREST {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getById(" + guid + ", " + minExtInfo + " )"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getById(" + guid + ", " + minExtInfo + " )");
} }
return entitiesStore.getById(guid, minExtInfo); return entitiesStore.getById(guid, minExtInfo, ignoreRelationships);
} finally { } finally {
AtlasPerfTracer.log(perf); AtlasPerfTracer.log(perf);
} }
...@@ -165,7 +165,7 @@ public class EntityREST { ...@@ -165,7 +165,7 @@ public class EntityREST {
@GET @GET
@Path("/uniqueAttribute/type/{typeName}") @Path("/uniqueAttribute/type/{typeName}")
public AtlasEntityWithExtInfo getByUniqueAttributes(@PathParam("typeName") String typeName, @QueryParam("minExtInfo") @DefaultValue("false") boolean minExtInfo, 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); Servlets.validateQueryParamLength("typeName", typeName);
AtlasPerfTracer perf = null; AtlasPerfTracer perf = null;
...@@ -181,7 +181,7 @@ public class EntityREST { ...@@ -181,7 +181,7 @@ public class EntityREST {
validateUniqueAttribute(entityType, attributes); validateUniqueAttribute(entityType, attributes);
return entitiesStore.getByUniqueAttributes(entityType, attributes, minExtInfo); return entitiesStore.getByUniqueAttributes(entityType, attributes, minExtInfo, ignoreRelationships);
} finally { } finally {
AtlasPerfTracer.log(perf); AtlasPerfTracer.log(perf);
} }
...@@ -586,7 +586,7 @@ public class EntityREST { ...@@ -586,7 +586,7 @@ public class EntityREST {
*/ */
@GET @GET
@Path("/bulk") @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)) { if (CollectionUtils.isNotEmpty(guids)) {
for (String guid : guids) { for (String guid : guids) {
Servlets.validateQueryParamLength("guid", guid); Servlets.validateQueryParamLength("guid", guid);
...@@ -604,7 +604,7 @@ public class EntityREST { ...@@ -604,7 +604,7 @@ public class EntityREST {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids); throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
} }
return entitiesStore.getByIds(guids, minExtInfo); return entitiesStore.getByIds(guids, minExtInfo, ignoreRelationships);
} finally { } finally {
AtlasPerfTracer.log(perf); AtlasPerfTracer.log(perf);
} }
......
...@@ -165,7 +165,7 @@ public class TestEntitiesREST { ...@@ -165,7 +165,7 @@ public class TestEntitiesREST {
@Test(dependsOnMethods = "testCreateOrUpdateEntities") @Test(dependsOnMethods = "testCreateOrUpdateEntities")
public void testGetEntities() throws Exception { 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(); final List<AtlasEntity> entities = response.getEntities();
Assert.assertNotNull(entities); Assert.assertNotNull(entities);
......
...@@ -100,7 +100,7 @@ public class TestEntityREST { ...@@ -100,7 +100,7 @@ public class TestEntityREST {
@Test @Test
public void testGetEntityById() throws Exception { public void testGetEntityById() throws Exception {
createTestEntity(); createTestEntity();
AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid(), false); AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid(), false, false);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.getEntity()); Assert.assertNotNull(response.getEntity());
...@@ -184,7 +184,7 @@ public class TestEntityREST { ...@@ -184,7 +184,7 @@ public class TestEntityREST {
@Test(dependsOnMethods = "testAddAndGetClassification") @Test(dependsOnMethods = "testAddAndGetClassification")
public void testGetEntityWithAssociations() throws Exception { 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(); final List<AtlasClassification> retrievedClassifications = entity.getEntity().getClassifications();
Assert.assertNotNull(retrievedClassifications); Assert.assertNotNull(retrievedClassifications);
...@@ -316,7 +316,7 @@ public class TestEntityREST { ...@@ -316,7 +316,7 @@ public class TestEntityREST {
Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid); Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
//Get By unique attribute //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);
Assert.assertNotNull(entity.getEntity().getGuid()); Assert.assertNotNull(entity.getEntity().getGuid());
Assert.assertEquals(entity.getEntity().getGuid(), dbGuid); Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
...@@ -341,7 +341,7 @@ public class TestEntityREST { ...@@ -341,7 +341,7 @@ public class TestEntityREST {
Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid); Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
//Get By unique attribute //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);
Assert.assertNotNull(entity.getEntity().getGuid()); Assert.assertNotNull(entity.getEntity().getGuid());
Assert.assertEquals(entity.getEntity().getGuid(), dbGuid); Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
......
...@@ -71,13 +71,13 @@ public class TestEntityRESTDelete { ...@@ -71,13 +71,13 @@ public class TestEntityRESTDelete {
} }
private void assertSoftDelete(String guid) throws AtlasBaseException { 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); assertTrue(entity != null && entity.getEntity().getStatus() == AtlasEntity.Status.DELETED);
} }
private void assertHardDelete(String guid) { private void assertHardDelete(String guid) {
try { try {
entityREST.getById(guid, false); entityREST.getById(guid, false, false);
fail("Entity should have been deleted. Exception should have been thrown."); fail("Entity should have been deleted. Exception should have been thrown.");
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
assertTrue(true); assertTrue(true);
......
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