Search in sources :

Example 31 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.

the class LookupDataAdapterFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("1234567890").name("data-adapter-name").title("Data Adapter Title").description("Data Adapter Description").config(new FallbackAdapterConfig()).build();
    final EntityDescriptor descriptor = EntityDescriptor.create(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(dataAdapterDto, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entityV1.data(), LookupDataAdapterEntity.class);
    assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("data-adapter-name"));
    assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("Data Adapter Title"));
    assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("Data Adapter Description"));
    assertThat(lookupDataAdapterEntity.configuration()).containsEntry("type", ValueReference.of("FallbackAdapterConfig"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) Test(org.junit.Test)

Example 32 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.

the class LookupDataAdapterFacadeTest method exportEntityDescriptor.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void exportEntityDescriptor() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24a04b900a0fdb4e52c8", ModelTypes.LOOKUP_ADAPTER_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_ADAPTER_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entityV1.data(), LookupDataAdapterEntity.class);
    assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("http-dsv"));
    assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("HTTP DSV"));
    assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("HTTP DSV"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 33 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.

the class OutputFacadeTest method exportNativeEntity.

@Test
@MongoDBFixtures("OutputFacadeTest.json")
public void exportNativeEntity() throws NotFoundException {
    final Output output = outputService.load("5adf239e4b900a0fdb4e5197");
    final EntityDescriptor descriptor = EntityDescriptor.create(output.getId(), ModelTypes.OUTPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(output, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.OUTPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final OutputEntity outputEntity = objectMapper.convertValue(entityV1.data(), OutputEntity.class);
    assertThat(outputEntity.title()).isEqualTo(ValueReference.of("STDOUT"));
    assertThat(outputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.outputs.LoggingOutput"));
    assertThat(outputEntity.configuration()).containsEntry("prefix", ValueReference.of("Writing message: "));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) LoggingOutput(org.graylog2.outputs.LoggingOutput) Output(org.graylog2.plugin.streams.Output) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 34 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.

the class OutputFacadeTest method exportEntity.

@Test
public void exportEntity() {
    final ImmutableMap<String, Object> configuration = ImmutableMap.of("some-setting", "foobar");
    final OutputImpl output = OutputImpl.create("01234567890", "Output Title", "org.graylog2.outputs.LoggingOutput", "admin", configuration, new Date(0L), null);
    final EntityDescriptor descriptor = EntityDescriptor.create(output.getId(), ModelTypes.OUTPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(output, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.OUTPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final OutputEntity outputEntity = objectMapper.convertValue(entityV1.data(), OutputEntity.class);
    assertThat(outputEntity.title()).isEqualTo(ValueReference.of("Output Title"));
    assertThat(outputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.outputs.LoggingOutput"));
    assertThat(outputEntity.configuration()).containsEntry("some-setting", ValueReference.of("foobar"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) OutputImpl(org.graylog2.streams.OutputImpl) Date(java.util.Date) Test(org.junit.Test)

Example 35 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.

the class InputFacadeTest method exportEntity.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void exportEntity() {
    final ModelId id = ModelId.of("5acc84f84b900a4ff290d9a7");
    final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.INPUT_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.INPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
    assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Local Raw UDP"));
    assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
    assertThat(inputEntity.global()).isEqualTo(ValueReference.of(false));
    assertThat(inputEntity.configuration()).containsEntry("bind_address", ValueReference.of("127.0.0.1")).containsEntry("port", ValueReference.of(5555));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)36 Entity (org.graylog2.contentpacks.model.entities.Entity)35 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)35 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)34 Test (org.junit.Test)33 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)32 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)12 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11 ModelId (org.graylog2.contentpacks.model.ModelId)11 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)8 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)8 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)7 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)4 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)4 ConverterEntity (org.graylog2.contentpacks.model.entities.ConverterEntity)4 ExtractorEntity (org.graylog2.contentpacks.model.entities.ExtractorEntity)4