Search in sources :

Example 16 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class ClosingRetentionStrategy method getMaxNumberOfIndices.

@Override
protected Optional<Integer> getMaxNumberOfIndices(IndexSet indexSet) {
    final IndexSetConfig indexSetConfig = indexSet.getConfig();
    final RetentionStrategyConfig strategyConfig = indexSetConfig.retentionStrategy();
    if (!(strategyConfig instanceof ClosingRetentionStrategyConfig)) {
        throw new IllegalStateException("Invalid retention strategy config <" + strategyConfig.getClass().getCanonicalName() + "> for index set <" + indexSetConfig.id() + ">");
    }
    final ClosingRetentionStrategyConfig config = (ClosingRetentionStrategyConfig) strategyConfig;
    return Optional.of(config.maxNumberOfIndices());
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig)

Example 17 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class DeletionRetentionStrategy method getMaxNumberOfIndices.

@Override
protected Optional<Integer> getMaxNumberOfIndices(IndexSet indexSet) {
    final IndexSetConfig indexSetConfig = indexSet.getConfig();
    final RetentionStrategyConfig strategyConfig = indexSetConfig.retentionStrategy();
    if (!(strategyConfig instanceof DeletionRetentionStrategyConfig)) {
        throw new IllegalStateException("Invalid retention strategy config <" + strategyConfig.getClass().getCanonicalName() + "> for index set <" + indexSetConfig.id() + ">");
    }
    final DeletionRetentionStrategyConfig config = (DeletionRetentionStrategyConfig) strategyConfig;
    return Optional.of(config.maxNumberOfIndices());
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig)

Example 18 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class MongoIndexSetRegistry method findAllMongoIndexSets.

private Set<MongoIndexSet> findAllMongoIndexSets() {
    final List<IndexSetConfig> configs = this.indexSetsCache.get();
    final ImmutableSet.Builder<MongoIndexSet> mongoIndexSets = ImmutableSet.builder();
    for (IndexSetConfig config : configs) {
        final MongoIndexSet mongoIndexSet = mongoIndexSetFactory.create(config);
        mongoIndexSets.add(mongoIndexSet);
    }
    return mongoIndexSets.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig)

Example 19 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class SizeBasedRotationStrategyTest method testDontRotate.

@Test
public void testDontRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100000L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, never()).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 20 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class SizeBasedRotationStrategyTest method testRotate.

@Test
public void testRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, times(1)).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)53 Test (org.junit.Test)39 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)21 IndexSet (org.graylog2.indexer.IndexSet)11 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)10 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)10 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)8 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)5 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 IndexSetService (org.graylog2.indexer.indexset.IndexSetService)4 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)4