Search in sources :

Example 1 with RuleMetricsConfigDto

use of org.graylog.plugins.pipelineprocessor.db.RuleMetricsConfigDto 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;
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) ImmutableMap(com.google.common.collect.ImmutableMap) RuleMetricsConfigDto(org.graylog.plugins.pipelineprocessor.db.RuleMetricsConfigDto) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Pipeline (org.graylog.plugins.pipelineprocessor.ast.Pipeline)1 Rule (org.graylog.plugins.pipelineprocessor.ast.Rule)1 RuleMetricsConfigDto (org.graylog.plugins.pipelineprocessor.db.RuleMetricsConfigDto)1 ParseException (org.graylog.plugins.pipelineprocessor.parser.ParseException)1 PipelineConnections (org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)1