use of org.graylog2.plugin.indexer.retention.RetentionStrategy in project graylog2-server by Graylog2.
the class V20161116172100_DefaultIndexSetMigration method getRetentionStrategyConfig.
private RetentionStrategyConfig getRetentionStrategyConfig(IndexManagementConfig indexManagementConfig) {
final String strategyName = indexManagementConfig.retentionStrategy();
final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
checkState(provider != null, "Couldn't retrieve retention strategy provider for <" + strategyName + ">");
final RetentionStrategy retentionStrategy = provider.get();
@SuppressWarnings("unchecked") final Class<RetentionStrategyConfig> configClass = (Class<RetentionStrategyConfig>) retentionStrategy.configurationClass();
final RetentionStrategyConfig retentionStrategyConfig = clusterConfigService.get(configClass);
checkState(retentionStrategyConfig != null, "Couldn't retrieve retention strategy config for <" + strategyName + ">");
return retentionStrategyConfig;
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategy in project graylog2-server by Graylog2.
the class AbstractIndexCountBasedRetentionStrategyTest method shouldIgnoreWriteAliasWhenDeterminingRetainedIndices.
@Test
public void shouldIgnoreWriteAliasWhenDeterminingRetainedIndices() {
final String indexWithWriteIndexAlias = "index1";
final String writeIndexAlias = "WriteIndexAlias";
when(indexSet.getWriteIndexAlias()).thenReturn(writeIndexAlias);
indexMap.put(indexWithWriteIndexAlias, Collections.singleton(writeIndexAlias));
retentionStrategy.retain(indexSet);
final ArgumentCaptor<List> retainedIndexName = ArgumentCaptor.forClass(List.class);
verify(retentionStrategy, times(1)).retain(retainedIndexName.capture(), eq(indexSet));
assertThat(retainedIndexName.getValue()).containsExactly("index2");
verify(activityWriter, times(2)).write(any(Activity.class));
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategy in project graylog2-server by Graylog2.
the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgradeWhenOneAlreadyHasStrategiesSet.
@Test
public void upgradeWhenOneAlreadyHasStrategiesSet() throws Exception {
final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
final String retentionStrategyClass = DeletionRetentionStrategy.class.getCanonicalName();
final RotationStrategyConfig rotationStrategy = MessageCountRotationStrategyConfig.createDefault();
final RetentionStrategyConfig retentionStrategy = DeletionRetentionStrategyConfig.createDefault();
final IndexSetConfig config1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("prefix-1").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategyClass(retentionStrategyClass).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
final IndexSetConfig config2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("prefix-2").shards(1).replicas(0).rotationStrategyClass(rotationStrategyClass).rotationStrategy(rotationStrategy).retentionStrategyClass(retentionStrategyClass).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 13, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create(rotationStrategyClass, retentionStrategyClass));
when(indexSetService.findAll()).thenReturn(Lists.newArrayList(config1, config2));
migration.upgrade();
verify(indexSetService).save(config1.toBuilder().rotationStrategyClass(rotationStrategyClass).build());
verify(indexSetService, never()).save(config2);
verify(clusterConfigService).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(Collections.singleton("id-1"), Collections.singleton("id-2"), "id-1"));
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategy in project graylog2-server by Graylog2.
the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgradeDoeNotRunWhenAlreadyComplete.
@Test
public void upgradeDoeNotRunWhenAlreadyComplete() throws Exception {
final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
final String retentionStrategyClass = DeletionRetentionStrategy.class.getCanonicalName();
final RotationStrategyConfig rotationStrategy = MessageCountRotationStrategyConfig.createDefault();
final RetentionStrategyConfig retentionStrategy = DeletionRetentionStrategyConfig.createDefault();
final IndexSetConfig config1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("prefix-1").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
final IndexSetConfig config2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("prefix-2").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 13, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create(rotationStrategyClass, retentionStrategyClass));
when(indexSetService.findAll()).thenReturn(Lists.newArrayList(config1, config2));
when(clusterConfigService.get(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.class)).thenReturn(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(Collections.emptySet(), Collections.emptySet(), "id-1"));
migration.upgrade();
verify(indexSetService, never()).save(any(IndexSetConfig.class));
verify(clusterConfigService, never()).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.class);
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategy in project graylog2-server by Graylog2.
the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgrade.
@Test
public void upgrade() throws Exception {
final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
final String retentionStrategyClass = DeletionRetentionStrategy.class.getCanonicalName();
final RotationStrategyConfig rotationStrategy = MessageCountRotationStrategyConfig.createDefault();
final RetentionStrategyConfig retentionStrategy = DeletionRetentionStrategyConfig.createDefault();
final IndexSetConfig config1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("prefix-1").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
final IndexSetConfig config2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("prefix-2").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 10, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create(rotationStrategyClass, retentionStrategyClass));
when(indexSetService.findAll()).thenReturn(Lists.newArrayList(config1, config2));
migration.upgrade();
verify(indexSetService).save(config1.toBuilder().rotationStrategyClass(rotationStrategyClass).retentionStrategyClass(retentionStrategyClass).build());
verify(indexSetService).save(config2.toBuilder().rotationStrategyClass(rotationStrategyClass).retentionStrategyClass(retentionStrategyClass).build());
verify(clusterConfigService).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(ImmutableSet.of("id-1", "id-2"), Collections.emptySet(), "id-2"));
}
Aggregations