Search in sources :

Example 36 with Messages

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

the class GracefulShutdown method doRun.

private void doRun(boolean exit) {
    LOG.info("Graceful shutdown initiated.");
    serverStatus.shutdown();
    // Give possible load balancers time to recognize state change. State is DEAD because of HALTING.
    LOG.info("Node status: [{}]. Waiting <{}sec> for possible load balancers to recognize state change.", serverStatus.getLifecycle(), configuration.getLoadBalancerRecognitionPeriodSeconds());
    Uninterruptibles.sleepUninterruptibly(configuration.getLoadBalancerRecognitionPeriodSeconds(), TimeUnit.SECONDS);
    activityWriter.write(new Activity("Graceful shutdown initiated.", GracefulShutdown.class));
    /*
         * Wait a second to give for example the calling REST call some time to respond
         * to the client. Using a latch or something here might be a bit over-engineered.
         */
    Uninterruptibles.sleepUninterruptibly(SLEEP_SECS, TimeUnit.SECONDS);
    // Stop REST API service to avoid changes from outside.
    jerseyService.stopAsync();
    // stop all inputs so no new messages can come in
    inputSetupService.stopAsync();
    jerseyService.awaitTerminated();
    inputSetupService.awaitTerminated();
    journalReader.stopAsync().awaitTerminated();
    // Try to flush all remaining messages from the system
    bufferSynchronizerService.stopAsync().awaitTerminated();
    // stop all maintenance tasks
    periodicalsService.stopAsync().awaitTerminated();
    auditEventSender.success(AuditActor.system(serverStatus.getNodeId()), NODE_SHUTDOWN_COMPLETE);
    // Shut down hard with no shutdown hooks running.
    LOG.info("Goodbye.");
    if (exit) {
        System.exit(0);
    }
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Example 37 with Messages

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

the class MessageFilterChainProcessorTest method testHandleMessage.

@Test
public void testHandleMessage() {
    MessageFilter filterOnlyFirst = new MessageFilter() {

        private boolean filterOut = true;

        @Override
        public boolean filter(Message msg) {
            if (filterOut) {
                msg.setFilterOut(true);
                filterOut = false;
                return true;
            }
            return false;
        }

        @Override
        public String getName() {
            return "first filtered out, subsequent pass";
        }

        @Override
        public int getPriority() {
            return 0;
        }
    };
    final MessageFilterChainProcessor filterTest = new MessageFilterChainProcessor(new MetricRegistry(), Collections.singleton(filterOnlyFirst), journal, serverStatus);
    Message filteredoutMessage = new Message("filtered out", "source", Tools.nowUTC());
    filteredoutMessage.setJournalOffset(1);
    Message unfilteredMessage = new Message("filtered out", "source", Tools.nowUTC());
    final Messages messages1 = filterTest.process(filteredoutMessage);
    final Messages messages2 = filterTest.process(unfilteredMessage);
    Assert.assertTrue(filteredoutMessage.getFilterOut());
    Assert.assertFalse(unfilteredMessage.getFilterOut());
    Assert.assertEquals(0, Iterables.size(messages1));
    Assert.assertEquals(1, Iterables.size(messages2));
}
Also used : Messages(org.graylog2.plugin.Messages) Message(org.graylog2.plugin.Message) MetricRegistry(com.codahale.metrics.MetricRegistry) MessageFilter(org.graylog2.plugin.filters.MessageFilter) Test(org.junit.Test)

Example 38 with Messages

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

the class V20161116172200_CreateDefaultStreamMigrationTest method upgrade.

@Test
public void upgrade() throws Exception {
    final ArgumentCaptor<Stream> streamArgumentCaptor = ArgumentCaptor.forClass(Stream.class);
    when(streamService.load("000000000000000000000001")).thenThrow(NotFoundException.class);
    when(indexSetRegistry.getDefault()).thenReturn(indexSet);
    migration.upgrade();
    verify(streamService).save(streamArgumentCaptor.capture());
    final Stream stream = streamArgumentCaptor.getValue();
    assertThat(stream.getTitle()).isEqualTo("All messages");
    assertThat(stream.getDisabled()).isFalse();
    assertThat(stream.getMatchingType()).isEqualTo(StreamImpl.MatchingType.DEFAULT);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 39 with Messages

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

the class MessageFilterChainProcessorTest method testMessagesCanBeDropped.

@Test
public void testMessagesCanBeDropped() {
    final MessageFilter first = new DummyFilter(10);
    final MessageFilter second = new RemovingMessageFilter();
    final Set<MessageFilter> filters = ImmutableSet.of(first, second);
    final MessageFilterChainProcessor processor = new MessageFilterChainProcessor(new MetricRegistry(), filters, journal, serverStatus);
    final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
    final Messages result = processor.process(message);
    assertThat(result).isEmpty();
}
Also used : Messages(org.graylog2.plugin.Messages) Message(org.graylog2.plugin.Message) MetricRegistry(com.codahale.metrics.MetricRegistry) MessageFilter(org.graylog2.plugin.filters.MessageFilter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 40 with Messages

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

the class CmdLineTool method run.

@Override
public void run() {
    final Level logLevel = setupLogger();
    final PluginBindings pluginBindings = installPluginConfigAndBindings(getPluginPath(configFile), chainingClassLoader);
    if (isDumpDefaultConfig()) {
        dumpDefaultConfigAndExit();
    }
    final NamedConfigParametersModule configModule = readConfiguration(configFile);
    if (isDumpConfig()) {
        dumpCurrentConfigAndExit();
    }
    if (!validateConfiguration()) {
        LOG.error("Validating configuration file failed - exiting.");
        System.exit(1);
    }
    beforeStart();
    final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
    injector = setupInjector(configModule, pluginBindings, binder -> binder.bind(ChainingClassLoader.class).toInstance(chainingClassLoader));
    if (injector == null) {
        LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug reports.)");
        System.exit(1);
    }
    // This is holding all our metrics.
    final MetricRegistry metrics = injector.getInstance(MetricRegistry.class);
    addInstrumentedAppender(metrics, logLevel);
    // Report metrics via JMX.
    final JmxReporter reporter = JmxReporter.forRegistry(metrics).build();
    reporter.start();
    startCommand();
}
Also used : NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) Option(com.github.rvesse.airline.annotations.Option) Module(com.google.inject.Module) Plugin(org.graylog2.plugin.Plugin) Arrays(java.util.Arrays) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) GuiceInjectorHolder(org.graylog2.shared.bindings.GuiceInjectorHolder) RepositoryException(com.github.joschi.jadconfig.RepositoryException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Level(org.apache.logging.log4j.Level) InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory) Message(com.google.inject.spi.Message) PluginLoaderConfig(org.graylog2.plugin.PluginLoaderConfig) Map(java.util.Map) InternalLoggerFactory(org.jboss.netty.logging.InternalLoggerFactory) Version(org.graylog2.plugin.Version) JmxReporter(com.codahale.metrics.JmxReporter) PropertiesRepository(com.github.joschi.jadconfig.repositories.PropertiesRepository) Command(com.github.rvesse.airline.annotations.Command) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) PluginModule(org.graylog2.plugin.PluginModule) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) JodaTimeConverterFactory(com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory) Collection(java.util.Collection) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) ValidationException(com.github.joschi.jadconfig.ValidationException) Sets(com.google.common.collect.Sets) List(java.util.List) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PluginMetaData(org.graylog2.plugin.PluginMetaData) UI(org.graylog2.shared.UI) AccessDeniedException(java.nio.file.AccessDeniedException) GuavaConverterFactory(com.github.joschi.jadconfig.guava.GuavaConverterFactory) Joiner(com.google.common.base.Joiner) EnvironmentRepository(com.github.joschi.jadconfig.repositories.EnvironmentRepository) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) SystemPropertiesRepository(com.github.joschi.jadconfig.repositories.SystemPropertiesRepository) JadConfig(com.github.joschi.jadconfig.JadConfig) ManagementFactory(java.lang.management.ManagementFactory) NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PluginConfigBean(org.graylog2.plugin.PluginConfigBean) Names(com.google.inject.name.Names) PluginLoader(org.graylog2.shared.plugins.PluginLoader) File(java.io.File) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) Repository(com.github.joschi.jadconfig.Repository) BaseConfiguration(org.graylog2.plugin.BaseConfiguration) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) PluginBindings(org.graylog2.shared.bindings.PluginBindings) MetricRegistry(com.codahale.metrics.MetricRegistry) Level(org.apache.logging.log4j.Level) JmxReporter(com.codahale.metrics.JmxReporter) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader)

Aggregations

Message (org.graylog2.plugin.Message)15 Timed (com.codahale.metrics.annotation.Timed)11 ApiOperation (io.swagger.annotations.ApiOperation)11 Produces (javax.ws.rs.Produces)10 ApiResponses (io.swagger.annotations.ApiResponses)9 Test (org.junit.Test)9 GET (javax.ws.rs.GET)8 Map (java.util.Map)6 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)6 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)6 MetricRegistry (com.codahale.metrics.MetricRegistry)5 IndexSet (org.graylog2.indexer.IndexSet)5 ResultMessage (org.graylog2.indexer.results.ResultMessage)5 Sorting (org.graylog2.indexer.searches.Sorting)5 Timer (com.codahale.metrics.Timer)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Stream (org.graylog2.plugin.streams.Stream)4 AccessDeniedException (java.nio.file.AccessDeniedException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3