Search in sources :

Example 21 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ExtractorsResource method create.

@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add an extractor to an input", response = ExtractorCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "No such extractor type."), @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.EXTRACTOR_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final Input mongoInput = inputService.find(inputId);
    final String id = new com.eaio.uuid.UUID().toString();
    final Extractor extractor = buildExtractorFromRequest(cer, id);
    try {
        inputService.addExtractor(mongoInput, extractor);
    } catch (ValidationException e) {
        final String msg = "Extractor persist validation failed.";
        LOG.error(msg, e);
        throw new BadRequestException(msg, e);
    }
    final String msg = "Added extractor <" + id + "> of type [" + cer.extractorType() + "] to input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, ExtractorsResource.class));
    final ExtractorCreated result = ExtractorCreated.create(id);
    final URI extractorUri = getUriBuilderToSelf().path(ExtractorsResource.class).path("{inputId}").build(mongoInput.getId());
    return Response.created(extractorUri).entity(result).build();
}
Also used : ExtractorCreated(org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorCreated) Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Activity(org.graylog2.shared.system.activities.Activity) Extractor(org.graylog2.plugin.inputs.Extractor) URI(java.net.URI) 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) ApiResponses(io.swagger.annotations.ApiResponses)

Example 22 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ClusterResource method nodes.

@GET
@Timed
@Path("/nodes")
@ApiOperation(value = "List all active nodes in this cluster.")
public NodeSummaryList nodes() {
    final Map<String, Node> nodes = nodeService.allActive(Node.Type.SERVER);
    final List<NodeSummary> nodeList = new ArrayList<>(nodes.size());
    for (Node node : nodes.values()) {
        nodeList.add(nodeSummary(node));
    }
    return NodeSummaryList.create(nodeList);
}
Also used : NodeSummary(org.graylog2.rest.models.system.cluster.responses.NodeSummary) Node(org.graylog2.cluster.Node) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 23 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class StreamOutputResource method get.

@GET
@Timed
@ApiOperation(value = "Get a list of all outputs for a stream")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream on this node.") })
public OutputListResponse get(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_READ, streamid);
    checkPermission(RestPermissions.STREAM_OUTPUTS_READ);
    final Stream stream = streamService.load(streamid);
    final Set<OutputSummary> outputs = new HashSet<>();
    for (Output output : stream.getOutputs()) outputs.add(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack()));
    return OutputListResponse.create(outputs);
}
Also used : OutputSummary(org.graylog2.rest.models.system.outputs.responses.OutputSummary) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class VersionProbe method probeSingleHost.

private Optional<SearchVersion> probeSingleHost(URI host) {
    final Retrofit retrofit;
    try {
        retrofit = new Retrofit.Builder().baseUrl(host.toURL()).addConverterFactory(JacksonConverterFactory.create(objectMapper)).client(addAuthenticationIfPresent(host, okHttpClient)).build();
    } catch (MalformedURLException e) {
        LOG.error("Elasticsearch node URL is invalid: " + host.toString(), e);
        return Optional.empty();
    }
    final RootRoute root = retrofit.create(RootRoute.class);
    final Converter<ResponseBody, ErrorResponse> errorResponseConverter = retrofit.responseBodyConverter(ErrorResponse.class, new Annotation[0]);
    final Consumer<ResponseBody> errorLogger = (responseBody) -> {
        try {
            final ErrorResponse errorResponse = errorResponseConverter.convert(responseBody);
            LOG.error("Unable to retrieve version from Elasticsearch node {}:{}: {}", host.getHost(), host.getPort(), errorResponse);
        } catch (IOException e) {
            LOG.error("Unable to retrieve version from Elasticsearch node {}:{}: unknown error - an exception occurred while deserializing error response: {}", host.getHost(), host.getPort(), e);
        }
    };
    return rootResponse(root, errorLogger).map(RootResponse::version).flatMap(this::parseVersion);
}
Also used : RetryerBuilder(com.github.rholder.retry.RetryerBuilder) RetryException(com.github.rholder.retry.RetryException) LoggerFactory(org.slf4j.LoggerFactory) Response(retrofit2.Response) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Duration(com.github.joschi.jadconfig.util.Duration) Named(javax.inject.Named) URI(java.net.URI) Version(org.graylog2.plugin.Version) ResponseBody(okhttp3.ResponseBody) WaitStrategies(com.github.rholder.retry.WaitStrategies) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) Converter(retrofit2.Converter) Request(okhttp3.Request) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Attempt(com.github.rholder.retry.Attempt) IOException(java.io.IOException) Credentials(okhttp3.Credentials) SearchVersion(org.graylog2.storage.SearchVersion) RetryListener(com.github.rholder.retry.RetryListener) Retrofit(retrofit2.Retrofit) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) OkHttpClient(okhttp3.OkHttpClient) StopStrategies(com.github.rholder.retry.StopStrategies) JacksonConverterFactory(retrofit2.converter.jackson.JacksonConverterFactory) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) Retrofit(retrofit2.Retrofit) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Example 25 with Node

use of org.graylog2.indexer.cluster.Node 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(InputImpl.FIELD_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(InputImpl.FIELD_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)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)29 ApiOperation (io.swagger.annotations.ApiOperation)28 MessageInput (org.graylog2.plugin.inputs.MessageInput)23 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)19 Input (org.graylog2.inputs.Input)15 AuditEvent (org.graylog2.audit.jersey.AuditEvent)14 Test (org.junit.Test)14 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 Node (org.graylog2.cluster.Node)12 Map (java.util.Map)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PUT (javax.ws.rs.PUT)6 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)6 Notification (org.graylog2.notifications.Notification)6 Activity (org.graylog2.shared.system.activities.Activity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EventBus (com.google.common.eventbus.EventBus)5 URI (java.net.URI)5