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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations