Search in sources :

Example 16 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class IndexRotationThread method checkAndRepair.

protected void checkAndRepair(IndexSet indexSet) {
    if (!indexSet.isUp()) {
        if (indices.exists(indexSet.getWriteIndexAlias())) {
            // Publish a notification if there is an *index* called graylog2_deflector
            Notification notification = notificationService.buildNow().addType(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX).addSeverity(Notification.Severity.URGENT);
            final boolean published = notificationService.publishIfFirst(notification);
            if (published) {
                LOG.warn("There is an index called [" + indexSet.getWriteIndexAlias() + "]. Cannot fix this automatically and published a notification.");
            }
        } else {
            indexSet.setUp();
        }
    } else {
        try {
            String currentTarget;
            try {
                currentTarget = indexSet.getActiveWriteIndex();
            } catch (TooManyAliasesException e) {
                // If we get this exception, there are multiple indices which have the deflector alias set.
                // We try to cleanup the alias and try again. This should not happen, but might under certain
                // circumstances.
                indexSet.cleanupAliases(e.getIndices());
                try {
                    currentTarget = indexSet.getActiveWriteIndex();
                } catch (TooManyAliasesException e1) {
                    throw new IllegalStateException(e1);
                }
            }
            String shouldBeTarget = indexSet.getNewestIndex();
            if (!shouldBeTarget.equals(currentTarget)) {
                String msg = "Deflector is pointing to [" + currentTarget + "], not the newest one: [" + shouldBeTarget + "]. Re-pointing.";
                LOG.warn(msg);
                activityWriter.write(new Activity(msg, IndexRotationThread.class));
                if (ClusterHealthStatus.RED == indices.waitForRecovery(shouldBeTarget)) {
                    LOG.error("New target index for deflector didn't get healthy within timeout. Skipping deflector update.");
                } else {
                    indexSet.pointTo(shouldBeTarget, currentTarget);
                }
            }
        } catch (NoTargetIndexException e) {
            LOG.warn("Deflector is not up. Not trying to point to another index.");
        }
    }
}
Also used : NoTargetIndexException(org.graylog2.indexer.NoTargetIndexException) Activity(org.graylog2.shared.system.activities.Activity) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) Notification(org.graylog2.notifications.Notification)

Example 17 with Activity

use of org.graylog2.shared.system.activities.Activity 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 18 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class GracefulShutdown method doRun.

private void doRun(boolean exit) {
    LOG.info("Graceful shutdown initiated.");
    serverStatus.shutdown();
    // Give possible load balancers time to recognize state change. State is DEAD because of HALTING.
    LOG.info("Node status: [{}]. Waiting <{}sec> for possible load balancers to recognize state change.", serverStatus.getLifecycle(), configuration.getLoadBalancerRecognitionPeriodSeconds());
    Uninterruptibles.sleepUninterruptibly(configuration.getLoadBalancerRecognitionPeriodSeconds(), TimeUnit.SECONDS);
    activityWriter.write(new Activity("Graceful shutdown initiated.", GracefulShutdown.class));
    /*
         * Wait a second to give for example the calling REST call some time to respond
         * to the client. Using a latch or something here might be a bit over-engineered.
         */
    Uninterruptibles.sleepUninterruptibly(SLEEP_SECS, TimeUnit.SECONDS);
    // Stop REST API service to avoid changes from outside.
    jerseyService.stopAsync();
    // stop all inputs so no new messages can come in
    inputSetupService.stopAsync();
    jerseyService.awaitTerminated();
    inputSetupService.awaitTerminated();
    journalReader.stopAsync().awaitTerminated();
    // Try to flush all remaining messages from the system
    bufferSynchronizerService.stopAsync().awaitTerminated();
    // stop all maintenance tasks
    periodicalsService.stopAsync().awaitTerminated();
    auditEventSender.success(AuditActor.system(serverStatus.getNodeId()), NODE_SHUTDOWN_COMPLETE);
    // Shut down hard with no shutdown hooks running.
    LOG.info("Goodbye.");
    if (exit) {
        System.exit(0);
    }
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Example 19 with Activity

use of org.graylog2.shared.system.activities.Activity 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)

Example 20 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class ExtractorsResource method update.

@PUT
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an extractor")
@Path("/{extractorId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such extractor on this input."), @ApiResponse(code = 400, message = "No such extractor type."), @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.EXTRACTOR_UPDATE)
public ExtractorSummary update(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "extractorId", required = true) @PathParam("extractorId") String extractorId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final Input mongoInput = inputService.find(inputId);
    final Extractor originalExtractor = inputService.getExtractor(mongoInput, extractorId);
    final Extractor extractor = buildExtractorFromRequest(cer, originalExtractor.getId());
    inputService.removeExtractor(mongoInput, originalExtractor.getId());
    try {
        inputService.addExtractor(mongoInput, extractor);
    } catch (ValidationException e) {
        LOG.error("Extractor persist validation failed.", e);
        throw new BadRequestException(e);
    }
    final String msg = "Updated extractor <" + originalExtractor.getId() + "> of type [" + cer.extractorType() + "] in input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, ExtractorsResource.class));
    return toSummary(extractor);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Activity(org.graylog2.shared.system.activities.Activity) Extractor(org.graylog2.plugin.inputs.Extractor) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Activity (org.graylog2.shared.system.activities.Activity)23 Timed (com.codahale.metrics.annotation.Timed)9 ApiOperation (io.swagger.annotations.ApiOperation)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 ApiResponses (io.swagger.annotations.ApiResponses)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 MessageInput (org.graylog2.plugin.inputs.MessageInput)6 Input (org.graylog2.inputs.Input)5 Consumes (javax.ws.rs.Consumes)4 DELETE (javax.ws.rs.DELETE)4 POST (javax.ws.rs.POST)4 IndexSet (org.graylog2.indexer.IndexSet)4 Notification (org.graylog2.notifications.Notification)4 BadRequestException (javax.ws.rs.BadRequestException)3 NotFoundException (org.graylog2.database.NotFoundException)3 Extractor (org.graylog2.plugin.inputs.Extractor)3 ActivityWriter (org.graylog2.shared.system.activities.ActivityWriter)3 URI (java.net.URI)2 LinkedHashSet (java.util.LinkedHashSet)2