use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.
the class StreamOutputResource method add.
@POST
@Timed
@ApiOperation(value = "Associate outputs with a stream")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid output specification in input.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_CREATE)
public Response add(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull AddOutputRequest aor) throws ValidationException, NotFoundException {
final Stream stream = streamService.load(streamid);
for (String outputId : aor.outputs()) {
final Output output = outputService.load(outputId);
streamService.addOutput(stream, output);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
return Response.accepted().build();
}
use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.
the class StreamOutputResource method remove.
@DELETE
@Path("/{outputId}")
@Timed
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_DELETE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete output of a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_DELETE)
public void remove(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
final Stream stream = streamService.load(streamid);
final Output output = outputService.load(outputId);
streamService.removeOutput(stream, output);
outputRegistry.removeOutput(output);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.
the class OutputRegistry method removeOutput.
public void removeOutput(Output output) {
final MessageOutput messageOutput = runningMessageOutputs.getIfPresent(output.getId());
if (messageOutput != null) {
messageOutput.stop();
}
runningMessageOutputs.invalidate(output.getId());
faultCounters.invalidate(output.getId());
}
use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.
the class BatchedElasticSearchOutputFlushThread method doRun.
@Override
public void doRun() {
LOG.debug("Checking for outputs to flush ...");
for (MessageOutput output : outputRegistry.getMessageOutputs()) {
if (output instanceof BlockingBatchedESOutput) {
try {
LOG.debug("Flushing output <{}>", output);
((BlockingBatchedESOutput) output).forceFlushIfTimedout();
} catch (Exception e) {
LOG.error("Caught exception while trying to flush output: {}", e);
}
}
}
}
use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.
the class StreamServiceImpl method loadAll.
private List<Stream> loadAll(DBObject query) {
final List<DBObject> results = query(StreamImpl.class, query);
final List<String> streamIds = results.stream().map(o -> o.get("_id").toString()).collect(Collectors.toList());
final Map<String, List<StreamRule>> allStreamRules = streamRuleService.loadForStreamIds(streamIds);
final ImmutableList.Builder<Stream> streams = ImmutableList.builder();
for (DBObject o : results) {
final ObjectId objectId = (ObjectId) o.get("_id");
final String id = objectId.toHexString();
final List<StreamRule> streamRules = allStreamRules.getOrDefault(id, Collections.emptyList());
LOG.debug("Found {} rules for stream <{}>", streamRules.size(), id);
final Set<Output> outputs = loadOutputsForRawStream(o);
@SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap();
streams.add(new StreamImpl(objectId, fields, streamRules, outputs, getIndexSet(o)));
}
return streams.build();
}
Aggregations