Search in sources :

Example 1 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class SQLMetadataRuleManagerTest method testRuleInsert.

@Test
public void testRuleInsert() {
    List<Rule> rules = Arrays.<Rule>asList(new IntervalLoadRule(new Interval("2015-01-01/2015-02-01"), ImmutableMap.<String, Integer>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);
    // New rule should be be reflected in the in memory rules map immediately after being set by user
    Map<String, List<Rule>> allRules = ruleManager.getAllRules();
    Assert.assertEquals(1, allRules.size());
    Assert.assertEquals(1, allRules.get("test_dataSource").size());
    Assert.assertEquals(rules.get(0), allRules.get("test_dataSource").get(0));
}
Also used : AuditInfo(io.druid.audit.AuditInfo) IntervalLoadRule(io.druid.server.coordinator.rules.IntervalLoadRule) List(java.util.List) IntervalLoadRule(io.druid.server.coordinator.rules.IntervalLoadRule) Rule(io.druid.server.coordinator.rules.Rule) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 2 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class SQLMetadataRuleManagerTest method testAuditEntryCreated.

@Test
public void testAuditEntryCreated() throws Exception {
    List<Rule> rules = Arrays.<Rule>asList(new IntervalLoadRule(new Interval("2015-01-01/2015-02-01"), ImmutableMap.<String, Integer>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(io.druid.audit.AuditInfo) IntervalLoadRule(io.druid.server.coordinator.rules.IntervalLoadRule) AuditEntry(io.druid.audit.AuditEntry) IntervalLoadRule(io.druid.server.coordinator.rules.IntervalLoadRule) Rule(io.druid.server.coordinator.rules.Rule) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class SQLMetadataRuleManagerTest method testFetchAuditEntriesForAllDataSources.

@Test
public void testFetchAuditEntriesForAllDataSources() throws Exception {
    List<Rule> rules = Arrays.<Rule>asList(new IntervalLoadRule(new Interval("2015-01-01/2015-02-01"), ImmutableMap.<String, Integer>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);
    ruleManager.overrideRule("test_dataSource2", rules, auditInfo);
    // fetch rules from metadata storage
    ruleManager.poll();
    Assert.assertEquals(rules, ruleManager.getRules("test_dataSource"));
    Assert.assertEquals(rules, ruleManager.getRules("test_dataSource2"));
    // test fetch audit entries
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("rules", null);
    Assert.assertEquals(2, auditEntries.size());
    for (AuditEntry entry : auditEntries) {
        Assert.assertEquals(rules, mapper.readValue(entry.getPayload(), new TypeReference<List<Rule>>() {
        }));
        Assert.assertEquals(auditInfo, entry.getAuditInfo());
    }
}
Also used : AuditInfo(io.druid.audit.AuditInfo) IntervalLoadRule(io.druid.server.coordinator.rules.IntervalLoadRule) AuditEntry(io.druid.audit.AuditEntry) IntervalLoadRule(io.druid.server.coordinator.rules.IntervalLoadRule) Rule(io.druid.server.coordinator.rules.Rule) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 4 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class SQLAuditManagerTest method testFetchAuditHistoryByKeyAndTypeWithLimit.

@Test(timeout = 10_000L)
public void testFetchAuditHistoryByKeyAndTypeWithLimit() throws IOException {
    AuditEntry entry1 = new AuditEntry("testKey1", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-01T00:00:00Z"));
    AuditEntry entry2 = new AuditEntry("testKey2", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-02T00:00:00Z"));
    auditManager.doAudit(entry1);
    auditManager.doAudit(entry2);
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testKey1", "testType", 1);
    Assert.assertEquals(1, auditEntries.size());
    Assert.assertEquals(entry1, auditEntries.get(0));
}
Also used : AuditInfo(io.druid.audit.AuditInfo) AuditEntry(io.druid.audit.AuditEntry) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class SQLAuditManagerTest method testCreateAuditEntry.

@Test(timeout = 10_000L)
public void testCreateAuditEntry() throws IOException {
    AuditEntry entry = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-01T00:00:00Z"));
    auditManager.doAudit(entry);
    byte[] payload = connector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getAuditTable(), "audit_key", "payload", "testKey");
    AuditEntry dbEntry = mapper.readValue(payload, AuditEntry.class);
    Assert.assertEquals(entry, dbEntry);
}
Also used : AuditInfo(io.druid.audit.AuditInfo) AuditEntry(io.druid.audit.AuditEntry) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

AuditInfo (io.druid.audit.AuditInfo)33 Test (org.junit.Test)31 Response (javax.ws.rs.core.Response)13 AuditEntry (io.druid.audit.AuditEntry)11 Map (java.util.Map)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 LookupCoordinatorManager (io.druid.server.lookup.cache.LookupCoordinatorManager)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 DateTime (org.joda.time.DateTime)9 Interval (org.joda.time.Interval)6 List (java.util.List)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 ImmutableList (com.google.common.collect.ImmutableList)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IntervalLoadRule (io.druid.server.coordinator.rules.IntervalLoadRule)3 Rule (io.druid.server.coordinator.rules.Rule)3 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1