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 {
}
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);
}
......
......@@ -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);
}
}
......
......@@ -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;
/**
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
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