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);
}
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations