use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class InputEventListener method inputCreated.
@Subscribe
public void inputCreated(InputCreated inputCreatedEvent) {
LOG.debug("Input created/changed: " + inputCreatedEvent.id());
final Input input;
try {
input = inputService.find(inputCreatedEvent.id());
} catch (NotFoundException e) {
LOG.warn("Received InputCreated event but could not find Input: ", e);
return;
}
final IOState<MessageInput> inputState = inputRegistry.getInputState(inputCreatedEvent.id());
if (inputState != null) {
inputRegistry.remove(inputState);
}
if (!input.isGlobal() && !this.nodeId.toString().equals(input.getNodeId())) {
return;
}
final MessageInput messageInput;
try {
messageInput = inputService.getMessageInput(input);
messageInput.initialize();
} catch (NoSuchInputTypeException e) {
LOG.warn("Newly created input is of invalid type: " + input.getType(), e);
return;
}
final IOState<MessageInput> newInputState = inputLauncher.launch(messageInput);
inputRegistry.add(newInputState);
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class InputServiceImpl method findForThisNode.
@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
final List<BasicDBObject> forThisNode = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, false));
final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)), new BasicDBObject("$and", forThisNode));
final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
if (o == null) {
throw new NotFoundException("Couldn't find input " + id + " on Graylog node " + nodeId);
} else {
return new InputImpl((ObjectId) o.get("_id"), o.toMap());
}
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class PersistedInputsImpl method remove.
@Override
public boolean remove(Object o) {
if (o instanceof MessageInput) {
final MessageInput messageInput = (MessageInput) o;
if (isNullOrEmpty(messageInput.getId()))
return false;
try {
final Input input = inputService.find(messageInput.getId());
inputService.destroy(input);
return true;
} catch (NotFoundException e) {
return false;
}
}
return false;
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class PersistedInputsImpl method update.
@Override
public boolean update(String id, MessageInput newInput) {
try {
final Input oldInput = inputService.find(id);
newInput.setPersistId(id);
final Input mongoInput = getInput(newInput);
final List<Extractor> extractors = inputService.getExtractors(oldInput);
final Map<String, String> staticFields = oldInput.getStaticFields();
inputService.save(mongoInput);
for (Map.Entry<String, String> entry : staticFields.entrySet()) inputService.addStaticField(mongoInput, entry.getKey(), entry.getValue());
for (Extractor extractor : extractors) inputService.addExtractor(mongoInput, extractor);
return true;
} catch (NotFoundException | ValidationException e) {
return false;
}
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamResource method resume.
@POST
@Path("/{streamId}/resume")
@Timed
@ApiOperation(value = "Resume a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid or missing Stream id.") })
@AuditEvent(type = AuditEventTypes.STREAM_START)
public void resume(@ApiParam(name = "streamId", required = true) @PathParam("streamId") @NotEmpty String streamId) throws NotFoundException, ValidationException {
checkAnyPermission(new String[] { RestPermissions.STREAMS_CHANGESTATE, RestPermissions.STREAMS_EDIT }, streamId);
checkNotDefaultStream(streamId, "The default stream cannot be resumed.");
final Stream stream = streamService.load(streamId);
streamService.resume(stream);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
Aggregations