This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new 16ced36 ATLAS-3877: fix for error in retrieving audit for purged
entity
16ced36 is described below
commit 16ced369e741a00cd31da4d6fd5d4fa3dc05ec1a
Author: sidmishra <[email protected]>
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 <[email protected]>
---
.../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;
+ }
}