Search in sources :

Example 1 with MongoIndexSet

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

the class MongoIndexSetRegistry method findAllMongoIndexSets.

private Set<MongoIndexSet> findAllMongoIndexSets() {
    final List<IndexSetConfig> configs = this.indexSetsCache.get();
    final ImmutableSet.Builder<MongoIndexSet> mongoIndexSets = ImmutableSet.builder();
    for (IndexSetConfig config : configs) {
        final MongoIndexSet mongoIndexSet = mongoIndexSetFactory.create(config);
        mongoIndexSets.add(mongoIndexSet);
    }
    return mongoIndexSets.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig)

Example 2 with MongoIndexSet

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

the class MongoIndexSetTest method cycleSetsOldIndexToReadOnly.

@Test
public void cycleSetsOldIndexToReadOnly() throws SystemJobConcurrencyException {
    final String newIndexName = "graylog_1";
    final String oldIndexName = "graylog_0";
    final Map<String, Set<String>> indexNameAliases = ImmutableMap.of(oldIndexName, Collections.singleton("graylog_deflector"));
    when(indices.getIndexNamesAndAliases(anyString())).thenReturn(indexNameAliases);
    when(indices.create(newIndexName, mongoIndexSet)).thenReturn(true);
    when(indices.waitForRecovery(newIndexName)).thenReturn(HealthStatus.Green);
    final SetIndexReadOnlyAndCalculateRangeJob rangeJob = mock(SetIndexReadOnlyAndCalculateRangeJob.class);
    when(jobFactory.create(oldIndexName)).thenReturn(rangeJob);
    final MongoIndexSet mongoIndexSet = createIndexSet(config);
    mongoIndexSet.cycle();
    verify(jobFactory, times(1)).create(oldIndexName);
    verify(systemJobManager, times(1)).submitWithDelay(rangeJob, 30L, TimeUnit.SECONDS);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) SetIndexReadOnlyAndCalculateRangeJob(org.graylog2.indexer.indices.jobs.SetIndexReadOnlyAndCalculateRangeJob) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with MongoIndexSet

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

the class MongoIndexSetTest method identifiesRestoredArchivesAsBeingManaged.

@Test
public void identifiesRestoredArchivesAsBeingManaged() {
    final IndexSetConfig restoredArchives = config.toBuilder().title("Restored Archives").description("Indices which have been restored from an archive.").indexPrefix("restored-archive").indexMatchPattern("restored-archive\\S*").indexWildcard("restored-archive*").build();
    final String indexName = restoredArchives.indexPrefix() + "-graylog_33";
    final MongoIndexSet mongoIndexSet = createIndexSet(restoredArchives);
    assertThat(mongoIndexSet.isManagedIndex(indexName)).isTrue();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with MongoIndexSet

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

the class MongoIndexSetRegistryTest method isManagedIndexWithUnmanagedIndexReturnsFalse.

@Test
public void isManagedIndexWithUnmanagedIndexReturnsFalse() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    final MongoIndexSet indexSet = mock(MongoIndexSet.class);
    when(mongoIndexSetFactory.create(indexSetConfig)).thenReturn(indexSet);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    when(indexSet.isManagedIndex("index")).thenReturn(false);
    assertThat(indexSetRegistry.isManagedIndex("index")).isFalse();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 5 with MongoIndexSet

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

the class MongoIndexSetRegistryTest method isManagedIndexReturnsAMapOfIndices.

@Test
public void isManagedIndexReturnsAMapOfIndices() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    final MongoIndexSet indexSet = mock(MongoIndexSet.class);
    when(mongoIndexSetFactory.create(indexSetConfig)).thenReturn(indexSet);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    when(indexSet.isManagedIndex("index1")).thenReturn(true);
    when(indexSet.isManagedIndex("index2")).thenReturn(false);
    final Map<String, Boolean> managedStatus = indexSetRegistry.isManagedIndex(ImmutableSet.of("index1", "index2"));
    assertThat(managedStatus).containsEntry("index1", true).containsEntry("index2", false);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)8 Test (org.junit.Test)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1 MongoIndexSet (org.graylog2.indexer.MongoIndexSet)1 TooManyAliasesException (org.graylog2.indexer.indices.TooManyAliasesException)1 SetIndexReadOnlyAndCalculateRangeJob (org.graylog2.indexer.indices.jobs.SetIndexReadOnlyAndCalculateRangeJob)1