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();
}
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();
}
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();
}
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();
}
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());
}
});
}
Aggregations