Search in sources :

Example 6 with IndexSetRegistry

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();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) Test(org.junit.Test)

Example 7 with IndexSetRegistry

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);
}
Also used : IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 8 with IndexSetRegistry

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));
}
Also used : IndexRange(org.graylog2.indexer.ranges.IndexRange) Optional(java.util.Optional) IndexSet(org.graylog2.indexer.IndexSet) Notification(org.graylog2.notifications.Notification)

Example 9 with IndexSetRegistry

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);
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 10 with IndexSetRegistry

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);
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)10 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 Path (javax.ws.rs.Path)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 ApiResponses (io.swagger.annotations.ApiResponses)4 DELETE (javax.ws.rs.DELETE)4 NotFoundException (javax.ws.rs.NotFoundException)4 POST (javax.ws.rs.POST)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3