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 2020/07/08 14:42:48 UTC
[atlas] branch branch-2.0 updated: ATLAS-3877: fix for error in
retrieving audit for purged entity
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new da35519 ATLAS-3877: fix for error in retrieving audit for purged entity
da35519 is described below
commit da3551938deceaf714f80ec8c0927161646cb8bb
Author: sidmishra <si...@cloudera.com>
AuthorDate: Tue Jul 7 23:03:32 2020 -0700
ATLAS-3877: fix for error in retrieving audit for purged entity
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
(cherry picked from commit 16ced369e741a00cd31da4d6fd5d4fa3dc05ec1a)
---
.../repository/store/graph/v1/DeleteHandlerV1.java | 8 ++++++-
.../store/graph/v2/AtlasEntityStoreV2.java | 2 +-
.../java/org/apache/atlas/web/rest/EntityREST.java | 28 ++++++++++++++++++++--
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
index 717310d..06341a6 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
@@ -108,7 +108,13 @@ public abstract class DeleteHandlerV1 {
// Record all deletion candidate entities in RequestContext
// and gather deletion candidate vertices.
for (GraphHelper.VertexInfo vertexInfo : getOwnedVertices(instanceVertex)) {
- requestContext.recordEntityDelete(vertexInfo.getEntity());
+ AtlasEntityHeader entityHeader = vertexInfo.getEntity();
+
+ if (requestContext.isPurgeRequested()) {
+ entityHeader.setClassifications(entityRetriever.getAllClassifications(vertexInfo.getVertex()));
+ }
+
+ requestContext.recordEntityDelete(entityHeader);
deletionCandidateVertices.add(vertexInfo.getVertex());
}
}
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 bf1629c..9a33e27 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
@@ -177,7 +177,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
EntityGraphRetriever entityRetriever = new EntityGraphRetriever(graph, typeRegistry);
- AtlasEntityHeader ret = entityRetriever.toAtlasEntityHeader(guid);
+ AtlasEntityHeader ret = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
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 88de8b6..0d6d0c8 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
@@ -21,6 +21,9 @@ import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.authorize.AtlasAuthorizationUtils;
+import org.apache.atlas.authorize.AtlasEntityAccessRequest;
+import org.apache.atlas.authorize.AtlasPrivilege;
import org.apache.atlas.bulkimport.BulkImportResponse;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
@@ -806,8 +809,18 @@ public class EntityREST {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")");
}
- // following call enforces authorization for entity-read
- entitiesStore.getHeaderById(guid);
+ // Enforces authorization for entity-read
+ try {
+ entitiesStore.getHeaderById(guid);
+ } catch (AtlasBaseException e) {
+ if (e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND) {
+ AtlasEntityHeader entityHeader = getEntityHeaderFromPurgedAudit(guid);
+
+ AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, entityHeader), "read entity audit: guid=", guid);
+ } else {
+ throw e;
+ }
+ }
List<EntityAuditEventV2> ret = new ArrayList<>();
@@ -1232,4 +1245,15 @@ public class EntityREST {
return entitiesStore.bulkCreateOrUpdateBusinessAttributes(uploadedInputStream, fileDetail.getFileName());
}
+
+ private AtlasEntityHeader getEntityHeaderFromPurgedAudit(String guid) throws AtlasBaseException {
+ List<EntityAuditEventV2> auditEvents = auditRepository.listEventsV2(guid, EntityAuditActionV2.ENTITY_PURGE, null, (short)1);
+ AtlasEntityHeader ret = CollectionUtils.isNotEmpty(auditEvents) ? auditEvents.get(0).getEntityHeader() : null;
+
+ if (ret == null) {
+ throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
+ }
+
+ return ret;
+ }
}