Search in sources :

Example 11 with Node

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

the class IndexStatistics method buildShardRoutings.

private static List<ShardRouting> buildShardRoutings(JsonNode shardRoutings) {
    final ImmutableList.Builder<ShardRouting> shardRoutingsBuilder = ImmutableList.builder();
    final Iterator<Map.Entry<String, JsonNode>> it = shardRoutings.fields();
    while (it.hasNext()) {
        final Map.Entry<String, JsonNode> entry = it.next();
        final int shardId = Integer.parseInt(entry.getKey());
        final JsonNode shards = entry.getValue();
        for (JsonNode jsonElement : shards) {
            final JsonNode routing = jsonElement.path("routing");
            final String state = routing.path("state").asText("unknown").toLowerCase(Locale.ENGLISH);
            // Taken from org.elasticsearch.cluster.routing.ShardRouting
            final boolean active = "started".equals(state) || "relocating".equals(state);
            final boolean primary = routing.path("primary").asBoolean(false);
            final String nodeId = routing.path("node").asText("Unknown");
            // Node name and hostname should be filled when necessary (requiring an additional round trip to Elasticsearch)
            final String nodeName = null;
            final String nodeHostname = null;
            final String relocatingNode = routing.path("relocating_node").asText(null);
            final ShardRouting shardRouting = ShardRouting.create(shardId, state, active, primary, nodeId, nodeName, nodeHostname, relocatingNode);
            shardRoutingsBuilder.add(shardRouting);
        }
    }
    return shardRoutingsBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) Map(java.util.Map)

Example 12 with Node

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

the class RemoteInterfaceProvider method get.

public <T> T get(Node node, final String authorizationToken, Class<T> interfaceClass) {
    final OkHttpClient okHttpClient = this.okHttpClient.newBuilder().addInterceptor(chain -> {
        final Request original = chain.request();
        Request.Builder builder = original.newBuilder().header(HttpHeaders.ACCEPT, MediaType.JSON_UTF_8.toString()).header(CsrfProtectionFilter.HEADER_NAME, "Graylog Server").method(original.method(), original.body());
        if (authorizationToken != null) {
            builder = builder.header(HttpHeaders.AUTHORIZATION, authorizationToken).header(SessionAuthenticator.X_GRAYLOG_NO_SESSION_EXTENSION, "true");
        }
        return chain.proceed(builder.build());
    }).build();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(node.getTransportAddress()).addConverterFactory(JacksonConverterFactory.create(objectMapper)).client(okHttpClient).build();
    return retrofit.create(interfaceClass);
}
Also used : Inject(javax.inject.Inject) MediaType(com.google.common.net.MediaType) Request(okhttp3.Request) Node(org.graylog2.cluster.Node) OkHttpClient(okhttp3.OkHttpClient) HttpHeaders(com.google.common.net.HttpHeaders) JacksonConverterFactory(retrofit2.converter.jackson.JacksonConverterFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CsrfProtectionFilter(org.glassfish.jersey.client.filter.CsrfProtectionFilter) Retrofit(retrofit2.Retrofit) SessionAuthenticator(org.graylog2.security.realm.SessionAuthenticator) Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request)

Example 13 with Node

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

the class ExtractorsResource method order.

@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update extractor order of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@Path("order")
@AuditEvent(type = AuditEventTypes.EXTRACTOR_ORDER_UPDATE)
public void order(@ApiParam(name = "inputId", value = "Persist ID (!) of input.", required = true) @PathParam("inputId") String inputPersistId, @ApiParam(name = "JSON body", required = true) OrderExtractorsRequest oer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputPersistId);
    final Input mongoInput = inputService.find(inputPersistId);
    for (Extractor extractor : inputService.getExtractors(mongoInput)) {
        if (oer.order().containsValue(extractor.getId())) {
            extractor.setOrder(Tools.getKeyByValue(oer.order(), extractor.getId()));
        }
        // Docs embedded in MongoDB array cannot be updated atomically... :/
        inputService.removeExtractor(mongoInput, extractor.getId());
        try {
            inputService.addExtractor(mongoInput, extractor);
        } catch (ValidationException e) {
            LOG.warn("Validation error for extractor update.", e);
        }
    }
    LOG.info("Updated extractor ordering of input <persist:{}>.", inputPersistId);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) Extractor(org.graylog2.plugin.inputs.Extractor) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with Node

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

the class InputsResource method get.

@GET
@Timed
@ApiOperation(value = "Get information of a single input on this node")
@Path("/{inputId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input.") })
public InputSummary get(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.INPUTS_READ, inputId);
    final Input input = inputService.find(inputId);
    return getInputSummary(input);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with Node

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

the class InputsResource method terminate.

@DELETE
@Timed
@Path("/{inputId}")
@ApiOperation(value = "Terminate input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_DELETE)
public void terminate(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.INPUTS_TERMINATE, inputId);
    final Input input = inputService.find(inputId);
    inputService.destroy(input);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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)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