Search in sources :

Example 6 with PipelineConnections

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;
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)

Example 7 with PipelineConnections

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
    }
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) NotFoundException(org.graylog2.database.NotFoundException)

Example 8 with PipelineConnections

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

Example 9 with PipelineConnections

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);
        }
    }
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) NotFoundException(org.graylog2.database.NotFoundException) Stream(org.graylog2.plugin.streams.Stream)

Example 10 with PipelineConnections

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());
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) RuleService(org.graylog.plugins.pipelineprocessor.db.RuleService) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Entity(org.graylog2.contentpacks.model.entities.Entity) Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) ModelType(org.graylog2.contentpacks.model.ModelType) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Inject(javax.inject.Inject) PipelineService(org.graylog.plugins.pipelineprocessor.db.PipelineService) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) PipelineStreamConnectionsService(org.graylog.plugins.pipelineprocessor.db.PipelineStreamConnectionsService) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonNode(com.fasterxml.jackson.databind.JsonNode) PipelineRuleParser(org.graylog.plugins.pipelineprocessor.parser.PipelineRuleParser) NotFoundException(org.graylog2.database.NotFoundException) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) MissingNativeEntityException(org.graylog2.contentpacks.exceptions.MissingNativeEntityException) Set(java.util.Set) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Objects(java.util.Objects) Stream(org.graylog2.plugin.streams.Stream) StreamService(org.graylog2.streams.StreamService) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Collections(java.util.Collections) Graph(com.google.common.graph.Graph) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)

Aggregations

PipelineConnections (org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)11 NotFoundException (org.graylog2.database.NotFoundException)6 Pipeline (org.graylog.plugins.pipelineprocessor.ast.Pipeline)3 PipelineDao (org.graylog.plugins.pipelineprocessor.db.PipelineDao)3 PipelineStreamConnectionsService (org.graylog.plugins.pipelineprocessor.db.PipelineStreamConnectionsService)3 PipelineRuleParser (org.graylog.plugins.pipelineprocessor.parser.PipelineRuleParser)3 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Graph (com.google.common.graph.Graph)2 GraphBuilder (com.google.common.graph.GraphBuilder)2 ImmutableGraph (com.google.common.graph.ImmutableGraph)2 MutableGraph (com.google.common.graph.MutableGraph)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2