Search in sources :

Example 11 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-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;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Audit events request for entity {}, start key {}, number of results required {}", guid, startKey, count);
    }
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")");
        }
        List<EntityAuditEvent> events = metadataService.getAuditEvents(guid, startKey, count);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.EVENTS, getJSONArray(events));
        return Response.ok(response).build();
    } catch (AtlasException | 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 : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasException(org.apache.atlas.AtlasException)

Example 12 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testRequestUser.

@Test
public void testRequestUser() throws Exception {
    Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    entity.set("name", dbName);
    entity.set(QUALIFIED_NAME, dbName);
    entity.set("clusterName", randomString());
    entity.set("description", randomString());
    entity.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    entity.set("owner", "user1");
    entity.set("clusterName", "cl1");
    entity.set("parameters", Collections.EMPTY_MAP);
    entity.set("location", "/tmp");
    String user = "admin";
    AtlasClient localClient = null;
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        localClient = new AtlasClient(atlasUrls, new String[] { "admin", "admin" });
    } else {
        localClient = new AtlasClient(atlasUrls);
    }
    String entityId = localClient.createEntity(entity).get(0);
    List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(entityId, (short) 10);
    assertEquals(events.size(), 1);
    assertEquals(events.get(0).getUser(), user);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasClient(org.apache.atlas.AtlasClient) Test(org.testng.annotations.Test)

Example 13 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class EntityJerseyResourceIT method assertEntityAudit.

private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction) throws Exception {
    List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
    for (EntityAuditEvent event : events) {
        if (event.getAction() == auditAction) {
            return;
        }
    }
    fail("Expected audit event with action = " + auditAction);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent)

Example 14 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class DefaultMetadataServiceTest method assertAuditEvents.

private void assertAuditEvents(String id, EntityAuditEvent.EntityAuditAction expectedAction) throws Exception {
    List<EntityAuditEvent> events = auditRepository.listEvents(id, null, (short) 10);
    for (EntityAuditEvent event : events) {
        if (event.getAction() == expectedAction) {
            return;
        }
    }
    fail("Expected audit action " + expectedAction);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent)

Example 15 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method assertEntityAudit.

private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction) throws Exception {
    List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
    for (EntityAuditEvent event : events) {
        if (event.getAction() == auditAction) {
            return;
        }
    }
    fail("Expected audit event with action = " + auditAction);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent)

Aggregations

EntityAuditEvent (org.apache.atlas.EntityAuditEvent)20 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)5 Referenceable (org.apache.atlas.typesystem.Referenceable)4 AtlasException (org.apache.atlas.AtlasException)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 IOException (java.io.IOException)2 IStruct (org.apache.atlas.typesystem.IStruct)2 Table (org.apache.hadoop.hbase.client.Table)2 BeforeTest (org.testng.annotations.BeforeTest)2 AtlasClient (org.apache.atlas.AtlasClient)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 HookNotification (org.apache.atlas.notification.hook.HookNotification)1 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)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 Scan (org.apache.hadoop.hbase.client.Scan)1 PageFilter (org.apache.hadoop.hbase.filter.PageFilter)1 JSONArray (org.codehaus.jettison.json.JSONArray)1