Search in sources :

Example 16 with EntityDescriptorIds

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

the class SidecarCollectorConfigurationFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(Configuration configuration, EntityDescriptorIds entityDescriptorIds) {
    final SidecarCollectorConfigurationEntity configurationEntity = SidecarCollectorConfigurationEntity.create(ValueReference.of(entityDescriptorIds.getOrThrow(configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1)), ValueReference.of(configuration.name()), ValueReference.of(configuration.color()), ValueReference.of(configuration.template()));
    final JsonNode data = objectMapper.convertValue(configurationEntity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(configuration.id(), ModelTypes.SIDECAR_COLLECTOR_CONFIGURATION_V1))).type(TYPE_V1).data(data).build();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 17 with EntityDescriptorIds

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

the class StreamFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(Stream stream, EntityDescriptorIds entityDescriptorIds) {
    final List<StreamRuleEntity> streamRules = stream.getStreamRules().stream().map(this::encodeStreamRule).collect(Collectors.toList());
    final Set<ValueReference> outputIds = stream.getOutputs().stream().map(output -> entityDescriptorIds.getOrThrow(output.getId(), ModelTypes.OUTPUT_V1)).map(ValueReference::of).collect(Collectors.toSet());
    final StreamEntity streamEntity = StreamEntity.create(ValueReference.of(stream.getTitle()), ValueReference.of(stream.getDescription()), ValueReference.of(stream.getDisabled()), ValueReference.of(stream.getMatchingType()), streamRules, // Kept for backwards compatibility
    Collections.emptyList(), // Kept for backwards compatibility
    Collections.emptyList(), outputIds, ValueReference.of(stream.isDefaultStream()), ValueReference.of(stream.getRemoveMatchesFromDefaultStream()));
    final JsonNode data = objectMapper.convertValue(streamEntity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(stream.getId(), ModelTypes.STREAM_V1))).type(ModelTypes.STREAM_V1).data(data).build();
}
Also used : StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamRuleEntity(org.graylog2.contentpacks.model.entities.StreamRuleEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with EntityDescriptorIds

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

the class GrokPatternFacadeTest method exportEntity.

@Test
public void exportEntity() throws ValidationException {
    grokPatternService.save(GrokPattern.create("Test1", "[a-z]+"));
    grokPatternService.save(GrokPattern.create("Test2", "[a-z]+"));
    final EntityDescriptor descriptor = EntityDescriptor.create("1", ModelTypes.GROK_PATTERN_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Map<String, Object> entity = ImmutableMap.of("name", "Test1", "pattern", "[a-z]+");
    final JsonNode entityData = objectMapper.convertValue(entity, JsonNode.class);
    final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(collectedEntity).isPresent();
    final EntityV1 entityV1 = (EntityV1) collectedEntity.get();
    assertThat(entityV1.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entityV1.type()).isEqualTo(ModelTypes.GROK_PATTERN_V1);
    assertThat(entityV1.data()).isEqualTo(entityData);
}
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) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 19 with EntityDescriptorIds

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

the class LookupCacheFacadeTest method collectEntity.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    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.LOOKUP_CACHE_V1);
    final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entity.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"));
}
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)

Example 20 with EntityDescriptorIds

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

the class LookupCacheFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final CacheDto cacheDto = CacheDto.builder().id("1234567890").name("cache-name").title("Cache Title").description("Cache Description").config(new FallbackCacheConfig()).build();
    final EntityDescriptor descriptor = EntityDescriptor.create(cacheDto.id(), ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(cacheDto, entityDescriptorIds);
    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("cache-name"));
    assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("Cache Title"));
    assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("Cache Description"));
    assertThat(lookupCacheEntity.configuration()).containsEntry("type", ValueReference.of("FallbackCacheConfig"));
}
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) CacheDto(org.graylog2.lookup.dto.CacheDto) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) FallbackCacheConfig(org.graylog2.plugin.lookup.FallbackCacheConfig) 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