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);
}
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);
}
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");
}
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);
}
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.");
}
}
}
Aggregations