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