Search in sources :

Example 11 with AuditEntry

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();
}
Also used : AuditEntry(org.apache.druid.audit.AuditEntry) Interval(org.joda.time.Interval) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with AuditEntry

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());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) AuditEntry(org.apache.druid.audit.AuditEntry) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) Rule(org.apache.druid.server.coordinator.rules.Rule) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 13 with AuditEntry

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);
}
Also used : Response(javax.ws.rs.core.Response) AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 14 with AuditEntry

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);
}
Also used : Response(javax.ws.rs.core.Response) AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 15 with AuditEntry

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);
}
Also used : Response(javax.ws.rs.core.Response) AuditInfo(org.apache.druid.audit.AuditInfo) AuditEntry(org.apache.druid.audit.AuditEntry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

AuditEntry (org.apache.druid.audit.AuditEntry)19 AuditInfo (org.apache.druid.audit.AuditInfo)16 Test (org.junit.Test)16 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Response (javax.ws.rs.core.Response)4 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)3 Interval (org.joda.time.Interval)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 IntervalLoadRule (org.apache.druid.server.coordinator.rules.IntervalLoadRule)2 Rule (org.apache.druid.server.coordinator.rules.Rule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1 Handle (org.skife.jdbi.v2.Handle)1