Search in sources :

Example 16 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class V20161116172100_DefaultIndexSetMigrationTest method upgradeCreatesDefaultIndexSet.

@Test
@SuppressWarnings("deprecation")
public void upgradeCreatesDefaultIndexSet() throws Exception {
    final StubRotationStrategyConfig rotationStrategyConfig = new StubRotationStrategyConfig();
    final StubRetentionStrategyConfig retentionStrategyConfig = new StubRetentionStrategyConfig();
    final IndexSetConfig savedIndexSetConfig = IndexSetConfig.builder().id("id").title("title").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();
    when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create("test", "test"));
    when(clusterConfigService.get(StubRotationStrategyConfig.class)).thenReturn(rotationStrategyConfig);
    when(clusterConfigService.get(StubRetentionStrategyConfig.class)).thenReturn(retentionStrategyConfig);
    when(indexSetService.save(any(IndexSetConfig.class))).thenReturn(savedIndexSetConfig);
    final ArgumentCaptor<IndexSetConfig> indexSetConfigCaptor = ArgumentCaptor.forClass(IndexSetConfig.class);
    migration.upgrade();
    verify(indexSetService).save(indexSetConfigCaptor.capture());
    verify(clusterConfigService).write(DefaultIndexSetConfig.create("id"));
    verify(clusterConfigService).write(DefaultIndexSetCreated.create());
    final IndexSetConfig capturedIndexSetConfig = indexSetConfigCaptor.getValue();
    assertThat(capturedIndexSetConfig.id()).isNull();
    assertThat(capturedIndexSetConfig.title()).isEqualTo("Default index set");
    assertThat(capturedIndexSetConfig.description()).isEqualTo("The Graylog default index set");
    assertThat(capturedIndexSetConfig.indexPrefix()).isEqualTo(elasticsearchConfiguration.getIndexPrefix());
    assertThat(capturedIndexSetConfig.shards()).isEqualTo(elasticsearchConfiguration.getShards());
    assertThat(capturedIndexSetConfig.replicas()).isEqualTo(elasticsearchConfiguration.getReplicas());
    assertThat(capturedIndexSetConfig.rotationStrategy()).isInstanceOf(StubRotationStrategyConfig.class);
    assertThat(capturedIndexSetConfig.retentionStrategy()).isInstanceOf(StubRetentionStrategyConfig.class);
    assertThat(capturedIndexSetConfig.indexAnalyzer()).isEqualTo(elasticsearchConfiguration.getAnalyzer());
    assertThat(capturedIndexSetConfig.indexTemplateName()).isEqualTo(elasticsearchConfiguration.getTemplateName());
    assertThat(capturedIndexSetConfig.indexOptimizationMaxNumSegments()).isEqualTo(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments());
    assertThat(capturedIndexSetConfig.indexOptimizationDisabled()).isEqualTo(elasticsearchConfiguration.isDisableIndexOptimization());
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) Test(org.junit.Test)

Example 17 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class V20161216123500_DefaultIndexSetMigrationTest method upgradeCreatesDefaultIndexSet.

@Test
@SuppressWarnings("deprecation")
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(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());
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) Test(org.junit.Test)

Example 18 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class IndexRotationThreadTest method testDoNotPerformRotationIfClusterIsDown.

@Test
public void testDoNotPerformRotationIfClusterIsDown() throws NoTargetIndexException {
    final Provider<RotationStrategy> provider = spy(new RotationStrategyProvider());
    when(cluster.isConnected()).thenReturn(false);
    final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
    rotationThread.doRun();
    verify(indexSet, never()).cycle();
    verify(provider, never()).get();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) Test(org.junit.Test)

Example 19 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class IndexRotationThreadTest method testPerformRotation.

@Test
public void testPerformRotation() throws NoTargetIndexException {
    final Provider<RotationStrategy> provider = new RotationStrategyProvider() {

        @Override
        public void doRotate(IndexSet indexSet) {
            indexSet.cycle();
        }
    };
    final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
    when(indexSetConfig.rotationStrategyClass()).thenReturn("strategy");
    rotationThread.checkForRotation(indexSet);
    verify(indexSet, times(1)).cycle();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 20 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class IndexRotationThread method checkForRotation.

protected void checkForRotation(IndexSet indexSet) {
    final IndexSetConfig config = indexSet.getConfig();
    final Provider<RotationStrategy> rotationStrategyProvider = rotationStrategyMap.get(config.rotationStrategyClass());
    if (rotationStrategyProvider == null) {
        LOG.warn("Rotation strategy \"{}\" not found, not running index rotation!", config.rotationStrategyClass());
        rotationProblemNotification("Index Rotation Problem!", "Index rotation strategy " + config.rotationStrategyClass() + " not found! Please fix your index rotation configuration!");
        return;
    }
    final RotationStrategy rotationStrategy = rotationStrategyProvider.get();
    if (rotationStrategy == null) {
        LOG.warn("No rotation strategy found, not running index rotation!");
        return;
    }
    rotationStrategy.rotate(indexSet);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)12 Test (org.junit.Test)12 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)9 RotationStrategy (org.graylog2.plugin.indexer.rotation.RotationStrategy)8 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)6 MessageCountRotationStrategyConfig (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig)6 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)6 IndexSet (org.graylog2.indexer.IndexSet)3 IndexManagementConfig (org.graylog2.indexer.management.IndexManagementConfig)3 NullActivityWriter (org.graylog2.shared.system.activities.NullActivityWriter)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)2 DeletionRetentionStrategy (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy)2 DateTime (org.joda.time.DateTime)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 SchemaFactoryWrapper (com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper)1 DuplicateKeyException (com.mongodb.DuplicateKeyException)1 ApiOperation (io.swagger.annotations.ApiOperation)1