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);
}
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();
}
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);
}
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;
}
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;
}
Aggregations