Search in sources :

Example 11 with Activity

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

the class FixDeflectorByDeleteJob method doExecute.

public void doExecute(IndexSet indexSet) {
    if (!indexSet.getConfig().isWritable()) {
        LOG.debug("No need to fix deflector for non-writable index set <{}> ({})", indexSet.getConfig().id(), indexSet.getConfig().title());
        return;
    }
    if (indexSet.isUp() || !indices.exists(indexSet.getWriteIndexAlias())) {
        LOG.error("There is no index <{}>. No need to run this job. Aborting.", indexSet.getWriteIndexAlias());
        return;
    }
    LOG.info("Attempting to fix deflector with delete strategy.");
    // Pause message processing and lock the pause.
    boolean wasProcessing = serverStatus.isProcessing();
    serverStatus.pauseMessageProcessing();
    progress = 10;
    bufferSynchronizer.waitForEmptyBuffers();
    progress = 25;
    // Delete deflector index.
    LOG.info("Deleting <{}> index.", indexSet.getWriteIndexAlias());
    indices.delete(indexSet.getWriteIndexAlias());
    progress = 70;
    // Set up deflector.
    indexSet.setUp();
    progress = 80;
    // Start message processing again.
    try {
        serverStatus.unlockProcessingPause();
        if (wasProcessing) {
            serverStatus.resumeMessageProcessing();
        }
    } catch (Exception e) {
        // lol checked exceptions
        throw new RuntimeException("Could not unlock processing pause.", e);
    }
    progress = 90;
    activityWriter.write(new Activity("Notification condition [" + Notification.Type.DEFLECTOR_EXISTS_AS_INDEX + "] " + "has been fixed.", this.getClass()));
    notificationService.fixed(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX);
    progress = 100;
    LOG.info("Finished.");
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Example 12 with Activity

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

the class FixDeflectorByMoveJob method doExecute.

public void doExecute(IndexSet indexSet) {
    if (!indexSet.getConfig().isWritable()) {
        LOG.debug("No need to fix deflector for non-writable index set <{}> ({})", indexSet.getConfig().id(), indexSet.getConfig().title());
        return;
    }
    if (indexSet.isUp() || !indices.exists(indexSet.getWriteIndexAlias())) {
        LOG.error("There is no index <{}>. No need to run this job. Aborting.", indexSet.getWriteIndexAlias());
        return;
    }
    LOG.info("Attempting to fix deflector with move strategy.");
    boolean wasProcessing = true;
    try {
        // Pause message processing and lock the pause.
        wasProcessing = serverStatus.isProcessing();
        serverStatus.pauseMessageProcessing();
        progress = 5;
        bufferSynchronizer.waitForEmptyBuffers();
        progress = 10;
        // Copy messages to new index.
        String newTarget = null;
        try {
            newTarget = indexSet.getNewestIndex();
            LOG.info("Starting to move <{}> to <{}>.", indexSet.getWriteIndexAlias(), newTarget);
            indices.move(indexSet.getWriteIndexAlias(), newTarget);
        } catch (Exception e) {
            LOG.error("Moving index failed. Rolling back.", e);
            if (newTarget != null) {
                indices.delete(newTarget);
            }
            throw new RuntimeException(e);
        }
        LOG.info("Done moving deflector index.");
        progress = 85;
        // Delete deflector index.
        LOG.info("Deleting <{}> index.", indexSet.getWriteIndexAlias());
        indices.delete(indexSet.getWriteIndexAlias());
        progress = 90;
        // Set up deflector.
        indexSet.setUp();
        progress = 95;
    } finally {
        // Start message processing again.
        serverStatus.unlockProcessingPause();
        if (wasProcessing) {
            serverStatus.resumeMessageProcessing();
        }
    }
    progress = 90;
    activityWriter.write(new Activity("Notification condition [" + Notification.Type.DEFLECTOR_EXISTS_AS_INDEX + "] " + "has been fixed.", this.getClass()));
    notificationService.fixed(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX);
    progress = 100;
    LOG.info("Finished.");
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Example 13 with Activity

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

the class OptimizeIndexJob method execute.

@Override
public void execute() {
    String msg = "Optimizing index <" + index + ">.";
    activityWriter.write(new Activity(msg, OptimizeIndexJob.class));
    LOG.info(msg);
    indices.optimizeIndex(index, maxNumSegments, indexOptimizationTimeout);
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Example 14 with Activity

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

the class DashboardWidgetsResource method remove.

@DELETE
@Timed
@ApiOperation(value = "Delete a widget")
@Path("/{widgetId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_DELETE)
public void remove(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId) throws NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    dashboardService.removeWidget(dashboard, widget);
    this.clusterEventBus.post(WidgetUpdatedEvent.create(widget));
    final String msg = "Deleted widget <" + widgetId + "> from dashboard <" + dashboardId + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DashboardsResource.class));
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) Activity(org.graylog2.shared.system.activities.Activity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with Activity

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

the class DashboardsResource method delete.

@DELETE
@Timed
@ApiOperation(value = "Delete a dashboard and all its widgets")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_DELETE)
public void delete(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId) throws NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    dashboard.getWidgets().values().forEach((widget) -> this.clusterEventBus.post(WidgetUpdatedEvent.create(widget)));
    dashboardService.destroy(dashboard);
    final String msg = "Deleted dashboard <" + dashboard.getId() + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DashboardsResource.class));
    this.serverEventBus.post(DashboardDeletedEvent.create(dashboard.getId()));
}
Also used : Dashboard(org.graylog2.dashboards.Dashboard) Activity(org.graylog2.shared.system.activities.Activity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) 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