Search in sources :

Example 6 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class InMemoryEntityAuditRepository method putEventsV2.

@Override
public void putEventsV2(List<EntityAuditEventV2> events) {
    for (EntityAuditEventV2 event : events) {
        String rowKey = event.getEntityId() + (Long.MAX_VALUE - event.getTimestamp());
        event.setEventKey(rowKey);
        auditEventsV2.put(rowKey, event);
    }
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2)

Example 7 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class EntityResource method getAuditEvents.

/**
 * Returns the entity audit events for a given entity id. The events are returned in the decreasing order of timestamp.
 * @param guid entity id
 * @param startKey used for pagination. Startkey is inclusive, the returned results contain the event with the given startkey.
 *                  First time getAuditEvents() is called for an entity, startKey should be null,
 *                  with count = (number of events required + 1). Next time getAuditEvents() is called for the same entity,
 *                  startKey should be equal to the entityKey of the last event returned in the previous call.
 * @param count number of events required
 * @return
 */
@GET
@Path("{guid}/audit")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getAuditEvents(@PathParam("guid") String guid, @QueryParam("startKey") String startKey, @QueryParam("count") @DefaultValue("100") short count) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getAuditEvents({}, {}, {})", guid, startKey, count);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")");
        }
        List events = entityAuditRepository.listEvents(guid, startKey, count);
        List<EntityAuditEvent> v1Events = new ArrayList<>();
        for (Object event : events) {
            if (event instanceof EntityAuditEvent) {
                v1Events.add((EntityAuditEvent) event);
            } else if (event instanceof EntityAuditEventV2) {
                v1Events.add(instanceConverter.toV1AuditEvent((EntityAuditEventV2) event));
            } else {
                LOG.warn("unknown entity-audit event type {}. Ignored", event != null ? event.getClass().getCanonicalName() : "null");
            }
        }
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.EVENTS, v1Events);
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getAuditEvents({}, {}, {})", guid, startKey, count);
        }
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) EntityAuditEvent(org.apache.atlas.EntityAuditEvent) EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class EntityREST method getAuditEvents.

@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);
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class EntityAuditListenerV2 method onEntitiesUpdated.

@Override
public void onEntitiesUpdated(List<AtlasEntity> entities, boolean isImport) throws AtlasBaseException {
    List<EntityAuditEventV2> events = new ArrayList<>();
    for (AtlasEntity entity : entities) {
        EntityAuditEventV2 event = createEvent(entity, isImport ? ENTITY_IMPORT_UPDATE : ENTITY_UPDATE);
        events.add(event);
    }
    auditRepository.putEventsV2(events);
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) ArrayList(java.util.ArrayList)

Example 10 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class EntityAuditListenerV2 method onEntitiesDeleted.

@Override
public void onEntitiesDeleted(List<AtlasEntity> entities, boolean isImport) throws AtlasBaseException {
    List<EntityAuditEventV2> events = new ArrayList<>();
    for (AtlasEntity entity : entities) {
        EntityAuditEventV2 event = createEvent(entity, isImport ? ENTITY_IMPORT_DELETE : ENTITY_DELETE, "Deleted entity");
        events.add(event);
    }
    auditRepository.putEventsV2(events);
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) ArrayList(java.util.ArrayList)

Aggregations

EntityAuditEventV2 (org.apache.atlas.model.audit.EntityAuditEventV2)13 ArrayList (java.util.ArrayList)10 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 IOException (java.io.IOException)2 List (java.util.List)2 AtlasException (org.apache.atlas.AtlasException)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 Table (org.apache.hadoop.hbase.client.Table)2 HashMap (java.util.HashMap)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)1 Put (org.apache.hadoop.hbase.client.Put)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1