Search in sources :

Example 41 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class V20161116172100_DefaultIndexSetMigrationTest method upgradeCreatesDefaultIndexSet.

@Test
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());
    verify(clusterEventBus).post(IndexSetCreatedEvent.create(savedIndexSetConfig));
    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 42 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgradeWhenAlreadyCompleted.

@Test
public void upgradeWhenAlreadyCompleted() throws Exception {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    when(indexSetConfig.id()).thenReturn("abc123");
    when(clusterConfigService.get(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.class)).thenReturn(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create("1", Collections.emptySet(), Collections.emptySet()));
    migration.upgrade();
    verify(streamService, never()).save(any(Stream.class));
    verify(clusterConfigService, never()).write(any(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.class));
    verify(clusterEventBus, never()).post(any(StreamsChangedEvent.class));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) StreamsChangedEvent(org.graylog2.streams.events.StreamsChangedEvent) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 43 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig 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 44 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.

the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgrade.

@Test
public void upgrade() 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, 10, 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).retentionStrategyClass(retentionStrategyClass).build());
    verify(indexSetService).save(config2.toBuilder().rotationStrategyClass(rotationStrategyClass).retentionStrategyClass(retentionStrategyClass).build());
    verify(clusterConfigService).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(ImmutableSet.of("id-1", "id-2"), Collections.emptySet(), "id-2"));
}
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 45 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig 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

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)53 Test (org.junit.Test)39 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)21 IndexSet (org.graylog2.indexer.IndexSet)11 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)10 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)10 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)8 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)5 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 IndexSetService (org.graylog2.indexer.indexset.IndexSetService)4 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)4