Search in sources :

Example 36 with AuditInfo

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

the class LookupCoordinatorManagerTest method testUpdateLookupsInitialization.

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

        @Override
        public Map<String, Map<String, LookupExtractorFactoryMapContainer>> getKnownLookups() {
            return null;
        }
    };
    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(EMPTY_TIERED_LOOKUP), EasyMock.eq(auditInfo))).andReturn(SetResult.ok()).once();
    EasyMock.replay(configManager);
    manager.updateLookups(EMPTY_TIERED_LOOKUP, 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)

Example 37 with AuditInfo

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());
}
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 38 with AuditInfo

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());
}
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 39 with AuditInfo

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());
}
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) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Example 40 with AuditInfo

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

the class LookupCoordinatorResourceTest method testFailedNew.

@Test
public void testFailedNew() throws Exception {
    final String author = "some author";
    final String comment = "some comment";
    final String ip = "127.0.0.1";
    final HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
    EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
    final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    EasyMock.expect(lookupCoordinatorManager.updateLookups(EasyMock.eq(SINGLE_TIER_MAP), EasyMock.capture(auditInfoCapture))).andReturn(false).once();
    EasyMock.replay(lookupCoordinatorManager, request);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, MAPPER, MAPPER);
    final Response response = lookupCoordinatorResource.updateAllLookups(SINGLE_TIER_MAP_SOURCE.openStream(), author, comment, request);
    Assert.assertEquals(500, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
    Assert.assertTrue(auditInfoCapture.hasCaptured());
    final AuditInfo auditInfo = auditInfoCapture.getValue();
    Assert.assertEquals(author, auditInfo.getAuthor());
    Assert.assertEquals(comment, auditInfo.getComment());
    Assert.assertEquals(ip, auditInfo.getIp());
    EasyMock.verify(lookupCoordinatorManager, request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) LookupCoordinatorManager(org.apache.druid.server.lookup.cache.LookupCoordinatorManager) AuditInfo(org.apache.druid.audit.AuditInfo) 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