Search in sources :

Example 6 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class V20161215163900_MoveIndexSetDefaultConfigTest method setUp.

@Before
public void setUp() throws Exception {
    this.clusterConfigService = spy(new ClusterConfigServiceImpl(objectMapperProvider, fongoRule.getConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), new ClusterEventBus()));
    this.collection = fongoRule.getDatabase().getCollection("index_sets");
    this.migration = new V20161215163900_MoveIndexSetDefaultConfig(fongoRule.getConnection(), clusterConfigService);
}
Also used : ClusterConfigServiceImpl(org.graylog2.cluster.ClusterConfigServiceImpl) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) ClusterEventBus(org.graylog2.events.ClusterEventBus) Before(org.junit.Before)

Example 7 with NodeId

use of org.graylog2.plugin.system.NodeId 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 8 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class MongoIndexSet method cycle.

@Override
public void cycle() {
    if (!getConfig().isWritable()) {
        LOG.debug("Not cycling non-writable index set <{}> ({})", getConfig().id(), getConfig().title());
        return;
    }
    int oldTargetNumber;
    try {
        oldTargetNumber = getNewestIndexNumber();
    } catch (NoTargetIndexException ex) {
        oldTargetNumber = -1;
    }
    final int newTargetNumber = oldTargetNumber + 1;
    final String newTarget = buildIndexName(newTargetNumber);
    final String oldTarget = buildIndexName(oldTargetNumber);
    if (oldTargetNumber == -1) {
        LOG.info("Cycling from <none> to <{}>.", newTarget);
    } else {
        LOG.info("Cycling from <{}> to <{}>.", oldTarget, newTarget);
    }
    // Create new index.
    LOG.info("Creating target index <{}>.", newTarget);
    if (!indices.create(newTarget, this)) {
        throw new RuntimeException("Could not create new target index <" + newTarget + ">.");
    }
    LOG.info("Waiting for allocation of index <{}>.", newTarget);
    ClusterHealthStatus healthStatus = indices.waitForRecovery(newTarget);
    LOG.debug("Health status of index <{}>: {}", newTarget, healthStatus);
    addDeflectorIndexRange(newTarget);
    LOG.info("Index <{}> has been successfully allocated.", newTarget);
    // Point deflector to new index.
    final String indexAlias = getWriteIndexAlias();
    LOG.info("Pointing index alias <{}> to new index <{}>.", indexAlias, newTarget);
    final Activity activity = new Activity(IndexSet.class);
    if (oldTargetNumber == -1) {
        // Only pointing, not cycling.
        pointTo(newTarget);
        activity.setMessage("Cycled index alias <" + indexAlias + "> from <none> to <" + newTarget + ">.");
    } else {
        // Re-pointing from existing old index to the new one.
        LOG.debug("Switching over index alias <{}>.", indexAlias);
        pointTo(newTarget, oldTarget);
        setIndexReadOnlyAndCalculateRange(oldTarget);
        activity.setMessage("Cycled index alias <" + indexAlias + "> from <" + oldTarget + "> to <" + newTarget + ">.");
    }
    LOG.info("Successfully pointed index alias <{}> to index <{}>.", indexAlias, newTarget);
    activityWriter.write(activity);
    auditEventSender.success(AuditActor.system(nodeId), ES_WRITE_INDEX_UPDATE, ImmutableMap.of("indexName", newTarget));
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) Activity(org.graylog2.shared.system.activities.Activity)

Example 9 with NodeId

use of org.graylog2.plugin.system.NodeId 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(ClusterHealthStatus.GREEN);
    final SetIndexReadOnlyAndCalculateRangeJob rangeJob = mock(SetIndexReadOnlyAndCalculateRangeJob.class);
    when(jobFactory.create(oldIndexName)).thenReturn(rangeJob);
    final MongoIndexSet mongoIndexSet = new MongoIndexSet(config, indices, nodeId, indexRangeService, auditEventSender, systemJobManager, jobFactory, activityWriter);
    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 10 with NodeId

use of org.graylog2.plugin.system.NodeId in project graylog2-server by Graylog2.

the class ClusterEventPeriodicalTest method setUpService.

@Before
public void setUpService() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TIME.getMillis());
    this.mongoConnection = mongoRule.getMongoConnection();
    MongoJackObjectMapperProvider provider = new MongoJackObjectMapperProvider(objectMapper);
    when(nodeId.toString()).thenReturn("ID");
    this.clusterEventPeriodical = new ClusterEventPeriodical(provider, mongoRule.getMongoConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), serverEventBus, clusterEventBus);
}
Also used : MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)13 Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 Node (org.graylog2.cluster.Node)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 Before (org.junit.Before)6 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)5 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Settings (org.elasticsearch.common.settings.Settings)4 ElasticsearchConfiguration (org.graylog2.configuration.ElasticsearchConfiguration)4 File (java.io.File)3 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)3 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)3 JadConfig (com.github.joschi.jadconfig.JadConfig)2 InMemoryRepository (com.github.joschi.jadconfig.repositories.InMemoryRepository)2 BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 Map (java.util.Map)2 PUT (javax.ws.rs.PUT)2