Search in sources :

Example 6 with ValueReference

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

the class InputFacade method createConverters.

private List<Converter> createConverters(final List<ConverterEntity> requestedConverters, final Map<String, ValueReference> parameters) {
    final ImmutableList.Builder<Converter> converters = ImmutableList.builder();
    for (final ConverterEntity converterEntity : requestedConverters) {
        try {
            final Converter converter = converterFactory.create(converterEntity.type().asEnum(parameters, Converter.Type.class), toValueMap(converterEntity.configuration(), parameters));
            converters.add(converter);
        } catch (ConverterFactory.NoSuchConverterException e) {
            LOG.warn("No such converter [" + converterEntity.type() + "]. Skipping.", e);
        } catch (org.graylog2.ConfigurationException e) {
            LOG.warn("Missing configuration for [" + converterEntity.type() + "]. Skipping.", e);
        }
    }
    return converters.build();
}
Also used : ModelType(org.graylog2.contentpacks.model.ModelType) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) ImmutableList(com.google.common.collect.ImmutableList) Converter(org.graylog2.plugin.inputs.Converter) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory)

Example 7 with ValueReference

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

the class LookupCacheFacade method findExisting.

private Optional<NativeEntity<CacheDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final LookupCacheEntity cacheEntity = objectMapper.convertValue(entity.data(), LookupCacheEntity.class);
    final String name = cacheEntity.name().asString(parameters);
    final Optional<CacheDto> existingCache = cacheService.get(name);
    return existingCache.map(cache -> NativeEntity.create(entity.id(), cache.id(), TYPE_V1, cache.title(), cache));
}
Also used : LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) CacheDto(org.graylog2.lookup.dto.CacheDto)

Example 8 with ValueReference

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

the class LookupCacheFacade method decode.

private NativeEntity<CacheDto> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entity.data(), LookupCacheEntity.class);
    final LookupCacheConfiguration configuration = objectMapper.convertValue(toValueMap(lookupCacheEntity.configuration(), parameters), LookupCacheConfiguration.class);
    final CacheDto cacheDto = CacheDto.builder().name(lookupCacheEntity.name().asString(parameters)).title(lookupCacheEntity.title().asString(parameters)).description(lookupCacheEntity.description().asString(parameters)).config(configuration).build();
    final CacheDto savedCacheDto = cacheService.save(cacheDto);
    return NativeEntity.create(entity.id(), savedCacheDto.id(), TYPE_V1, savedCacheDto.title(), savedCacheDto);
}
Also used : LookupCacheConfiguration(org.graylog2.plugin.lookup.LookupCacheConfiguration) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) CacheDto(org.graylog2.lookup.dto.CacheDto)

Example 9 with ValueReference

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

the class LookupTableFacade method resolveForInstallation.

private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
    final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entity);
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
    final String dataAdapterName = lookupTableEntity.dataAdapterName().asString(parameters);
    final EntityDescriptor dataAdapterDescriptor = adapterDescriptor(dataAdapterName);
    final Entity dataAdapterEntity = entities.get(dataAdapterDescriptor);
    if (dataAdapterEntity == null) {
        throw new ContentPackException("Missing data adapter \"" + dataAdapterName + "\" for lookup table " + entity.toEntityDescriptor());
    } else {
        mutableGraph.putEdge(entity, dataAdapterEntity);
    }
    final String cacheName = lookupTableEntity.cacheName().asString(parameters);
    final EntityDescriptor cacheDescriptor = cacheDescriptor(cacheName);
    final Entity cacheEntity = entities.get(cacheDescriptor);
    if (cacheEntity == null) {
        throw new ContentPackException("Missing cache \"" + cacheName + "\" for lookup table " + entity.toEntityDescriptor());
    } else {
        mutableGraph.putEdge(entity, cacheEntity);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity)

Example 10 with ValueReference

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

the class LookupTableFacade method decode.

private NativeEntity<LookupTableDto> decode(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities) {
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
    final String referencedDataAdapterName = lookupTableEntity.dataAdapterName().asString(parameters);
    final EntityDescriptor dataAdapterDescriptor = adapterDescriptor(referencedDataAdapterName);
    final Object dataAdapter = nativeEntities.get(dataAdapterDescriptor);
    final String dataAdapterId;
    if (dataAdapter instanceof DataAdapterDto) {
        dataAdapterId = ((DataAdapterDto) dataAdapter).id();
    } else {
        throw new MissingNativeEntityException(dataAdapterDescriptor);
    }
    final String referencedCacheName = lookupTableEntity.cacheName().asString(parameters);
    final EntityDescriptor cacheDescriptor = cacheDescriptor(referencedCacheName);
    final Object cache = nativeEntities.get(cacheDescriptor);
    final String cacheId;
    if (cache instanceof CacheDto) {
        cacheId = ((CacheDto) cache).id();
    } else {
        throw new MissingNativeEntityException(cacheDescriptor);
    }
    final LookupTableDto lookupTableDto = LookupTableDto.builder().name(lookupTableEntity.name().asString(parameters)).title(lookupTableEntity.title().asString(parameters)).description(lookupTableEntity.description().asString(parameters)).dataAdapterId(dataAdapterId).cacheId(cacheId).defaultSingleValue(lookupTableEntity.defaultSingleValue().asString(parameters)).defaultSingleValueType(lookupTableEntity.defaultSingleValueType().asEnum(parameters, LookupDefaultSingleValue.Type.class)).defaultMultiValue(lookupTableEntity.defaultMultiValue().asString(parameters)).defaultMultiValueType(lookupTableEntity.defaultMultiValueType().asEnum(parameters, LookupDefaultMultiValue.Type.class)).build();
    final LookupTableDto savedLookupTableDto = lookupTableService.save(lookupTableDto);
    return NativeEntity.create(entity.id(), savedLookupTableDto.id(), TYPE_V1, lookupTableDto.title(), savedLookupTableDto);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDefaultSingleValue(org.graylog2.lookup.LookupDefaultSingleValue) LookupDefaultMultiValue(org.graylog2.lookup.LookupDefaultMultiValue) MissingNativeEntityException(org.graylog2.contentpacks.exceptions.MissingNativeEntityException) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) CacheDto(org.graylog2.lookup.dto.CacheDto)

Aggregations

ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)18 Entity (org.graylog2.contentpacks.model.entities.Entity)16 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Map (java.util.Map)10 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)10 ModelType (org.graylog2.contentpacks.model.ModelType)10 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)10 Set (java.util.Set)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Graph (com.google.common.graph.Graph)8 GraphBuilder (com.google.common.graph.GraphBuilder)8 ImmutableGraph (com.google.common.graph.ImmutableGraph)8 MutableGraph (com.google.common.graph.MutableGraph)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Collection (java.util.Collection)7