Search in sources :

Example 6 with MongoIndexSet

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

the class MongoIndexSetRegistryTest method isManagedIndexWithManagedIndexReturnsTrue.

@Test
public void isManagedIndexWithManagedIndexReturnsTrue() {
    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(true);
    assertThat(indexSetRegistry.isManagedIndex("index")).isTrue();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 7 with MongoIndexSet

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

the class MongoIndexSetRegistryTest method getAllShouldBeCachedForNonEmptyList.

@Test
public void getAllShouldBeCachedForNonEmptyList() {
    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);
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    verify(indexSetService, times(1)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 8 with MongoIndexSet

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

the class MongoIndexSetTest method identifiesIndicesWithPlusAsBeingManaged.

@Test
public void identifiesIndicesWithPlusAsBeingManaged() {
    final IndexSetConfig configWithPlus = config.toBuilder().indexPrefix("some+index").build();
    final String indexName = configWithPlus.indexPrefix() + "_0";
    final MongoIndexSet mongoIndexSet = createIndexSet(configWithPlus);
    assertThat(mongoIndexSet.isManagedIndex(indexName)).isTrue();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with MongoIndexSet

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

the class MongoIndexSetRegistryTest method getAllShouldNotBeCachedForCallAfterInvalidate.

@Test
public void getAllShouldNotBeCachedForCallAfterInvalidate() {
    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);
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    this.indexSetsCache.invalidate();
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 10 with MongoIndexSet

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

the class IndexFieldTypePollerPeriodical method poll.

private void poll(IndexSetConfig indexSetConfig) {
    final String indexSetTitle = indexSetConfig.title();
    final String indexSetId = indexSetConfig.id();
    scheduler.submit(() -> {
        try {
            final MongoIndexSet indexSet = mongoIndexSetFactory.create(indexSetConfig);
            // Only check the active write index on a regular basis, the others don't change anymore
            final String activeWriteIndex = indexSet.getActiveWriteIndex();
            if (activeWriteIndex != null) {
                LOG.debug("Updating index field types for active write index <{}> in index set <{}/{}>", activeWriteIndex, indexSetTitle, indexSetId);
                poller.pollIndex(activeWriteIndex, indexSetId).ifPresent(dbService::upsert);
            } else {
                LOG.warn("Active write index for index set \"{}\" ({}) doesn't exist yet", indexSetTitle, indexSetId);
            }
        } catch (TooManyAliasesException e) {
            LOG.error("Couldn't get active write index", e);
        } catch (Exception e) {
            LOG.error("Couldn't update field types for index set <{}/{}>", indexSetTitle, indexSetId, e);
        } finally {
            lastPoll.put(indexSetId, Instant.now());
        }
    });
}
Also used : MongoIndexSet(org.graylog2.indexer.MongoIndexSet) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) TimeoutException(java.util.concurrent.TimeoutException) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException)

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