Search in sources :

Example 1 with NotFoundException

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);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) MessageInput(org.graylog2.plugin.inputs.MessageInput) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with NotFoundException

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());
    }
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) NotFoundException(org.graylog2.database.NotFoundException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 3 with NotFoundException

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;
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException)

Example 4 with NotFoundException

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;
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) NotFoundException(org.graylog2.database.NotFoundException) Extractor(org.graylog2.plugin.inputs.Extractor) Map(java.util.Map)

Example 5 with NotFoundException

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()));
}
Also used : Stream(org.graylog2.plugin.streams.Stream) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) 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