Search in sources :

Example 1 with IOState

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");
}
Also used : Stopwatch(com.google.common.base.Stopwatch) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 2 with IOState

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);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) MessageInput(org.graylog2.plugin.inputs.MessageInput) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with IOState

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);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) MessageInput(org.graylog2.plugin.inputs.MessageInput) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with IOState

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());
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) Activity(org.graylog2.shared.system.activities.Activity) InputRegistry(org.graylog2.shared.inputs.InputRegistry) Notification(org.graylog2.notifications.Notification) Subscribe(com.google.common.eventbus.Subscribe)

Example 5 with IOState

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));
}
Also used : IOState(org.graylog2.plugin.IOState) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Aggregations

MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Test (org.junit.Test)9 EventBus (com.google.common.eventbus.EventBus)4 Subscribe (com.google.common.eventbus.Subscribe)4 IOState (org.graylog2.plugin.IOState)4 NotFoundException (org.graylog2.database.NotFoundException)3 InputRegistry (org.graylog2.shared.inputs.InputRegistry)2 Stopwatch (com.google.common.base.Stopwatch)1 Inject (javax.inject.Inject)1 LeaderChangedEvent (org.graylog2.cluster.leader.LeaderChangedEvent)1 LeaderElectionService (org.graylog2.cluster.leader.LeaderElectionService)1 Notification (org.graylog2.notifications.Notification)1 ServerStatus (org.graylog2.plugin.ServerStatus)1 Lifecycle (org.graylog2.plugin.lifecycles.Lifecycle)1 NodeId (org.graylog2.plugin.system.NodeId)1 InputCreated (org.graylog2.rest.models.system.inputs.responses.InputCreated)1 InputDeleted (org.graylog2.rest.models.system.inputs.responses.InputDeleted)1 InputUpdated (org.graylog2.rest.models.system.inputs.responses.InputUpdated)1 InputLauncher (org.graylog2.shared.inputs.InputLauncher)1 NoSuchInputTypeException (org.graylog2.shared.inputs.NoSuchInputTypeException)1