Search in sources :

Example 66 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method updateCacheTime.

@Deprecated
@PUT
@Timed
@ApiOperation(value = "Update cache time of a widget")
@Path("/{widgetId}/cachetime")
@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_UPDATE)
public void updateCacheTime(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId, @ApiParam(name = "JSON body", required = true) @Valid UpdateWidgetRequest uwr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    if (widget == null) {
        final String msg = "Widget " + widgetId + " on dashboard " + dashboardId + " not found.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    dashboardService.updateWidgetCacheTime(dashboard, widget, uwr.cacheTime());
    this.clusterEventBus.post(WidgetUpdatedEvent.create(widget));
    LOG.info("Updated cache time of widget <" + widgetId + "> on dashboard <" + dashboardId + "> to " + "[" + uwr.cacheTime() + "]. Reason: REST request.");
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) 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)

Example 67 with NotFoundException

use of org.graylog2.database.NotFoundException 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 68 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method updateWidget.

@PUT
@Timed
@ApiOperation(value = "Update 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_UPDATE)
public void updateWidget(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull AddWidgetRequest awr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    if (widget == null) {
        final String msg = "Widget " + widgetId + " on dashboard " + dashboardId + " not found.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    try {
        final DashboardWidget updatedWidget = dashboardWidgetCreator.fromRequest(widgetId, awr, widget.getCreatorUserId());
        updatedWidget.setCacheTime(awr.cacheTime());
        dashboardService.removeWidget(dashboard, widget);
        dashboardService.addWidget(dashboard, updatedWidget);
        this.clusterEventBus.post(WidgetUpdatedEvent.create(updatedWidget));
    } catch (DashboardWidget.NoSuchWidgetTypeException e2) {
        LOG.error("No such widget type.", e2);
        throw new BadRequestException(e2);
    } catch (InvalidRangeParametersException e3) {
        LOG.error("Invalid timerange parameters provided.", e3);
        throw new BadRequestException(e3);
    } catch (InvalidWidgetConfigurationException e4) {
        LOG.error("Invalid widget configuration.", e4);
        throw new BadRequestException(e4);
    }
    LOG.info("Updated widget <" + widgetId + "> on dashboard <" + dashboardId + ">. Reason: REST request.");
}
Also used : InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InvalidWidgetConfigurationException(org.graylog2.dashboards.widgets.InvalidWidgetConfigurationException) Path(javax.ws.rs.Path) 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)

Example 69 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class DashboardsResource method setPositions.

@PUT
@Timed
@ApiOperation(value = "Update/set the positions of dashboard widgets.")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}/positions")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_POSITIONS_UPDATE)
public void setPositions(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "JSON body", required = true) @Valid WidgetPositionsRequest uwpr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    dashboardService.updateWidgetPositions(dashboard, uwpr);
}
Also used : Dashboard(org.graylog2.dashboards.Dashboard) Path(javax.ws.rs.Path) 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)

Example 70 with NotFoundException

use of org.graylog2.database.NotFoundException 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

ApiOperation (io.swagger.annotations.ApiOperation)91 Timed (com.codahale.metrics.annotation.Timed)77 Path (javax.ws.rs.Path)75 ApiResponses (io.swagger.annotations.ApiResponses)66 AuditEvent (org.graylog2.audit.jersey.AuditEvent)60 Produces (javax.ws.rs.Produces)44 NotFoundException (org.graylog2.database.NotFoundException)32 GET (javax.ws.rs.GET)30 PUT (javax.ws.rs.PUT)28 BadRequestException (javax.ws.rs.BadRequestException)27 Stream (org.graylog2.plugin.streams.Stream)27 NotFoundException (javax.ws.rs.NotFoundException)26 Consumes (javax.ws.rs.Consumes)21 DELETE (javax.ws.rs.DELETE)21 POST (javax.ws.rs.POST)19 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 MessageInput (org.graylog2.plugin.inputs.MessageInput)15 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)11 Input (org.graylog2.inputs.Input)11 ValidationException (org.graylog2.plugin.database.ValidationException)11