use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class IOStateTest method testEqualsSameState.
@Test
public void testEqualsSameState() throws Exception {
EventBus eventBus = mock(EventBus.class);
MessageInput messageInput = mock(MessageInput.class);
IOState<MessageInput> inputState1 = new IOState<>(eventBus, messageInput, IOState.Type.RUNNING);
IOState<MessageInput> inputState2 = new IOState<>(eventBus, messageInput, IOState.Type.RUNNING);
assertTrue(inputState1.equals(inputState2));
assertTrue(inputState2.equals(inputState1));
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class FromInput method evaluate.
@Override
public Boolean evaluate(FunctionArgs args, EvaluationContext context) {
String id = idParam.optional(args, context).orElse("");
MessageInput input = null;
if ("".equals(id)) {
final String name = nameParam.optional(args, context).orElse("");
for (IOState<MessageInput> messageInputIOState : inputRegistry.getInputStates()) {
final MessageInput messageInput = messageInputIOState.getStoppable();
if (messageInput.getTitle().equalsIgnoreCase(name)) {
input = messageInput;
break;
}
}
if ("".equals(name)) {
return null;
}
} else {
final IOState<MessageInput> inputState = inputRegistry.getInputState(id);
if (inputState != null) {
input = inputState.getStoppable();
}
}
return input != null && input.getId().equals(context.currentMessage().getSourceInputId());
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class InputServiceImpl method getMessageInput.
@Override
public MessageInput getMessageInput(Input io) throws NoSuchInputTypeException {
final Configuration configuration = new Configuration(io.getConfiguration());
final MessageInput input = messageInputFactory.create(io.getType(), configuration);
// Add all standard fields.
input.setTitle(io.getTitle());
input.setNodeId(io.getNodeId());
input.setCreatorUserId(io.getCreatorUserId());
input.setPersistId(io.getId());
input.setCreatedAt(io.getCreatedAt());
input.setContentPack(io.getContentPack());
input.setDesiredState(io.getDesiredState());
if (io.isGlobal()) {
input.setGlobal(true);
}
// Add static fields.
input.addStaticFields(io.getStaticFields());
return input;
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class InputEventListener method leaderChanged.
@Subscribe
public void leaderChanged(LeaderChangedEvent event) {
if (serverStatus.getLifecycle() == Lifecycle.STARTING) {
LOG.debug("Ignoring LeaderChangedEvent during server startup.");
return;
}
if (leaderElectionService.isLeader()) {
for (MessageInput input : persistedInputs) {
final IOState<MessageInput> inputState = inputRegistry.getInputState(input.getId());
if (input.onlyOnePerCluster() && input.isGlobal() && (inputState == null || inputState.canBeStarted()) && inputLauncher.shouldStartAutomatically(input)) {
LOG.info("Got leader role. Starting input [{}/{}/{}]", input.getName(), input.getTitle(), input.getId());
startMessageInput(input);
}
}
} else {
inputRegistry.getRunningInputs().stream().map(IOState::getStoppable).filter(input -> input.isGlobal() && input.onlyOnePerCluster()).forEach(input -> {
LOG.info("Lost leader role. Stopping input [{}/{}/{}]", input.getName(), input.getTitle(), input.getId());
inputDeleted(InputDeleted.create(input.getId()));
});
}
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class HttpTransport method getCustomChildChannelHandlers.
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getCustomChildChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
if (idleWriterTimeout > 0) {
// Install read timeout handler to close idle connections after a timeout.
// This avoids dangling HTTP connections when the HTTP client does not close the connection properly.
// For details see: https://github.com/Graylog2/graylog2-server/issues/3223#issuecomment-270350500
handlers.put("read-timeout-handler", () -> new ReadTimeoutHandler(idleWriterTimeout, TimeUnit.SECONDS));
}
handlers.put("decoder", () -> new HttpRequestDecoder(DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, maxChunkSize));
handlers.put("decompressor", HttpContentDecompressor::new);
handlers.put("encoder", HttpResponseEncoder::new);
handlers.put("aggregator", () -> new HttpObjectAggregator(maxChunkSize));
handlers.put("http-handler", () -> new HttpHandler(enableCors));
handlers.putAll(super.getCustomChildChannelHandlers(input));
return handlers;
}
Aggregations