use of org.graylog.plugins.pipelineprocessor.rest.PipelineConnections in project graylog2-server by Graylog2.
the class InMemoryPipelineStreamConnectionsService method save.
@Override
public PipelineConnections save(PipelineConnections connections) {
PipelineConnections toSave = connections.id() != null ? connections : connections.toBuilder().id(createId()).build();
store.put(toSave.id(), toSave);
clusterBus.post(PipelineConnectionsChangedEvent.create(toSave.streamId(), toSave.pipelineIds()));
return toSave;
}
use of org.graylog.plugins.pipelineprocessor.rest.PipelineConnections in project graylog2-server by Graylog2.
the class InMemoryPipelineStreamConnectionsService method delete.
@Override
public void delete(String streamId) {
try {
final PipelineConnections connections = load(streamId);
final Set<String> pipelineIds = connections.pipelineIds();
store.remove(connections.id());
clusterBus.post(PipelineConnectionsChangedEvent.create(streamId, pipelineIds));
} catch (NotFoundException e) {
// Do nothing
}
}
use of org.graylog.plugins.pipelineprocessor.rest.PipelineConnections in project graylog2-server by Graylog2.
the class ConfigurationStateUpdater method reloadAndSave.
// only the singleton instance should mutate itself, others are welcome to reload a new state, but we don't
// currently allow direct global state updates from external sources (if you need to, send an event on the bus instead)
private synchronized PipelineInterpreter.State reloadAndSave() {
// read all rules and parse them
Map<String, Rule> ruleNameMap = Maps.newHashMap();
ruleService.loadAll().forEach(ruleDao -> {
Rule rule;
try {
rule = pipelineRuleParser.parseRule(ruleDao.id(), ruleDao.source(), false);
} catch (ParseException e) {
log.warn("Ignoring non parseable rule <{}/{}> with errors <{}>", ruleDao.title(), ruleDao.id(), e.getErrors());
rule = Rule.alwaysFalse("Failed to parse rule: " + ruleDao.id());
}
ruleNameMap.put(rule.name(), rule);
});
// read all pipelines and parse them
ImmutableMap.Builder<String, Pipeline> pipelineIdMap = ImmutableMap.builder();
pipelineService.loadAll().forEach(pipelineDao -> {
Pipeline pipeline;
try {
pipeline = pipelineRuleParser.parsePipeline(pipelineDao.id(), pipelineDao.source());
} catch (ParseException e) {
pipeline = Pipeline.empty("Failed to parse pipeline" + pipelineDao.id());
}
// noinspection ConstantConditions
pipelineIdMap.put(pipelineDao.id(), resolvePipeline(pipeline, ruleNameMap));
});
final ImmutableMap<String, Pipeline> currentPipelines = pipelineIdMap.build();
// read all stream connections of those pipelines to allow processing messages through them
final HashMultimap<String, Pipeline> connections = HashMultimap.create();
for (PipelineConnections streamConnection : pipelineStreamConnectionsService.loadAll()) {
streamConnection.pipelineIds().stream().map(currentPipelines::get).filter(Objects::nonNull).forEach(pipeline -> connections.put(streamConnection.streamId(), pipeline));
}
ImmutableSetMultimap<String, Pipeline> streamPipelineConnections = ImmutableSetMultimap.copyOf(connections);
final RuleMetricsConfigDto ruleMetricsConfig = ruleMetricsConfigService.get();
final PipelineInterpreter.State newState = stateFactory.newState(currentPipelines, streamPipelineConnections, ruleMetricsConfig);
latestState.set(newState);
return newState;
}
use of org.graylog.plugins.pipelineprocessor.rest.PipelineConnections in project graylog2-server by Graylog2.
the class PipelineFacade method createPipelineConnections.
private void createPipelineConnections(String pipelineId, Set<Stream> connectedStreams) {
for (Stream stream : connectedStreams) {
final String streamId = stream.getId();
try {
final PipelineConnections connections = connectionsService.load(streamId);
final Set<String> newPipelines = ImmutableSet.<String>builder().addAll(connections.pipelineIds()).add(pipelineId).build();
final PipelineConnections newConnections = connections.toBuilder().pipelineIds(newPipelines).build();
final PipelineConnections savedConnections = connectionsService.save(newConnections);
LOG.trace("Saved pipeline connections: {}", savedConnections);
} catch (NotFoundException e) {
final PipelineConnections connections = PipelineConnections.builder().streamId(streamId).pipelineIds(Collections.singleton(pipelineId)).build();
final PipelineConnections savedConnections = connectionsService.save(connections);
LOG.trace("Saved pipeline connections: {}", savedConnections);
}
}
}
use of org.graylog.plugins.pipelineprocessor.rest.PipelineConnections in project graylog2-server by Graylog2.
the class PipelineFacade method delete.
@Override
public void delete(PipelineDao nativeEntity) {
final Set<PipelineConnections> pipelineConnections = connectionsService.loadByPipelineId(nativeEntity.id());
for (PipelineConnections connections : pipelineConnections) {
final Set<String> pipelineIds = connections.pipelineIds().stream().filter(pipelineId -> !pipelineId.equals(nativeEntity.id())).collect(Collectors.toSet());
if (pipelineIds.isEmpty()) {
LOG.trace("Removing pipeline connections for stream {}", connections.streamId());
connectionsService.delete(connections.streamId());
} else {
final PipelineConnections newConnections = connections.toBuilder().pipelineIds(pipelineIds).build();
LOG.trace("Saving updated pipeline connections: {}", newConnections);
connectionsService.save(newConnections);
}
}
pipelineService.delete(nativeEntity.id());
}
Aggregations