use of org.graylog2.indexer.cluster.Cluster in project graylog2-server by Graylog2.
the class NodePingThread method doRun.
@Override
public void doRun() {
final boolean isMaster = serverStatus.hasCapability(ServerStatus.Capability.MASTER);
try {
Node node = nodeService.byNodeId(serverStatus.getNodeId());
nodeService.markAsAlive(node, isMaster, configuration.getRestTransportUri());
} catch (NodeNotFoundException e) {
LOG.warn("Did not find meta info of this node. Re-registering.");
nodeService.registerServer(serverStatus.getNodeId().toString(), isMaster, configuration.getRestTransportUri(), Tools.getLocalCanonicalHostname());
}
try {
// Remove old nodes that are no longer running. (Just some housekeeping)
nodeService.dropOutdated();
// Check that we still have a master node in the cluster, if not, warn the user.
if (nodeService.isAnyMasterPresent()) {
Notification notification = notificationService.build().addType(Notification.Type.NO_MASTER);
boolean removedNotification = notificationService.fixed(notification);
if (removedNotification) {
activityWriter.write(new Activity("Notification condition [" + NotificationImpl.Type.NO_MASTER + "] " + "has been fixed.", NodePingThread.class));
}
} else {
Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.NO_MASTER).addSeverity(Notification.Severity.URGENT);
notificationService.publishIfFirst(notification);
}
} catch (Exception e) {
LOG.warn("Caught exception during node ping.", e);
}
}
use of org.graylog2.indexer.cluster.Cluster in project graylog2-server by Graylog2.
the class IndexRotationThreadTest method testPerformRotation.
@Test
public void testPerformRotation() throws NoTargetIndexException {
final Provider<RotationStrategy> provider = new RotationStrategyProvider() {
@Override
public void doRotate(IndexSet indexSet) {
indexSet.cycle();
}
};
final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
when(indexSetConfig.rotationStrategyClass()).thenReturn("strategy");
rotationThread.checkForRotation(indexSet);
verify(indexSet, times(1)).cycle();
}
use of org.graylog2.indexer.cluster.Cluster in project graylog2-server by Graylog2.
the class IndexRotationThreadTest method testDoNotPerformRotationIfClusterIsDown.
@Test
public void testDoNotPerformRotationIfClusterIsDown() throws NoTargetIndexException {
final Provider<RotationStrategy> provider = spy(new RotationStrategyProvider());
when(cluster.isConnected()).thenReturn(false);
final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
rotationThread.doRun();
verify(indexSet, never()).cycle();
verify(provider, never()).get();
}
use of org.graylog2.indexer.cluster.Cluster in project graylog2-server by Graylog2.
the class ClusterEventBusProvider method get.
@Override
public ClusterEventBus get() {
final ClusterEventBus eventBus = new ClusterEventBus("cluster-eventbus", executorService(asyncEventbusProcessors));
eventBus.registerClusterEventSubscriber(new DeadEventLoggingListener());
return eventBus;
}
use of org.graylog2.indexer.cluster.Cluster 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);
nodeService.registerServer(serverStatus.getNodeId().toString(), configuration.isMaster(), configuration.getRestTransportUri(), Tools.getLocalCanonicalHostname());
serverStatus.setLocalMode(isLocal());
if (configuration.isMaster() && !nodeService.isOnlyMaster(serverStatus.getNodeId())) {
LOG.warn("Detected another master in the cluster. Retrying in {} seconds to make sure it is not " + "an old stale instance.", TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleMasterTimeout()));
try {
Thread.sleep(configuration.getStaleMasterTimeout());
} catch (InterruptedException e) {
/* nope */
}
if (!nodeService.isOnlyMaster(serverStatus.getNodeId())) {
// All devils here.
String what = "Detected other master node in the cluster! Starting as non-master! " + "This is a mis-configuration you should fix.";
LOG.warn(what);
activityWriter.write(new Activity(what, Server.class));
// Write a notification.
final NotificationService notificationService = injector.getInstance(NotificationService.class);
Notification notification = notificationService.buildNow().addType(Notification.Type.MULTI_MASTER).addSeverity(Notification.Severity.URGENT);
notificationService.publishIfFirst(notification);
configuration.setIsMaster(false);
} else {
LOG.warn("Stale master has gone. Starting as master.");
}
}
}
Aggregations