use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class V20161116172100_DefaultIndexSetMigration method getRotationStrategyConfig.
private RotationStrategyConfig getRotationStrategyConfig(IndexManagementConfig indexManagementConfig) {
final String strategyName = indexManagementConfig.rotationStrategy();
final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
checkState(provider != null, "Couldn't retrieve rotation strategy provider for <" + strategyName + ">");
final RotationStrategy rotationStrategy = provider.get();
@SuppressWarnings("unchecked") final Class<RotationStrategyConfig> configClass = (Class<RotationStrategyConfig>) rotationStrategy.configurationClass();
final RotationStrategyConfig rotationStrategyConfig = clusterConfigService.get(configClass);
checkState(rotationStrategyConfig != null, "Couldn't retrieve rotation strategy config for <" + strategyName + ">");
return rotationStrategyConfig;
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class TimeBasedRotationStrategyConfigTest method testSerialization.
@Test
public void testSerialization() throws JsonProcessingException {
final RotationStrategyConfig config = TimeBasedRotationStrategyConfig.create(Period.days(1));
final ObjectMapper objectMapper = new ObjectMapperProvider().get();
final String json = objectMapper.writeValueAsString(config);
final Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);
assertThat((String) JsonPath.read(document, "$.type")).isEqualTo("org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategyConfig");
assertThat((String) JsonPath.read(document, "$.rotation_period")).isEqualTo("P1D");
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgradeWithWrongRetentionPrefix.
@Test
public void upgradeWithWrongRetentionPrefix() throws Exception {
final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
final String retentionStrategyClass = "bar";
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));
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("retention strategy config type <");
migration.upgrade();
verify(indexSetService, never()).save(any(IndexSetConfig.class));
verify(clusterConfigService, never()).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.class);
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgradeWithWrongRotationPrefix.
@Test
public void upgradeWithWrongRotationPrefix() throws Exception {
final String rotationStrategyClass = "foo";
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));
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("rotation strategy config type <");
migration.upgrade();
verify(indexSetService, never()).save(any(IndexSetConfig.class));
verify(clusterConfigService, never()).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.class);
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class MessageCountRotationStrategyConfigTest method testDeserialization.
@Test
public void testDeserialization() throws IOException {
final ObjectMapper objectMapper = new ObjectMapperProvider().get();
final String json = "{ \"type\": \"org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig\", \"max_docs_per_index\": 1000 }";
final RotationStrategyConfig config = objectMapper.readValue(json, RotationStrategyConfig.class);
assertThat(config).isInstanceOf(MessageCountRotationStrategyConfig.class);
assertThat(((MessageCountRotationStrategyConfig) config).maxDocsPerIndex()).isEqualTo(1000);
}
Aggregations