Search in sources :

Example 11 with AuditInfo

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

the class SQLMetadataRuleManagerTest method testRuleInsert.

@Test
public void testRuleInsert() {
    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);
    // 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(org.apache.druid.audit.AuditInfo) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) Rule(org.apache.druid.server.coordinator.rules.Rule) Test(org.junit.Test)

Example 12 with AuditInfo

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

the class SQLMetadataRuleManagerTest method testFetchAuditEntriesForAllDataSources.

@Test
public void testFetchAuditEntriesForAllDataSources() 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);
    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(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 AuditInfo

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

the class SQLMetadataRuleManagerTest method testRemoveRulesOlderThanWithNonExistenceDatasourceAndOlderThanTimestampShouldDelete.

@Test
public void testRemoveRulesOlderThanWithNonExistenceDatasourceAndOlderThanTimestampShouldDelete() {
    List<Rule> rules = ImmutableList.of(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);
    // Verify that rule was added
    ruleManager.poll();
    Map<String, List<Rule>> allRules = ruleManager.getAllRules();
    Assert.assertEquals(1, allRules.size());
    Assert.assertEquals(1, allRules.get("test_dataSource").size());
    // Now delete rules
    ruleManager.removeRulesForEmptyDatasourcesOlderThan(System.currentTimeMillis());
    // Verify that rule was deleted
    ruleManager.poll();
    allRules = ruleManager.getAllRules();
    Assert.assertEquals(0, allRules.size());
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IntervalLoadRule(org.apache.druid.server.coordinator.rules.IntervalLoadRule) Rule(org.apache.druid.server.coordinator.rules.Rule) Test(org.junit.Test)

Example 14 with AuditInfo

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

the class LookupCoordinatorManager method initializeLookupsConfigWatcher.

private void initializeLookupsConfigWatcher() {
    // Note: this call is idempotent, so multiple start() would not cause any problems.
    lookupMapConfigRef = configManager.watch(LOOKUP_CONFIG_KEY, new TypeReference<Map<String, Map<String, LookupExtractorFactoryMapContainer>>>() {
    }, null);
    // backward compatibility with 0.10.0
    if (lookupMapConfigRef.get() == null) {
        Map<String, Map<String, Map<String, Object>>> oldLookups = configManager.watch(OLD_LOOKUP_CONFIG_KEY, new TypeReference<Map<String, Map<String, Map<String, Object>>>>() {
        }, null).get();
        if (oldLookups != null) {
            Map<String, Map<String, LookupExtractorFactoryMapContainer>> converted = new HashMap<>();
            oldLookups.forEach((tier, oldTierLookups) -> {
                if (oldTierLookups != null && !oldTierLookups.isEmpty()) {
                    converted.put(tier, convertTierLookups(oldTierLookups));
                }
            });
            configManager.set(LOOKUP_CONFIG_KEY, converted, new AuditInfo("autoConversion", "autoConversion", "127.0.0.1"));
        }
    }
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) HashMap(java.util.HashMap) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 15 with AuditInfo

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

the class LookupCoordinatorManagerTest method testUpdateLookupsUpdates.

@Test
public void testUpdateLookupsUpdates() {
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, druidNodeDiscoveryProvider, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        public Map<String, Map<String, LookupExtractorFactoryMapContainer>> getKnownLookups() {
            return TIERED_LOOKUP_MAP_V0;
        }
    };
    manager.start();
    final AuditInfo auditInfo = new AuditInfo("author", "comment", "localhost");
    EasyMock.reset(configManager);
    EasyMock.expect(configManager.set(EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.eq(TIERED_LOOKUP_MAP_V1), EasyMock.eq(auditInfo))).andReturn(SetResult.ok()).once();
    EasyMock.replay(configManager);
    manager.updateLookups(TIERED_LOOKUP_MAP_V1, auditInfo);
    EasyMock.verify(configManager);
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

AuditInfo (org.apache.druid.audit.AuditInfo)50 Test (org.junit.Test)45 Map (java.util.Map)17 AuditEntry (org.apache.druid.audit.AuditEntry)16 ImmutableMap (com.google.common.collect.ImmutableMap)14 Response (javax.ws.rs.core.Response)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 LookupCoordinatorManager (org.apache.druid.server.lookup.cache.LookupCoordinatorManager)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)8 IntervalLoadRule (org.apache.druid.server.coordinator.rules.IntervalLoadRule)6 Rule (org.apache.druid.server.coordinator.rules.Rule)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 POST (javax.ws.rs.POST)3 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2