Search in sources :

Example 86 with NotFoundException

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

the class DecoratorResource method delete.

@DELETE
@Path("/{decoratorId}")
@Timed
@ApiOperation(value = "Create a decorator")
@AuditEvent(type = AuditEventTypes.MESSAGE_DECORATOR_DELETE)
public void delete(@ApiParam(name = "decorator id", required = true) @PathParam("decoratorId") final String decoratorId) throws NotFoundException {
    checkPermission(RestPermissions.DECORATORS_EDIT);
    final Decorator decorator = this.decoratorService.findById(decoratorId);
    if (decorator.stream().isPresent()) {
        checkPermission(RestPermissions.STREAMS_EDIT, decorator.stream().get());
    }
    this.decoratorService.delete(decoratorId);
}
Also used : SearchResponseDecorator(org.graylog2.plugin.decorators.SearchResponseDecorator) Decorator(org.graylog2.decorators.Decorator) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 87 with NotFoundException

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

the class StreamAlarmCallbackResource method create.

@POST
@Timed
@ApiOperation(value = "Create an alarm callback", response = CreateAlarmCallbackResponse.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_CREATE)
public Response create(@ApiParam(name = "streamid", value = "The stream id this new alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest originalCr) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    // make sure the values are correctly converted to the declared configuration types
    final CreateAlarmCallbackRequest cr = CreateAlarmCallbackRequest.create(originalCr.type(), originalCr.title(), convertConfigurationValues(originalCr));
    final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.create(streamid, cr, getCurrentUser().getName());
    final String id;
    try {
        alarmCallbackFactory.create(alarmCallbackConfiguration).checkConfiguration();
        id = alarmCallbackConfigurationService.save(alarmCallbackConfiguration);
    } catch (ValidationException | AlarmCallbackConfigurationException | ConfigurationException e) {
        LOG.error("Invalid alarm callback configuration.", e);
        throw new BadRequestException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        LOG.error("Invalid alarm callback type.", e);
        throw new BadRequestException("Invalid alarm callback type.", e);
    }
    final URI alarmCallbackUri = getUriBuilderToSelf().path(StreamAlarmCallbackResource.class).path("{alarmCallbackId}").build(streamid, id);
    return Response.created(alarmCallbackUri).entity(CreateAlarmCallbackResponse.create(id)).build();
}
Also used : CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) POST(javax.ws.rs.POST) 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)

Example 88 with NotFoundException

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

the class StreamServiceImpl method destroy.

@Override
public void destroy(Stream stream) throws NotFoundException {
    for (StreamRule streamRule : streamRuleService.loadForStream(stream)) {
        super.destroy(streamRule);
    }
    for (Notification notification : notificationService.all()) {
        Object rawValue = notification.getDetail("stream_id");
        if (rawValue != null && rawValue.toString().equals(stream.getId())) {
            LOG.debug("Removing notification that references stream: {}", notification);
            notificationService.destroy(notification);
        }
    }
    super.destroy(stream);
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Notification(org.graylog2.notifications.Notification)

Example 89 with NotFoundException

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

the class DefaultStreamProvider method get.

@Override
public Stream get() {
    Stream defaultStream = sharedInstance.get();
    if (defaultStream != null) {
        return defaultStream;
    }
    synchronized (this) {
        defaultStream = sharedInstance.get();
        if (defaultStream != null) {
            return defaultStream;
        }
        int i = 0;
        do {
            try {
                LOG.debug("Loading shared default stream instance");
                defaultStream = service.load(Stream.DEFAULT_STREAM_ID);
            } catch (NotFoundException ignored) {
                if (i % 10 == 0) {
                    LOG.warn("Unable to load default stream, tried {} times, retrying every 500ms. Processing is blocked until this succeeds.", i + 1);
                }
                i++;
                Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
            }
        } while (defaultStream == null);
        sharedInstance.set(defaultStream);
    }
    return defaultStream;
}
Also used : NotFoundException(org.graylog2.database.NotFoundException) Stream(org.graylog2.plugin.streams.Stream)

Example 90 with NotFoundException

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

the class DashboardServiceImpl method load.

@Override
public Dashboard load(String id) throws NotFoundException {
    final BasicDBObject o = (BasicDBObject) get(DashboardImpl.class, id);
    if (o == null) {
        throw new NotFoundException("Couldn't find dashboard with ID " + id);
    }
    final Dashboard dashboard = this.create((ObjectId) o.get("_id"), o.toMap());
    return dashboard;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) NotFoundException(org.graylog2.database.NotFoundException)

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