Search in sources :

Example 6 with ClusterConfigService

use of org.graylog2.plugin.cluster.ClusterConfigService in project graylog2-server by Graylog2.

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgradeWithAlreadyAssignedIndexSet.

@Test
public void upgradeWithAlreadyAssignedIndexSet() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    when(indexSetConfig.id()).thenReturn("abc123");
    when(stream1.getId()).thenReturn("stream1");
    when(stream2.getId()).thenReturn("stream2");
    when(streamService.loadAll()).thenReturn(Lists.newArrayList(stream1, stream2));
    when(stream2.getIndexSetId()).thenReturn("abc123");
    migration.upgrade();
    verify(stream1).setIndexSetId(indexSetConfig.id());
    verify(stream2, never()).setIndexSetId(indexSetConfig.id());
    verify(streamService, times(1)).save(stream1);
    verify(streamService, never()).save(stream2);
    verify(clusterConfigService, times(1)).write(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create(indexSetConfig.id(), Sets.newHashSet("stream1"), Collections.emptySet()));
    verify(clusterEventBus, times(1)).post(StreamsChangedEvent.create(ImmutableSet.of("stream1")));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 7 with ClusterConfigService

use of org.graylog2.plugin.cluster.ClusterConfigService in project graylog2-server by Graylog2.

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgradeWithFailedStreamUpdate.

@Test
public void upgradeWithFailedStreamUpdate() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    when(indexSetConfig.id()).thenReturn("abc123");
    when(stream1.getId()).thenReturn("stream1");
    when(stream2.getId()).thenReturn("stream2");
    when(streamService.loadAll()).thenReturn(Lists.newArrayList(stream1, stream2));
    // Updating stream1 should fail!
    when(streamService.save(stream1)).thenThrow(ValidationException.class);
    migration.upgrade();
    verify(stream1).setIndexSetId(indexSetConfig.id());
    verify(stream2).setIndexSetId(indexSetConfig.id());
    verify(streamService, times(1)).save(stream1);
    verify(streamService, times(1)).save(stream2);
    // Check that the failed stream1 will be recorded as failed!
    verify(clusterConfigService, times(1)).write(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create(indexSetConfig.id(), Sets.newHashSet("stream2"), Sets.newHashSet("stream1")));
    verify(clusterEventBus, times(1)).post(StreamsChangedEvent.create(ImmutableSet.of("stream2")));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 8 with ClusterConfigService

use of org.graylog2.plugin.cluster.ClusterConfigService in project graylog2-server by Graylog2.

the class V20161125161400_AlertReceiversMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    final MongoConnection mongoConnection = mock(MongoConnection.class);
    final DB database = mock(DB.class);
    when(mongoConnection.getDatabase()).thenReturn(database);
    when(database.getCollection(eq("streams"))).thenReturn(dbCollection);
    this.alertReceiversMigration = new V20161125161400_AlertReceiversMigration(clusterConfigService, streamService, alarmCallbackConfigurationService, mongoConnection);
}
Also used : MongoConnection(org.graylog2.database.MongoConnection) DB(com.mongodb.DB) Before(org.junit.Before)

Example 9 with ClusterConfigService

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

Example 10 with ClusterConfigService

use of org.graylog2.plugin.cluster.ClusterConfigService 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)

Aggregations

Test (org.junit.Test)14 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)13 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)6 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)6 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)5 MessageCountRotationStrategyConfig (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig)5 Before (org.junit.Before)5 Stream (org.graylog2.plugin.streams.Stream)4 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)3 ClusterEventBus (org.graylog2.events.ClusterEventBus)3 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)3 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)3 MongoConnection (org.graylog2.database.MongoConnection)2 IndexSet (org.graylog2.indexer.IndexSet)2 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)2 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 DB (com.mongodb.DB)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 IndexSetCreatedEvent (org.graylog2.indexer.indexset.events.IndexSetCreatedEvent)1