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