Search in sources :

Example 96 with EntityV1

use of org.graylog2.contentpacks.model.entities.EntityV1 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 97 with EntityV1

use of org.graylog2.contentpacks.model.entities.EntityV1 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 98 with EntityV1

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

the class GrokPatternFacadeTest method findExistingFailsWithDivergingPatterns.

@Test
public void findExistingFailsWithDivergingPatterns() throws ValidationException {
    grokPatternService.save(GrokPattern.create("Test", "[a-z]+"));
    final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "BOOM"), JsonNode.class)).build();
    assertThatThrownBy(() -> facade.findExisting(grokPatternEntity, Collections.emptyMap())).isInstanceOf(DivergingEntityConfigurationException.class).hasMessage("Expected Grok pattern for name \"Test\": <BOOM>; actual Grok pattern: <[a-z]+>");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) DivergingEntityConfigurationException(org.graylog2.contentpacks.exceptions.DivergingEntityConfigurationException) Test(org.junit.Test)

Example 99 with EntityV1

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

the class GrokPatternFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final GrokPattern grokPattern = GrokPattern.create("01234567890", "name", "pattern", null);
    final EntityDescriptor descriptor = EntityDescriptor.create(grokPattern.id(), ModelTypes.GROK_PATTERN_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(grokPattern, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.GROK_PATTERN_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entityV1.data(), GrokPatternEntity.class);
    assertThat(grokPatternEntity.name()).isEqualTo("name");
    assertThat(grokPatternEntity.pattern()).isEqualTo("pattern");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) GrokPattern(org.graylog2.grok.GrokPattern) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) Test(org.junit.Test)

Example 100 with EntityV1

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

the class LookupCacheFacadeTest method exportEntity.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void exportEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entityV1.data(), LookupCacheEntity.class);
    assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("no-op-cache"));
    assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("No-op cache"));
    assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("No-op cache"));
    assertThat(lookupCacheEntity.configuration()).containsEntry("type", ValueReference.of("none"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

Entity (org.graylog2.contentpacks.model.entities.Entity)82 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)78 Test (org.junit.Test)71 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)56 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)45 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)40 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)21 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)21 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)17 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)17 VisibleForTesting (com.google.common.annotations.VisibleForTesting)16 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)16 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 ModelId (org.graylog2.contentpacks.model.ModelId)14 HashMap (java.util.HashMap)12 InputEntity (org.graylog2.contentpacks.model.entities.InputEntity)11 Map (java.util.Map)10