use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class InputSetupService method shutDown.
@Override
protected void shutDown() throws Exception {
LOG.debug("Stopping InputSetupService");
eventBus.unregister(this);
for (IOState<MessageInput> state : inputRegistry.getRunningInputs()) {
MessageInput input = state.getStoppable();
LOG.info("Attempting to close input <{}> [{}].", input.getUniqueReadableId(), input.getName());
Stopwatch s = Stopwatch.createStarted();
try {
input.stop();
LOG.info("Input <{}> closed. Took [{}ms]", input.getUniqueReadableId(), s.elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
LOG.error("Unable to stop input <{}> [{}]: " + e.getMessage(), input.getUniqueReadableId(), input.getName());
} finally {
s.stop();
}
}
LOG.debug("Stopped InputSetupService");
}
use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class InputEventListener method inputUpdated.
@Subscribe
public void inputUpdated(InputUpdated inputUpdatedEvent) {
final String inputId = inputUpdatedEvent.id();
LOG.debug("Input updated: {}", inputId);
final Input input;
try {
input = inputService.find(inputId);
} catch (NotFoundException e) {
LOG.warn("Received InputUpdated event but could not find input {}", inputId, e);
return;
}
final boolean startInput;
final IOState<MessageInput> inputState = inputRegistry.getInputState(inputId);
if (inputState != null) {
startInput = inputState.getState() == IOState.Type.RUNNING;
inputRegistry.remove(inputState);
} else {
startInput = false;
}
if (startInput && (input.isGlobal() || this.nodeId.toString().equals(input.getNodeId()))) {
startInput(input);
}
}
use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class InputEventListener method inputCreated.
@Subscribe
public void inputCreated(InputCreated inputCreatedEvent) {
final String inputId = inputCreatedEvent.id();
LOG.debug("Input created: {}", inputId);
final Input input;
try {
input = inputService.find(inputId);
} catch (NotFoundException e) {
LOG.warn("Received InputCreated event but could not find input {}", inputId, e);
return;
}
final IOState<MessageInput> inputState = inputRegistry.getInputState(inputId);
if (inputState != null) {
inputRegistry.remove(inputState);
}
if (input.isGlobal() || this.nodeId.toString().equals(input.getNodeId())) {
startInput(input);
}
}
use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class InputStateListener method inputStateChanged.
@Subscribe
public void inputStateChanged(IOStateChangedEvent<MessageInput> event) {
final IOState<MessageInput> state = event.changedState();
final MessageInput input = state.getStoppable();
switch(event.newState()) {
case FAILED:
activityWriter.write(new Activity(state.getDetailedMessage(), InputRegistry.class));
Notification notification = notificationService.buildNow();
notification.addType(Notification.Type.INPUT_FAILED_TO_START).addSeverity(Notification.Severity.NORMAL);
notification.addNode(serverStatus.getNodeId().toString());
notification.addDetail("input_id", input.getId());
notification.addDetail("reason", state.getDetailedMessage());
notificationService.publishIfFirst(notification);
break;
case RUNNING:
notificationService.fixed(Notification.Type.NO_INPUT_RUNNING);
// fall through
default:
final String msg = "Input [" + input.getName() + "/" + input.getId() + "] is now " + event.newState().toString();
activityWriter.write(new Activity(msg, InputStateListener.class));
break;
}
LOG.debug("Input State of [{}/{}] changed: {} -> {}", input.getTitle(), input.getId(), event.oldState(), event.newState());
LOG.info("Input [{}/{}] is now {}", input.getName(), input.getId(), event.newState());
}
use of org.graylog2.plugin.IOState in project graylog2-server by Graylog2.
the class IOStateTest method testNotEqualIfDifferentInput.
@Test
public void testNotEqualIfDifferentInput() throws Exception {
EventBus eventBus = mock(EventBus.class);
MessageInput messageInput1 = mock(MessageInput.class);
MessageInput messageInput2 = mock(MessageInput.class);
IOState<MessageInput> inputState1 = new IOState<>(eventBus, messageInput1);
IOState<MessageInput> inputState2 = new IOState<>(eventBus, messageInput2);
assertFalse(inputState1.equals(inputState2));
assertFalse(inputState2.equals(inputState1));
}
Aggregations