Search in sources :

Example 1 with PipelineDao

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

the class InMemoryPipelineService method delete.

@Override
public void delete(String id) {
    if (id == null) {
        return;
    }
    final PipelineDao removed = store.remove(id);
    // clean up title index if the pipeline existed
    if (removed != null) {
        titleToId.remove(removed.title());
    }
    clusterBus.post(PipelinesChangedEvent.deletedPipelineId(id));
}
Also used : PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao)

Example 2 with PipelineDao

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

the class InMemoryPipelineService method save.

@Override
public PipelineDao save(PipelineDao pipeline) {
    PipelineDao toSave = pipeline.id() != null ? pipeline : pipeline.toBuilder().id(createId()).build();
    // enforce the title unique constraint
    if (titleToId.containsKey(toSave.title())) {
        // if this is an update and the title belongs to the passed pipeline, then it's fine
        if (!titleToId.get(toSave.title()).equals(toSave.id())) {
            throw new IllegalArgumentException("Duplicate pipeline titles are not allowed: " + toSave.title());
        }
    }
    titleToId.put(toSave.title(), toSave.id());
    store.put(toSave.id(), toSave);
    clusterBus.post(PipelinesChangedEvent.updatedPipelineId(toSave.id()));
    return toSave;
}
Also used : PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao)

Example 3 with PipelineDao

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

the class PipelineResource method get.

@ApiOperation(value = "Get a processing pipeline", notes = "It can take up to a second until the change is applied")
@Path("/{id}")
@GET
public PipelineSource get(@ApiParam(name = "id") @PathParam("id") String id) throws NotFoundException {
    checkPermission(PipelineRestPermissions.PIPELINE_READ, id);
    final PipelineDao dao = pipelineService.load(id);
    return PipelineSource.fromDao(pipelineRuleParser, dao);
}
Also used : PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with PipelineDao

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

the class PipelineResource method createFromParser.

@ApiOperation(value = "Create a processing pipeline from source")
@POST
@RequiresPermissions(PipelineRestPermissions.PIPELINE_CREATE)
@AuditEvent(type = PipelineProcessorAuditEventTypes.PIPELINE_CREATE)
public PipelineSource createFromParser(@ApiParam(name = "pipeline", required = true) @NotNull PipelineSource pipelineSource) throws ParseException {
    final Pipeline pipeline;
    try {
        pipeline = pipelineRuleParser.parsePipeline(pipelineSource.id(), pipelineSource.source());
    } catch (ParseException e) {
        throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
    }
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final PipelineDao pipelineDao = PipelineDao.builder().title(pipeline.name()).description(pipelineSource.description()).source(pipelineSource.source()).createdAt(now).modifiedAt(now).build();
    final PipelineDao save = pipelineService.save(pipelineDao);
    log.debug("Created new pipeline {}", save);
    return PipelineSource.fromDao(pipelineRuleParser, save);
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException) DateTime(org.joda.time.DateTime) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 5 with PipelineDao

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

the class PipelineResource method getPage.

@GET
@Path("/paginated")
@ApiOperation(value = "Get a paginated list of pipelines")
@Produces(MediaType.APPLICATION_JSON)
public PaginatedResponse<PipelineSource> getPage(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "title,description,id") @DefaultValue(PipelineDao.FIELD_TITLE) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order) {
    SearchQuery searchQuery;
    try {
        searchQuery = searchQueryParser.parse(query);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
    }
    Predicate<PipelineDao> filter = dao -> isPermitted(PipelineRestPermissions.PIPELINE_READ, dao.id());
    final PaginatedList<PipelineDao> result = paginatedPipelineService.findPaginated(searchQuery, filter, page, perPage, sort, order);
    final List<PipelineSource> pipelineList = result.stream().map(dao -> PipelineSource.fromDao(pipelineRuleParser, dao)).collect(Collectors.toList());
    final PaginatedList<PipelineSource> pipelines = new PaginatedList<>(pipelineList, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
    return PaginatedResponse.create("pipelines", pipelines);
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) DateTimeZone(org.joda.time.DateTimeZone) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) SearchQueryParser(org.graylog2.search.SearchQueryParser) GET(javax.ws.rs.GET) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) PaginatedList(org.graylog2.database.PaginatedList) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) Lists(com.google.common.collect.Lists) QueryParam(javax.ws.rs.QueryParam) PipelineService(org.graylog.plugins.pipelineprocessor.db.PipelineService) Consumes(javax.ws.rs.Consumes) SearchQueryField(org.graylog2.search.SearchQueryField) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) DefaultValue(javax.ws.rs.DefaultValue) PipelineRuleParser(org.graylog.plugins.pipelineprocessor.parser.PipelineRuleParser) BadRequestException(javax.ws.rs.BadRequestException) Api(io.swagger.annotations.Api) SearchQuery(org.graylog2.search.SearchQuery) NotFoundException(org.graylog2.database.NotFoundException) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) RestResource(org.graylog2.shared.rest.resources.RestResource) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) NotNull(javax.validation.constraints.NotNull) PipelineProcessorAuditEventTypes(org.graylog.plugins.pipelineprocessor.audit.PipelineProcessorAuditEventTypes) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) PaginatedPipelineService(org.graylog.plugins.pipelineprocessor.db.PaginatedPipelineService) PUT(javax.ws.rs.PUT) PaginatedResponse(org.graylog2.rest.models.PaginatedResponse) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) BadRequestException(javax.ws.rs.BadRequestException) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) PaginatedList(org.graylog2.database.PaginatedList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

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