use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class MessageCountRotationStrategyConfigTest method testSerialization.
@Test
public void testSerialization() throws JsonProcessingException {
final RotationStrategyConfig config = MessageCountRotationStrategyConfig.create(1000);
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.MessageCountRotationStrategyConfig");
assertThat((Integer) JsonPath.read(document, "$.max_docs_per_index")).isEqualTo(1000);
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class TimeBasedRotationStrategyConfigTest method testDeserialization.
@Test
public void testDeserialization() throws IOException {
final ObjectMapper objectMapper = new ObjectMapperProvider().get();
final String json = "{ \"type\": \"org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategyConfig\", \"rotation_period\": \"P1D\" }";
final RotationStrategyConfig config = objectMapper.readValue(json, RotationStrategyConfig.class);
assertThat(config).isInstanceOf(TimeBasedRotationStrategyConfig.class);
assertThat(((TimeBasedRotationStrategyConfig) config).rotationPeriod()).isEqualTo(Period.days(1));
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class RotationStrategyResource method config.
@GET
@Path("config")
@Timed
@ApiOperation(value = "Configuration of the current rotation strategy", notes = "This resource returns the configuration of the currently used rotation strategy.")
public RotationStrategySummary config() {
final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
if (indexManagementConfig == null) {
throw new InternalServerErrorException("Couldn't retrieve index management configuration");
}
final String strategyName = indexManagementConfig.rotationStrategy();
final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
if (provider == null) {
throw new InternalServerErrorException("Couldn't retrieve rotation strategy provider");
}
final RotationStrategy rotationStrategy = provider.get();
@SuppressWarnings("unchecked") final Class<RotationStrategyConfig> configClass = (Class<RotationStrategyConfig>) rotationStrategy.configurationClass();
final RotationStrategyConfig config = clusterConfigService.get(configClass);
return RotationStrategySummary.create(strategyName, config);
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class RotationStrategyResource method getRotationStrategyDescription.
private RotationStrategyDescription getRotationStrategyDescription(String strategyName) {
final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName);
}
final RotationStrategy rotationStrategy = provider.get();
final RotationStrategyConfig defaultConfig = rotationStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(rotationStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for rotation strategy " + strategyName, e);
}
return RotationStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of org.graylog2.plugin.indexer.rotation.RotationStrategyConfig in project graylog2-server by Graylog2.
the class V20161216123500_DefaultIndexSetMigrationTest method upgradeCreatesDefaultIndexSet.
@Test
public void upgradeCreatesDefaultIndexSet() throws Exception {
final RotationStrategyConfig rotationStrategyConfig = mock(RotationStrategyConfig.class);
final RetentionStrategyConfig retentionStrategyConfig = mock(RetentionStrategyConfig.class);
final IndexSetConfig defaultConfig = IndexSetConfig.builder().id("id").title("title").description("description").indexPrefix("prefix").shards(1).replicas(0).rotationStrategy(rotationStrategyConfig).retentionStrategy(retentionStrategyConfig).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("prefix-template").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
final IndexSetConfig additionalConfig = defaultConfig.toBuilder().id("foo").indexPrefix("foo").build();
final IndexSetConfig savedDefaultConfig = defaultConfig.toBuilder().indexAnalyzer(elasticsearchConfiguration.getAnalyzer()).indexTemplateName(elasticsearchConfiguration.getTemplateName()).indexOptimizationMaxNumSegments(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments()).indexOptimizationDisabled(elasticsearchConfiguration.isDisableIndexOptimization()).build();
final IndexSetConfig savedAdditionalConfig = additionalConfig.toBuilder().indexAnalyzer(elasticsearchConfiguration.getAnalyzer()).indexTemplateName("foo-template").indexOptimizationMaxNumSegments(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments()).indexOptimizationDisabled(elasticsearchConfiguration.isDisableIndexOptimization()).build();
when(indexSetService.save(any(IndexSetConfig.class))).thenReturn(savedAdditionalConfig, savedDefaultConfig);
when(indexSetService.getDefault()).thenReturn(defaultConfig);
when(indexSetService.findAll()).thenReturn(ImmutableList.of(defaultConfig, additionalConfig));
when(clusterConfigService.get(DefaultIndexSetCreated.class)).thenReturn(DefaultIndexSetCreated.create());
final ArgumentCaptor<IndexSetConfig> indexSetConfigCaptor = ArgumentCaptor.forClass(IndexSetConfig.class);
migration.upgrade();
verify(indexSetService, times(2)).save(indexSetConfigCaptor.capture());
verify(clusterEventBus, times(2)).post(any(IndexSetCreatedEvent.class));
verify(clusterConfigService).write(V20161216123500_Succeeded.create());
final List<IndexSetConfig> allValues = indexSetConfigCaptor.getAllValues();
assertThat(allValues).hasSize(2);
final IndexSetConfig capturedDefaultIndexSetConfig = allValues.get(0);
assertThat(capturedDefaultIndexSetConfig.id()).isEqualTo("id");
assertThat(capturedDefaultIndexSetConfig.title()).isEqualTo("title");
assertThat(capturedDefaultIndexSetConfig.description()).isEqualTo("description");
assertThat(capturedDefaultIndexSetConfig.indexPrefix()).isEqualTo("prefix");
assertThat(capturedDefaultIndexSetConfig.shards()).isEqualTo(1);
assertThat(capturedDefaultIndexSetConfig.replicas()).isEqualTo(0);
assertThat(capturedDefaultIndexSetConfig.rotationStrategy()).isEqualTo(rotationStrategyConfig);
assertThat(capturedDefaultIndexSetConfig.retentionStrategy()).isEqualTo(retentionStrategyConfig);
assertThat(capturedDefaultIndexSetConfig.indexAnalyzer()).isEqualTo(elasticsearchConfiguration.getAnalyzer());
assertThat(capturedDefaultIndexSetConfig.indexTemplateName()).isEqualTo(elasticsearchConfiguration.getTemplateName());
assertThat(capturedDefaultIndexSetConfig.indexOptimizationMaxNumSegments()).isEqualTo(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments());
assertThat(capturedDefaultIndexSetConfig.indexOptimizationDisabled()).isEqualTo(elasticsearchConfiguration.isDisableIndexOptimization());
final IndexSetConfig capturedAdditionalIndexSetConfig = allValues.get(1);
assertThat(capturedAdditionalIndexSetConfig.id()).isEqualTo("foo");
assertThat(capturedAdditionalIndexSetConfig.title()).isEqualTo("title");
assertThat(capturedAdditionalIndexSetConfig.description()).isEqualTo("description");
assertThat(capturedAdditionalIndexSetConfig.indexPrefix()).isEqualTo("foo");
assertThat(capturedAdditionalIndexSetConfig.shards()).isEqualTo(1);
assertThat(capturedAdditionalIndexSetConfig.replicas()).isEqualTo(0);
assertThat(capturedAdditionalIndexSetConfig.rotationStrategy()).isEqualTo(rotationStrategyConfig);
assertThat(capturedAdditionalIndexSetConfig.retentionStrategy()).isEqualTo(retentionStrategyConfig);
assertThat(capturedAdditionalIndexSetConfig.indexAnalyzer()).isEqualTo(elasticsearchConfiguration.getAnalyzer());
assertThat(capturedAdditionalIndexSetConfig.indexTemplateName()).isEqualTo("foo-template");
assertThat(capturedAdditionalIndexSetConfig.indexOptimizationMaxNumSegments()).isEqualTo(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments());
assertThat(capturedAdditionalIndexSetConfig.indexOptimizationDisabled()).isEqualTo(elasticsearchConfiguration.isDisableIndexOptimization());
}
Aggregations