use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class InputEventListenerTest method inputCreatedStopsInputIfItIsRunning.
@Test
public void inputCreatedStopsInputIfItIsRunning() throws Exception {
final String inputId = "input-id";
final Input input = mock(Input.class);
@SuppressWarnings("unchecked") final IOState<MessageInput> inputState = mock(IOState.class);
when(inputService.find(inputId)).thenReturn(input);
when(inputRegistry.getInputState(inputId)).thenReturn(inputState);
listener.inputCreated(InputCreated.create(inputId));
verify(inputRegistry, times(1)).remove(inputState);
}
use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class IOStateTest method testNotEqualIfDifferentState.
@Test
public void testNotEqualIfDifferentState() 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.STOPPED);
assertTrue(inputState1.equals(inputState2));
assertTrue(inputState2.equals(inputState1));
}
use of org.graylog2.plugin.IOState 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.IOState 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.IOState 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()));
});
}
}
Aggregations