Search in sources :

Example 1 with ClusterConfigService

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

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

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

the class V20161125142400_EmailAlarmCallbackMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    final User localAdmin = mock(User.class);
    when(localAdmin.getId()).thenReturn(localAdminId);
    when(userService.getAdminUser()).thenReturn(localAdmin);
    this.emailAlarmCallbackMigrationPeriodical = new V20161125142400_EmailAlarmCallbackMigration(clusterConfigService, streamService, alarmCallbackConfigurationService, emailAlarmCallback, userService);
}
Also used : User(org.graylog2.plugin.database.users.User) Before(org.junit.Before)

Example 4 with ClusterConfigService

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

the class V20161215163900_MoveIndexSetDefaultConfigTest method setUp.

@Before
public void setUp() throws Exception {
    this.clusterConfigService = spy(new ClusterConfigServiceImpl(objectMapperProvider, fongoRule.getConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), new ClusterEventBus()));
    this.collection = fongoRule.getDatabase().getCollection("index_sets");
    this.migration = new V20161215163900_MoveIndexSetDefaultConfig(fongoRule.getConnection(), clusterConfigService);
}
Also used : ClusterConfigServiceImpl(org.graylog2.cluster.ClusterConfigServiceImpl) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) ClusterEventBus(org.graylog2.events.ClusterEventBus) Before(org.junit.Before)

Example 5 with ClusterConfigService

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

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgrade.

@Test
public void upgrade() 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));
    migration.upgrade();
    verify(stream1).setIndexSetId(indexSetConfig.id());
    verify(stream2).setIndexSetId(indexSetConfig.id());
    verify(streamService, times(1)).save(stream1);
    verify(streamService, times(1)).save(stream2);
    verify(clusterConfigService, times(1)).write(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create(indexSetConfig.id(), Sets.newHashSet("stream1", "stream2"), Collections.emptySet()));
    verify(clusterEventBus, times(1)).post(StreamsChangedEvent.create(ImmutableSet.of("stream1", "stream2")));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream) 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