use of org.graylog2.indexer.IndexSetRegistry in project graylog2-server by Graylog2.
the class IndexRotationThreadTest method testDoNotPerformRotation.
@Test
public void testDoNotPerformRotation() throws NoTargetIndexException {
final Provider<RotationStrategy> provider = new RotationStrategyProvider();
final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
when(indexSetConfig.rotationStrategyClass()).thenReturn("strategy");
rotationThread.checkForRotation(indexSet);
verify(indexSet, never()).cycle();
}
use of org.graylog2.indexer.IndexSetRegistry in project graylog2-server by Graylog2.
the class IndexSetsResourceTest method delete.
@Test
public void delete() throws Exception {
final IndexSet indexSet = mock(IndexSet.class);
final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
when(indexSetCleanupJobFactory.create(indexSet)).thenReturn(mock(IndexSetCleanupJob.class));
when(indexSetRegistry.getDefault()).thenReturn(null);
when(indexSetService.delete("id")).thenReturn(1);
indexSetsResource.delete("id", false);
indexSetsResource.delete("id", true);
verify(indexSetRegistry, times(2)).getDefault();
verify(indexSetService, times(2)).delete("id");
verify(systemJobManager, times(1)).submit(any(IndexSetCleanupJob.class));
verifyNoMoreInteractions(indexSetService);
}
use of org.graylog2.indexer.IndexSetRegistry in project graylog2-server by Graylog2.
the class IndexRangesMigrationPeriodical method doRun.
@Override
public void doRun() {
final MongoIndexRangesMigrationComplete migrationComplete = clusterConfigService.get(MongoIndexRangesMigrationComplete.class);
if (migrationComplete != null && migrationComplete.complete) {
LOG.debug("Migration of index ranges (pre Graylog 1.2.2) already complete. Skipping migration process.");
return;
}
while (!cluster.isConnected() || !cluster.isHealthy()) {
Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
}
final Set<String> indexNames = ImmutableSet.copyOf(indexSetRegistry.getManagedIndices());
// Migrate old MongoDB index ranges
final SortedSet<IndexRange> mongoIndexRanges = legacyMongoIndexRangeService.findAll();
for (IndexRange indexRange : mongoIndexRanges) {
if (indexNames.contains(indexRange.indexName())) {
LOG.info("Migrating index range from MongoDB: {}", indexRange);
indexRangeService.save(indexRange);
} else {
LOG.info("Removing stale index range from MongoDB: {}", indexRange);
}
legacyMongoIndexRangeService.delete(indexRange.indexName());
}
// Check whether all index ranges have been migrated
final int numberOfIndices = indexNames.size();
final SortedSet<IndexRange> allIndexRanges = indexRangeService.findAll();
final int numberOfIndexRanges = allIndexRanges.size();
if (numberOfIndices > numberOfIndexRanges) {
LOG.info("There are more indices ({}) than there are index ranges ({}). Notifying administrator.", numberOfIndices, numberOfIndexRanges);
// remove all present index names so we can display the index sets that need manual fixing
final Set<String> extraIndices = Sets.newHashSet(indexNames);
allIndexRanges.forEach(indexRange -> extraIndices.remove(indexRange.indexName()));
final Set<String> affectedIndexSetNames = extraIndices.stream().map(indexSetRegistry::getForIndex).filter(Optional::isPresent).map(Optional::get).map(IndexSet::getConfig).map(IndexSetConfig::title).collect(Collectors.toSet());
final Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.URGENT).addType(Notification.Type.INDEX_RANGES_RECALCULATION).addDetail("indices", numberOfIndices).addDetail("index_ranges", numberOfIndexRanges).addDetail("index_sets", affectedIndexSetNames.isEmpty() ? null : Joiner.on(", ").join(affectedIndexSetNames));
notificationService.publishIfFirst(notification);
}
clusterConfigService.write(new MongoIndexRangesMigrationComplete(true));
}
use of org.graylog2.indexer.IndexSetRegistry in project graylog2-server by Graylog2.
the class MongoIndexRangeServiceTest method setUp.
@Before
public void setUp() throws Exception {
localEventBus = new EventBus("local-event-bus");
indexRangeService = new MongoIndexRangeService(mongodb.mongoConnection(), objectMapperProvider, indices, indexSetRegistry, new NullAuditEventSender(), mock(NodeId.class), localEventBus);
}
use of org.graylog2.indexer.IndexSetRegistry in project graylog2-server by Graylog2.
the class IndexSetsResourceTest method delete0.
@Test
public void delete0() throws Exception {
final IndexSet indexSet = mock(IndexSet.class);
final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetRegistry.getDefault()).thenReturn(null);
when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
when(indexSetService.delete("id")).thenReturn(0);
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Couldn't delete index set with ID <id>");
try {
indexSetsResource.delete("id", false);
} finally {
verify(indexSetRegistry, times(1)).getDefault();
verify(indexSetService, times(1)).delete("id");
verifyNoMoreInteractions(indexSetService);
}
}
Aggregations