Search in sources :

Example 46 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputEventListenerTest method inputCreatedStartsLocalInputOnLocalNode.

@Test
public void inputCreatedStartsLocalInputOnLocalNode() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    when(inputService.find(inputId)).thenReturn(input);
    when(nodeId.toString()).thenReturn("node-id");
    when(input.getNodeId()).thenReturn("node-id");
    when(input.isGlobal()).thenReturn(false);
    final MessageInput messageInput = mock(MessageInput.class);
    when(inputService.getMessageInput(input)).thenReturn(messageInput);
    listener.inputCreated(InputCreated.create(inputId));
    verify(inputLauncher, times(1)).launch(messageInput);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Example 47 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputEventListenerTest method inputUpdatedRestartsLocalInputOnLocalNode.

@Test
public void inputUpdatedRestartsLocalInputOnLocalNode() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    @SuppressWarnings("unchecked") final IOState<MessageInput> inputState = mock(IOState.class);
    when(inputState.getState()).thenReturn(IOState.Type.RUNNING);
    when(inputService.find(inputId)).thenReturn(input);
    when(inputRegistry.getInputState(inputId)).thenReturn(inputState);
    when(nodeId.toString()).thenReturn("node-id");
    when(input.getNodeId()).thenReturn("node-id");
    when(input.isGlobal()).thenReturn(false);
    final MessageInput messageInput = mock(MessageInput.class);
    when(inputService.getMessageInput(input)).thenReturn(messageInput);
    listener.inputUpdated(InputUpdated.create(inputId));
    verify(inputLauncher, times(1)).launch(messageInput);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Example 48 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class IndexFieldTypePollerIT method setUp.

@Before
public void setUp() throws Exception {
    final Node node = mock(Node.class);
    @SuppressWarnings("UnstableApiUsage") final Indices indices = new Indices(new IndexMappingFactory(node, ImmutableMap.of(MESSAGE_TEMPLATE_TYPE, new MessageIndexTemplateProvider())), mock(NodeId.class), new NullAuditEventSender(), mock(EventBus.class), createIndicesAdapter());
    poller = new IndexFieldTypePoller(indices, new MetricRegistry(), createIndexFieldTypePollerAdapter());
    indexSet = new TestIndexSet(indexSetConfig);
    importFixture("org/graylog2/indexer/fieldtypes/IndexFieldTypePollerIT.json");
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) TestIndexSet(org.graylog2.indexer.TestIndexSet) IndexMappingFactory(org.graylog2.indexer.IndexMappingFactory) Node(org.graylog2.indexer.cluster.Node) MetricRegistry(com.codahale.metrics.MetricRegistry) NodeId(org.graylog2.plugin.system.NodeId) Indices(org.graylog2.indexer.indices.Indices) MessageIndexTemplateProvider(org.graylog2.indexer.MessageIndexTemplateProvider) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 49 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ClusterEventPeriodicalTest method runHandlesAutoValueCorrectly.

@Test
public void runHandlesAutoValueCorrectly() throws Exception {
    final DebugEvent event = DebugEvent.create("Node ID", TIME, "test");
    DBObject dbObject = new BasicDBObjectBuilder().add("timestamp", TIME.getMillis()).add("producer", "TEST-PRODUCER").add("consumers", Collections.emptyList()).add("event_class", DebugEvent.class.getCanonicalName()).add("payload", objectMapper.convertValue(event, Map.class)).get();
    @SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
    collection.save(dbObject);
    assertThat(collection.count()).isEqualTo(1L);
    clusterEventPeriodical.run();
    assertThat(collection.count()).isEqualTo(1L);
    @SuppressWarnings("unchecked") final List<String> consumers = (List<String>) collection.findOne().get("consumers");
    assertThat(consumers).containsExactly(nodeId.toString());
    verify(serverEventBus, times(1)).post(event);
    verify(clusterEventBus, never()).post(event);
}
Also used : DBCollection(com.mongodb.DBCollection) DebugEvent(org.graylog2.system.debug.DebugEvent) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) BasicDBList(com.mongodb.BasicDBList) List(java.util.List) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 50 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class Server method startNodeRegistration.

@Override
protected void startNodeRegistration(Injector injector) {
    // Register this node.
    final NodeService nodeService = injector.getInstance(NodeService.class);
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    final ActivityWriter activityWriter = injector.getInstance(ActivityWriter.class);
    final LeaderElectionService leaderElectionService = injector.getInstance(LeaderElectionService.class);
    nodeService.registerServer(serverStatus.getNodeId().toString(), leaderElectionService.isLeader(), httpConfiguration.getHttpPublishUri(), Tools.getLocalCanonicalHostname());
    serverStatus.setLocalMode(isLocal());
    if (leaderElectionService.isLeader() && !nodeService.isOnlyLeader(serverStatus.getNodeId())) {
        LOG.warn("Detected another leader in the cluster. Retrying in {} seconds to make sure it is not " + "an old stale instance.", TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleLeaderTimeout()));
        try {
            Thread.sleep(configuration.getStaleLeaderTimeout());
        } catch (InterruptedException e) {
        /* nope */
        }
        if (!nodeService.isOnlyLeader(serverStatus.getNodeId())) {
            // All devils here.
            String what = "Detected other leader node in the cluster! Starting as non-leader! " + "This is a mis-configuration you should fix.";
            LOG.warn(what);
            activityWriter.write(new Activity(what, Server.class));
            final NotificationService notificationService = injector.getInstance(NotificationService.class);
            // remove legacy notification, if present
            // noinspection deprecation
            notificationService.fixed(notificationService.build().addType(Notification.Type.MULTI_MASTER));
            // Write a notification.
            Notification notification = notificationService.buildNow().addType(Notification.Type.MULTI_LEADER).addSeverity(Notification.Severity.URGENT);
            notificationService.publishIfFirst(notification);
            configuration.setIsLeader(false);
        } else {
            LOG.warn("Stale leader has gone. Starting as leader.");
        }
    }
}
Also used : NodeService(org.graylog2.cluster.NodeService) ServerStatus(org.graylog2.plugin.ServerStatus) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) LeaderElectionService(org.graylog2.cluster.leader.LeaderElectionService) Activity(org.graylog2.shared.system.activities.Activity) NotificationService(org.graylog2.notifications.NotificationService) Notification(org.graylog2.notifications.Notification)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)29 ApiOperation (io.swagger.annotations.ApiOperation)28 MessageInput (org.graylog2.plugin.inputs.MessageInput)23 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)19 Input (org.graylog2.inputs.Input)15 AuditEvent (org.graylog2.audit.jersey.AuditEvent)14 Test (org.junit.Test)14 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 Node (org.graylog2.cluster.Node)12 Map (java.util.Map)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PUT (javax.ws.rs.PUT)6 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)6 Notification (org.graylog2.notifications.Notification)6 Activity (org.graylog2.shared.system.activities.Activity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EventBus (com.google.common.eventbus.EventBus)5 URI (java.net.URI)5