Search in sources :

Example 16 with ConfigurationException

use of org.graylog2.plugin.configuration.ConfigurationException in project graylog2-server by Graylog2.

the class InputsResource method create.

@POST
@Timed
@ApiOperation(value = "Launch input on this node", response = InputCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input type registered"), @ApiResponse(code = 400, message = "Missing or invalid configuration"), @ApiResponse(code = 400, message = "Type is exclusive and already has input running") })
@RequiresPermissions(RestPermissions.INPUTS_CREATE)
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) @Valid @NotNull InputCreateRequest lr) throws ValidationException {
    try {
        // TODO Configuration type values need to be checked. See ConfigurationMapConverter.convertValues()
        final MessageInput messageInput = messageInputFactory.create(lr, getCurrentUser().getName(), lr.node());
        messageInput.checkConfiguration();
        final Input input = this.inputService.create(messageInput.asMap());
        final String newId = inputService.save(input);
        final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(newId);
        return Response.created(inputUri).entity(InputCreated.create(newId)).build();
    } catch (NoSuchInputTypeException e) {
        LOG.error("There is no such input type registered.", e);
        throw new NotFoundException("There is no such input type registered.", e);
    } catch (ConfigurationException e) {
        LOG.error("Missing or invalid input configuration.", e);
        throw new BadRequestException("Missing or invalid input configuration.", e);
    }
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) MessageInput(org.graylog2.plugin.inputs.MessageInput) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 BadRequestException (javax.ws.rs.BadRequestException)7 AuditEvent (org.graylog2.audit.jersey.AuditEvent)7 ConfigurationException (org.graylog2.plugin.configuration.ConfigurationException)7 ApiResponses (io.swagger.annotations.ApiResponses)5 URI (java.net.URI)5 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)4 MessageInput (org.graylog2.plugin.inputs.MessageInput)4 Consumes (javax.ws.rs.Consumes)3 PUT (javax.ws.rs.PUT)3 Produces (javax.ws.rs.Produces)3 ConfigurationException (org.graylog2.ConfigurationException)3 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)3 Stream (org.graylog2.plugin.streams.Stream)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Input (org.graylog2.inputs.Input)2 AlarmCallbackConfigurationException (org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException)2