Search in sources :

Example 16 with ClusterConfigService

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

the class MongoIndexSetServiceTest method setUp.

@Before
public void setUp() throws Exception {
    clusterEventBus = new ClusterEventBus();
    clusterConfigService = new ClusterConfigServiceImpl(objectMapperProvider, mongoRule.getMongoConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), clusterEventBus);
    indexSetService = new MongoIndexSetService(mongoRule.getMongoConnection(), objectMapperProvider, streamService, clusterConfigService, clusterEventBus);
}
Also used : ClusterConfigServiceImpl(org.graylog2.cluster.ClusterConfigServiceImpl) ClusterEventBus(org.graylog2.events.ClusterEventBus) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Before(org.junit.Before)

Example 17 with ClusterConfigService

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

the class IndexSetsResourceTest method setDefaultMakesIndexDefaultIfWritable.

@Test
public void setDefaultMakesIndexDefaultIfWritable() throws Exception {
    final String indexSetId = "newDefaultIndexSetId";
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = IndexSetConfig.create(indexSetId, "title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetService.get(indexSetId)).thenReturn(Optional.of(indexSetConfig));
    indexSetsResource.setDefault(indexSetId);
    final ArgumentCaptor<DefaultIndexSetConfig> defaultIndexSetIdCaptor = ArgumentCaptor.forClass(DefaultIndexSetConfig.class);
    verify(clusterConfigService, times(1)).write(defaultIndexSetIdCaptor.capture());
    final DefaultIndexSetConfig defaultIndexSetConfig = defaultIndexSetIdCaptor.getValue();
    assertThat(defaultIndexSetConfig).isNotNull();
    assertThat(defaultIndexSetConfig.defaultIndexSetId()).isEqualTo(indexSetId);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 18 with ClusterConfigService

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

the class IndexSetsResourceTest method setDefaultDoesNotDoAnythingIfIndexSetIsNotWritable.

@Test
public void setDefaultDoesNotDoAnythingIfIndexSetIsNotWritable() throws Exception {
    final String readOnlyIndexSetId = "newDefaultIndexSetId";
    final IndexSet readOnlyIndexSet = mock(IndexSet.class);
    final IndexSetConfig readOnlyIndexSetConfig = IndexSetConfig.create(readOnlyIndexSetId, "title", "description", false, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    when(readOnlyIndexSet.getConfig()).thenReturn(readOnlyIndexSetConfig);
    when(indexSetService.get(readOnlyIndexSetId)).thenReturn(Optional.of(readOnlyIndexSetConfig));
    expectedException.expect(ClientErrorException.class);
    expectedException.expectMessage("Default index set must be writable.");
    try {
        indexSetsResource.setDefault(readOnlyIndexSetId);
    } finally {
        verifyZeroInteractions(clusterConfigService);
    }
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 19 with ClusterConfigService

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

the class SearchResourceTest method restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet.

@Test
public void restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet() {
    when(clusterConfigService.get(SearchesClusterConfig.class)).thenReturn(SearchesClusterConfig.createDefault().toBuilder().queryTimeRangeLimit(Period.ZERO).build());
    final SearchResource resource = new SearchResource(searches, clusterConfigService, decoratorProcessor) {
    };
    final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC);
    final DateTime to = from.plusYears(1);
    final TimeRange timeRange = AbsoluteRange.create(from, to);
    final TimeRange restrictedTimeRange = resource.restrictTimeRange(timeRange);
    assertThat(restrictedTimeRange).isNotNull();
    assertThat(restrictedTimeRange.getFrom()).isEqualTo(from);
    assertThat(restrictedTimeRange.getTo()).isEqualTo(to);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateTime(org.joda.time.DateTime) 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