Search in sources :

Example 11 with NodeId

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

the class SizeBasedRotationStrategyTest method testDontRotate.

@Test
public void testDontRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100000L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, never()).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 12 with NodeId

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

the class SizeBasedRotationStrategyTest method testRotate.

@Test
public void testRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, times(1)).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 13 with NodeId

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

the class ClusterConfigServiceImplTest 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.clusterConfigService = new ClusterConfigServiceImpl(provider, mongoRule.getMongoConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), clusterEventBus);
}
Also used : MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Before(org.junit.Before)

Example 14 with NodeId

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

the class RawMessageTest method minimalEncodeDecode.

@Test
public void minimalEncodeDecode() throws IOException {
    final RawMessage rawMessage = new RawMessage("testmessage".getBytes(StandardCharsets.UTF_8));
    final File tempFile = File.createTempFile("node", "test");
    rawMessage.addSourceNode("inputid", new NodeId(tempFile.getAbsolutePath()));
    rawMessage.setCodecName("raw");
    rawMessage.setCodecConfig(Configuration.EMPTY_CONFIGURATION);
    final byte[] encoded = rawMessage.encode();
    final RawMessage decodedMsg = RawMessage.decode(encoded, 1);
    assertNotNull(decodedMsg);
    assertArrayEquals("testmessage".getBytes(StandardCharsets.UTF_8), decodedMsg.getPayload());
    assertEquals("raw", decodedMsg.getCodecName());
}
Also used : NodeId(org.graylog2.plugin.system.NodeId) File(java.io.File) Test(org.junit.Test)

Example 15 with NodeId

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

the class CmdLineTool method annotateInjectorExceptions.

protected void annotateInjectorExceptions(Collection<Message> messages) {
    for (Message message : messages) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final Throwable rootCause = ExceptionUtils.getRootCause(message.getCause());
        if (rootCause instanceof NodeIdPersistenceException) {
            LOG.error(UI.wallString("Unable to read or persist your NodeId file. This means your node id file (" + configuration.getNodeIdFile() + ") is not readable or writable by the current user. The following exception might give more information: " + message));
            System.exit(-1);
        } else if (rootCause instanceof AccessDeniedException) {
            LOG.error(UI.wallString("Unable to access file " + rootCause.getMessage()));
            System.exit(-2);
        } else {
            // other guice error, still print the raw messages
            // TODO this could potentially print duplicate messages depending on what a subclass does...
            LOG.error("Guice error (more detail on log level debug): {}", message.getMessage());
            if (rootCause != null) {
                LOG.debug("Stacktrace:", rootCause);
            }
        }
    }
}
Also used : AccessDeniedException(java.nio.file.AccessDeniedException) Message(com.google.inject.spi.Message) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException)

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