use of org.graylog.plugins.pipelineprocessor.db.PipelineDao in project graylog2-server by Graylog2.
the class PipelineFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
try {
final PipelineDao pipelineDao = pipelineService.load(modelId.id());
final String pipelineSource = pipelineDao.source();
final Collection<String> referencedRules = referencedRules(pipelineSource);
referencedRules.stream().map(ModelId::of).map(id -> EntityDescriptor.create(id, ModelTypes.PIPELINE_RULE_V1)).forEach(rule -> mutableGraph.putEdge(entityDescriptor, rule));
final Set<PipelineConnections> pipelineConnections = connectionsService.loadByPipelineId(pipelineDao.id());
pipelineConnections.stream().map(PipelineConnections::streamId).map(ModelId::of).map(id -> EntityDescriptor.create(id, ModelTypes.STREAM_V1)).forEach(stream -> mutableGraph.putEdge(entityDescriptor, stream));
} catch (NotFoundException e) {
LOG.debug("Couldn't find pipeline {}", entityDescriptor, e);
}
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog.plugins.pipelineprocessor.db.PipelineDao in project graylog2-server by Graylog2.
the class PipelineFacade method decode.
private NativeEntity<PipelineDao> decode(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities) {
final DateTime now = Tools.nowUTC();
final PipelineEntity pipelineEntity = objectMapper.convertValue(entity.data(), PipelineEntity.class);
final ValueReference description = pipelineEntity.description();
final PipelineDao pipelineDao = PipelineDao.builder().title(pipelineEntity.title().asString(parameters)).description(description == null ? null : description.asString(parameters)).source(pipelineEntity.source().asString(parameters)).createdAt(now).modifiedAt(now).build();
final PipelineDao savedPipelineDao = pipelineService.save(pipelineDao);
final String pipelineId = requireNonNull(savedPipelineDao.id(), "Saved pipeline ID must not be null");
final Set<EntityDescriptor> connectedStreamEntities = pipelineEntity.connectedStreams().stream().map(valueReference -> valueReference.asString(parameters)).map(streamId -> EntityDescriptor.create(streamId, ModelTypes.STREAM_V1)).collect(Collectors.toSet());
final Set<Stream> connectedStreams = connectedStreams(connectedStreamEntities, nativeEntities);
createPipelineConnections(pipelineId, connectedStreams);
return NativeEntity.create(entity.id(), pipelineId, TYPE_V1, savedPipelineDao.title(), savedPipelineDao);
}
use of org.graylog.plugins.pipelineprocessor.db.PipelineDao in project graylog2-server by Graylog2.
the class PipelineFacadeTest method exportEntity.
@Test
public void exportEntity() {
final PipelineDao pipeline = PipelineDao.builder().id("pipeline-1234").title("title").description("description").source("pipeline \"Test\"\nstage 0 match either\nrule \"debug\"\nend").build();
final PipelineConnections connections = PipelineConnections.create("id", "stream-1234", Collections.singleton("pipeline-1234"));
connectionsService.save(connections);
final EntityDescriptor descriptor = EntityDescriptor.create(pipeline.id(), ModelTypes.PIPELINE_V1);
final EntityDescriptor streamDescriptor = EntityDescriptor.create("stream-1234", ModelTypes.STREAM_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, streamDescriptor);
final Entity entity = facade.exportNativeEntity(pipeline, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final PipelineEntity pipelineEntity = objectMapper.convertValue(entityV1.data(), PipelineEntity.class);
assertThat(pipelineEntity.title()).isEqualTo(ValueReference.of("title"));
assertThat(pipelineEntity.description()).isEqualTo(ValueReference.of("description"));
assertThat(pipelineEntity.source().asString(Collections.emptyMap())).startsWith("pipeline \"Test\"");
assertThat(pipelineEntity.connectedStreams()).containsOnly(ValueReference.of(entityDescriptorIds.get(streamDescriptor).orElse(null)));
}
use of org.graylog.plugins.pipelineprocessor.db.PipelineDao in project graylog2-server by Graylog2.
the class PipelineFacadeTest method delete.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void delete() throws NotFoundException {
final PipelineDao pipelineDao = pipelineService.load("5a85c4854b900afd5d662be3");
assertThat(pipelineService.loadAll()).hasSize(1);
facade.delete(pipelineDao);
assertThat(pipelineService.loadAll()).isEmpty();
assertThatThrownBy(() -> pipelineService.load("5a85c4854b900afd5d662be3")).isInstanceOf(NotFoundException.class);
}
use of org.graylog.plugins.pipelineprocessor.db.PipelineDao in project graylog2-server by Graylog2.
the class PipelineFacadeTest method createExcerpt.
@Test
public void createExcerpt() {
final PipelineDao pipeline = PipelineDao.builder().id("id").title("title").description("description").source("pipeline \"Test\"\nstage 0 match either\nrule \"debug\"\nend").build();
final EntityExcerpt excerpt = facade.createExcerpt(pipeline);
assertThat(excerpt.id()).isEqualTo(ModelId.of("id"));
assertThat(excerpt.type()).isEqualTo(ModelTypes.PIPELINE_V1);
assertThat(excerpt.title()).isEqualTo("title");
}
Aggregations