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();
}
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();
}
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);
}
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"));
}
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"));
}
Aggregations