Search in sources :

Example 6 with StreamEntity

use of org.graylog2.contentpacks.model.entities.StreamEntity in project graylog2-server by Graylog2.

the class StreamCatalogTest method collectEntity.

@Test
@MongoDBFixtures("StreamCatalogTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
    final EntityDescriptor outputDescriptor = EntityDescriptor.create("5adf239e4b900a0fdb4e5197", ModelTypes.OUTPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, outputDescriptor);
    final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
    final EntityV1 entity = (EntityV1) collectedEntity.orElseThrow(AssertionError::new);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.STREAM_V1);
    final StreamEntity streamEntity = objectMapper.convertValue(entity.data(), StreamEntity.class);
    assertThat(streamEntity.title()).isEqualTo(ValueReference.of("Test"));
    assertThat(streamEntity.description()).isEqualTo(ValueReference.of("Description"));
    assertThat(streamEntity.matchingType()).isEqualTo(ValueReference.of(Stream.MatchingType.AND));
    assertThat(streamEntity.streamRules()).hasSize(7);
    assertThat(streamEntity.outputs()).containsExactly(ValueReference.of(entityDescriptorIds.get(outputDescriptor).orElse(null)));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Entity(org.graylog2.contentpacks.model.entities.Entity) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 7 with StreamEntity

use of org.graylog2.contentpacks.model.entities.StreamEntity in project graylog2-server by Graylog2.

the class PipelineFacadeTest method resolve.

@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void resolve() {
    final Stage stage = Stage.builder().stage(0).match(Stage.Match.EITHER).ruleReferences(ImmutableList.of("debug", "no-op")).build();
    RuleDao ruleDao1 = RuleDao.builder().id("2342353045938450345").title("debug").source("rule \\\"debug\\\"\\nrule \\\"no-op\\\"\\nend\"").build();
    org.graylog.plugins.pipelineprocessor.ast.Rule rule1 = org.graylog.plugins.pipelineprocessor.ast.Rule.builder().id("1").name("debug").when(mock(LogicalExpression.class)).then(Collections.emptyList()).build();
    RuleDao ruleDao2 = RuleDao.builder().id("2342353045938450346").title("no-op").source("rule \\\"debug\\\"\\nrule \\\"no-op\\\"\\nend\"").build();
    org.graylog.plugins.pipelineprocessor.ast.Rule rule2 = org.graylog.plugins.pipelineprocessor.ast.Rule.builder().id("2").name("no-op").when(mock(LogicalExpression.class)).then(Collections.emptyList()).build();
    stage.setRules(ImmutableList.of(rule1, rule2));
    final Pipeline pipeline = Pipeline.builder().id("5a85c4854b900afd5d662be3").name("Test").stages(ImmutableSortedSet.of(stage)).build();
    when(pipelineRuleParser.parsePipeline(eq("dummy"), anyString())).thenReturn(pipeline);
    when(ruleService.findByName("no-op")).thenReturn(Optional.of(ruleDao1));
    when(ruleService.findByName("debug")).thenReturn(Optional.of(ruleDao2));
    final EntityDescriptor pipelineEntity = EntityDescriptor.create("5a85c4854b900afd5d662be3", ModelTypes.PIPELINE_V1);
    final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(pipelineEntity);
    final EntityDescriptor streamEntity = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
    final EntityDescriptor ruleEntity1 = EntityDescriptor.create("2342353045938450345", ModelTypes.PIPELINE_RULE_V1);
    final EntityDescriptor ruleEntity2 = EntityDescriptor.create("2342353045938450346", ModelTypes.PIPELINE_RULE_V1);
    assertThat(graph.nodes()).containsOnly(pipelineEntity, streamEntity, ruleEntity1, ruleEntity2);
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) LogicalExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 8 with StreamEntity

use of org.graylog2.contentpacks.model.entities.StreamEntity in project graylog2-server by Graylog2.

the class ViewFacadeTest method itShouldResolveDependencyForInstallation.

@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldResolveDependencyForInstallation() throws Exception {
    Entity streamEntity = createStreamEntity();
    Entity entity = createViewEntity();
    final EntityDescriptor depDescriptor = streamEntity.toEntityDescriptor();
    final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = ImmutableMap.of(depDescriptor, streamEntity);
    Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), entityDescriptorEntityMap);
    assertThat(graph.nodes().toArray()).contains(streamEntity);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) QueryEntity(org.graylog2.contentpacks.model.entities.QueryEntity) EventListEntity(org.graylog2.contentpacks.model.entities.EventListEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) MessageListEntity(org.graylog2.contentpacks.model.entities.MessageListEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)7 Entity (org.graylog2.contentpacks.model.entities.Entity)6 StreamEntity (org.graylog2.contentpacks.model.entities.StreamEntity)6 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)5 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)4 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)4 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Graph (com.google.common.graph.Graph)3 GraphBuilder (com.google.common.graph.GraphBuilder)3 ImmutableGraph (com.google.common.graph.ImmutableGraph)3 MutableGraph (com.google.common.graph.MutableGraph)3 Collections (java.util.Collections)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3