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);
}
}
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));
}
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);
}
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();
}
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();
}
Aggregations