Commit 06cd0cb3 by chaitali borole Committed by nixonrodrigues

ATLAS-3855 :- Bulk entity tag association and bulk api enhancement, authorization fix.

parent 682d16dd
...@@ -210,10 +210,24 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -210,10 +210,24 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo); AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo);
if(ret != null){ if(ret != null){
for(String guid : guids){ for(String guid : guids) {
try {
AtlasEntity entity = ret.getEntity(guid); AtlasEntity entity = ret.getEntity(guid);
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity: guid=", guid); AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity: guid=", guid);
} catch (AtlasBaseException e) {
if (RequestContext.get().isSkipFailedEntities()) {
if (LOG.isDebugEnabled()) {
LOG.debug("getByIds(): ignoring failure for entity {}: error code={}, message={}", guid, e.getAtlasErrorCode(), e.getMessage());
}
ret.removeEntity(guid);
continue;
}
throw e;
}
} }
} }
...@@ -706,15 +720,21 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -706,15 +720,21 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
if (CollectionUtils.isEmpty(guids)) { if (CollectionUtils.isEmpty(guids)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified"); throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
} }
if (classification == null) { if (classification == null) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classification not specified"); throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classification not specified");
} }
validateAndNormalize(classification);
EntityMutationContext context = new EntityMutationContext(); EntityMutationContext context = new EntityMutationContext();
List<AtlasClassification> classifications = Collections.singletonList(classification);
List<String> validGuids = new ArrayList<>();
GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guids); GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guids);
for (String guid : guids) { for (String guid : guids) {
try {
AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(graph, guid); AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(graph, guid);
if (entityVertex == null) { if (entityVertex == null) {
...@@ -726,17 +746,24 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -726,17 +746,24 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_ADD_CLASSIFICATION, entityHeader, classification), AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_ADD_CLASSIFICATION, entityHeader, classification),
"add classification: guid=", guid, ", classification=", classification.getTypeName()); "add classification: guid=", guid, ", classification=", classification.getTypeName());
validateEntityAssociations(guid, classifications);
validGuids.add(guid);
context.cacheEntity(guid, entityVertex, typeRegistry.getEntityTypeByName(entityHeader.getTypeName())); context.cacheEntity(guid, entityVertex, typeRegistry.getEntityTypeByName(entityHeader.getTypeName()));
} catch (AtlasBaseException abe) {
if (RequestContext.get().isSkipFailedEntities()) {
if (LOG.isDebugEnabled()) {
LOG.debug("addClassification(): ignoring failure for entity {}: error code={}, message={}", guid, abe.getAtlasErrorCode(), abe.getMessage());
} }
continue;
}
validateAndNormalize(classification); throw abe;
}
List<AtlasClassification> classifications = Collections.singletonList(classification); }
for (String guid : guids) {
validateEntityAssociations(guid, classifications);
for (String guid : validGuids) {
entityGraphMapper.addClassifications(context, guid, classifications); entityGraphMapper.addClassifications(context, guid, classifications);
} }
} }
......
...@@ -71,6 +71,7 @@ public class RequestContext { ...@@ -71,6 +71,7 @@ public class RequestContext {
private boolean isInNotificationProcessing = false; private boolean isInNotificationProcessing = false;
private boolean isInTypePatching = false; private boolean isInTypePatching = false;
private boolean createShellEntityForNonExistingReference = false; private boolean createShellEntityForNonExistingReference = false;
private boolean skipFailedEntities = false;
private RequestContext() { private RequestContext() {
} }
...@@ -208,6 +209,14 @@ public class RequestContext { ...@@ -208,6 +209,14 @@ public class RequestContext {
this.createShellEntityForNonExistingReference = createShellEntityForNonExistingReference; this.createShellEntityForNonExistingReference = createShellEntityForNonExistingReference;
} }
public boolean isSkipFailedEntities() {
return skipFailedEntities;
}
public void setSkipFailedEntities(boolean skipFailedEntities) {
this.skipFailedEntities = skipFailedEntities;
}
public void recordEntityUpdate(AtlasEntityHeader entity) { public void recordEntityUpdate(AtlasEntityHeader entity) {
if (entity != null && entity.getGuid() != null && ! entitiesToSkipUpdate.contains(entity.getGuid())) { if (entity != null && entity.getGuid() != null && ! entitiesToSkipUpdate.contains(entity.getGuid())) {
updatedEntities.put(entity.getGuid(), entity); updatedEntities.put(entity.getGuid(), entity);
......
...@@ -82,6 +82,7 @@ public class AuditFilter implements Filter { ...@@ -82,6 +82,7 @@ public class AuditFilter implements Filter {
final String user = AtlasAuthorizationUtils.getCurrentUserName(); final String user = AtlasAuthorizationUtils.getCurrentUserName();
final Set<String> userGroups = AtlasAuthorizationUtils.getCurrentUserGroups(); final Set<String> userGroups = AtlasAuthorizationUtils.getCurrentUserGroups();
final String deleteType = httpRequest.getParameter("deleteType"); final String deleteType = httpRequest.getParameter("deleteType");
final boolean skipFailedEntities = Boolean.parseBoolean(httpRequest.getParameter("skipFailedEntities"));
try { try {
currentThread.setName(formatName(oldName, requestId)); currentThread.setName(formatName(oldName, requestId));
...@@ -92,6 +93,7 @@ public class AuditFilter implements Filter { ...@@ -92,6 +93,7 @@ public class AuditFilter implements Filter {
requestContext.setClientIPAddress(AtlasAuthorizationUtils.getRequestIpAddress(httpRequest)); requestContext.setClientIPAddress(AtlasAuthorizationUtils.getRequestIpAddress(httpRequest));
requestContext.setCreateShellEntityForNonExistingReference(createShellEntityForNonExistingReference); requestContext.setCreateShellEntityForNonExistingReference(createShellEntityForNonExistingReference);
requestContext.setForwardedAddresses(AtlasAuthorizationUtils.getForwardedAddressesFromRequest(httpRequest)); requestContext.setForwardedAddresses(AtlasAuthorizationUtils.getForwardedAddressesFromRequest(httpRequest));
requestContext.setSkipFailedEntities(skipFailedEntities);
if (StringUtils.isNotEmpty(deleteType)) { if (StringUtils.isNotEmpty(deleteType)) {
if (deleteTypeOverrideEnabled) { if (deleteTypeOverrideEnabled) {
......
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