Search in sources :

Example 1 with NativeEntity

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

the class InputFacade method decode.

private NativeEntity<InputWithExtractors> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
    final InputEntity inputEntity = objectMapper.convertValue(entity.data(), InputEntity.class);
    final Map<String, ValueReference> staticFields = inputEntity.staticFields();
    final MessageInput messageInput;
    try {
        messageInput = createMessageInput(inputEntity.title().asString(parameters), inputEntity.type().asString(parameters), inputEntity.global().asBoolean(parameters), toValueMap(inputEntity.configuration(), parameters), username);
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create input", e);
    }
    final Input input;
    try {
        input = inputService.find(messageInput.getPersistId());
    } catch (NotFoundException e) {
        throw new RuntimeException("Couldn't find persisted input", e);
    }
    try {
        addStaticFields(input, messageInput, staticFields, parameters);
    } catch (ValidationException e) {
        throw new RuntimeException("Couldn't add static fields to input", e);
    }
    final List<Extractor> extractors;
    try {
        extractors = createExtractors(input, inputEntity.extractors(), username, parameters);
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create extractors", e);
    }
    return NativeEntity.create(entity.id(), input.getId(), TYPE_V1, input.getTitle(), InputWithExtractors.create(input, extractors));
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) ValidationException(org.graylog2.plugin.database.ValidationException) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference)

Example 2 with NativeEntity

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

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

use of org.graylog2.contentpacks.model.entities.NativeEntity 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)

Example 5 with NativeEntity

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

the class LookupTableFacade method findExisting.

private Optional<NativeEntity<LookupTableDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
    final String name = lookupTableEntity.name().asString(parameters);
    final String title = lookupTableEntity.title().asString(parameters);
    final Optional<LookupTableDto> lookupTable = lookupTableService.get(name);
    lookupTable.ifPresent(existingLookupTable -> compareLookupTable(name, title, existingLookupTable));
    return lookupTable.map(lt -> NativeEntity.create(entity.id(), lt.id(), TYPE_V1, lt.title(), lt));
}
Also used : LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto)

Aggregations

NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)30 Entity (org.graylog2.contentpacks.model.entities.Entity)28 Test (org.junit.Test)26 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)14 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)12 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)7 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)7 HashMap (java.util.HashMap)6 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)6 CacheDto (org.graylog2.lookup.dto.CacheDto)6 Map (java.util.Map)5 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)5 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)5 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)5 Graph (com.google.common.graph.Graph)4 GraphBuilder (com.google.common.graph.GraphBuilder)4 ImmutableGraph (com.google.common.graph.ImmutableGraph)4