Search in sources :

Example 6 with RetentionStrategyConfig

use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig in project graylog2-server by Graylog2.

the class DeletionRetentionStrategyConfigTest method testDeserialization.

@Test
public void testDeserialization() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final String json = "{ \"type\": \"org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig\", \"max_number_of_indices\": 23}";
    final RetentionStrategyConfig config = objectMapper.readValue(json, RetentionStrategyConfig.class);
    assertThat(config).isInstanceOf(DeletionRetentionStrategyConfig.class);
    assertThat(((DeletionRetentionStrategyConfig) config).maxNumberOfIndices()).isEqualTo(23);
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Example 7 with RetentionStrategyConfig

use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig in project graylog2-server by Graylog2.

the class RetentionStrategyResource method config.

@GET
@Path("config")
@Timed
@ApiOperation(value = "Configuration of the current retention strategy", notes = "This resource returns the configuration of the currently used retention strategy.")
public RetentionStrategySummary config() {
    final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
    if (indexManagementConfig == null) {
        throw new InternalServerErrorException("Couldn't retrieve index management configuration");
    }
    final String strategyName = indexManagementConfig.retentionStrategy();
    final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
    if (provider == null) {
        LOG.error("Couldn't retrieve retention strategy provider for {}. Returning no-op strategy config.", strategyName);
        return RetentionStrategySummary.create(NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.createDefault());
    }
    final RetentionStrategy retentionStrategy = provider.get();
    @SuppressWarnings("unchecked") final Class<RetentionStrategyConfig> configClass = (Class<RetentionStrategyConfig>) retentionStrategy.configurationClass();
    final RetentionStrategyConfig config = clusterConfigService.get(configClass);
    return RetentionStrategySummary.create(strategyName, config);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) NoopRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.NoopRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) RetentionStrategy(org.graylog2.plugin.indexer.retention.RetentionStrategy) NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with RetentionStrategyConfig

use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig in project graylog2-server by Graylog2.

the class ClosingRetentionStrategyConfigTest method testDeserialization.

@Test
public void testDeserialization() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final String json = "{ \"type\": \"org.graylog2.indexer.retention.strategies.ClosingRetentionStrategyConfig\", \"max_number_of_indices\": 25}";
    final RetentionStrategyConfig config = objectMapper.readValue(json, RetentionStrategyConfig.class);
    assertThat(config).isInstanceOf(ClosingRetentionStrategyConfig.class);
    assertThat(((ClosingRetentionStrategyConfig) config).maxNumberOfIndices()).isEqualTo(25);
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Example 9 with RetentionStrategyConfig

use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig 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"));
}
Also used : DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) Test(org.junit.Test)

Example 10 with RetentionStrategyConfig

use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig 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);
}
Also used : DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) Test(org.junit.Test)

Aggregations

RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)13 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)9 Test (org.junit.Test)9 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)6 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)5 MessageCountRotationStrategyConfig (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig)5 RetentionStrategy (org.graylog2.plugin.indexer.retention.RetentionStrategy)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 ObjectMapperProvider (org.graylog2.shared.bindings.providers.ObjectMapperProvider)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 SchemaFactoryWrapper (com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper)1 ApiOperation (io.swagger.annotations.ApiOperation)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)1 IndexManagementConfig (org.graylog2.indexer.management.IndexManagementConfig)1 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)1