use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig 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());
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig 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());
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig in project graylog2-server by Graylog2.
the class RetentionStrategyResource method getRetentionStrategyDescription.
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) {
final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName);
}
final RetentionStrategy retentionStrategy = provider.get();
final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e);
}
return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of org.graylog2.plugin.indexer.retention.RetentionStrategyConfig 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.retention.RetentionStrategyConfig 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);
}
Aggregations