Repository: atlas Updated Branches: refs/heads/branch-1.0 327368b2d -> 75f6cfbec
ATLAS-2815: Restoring the deleted audit call Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/75f6cfbe Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/75f6cfbe Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/75f6cfbe Branch: refs/heads/branch-1.0 Commit: 75f6cfbecee3896e869566cc5abf166571f5652d Parents: 327368b Author: apoorvnaik <[email protected]> Authored: Mon Aug 13 07:20:17 2018 -0700 Committer: apoorvnaik <[email protected]> Committed: Mon Aug 13 07:20:25 2018 -0700 ---------------------------------------------------------------------- .../org/apache/atlas/web/rest/EntityREST.java | 54 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/75f6cfbe/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java ---------------------------------------------------------------------- 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 d488b1d..5747f92 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 @@ -18,8 +18,10 @@ package org.apache.atlas.web.rest; import org.apache.atlas.AtlasErrorCode; +import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.TypeCategory; +import org.apache.atlas.model.audit.EntityAuditEventV2; import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; @@ -27,6 +29,8 @@ import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.ClassificationAssociateRequest; import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; +import org.apache.atlas.repository.audit.EntityAuditRepository; +import org.apache.atlas.repository.converters.AtlasInstanceConverter; import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.v2.AtlasEntityStream; import org.apache.atlas.repository.store.graph.v2.EntityStream; @@ -39,6 +43,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.inject.Inject; @@ -61,17 +66,24 @@ import java.util.Map; @Singleton @Service public class EntityREST { + private static final Logger LOG = LoggerFactory.getLogger(EntityREST.class); private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.EntityREST"); public static final String PREFIX_ATTR = "attr:"; - private final AtlasTypeRegistry typeRegistry; - private final AtlasEntityStore entitiesStore; + private final AtlasTypeRegistry typeRegistry; + private final AtlasEntityStore entitiesStore; + private final EntityAuditRepository auditRepository; + private final AtlasInstanceConverter instanceConverter; + @Inject - public EntityREST(AtlasTypeRegistry typeRegistry, AtlasEntityStore entitiesStore) { - this.typeRegistry = typeRegistry; - this.entitiesStore = entitiesStore; + public EntityREST(AtlasTypeRegistry typeRegistry, AtlasEntityStore entitiesStore, + EntityAuditRepository auditRepository, AtlasInstanceConverter instanceConverter) { + this.typeRegistry = typeRegistry; + this.entitiesStore = entitiesStore; + this.auditRepository = auditRepository; + this.instanceConverter = instanceConverter; } /** @@ -701,6 +713,38 @@ public class EntityREST { } } + @GET + @Path("{guid}/audit") + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + public List<EntityAuditEventV2> getAuditEvents(@PathParam("guid") String guid, @QueryParam("startKey") String startKey, + @QueryParam("count") @DefaultValue("100") short count) throws AtlasBaseException { + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")"); + } + + List events = auditRepository.listEvents(guid, startKey, count); + List<EntityAuditEventV2> ret = new ArrayList<>(); + + for (Object event : events) { + if (event instanceof EntityAuditEventV2) { + ret.add((EntityAuditEventV2) event); + } else if (event instanceof EntityAuditEvent) { + ret.add(instanceConverter.toV2AuditEvent((EntityAuditEvent) event)); + } else { + LOG.warn("unknown entity-audit event type {}. Ignored", event != null ? event.getClass().getCanonicalName() : "null"); + } + } + + return ret; + } finally { + AtlasPerfTracer.log(perf); + } + } + private AtlasEntityType ensureEntityType(String typeName) throws AtlasBaseException { AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName);
