use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class OverlordResource method getWorkerConfigHistory.
@GET
@Path("/worker/history")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(ConfigResourceFilter.class)
public Response getWorkerConfigHistory(@QueryParam("interval") final String interval, @QueryParam("count") final Integer count) {
Interval theInterval = interval == null ? null : Intervals.of(interval);
if (theInterval == null && count != null) {
try {
List<AuditEntry> workerEntryList = auditManager.fetchAuditHistory(WorkerBehaviorConfig.CONFIG_KEY, WorkerBehaviorConfig.CONFIG_KEY, count);
return Response.ok(workerEntryList).build();
} catch (IllegalArgumentException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ImmutableMap.<String, Object>of("error", e.getMessage())).build();
}
}
List<AuditEntry> workerEntryList = auditManager.fetchAuditHistory(WorkerBehaviorConfig.CONFIG_KEY, WorkerBehaviorConfig.CONFIG_KEY, theInterval);
return Response.ok(workerEntryList).build();
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class SQLMetadataRuleManagerTest method testAuditEntryCreated.
@Test
public void testAuditEntryCreated() throws Exception {
List<Rule> rules = Collections.singletonList(new IntervalLoadRule(Intervals.of("2015-01-01/2015-02-01"), ImmutableMap.of(DruidServer.DEFAULT_TIER, DruidServer.DEFAULT_NUM_REPLICANTS)));
AuditInfo auditInfo = new AuditInfo("test_author", "test_comment", "127.0.0.1");
ruleManager.overrideRule("test_dataSource", rules, auditInfo);
// fetch rules from metadata storage
ruleManager.poll();
Assert.assertEquals(rules, ruleManager.getRules("test_dataSource"));
// verify audit entry is created
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("test_dataSource", "rules", null);
Assert.assertEquals(1, auditEntries.size());
AuditEntry entry = auditEntries.get(0);
Assert.assertEquals(rules, mapper.readValue(entry.getPayload(), new TypeReference<List<Rule>>() {
}));
Assert.assertEquals(auditInfo, entry.getAuditInfo());
Assert.assertEquals("test_dataSource", entry.getKey());
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class RulesResourceTest method testGetAllDatasourcesRuleHistoryWithInterval.
@Test
public void testGetAllDatasourcesRuleHistoryWithInterval() {
String interval = "P2D/2013-01-02T00:00:00Z";
Interval theInterval = Intervals.of(interval);
AuditEntry entry1 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-02T00:00:00Z"));
AuditEntry entry2 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-01T00:00:00Z"));
EasyMock.expect(auditManager.fetchAuditHistory(EasyMock.eq("rules"), EasyMock.eq(theInterval))).andReturn(ImmutableList.of(entry1, entry2)).once();
EasyMock.replay(auditManager);
RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
Response response = rulesResource.getDatasourceRuleHistory(interval, null);
List<AuditEntry> rulesHistory = (List) response.getEntity();
Assert.assertEquals(2, rulesHistory.size());
Assert.assertEquals(entry1, rulesHistory.get(0));
Assert.assertEquals(entry2, rulesHistory.get(1));
EasyMock.verify(auditManager);
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class RulesResourceTest method testGetAllDatasourcesRuleHistoryWithCount.
@Test
public void testGetAllDatasourcesRuleHistoryWithCount() {
AuditEntry entry1 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-02T00:00:00Z"));
AuditEntry entry2 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-01T00:00:00Z"));
EasyMock.expect(auditManager.fetchAuditHistory(EasyMock.eq("rules"), EasyMock.eq(2))).andReturn(ImmutableList.of(entry1, entry2)).once();
EasyMock.replay(auditManager);
RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
Response response = rulesResource.getDatasourceRuleHistory(null, 2);
List<AuditEntry> rulesHistory = (List) response.getEntity();
Assert.assertEquals(2, rulesHistory.size());
Assert.assertEquals(entry1, rulesHistory.get(0));
Assert.assertEquals(entry2, rulesHistory.get(1));
EasyMock.verify(auditManager);
}
use of org.apache.druid.audit.AuditEntry in project druid by druid-io.
the class RulesResourceTest method testGetDatasourceRuleHistoryWithInterval.
@Test
public void testGetDatasourceRuleHistoryWithInterval() {
String interval = "P2D/2013-01-02T00:00:00Z";
Interval theInterval = Intervals.of(interval);
AuditEntry entry1 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-02T00:00:00Z"));
AuditEntry entry2 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", DateTimes.of("2013-01-01T00:00:00Z"));
EasyMock.expect(auditManager.fetchAuditHistory(EasyMock.eq("datasource1"), EasyMock.eq("rules"), EasyMock.eq(theInterval))).andReturn(ImmutableList.of(entry1, entry2)).once();
EasyMock.replay(auditManager);
RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
Response response = rulesResource.getDatasourceRuleHistory("datasource1", interval, null);
List<AuditEntry> rulesHistory = (List) response.getEntity();
Assert.assertEquals(2, rulesHistory.size());
Assert.assertEquals(entry1, rulesHistory.get(0));
Assert.assertEquals(entry2, rulesHistory.get(1));
EasyMock.verify(auditManager);
}
Aggregations