Search in sources :

Example 11 with PipelineDao

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

the class PipelineFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() throws NotFoundException {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.PIPELINE_V1).data(objectMapper.convertValue(PipelineEntity.create(ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("pipeline \"Title\"\nstage 0 match either\nrule \"debug\"\nrule \"no-op\"\nend"), Collections.singleton(ValueReference.of("5adf23894b900a0f00000001"))), JsonNode.class)).build();
    final EntityDescriptor streamDescriptor = EntityDescriptor.create("5adf23894b900a0f00000001", ModelTypes.STREAM_V1);
    final Stream stream = mock(Stream.class);
    when(stream.getId()).thenReturn("5adf23894b900a0f00000001");
    final Map<EntityDescriptor, Object> nativeEntities = Collections.singletonMap(streamDescriptor, stream);
    final NativeEntity<PipelineDao> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), nativeEntities, "username");
    assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.PIPELINE_V1);
    assertThat(nativeEntity.entity().title()).isEqualTo("Title");
    assertThat(nativeEntity.entity().description()).isEqualTo("Description");
    assertThat(nativeEntity.entity().source()).startsWith("pipeline \"Title\"");
    assertThat(connectionsService.load("5adf23894b900a0f00000001").pipelineIds()).containsOnly(nativeEntity.entity().id());
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 12 with PipelineDao

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

the class PipelineFacadeTest method createNativeEntityWithDefaultStream.

@Test
public void createNativeEntityWithDefaultStream() throws NotFoundException {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.PIPELINE_V1).data(objectMapper.convertValue(PipelineEntity.create(ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("pipeline \"Title\"\nstage 0 match either\nrule \"debug\"\nrule \"no-op\"\nend"), Collections.singleton(ValueReference.of(Stream.DEFAULT_STREAM_ID))), JsonNode.class)).build();
    final FakeStream fakeDefaultStream = new FakeStream("All message Fake") {

        @Override
        protected ObjectId getObjectId() {
            return new ObjectId(Stream.DEFAULT_STREAM_ID);
        }
    };
    when(streamService.load(Stream.DEFAULT_STREAM_ID)).thenReturn(fakeDefaultStream);
    final Map<EntityDescriptor, Object> nativeEntities = Collections.emptyMap();
    final NativeEntity<PipelineDao> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), nativeEntities, "username");
    assertThat(connectionsService.load(fakeDefaultStream.getId()).pipelineIds()).containsOnly(nativeEntity.entity().id());
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) ObjectId(org.bson.types.ObjectId) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) Test(org.junit.Test)

Example 13 with PipelineDao

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

the class MongoDbPipelineService method loadByName.

@Override
public PipelineDao loadByName(String name) throws NotFoundException {
    final DBQuery.Query query = DBQuery.is("title", name);
    final PipelineDao pipeline = dbCollection.findOne(query);
    if (pipeline == null) {
        throw new NotFoundException("No pipeline with name " + name);
    }
    return pipeline;
}
Also used : DBQuery(org.mongojack.DBQuery) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) NotFoundException(org.graylog2.database.NotFoundException)

Example 14 with PipelineDao

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

the class MongoDbPipelineService method save.

@Override
public PipelineDao save(PipelineDao pipeline) {
    final WriteResult<PipelineDao, String> save = dbCollection.save(pipeline);
    final PipelineDao savedPipeline = save.getSavedObject();
    clusterBus.post(PipelinesChangedEvent.updatedPipelineId(savedPipeline.id()));
    return savedPipeline;
}
Also used : PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao)

Example 15 with PipelineDao

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

the class PipelineResource method getAll.

@ApiOperation(value = "Get all processing pipelines")
@GET
public Collection<PipelineSource> getAll() {
    final Collection<PipelineDao> daos = pipelineService.loadAll();
    final ArrayList<PipelineSource> results = Lists.newArrayList();
    for (PipelineDao dao : daos) {
        if (isPermitted(PipelineRestPermissions.PIPELINE_READ, dao.id())) {
            results.add(PipelineSource.fromDao(pipelineRuleParser, dao));
        }
    }
    return results;
}
Also used : PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) 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