Search in sources :

Example 16 with PipelineDao

use of org.graylog.plugins.pipelineprocessor.db.PipelineDao in project graylog2-server by Graylog2.

the class PipelineResource method update.

@ApiOperation(value = "Modify a processing pipeline", notes = "It can take up to a second until the change is applied")
@Path("/{id}")
@PUT
@AuditEvent(type = PipelineProcessorAuditEventTypes.PIPELINE_UPDATE)
public PipelineSource update(@ApiParam(name = "id") @PathParam("id") String id, @ApiParam(name = "pipeline", required = true) @NotNull PipelineSource update) throws NotFoundException {
    checkPermission(PipelineRestPermissions.PIPELINE_EDIT, id);
    final PipelineDao dao = pipelineService.load(id);
    final Pipeline pipeline;
    try {
        pipeline = pipelineRuleParser.parsePipeline(update.id(), update.source());
    } catch (ParseException e) {
        throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
    }
    final PipelineDao toSave = dao.toBuilder().title(pipeline.name()).description(update.description()).source(update.source()).modifiedAt(DateTime.now(DateTimeZone.UTC)).build();
    final PipelineDao savedPipeline = pipelineService.save(toSave);
    return PipelineSource.fromDao(pipelineRuleParser, savedPipeline);
}
Also used : PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) BadRequestException(javax.ws.rs.BadRequestException) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) PUT(javax.ws.rs.PUT)

Example 17 with PipelineDao

use of org.graylog.plugins.pipelineprocessor.db.PipelineDao 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

PipelineDao (org.graylog.plugins.pipelineprocessor.db.PipelineDao)17 Pipeline (org.graylog.plugins.pipelineprocessor.ast.Pipeline)6 Entity (org.graylog2.contentpacks.model.entities.Entity)6 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)6 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)6 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)6 ApiOperation (io.swagger.annotations.ApiOperation)5 NotFoundException (org.graylog2.database.NotFoundException)5 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 PipelineService (org.graylog.plugins.pipelineprocessor.db.PipelineService)4 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Graph (com.google.common.graph.Graph)3 GraphBuilder (com.google.common.graph.GraphBuilder)3