use of org.apache.druid.audit.AuditInfo in project druid by druid-io.
the class SQLAuditManagerTest method testFetchAuditHistoryByTypeWithLimit.
@Test(timeout = 60_000L)
public void testFetchAuditHistoryByTypeWithLimit() {
String entry1Key = "testKey";
String entry1Type = "testType";
AuditInfo entry1AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry1Payload = "testPayload1";
String entry2Key = "testKey";
String entry2Type = "testType";
AuditInfo entry2AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry2Payload = "testPayload2";
String entry3Key = "testKey";
String entry3Type = "testType";
AuditInfo entry3AuditInfo = new AuditInfo("testAuthor", "testComment", "127.0.0.1");
String entry3Payload = "testPayload3";
auditManager.doAudit(entry1Key, entry1Type, entry1AuditInfo, entry1Payload, stringConfigSerde);
auditManager.doAudit(entry2Key, entry2Type, entry2AuditInfo, entry2Payload, stringConfigSerde);
auditManager.doAudit(entry3Key, entry3Type, entry3AuditInfo, entry3Payload, stringConfigSerde);
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testType", 2);
Assert.assertEquals(2, auditEntries.size());
Assert.assertEquals(entry3Key, auditEntries.get(0).getKey());
Assert.assertEquals(entry3Payload, auditEntries.get(0).getPayload());
Assert.assertEquals(entry3Type, auditEntries.get(0).getType());
Assert.assertEquals(entry3AuditInfo, auditEntries.get(0).getAuditInfo());
Assert.assertEquals(entry2Key, auditEntries.get(1).getKey());
Assert.assertEquals(entry2Payload, auditEntries.get(1).getPayload());
Assert.assertEquals(entry2Type, auditEntries.get(1).getType());
Assert.assertEquals(entry2AuditInfo, auditEntries.get(1).getAuditInfo());
}
use of org.apache.druid.audit.AuditInfo in project druid by druid-io.
the class SQLMetadataRuleManagerTest method testRemoveRulesOlderThanWithNonExistenceDatasourceAndNewerThanTimestampShouldNotDelete.
@Test
public void testRemoveRulesOlderThanWithNonExistenceDatasourceAndNewerThanTimestampShouldNotDelete() {
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());
// This will not delete the rule as the rule was created just now so it will have the created timestamp later than
// the timestamp 2012-01-01T00:00:00Z
ruleManager.removeRulesForEmptyDatasourcesOlderThan(DateTimes.of("2012-01-01T00:00:00Z").getMillis());
// Verify that rule was not deleted
ruleManager.poll();
allRules = ruleManager.getAllRules();
Assert.assertEquals(1, allRules.size());
Assert.assertEquals(1, allRules.get("test_dataSource").size());
}
use of org.apache.druid.audit.AuditInfo 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.AuditInfo in project druid by druid-io.
the class SQLMetadataRuleManagerTest method testRemoveRulesOlderThanWithActiveDatasourceShouldNotDelete.
@Test
public void testRemoveRulesOlderThanWithActiveDatasourceShouldNotDelete() throws Exception {
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());
// Add segment metadata to segment table so that the datasource is considered active
DataSegment dataSegment = new DataSegment("test_dataSource", Intervals.of("2015-01-01/2015-02-01"), "1", ImmutableMap.of("type", "s3_zip", "bucket", "test", "key", "test_dataSource/xxx"), ImmutableList.of("dim1", "dim2", "dim3"), ImmutableList.of("count", "value"), NoneShardSpec.instance(), 1, 1234L);
publisher.publishSegment(dataSegment);
// This will not delete the rule as the datasource has segment in the segment metadata table
ruleManager.removeRulesForEmptyDatasourcesOlderThan(System.currentTimeMillis());
// Verify that rule was not deleted
ruleManager.poll();
allRules = ruleManager.getAllRules();
Assert.assertEquals(1, allRules.size());
Assert.assertEquals(1, allRules.get("test_dataSource").size());
}
use of org.apache.druid.audit.AuditInfo in project druid by druid-io.
the class CoordinatorDynamicConfigsResource method setDynamicConfigs.
// default value is used for backwards compatibility
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response setDynamicConfigs(final CoordinatorDynamicConfig.Builder dynamicConfigBuilder, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, @Context HttpServletRequest req) {
try {
CoordinatorDynamicConfig current = CoordinatorDynamicConfig.current(manager);
final SetResult setResult = manager.set(CoordinatorDynamicConfig.CONFIG_KEY, dynamicConfigBuilder.build(current), new AuditInfo(author, comment, req.getRemoteAddr()));
if (setResult.isOk()) {
return Response.ok().build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(setResult.getException())).build();
}
} catch (IllegalArgumentException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
Aggregations