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