Search in sources :

Example 16 with Cluster

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);
    }
}
Also used : NodeNotFoundException(org.graylog2.cluster.NodeNotFoundException) Node(org.graylog2.cluster.Node) Activity(org.graylog2.shared.system.activities.Activity) Notification(org.graylog2.notifications.Notification) NodeNotFoundException(org.graylog2.cluster.NodeNotFoundException)

Example 17 with Cluster

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();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 18 with Cluster

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();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) Test(org.junit.Test)

Example 19 with Cluster

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;
}
Also used : DeadEventLoggingListener(org.graylog2.shared.events.DeadEventLoggingListener) ClusterEventBus(org.graylog2.events.ClusterEventBus)

Example 20 with Cluster

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.");
        }
    }
}
Also used : NodeService(org.graylog2.cluster.NodeService) ServerStatus(org.graylog2.plugin.ServerStatus) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) Activity(org.graylog2.shared.system.activities.Activity) NotificationService(org.graylog2.notifications.NotificationService) Notification(org.graylog2.notifications.Notification)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)5 IOException (java.io.IOException)4 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)4 Notification (org.graylog2.notifications.Notification)4 Test (org.junit.Test)4 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Map (java.util.Map)3 Set (java.util.Set)3 Path (javax.ws.rs.Path)3 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Inject (javax.inject.Inject)2 GET (javax.ws.rs.GET)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2