Search in sources :

Example 6 with NotificationService

use of org.graylog2.notifications.NotificationService 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 7 with NotificationService

use of org.graylog2.notifications.NotificationService in project graylog2-server by Graylog2.

the class IndexerClusterCheckerThreadTest method ignoresNonDataNodes.

@Test
public void ignoresNonDataNodes() throws Exception {
    final Set<NodeDiskUsageStats> nodeDiskUsageStats = mockNodeDiskUsageStats(EnumSet.of(MASTER_ELIGIBLE, TRANSFORM));
    when(cluster.getDiskUsageStats()).thenReturn(nodeDiskUsageStats);
    when(cluster.getClusterAllocationDiskSettings()).thenReturn(buildThresholdTriggeredClusterAllocationDiskSettings(ES_NODE_DISK_WATERMARK_LOW, WatermarkSettings.SettingsType.ABSOLUTE));
    Notification notification = new NotificationImpl();
    when(notificationService.buildNow()).thenReturn(notification);
    when(notificationService.isFirst(ES_NODE_DISK_WATERMARK_LOW)).thenReturn(true);
    indexerClusterCheckerThread.checkDiskUsage();
    verify(notificationService, never()).publishIfFirst(any());
}
Also used : NotificationImpl(org.graylog2.notifications.NotificationImpl) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) Notification(org.graylog2.notifications.Notification) Test(org.junit.Test)

Example 8 with NotificationService

use of org.graylog2.notifications.NotificationService in project graylog2-server by Graylog2.

the class IndexerClusterCheckerThreadTest method notificationCreated.

private void notificationCreated(Notification.Type notificationType, WatermarkSettings.SettingsType watermarkSettingsType) throws Exception {
    Set<NodeDiskUsageStats> nodeDiskUsageStats = mockNodeDiskUsageStats();
    when(cluster.getDiskUsageStats()).thenReturn(nodeDiskUsageStats);
    if (watermarkSettingsType == WatermarkSettings.SettingsType.ABSOLUTE) {
        when(cluster.getClusterAllocationDiskSettings()).thenReturn(buildThresholdTriggeredClusterAllocationDiskSettings(notificationType, WatermarkSettings.SettingsType.ABSOLUTE));
    } else {
        when(cluster.getClusterAllocationDiskSettings()).thenReturn(buildThresholdTriggeredClusterAllocationDiskSettings(notificationType, WatermarkSettings.SettingsType.PERCENTAGE));
    }
    when(notificationService.isFirst(notificationType)).thenReturn(true);
    Notification notification = new NotificationImpl();
    when(notificationService.buildNow()).thenReturn(notification);
    indexerClusterCheckerThread.checkDiskUsage();
    ArgumentCaptor<Notification> argument = ArgumentCaptor.forClass(Notification.class);
    verify(notificationService, times(1)).publishIfFirst(argument.capture());
    Notification publishedNotification = argument.getValue();
    assertThat(publishedNotification.getType()).isEqualTo(notificationType);
}
Also used : NotificationImpl(org.graylog2.notifications.NotificationImpl) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) Notification(org.graylog2.notifications.Notification)

Example 9 with NotificationService

use of org.graylog2.notifications.NotificationService 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

Test (org.junit.Test)4 Notification (org.graylog2.notifications.Notification)3 RotationStrategy (org.graylog2.plugin.indexer.rotation.RotationStrategy)3 NullActivityWriter (org.graylog2.shared.system.activities.NullActivityWriter)3 Before (org.junit.Before)3 DBNotificationService (org.graylog.events.notifications.DBNotificationService)2 NotificationResourceHandler (org.graylog.events.notifications.NotificationResourceHandler)2 DBEventDefinitionService (org.graylog.events.processor.DBEventDefinitionService)2 DBJobDefinitionService (org.graylog.scheduler.DBJobDefinitionService)2 MongoConnection (org.graylog2.database.MongoConnection)2 NodeDiskUsageStats (org.graylog2.indexer.cluster.health.NodeDiskUsageStats)2 NotificationImpl (org.graylog2.notifications.NotificationImpl)2 SuppressForbidden (org.graylog2.shared.SuppressForbidden)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)1 Date (java.util.Date)1 JobSchedulerTestClock (org.graylog.events.JobSchedulerTestClock)1 DBEventProcessorStateService (org.graylog.events.processor.DBEventProcessorStateService)1 EventDefinitionHandler (org.graylog.events.processor.EventDefinitionHandler)1 AggregationEventProcessorConfig (org.graylog.events.processor.aggregation.AggregationEventProcessorConfig)1