Search in sources :

Example 21 with EntityV1

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

the class GrokPatternFacade method decode.

private NativeEntity<GrokPattern> decode(EntityV1 entity) {
    final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entity.data(), GrokPatternEntity.class);
    final GrokPattern grokPattern = GrokPattern.create(grokPatternEntity.name(), grokPatternEntity.pattern());
    try {
        final GrokPattern savedGrokPattern = grokPatternService.save(grokPattern);
        return NativeEntity.create(entity.id(), savedGrokPattern.id(), TYPE_V1, savedGrokPattern.name(), savedGrokPattern);
    } catch (ValidationException e) {
        throw new RuntimeException("Couldn't create grok pattern " + grokPattern.name());
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) GrokPattern(org.graylog2.grok.GrokPattern) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity)

Example 22 with EntityV1

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

the class LookupDataAdapterFacade method findExisting.

private Optional<NativeEntity<DataAdapterDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final LookupDataAdapterEntity dataAdapterEntity = objectMapper.convertValue(entity.data(), LookupDataAdapterEntity.class);
    final String name = dataAdapterEntity.name().asString(parameters);
    final Optional<DataAdapterDto> existingDataAdapter = dataAdapterService.get(name);
    return existingDataAdapter.map(dataAdapter -> NativeEntity.create(entity.id(), dataAdapter.id(), TYPE_V1, dataAdapter.title(), dataAdapter));
}
Also used : LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto)

Example 23 with EntityV1

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

the class LookupDataAdapterFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(DataAdapterDto dataAdapterDto, EntityDescriptorIds entityDescriptorIds) {
    // TODO: Create independent representation of entity?
    final Map<String, Object> configuration = objectMapper.convertValue(dataAdapterDto.config(), TypeReferences.MAP_STRING_OBJECT);
    final LookupDataAdapterEntity lookupDataAdapterEntity = LookupDataAdapterEntity.create(ValueReference.of(dataAdapterDto.name()), ValueReference.of(dataAdapterDto.title()), ValueReference.of(dataAdapterDto.description()), toReferenceMap(configuration));
    final JsonNode data = objectMapper.convertValue(lookupDataAdapterEntity, JsonNode.class);
    final Set<Constraint> constraints = versionConstraints(dataAdapterDto);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1))).type(ModelTypes.LOOKUP_ADAPTER_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
Also used : LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 with EntityV1

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

the class LookupDataAdapterFacade method decode.

private NativeEntity<DataAdapterDto> decode(EntityV1 entity, final Map<String, ValueReference> parameters) {
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entity.data(), LookupDataAdapterEntity.class);
    final LookupDataAdapterConfiguration configuration = objectMapper.convertValue(toValueMap(lookupDataAdapterEntity.configuration(), parameters), LookupDataAdapterConfiguration.class);
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().name(lookupDataAdapterEntity.name().asString(parameters)).title(lookupDataAdapterEntity.title().asString(parameters)).description(lookupDataAdapterEntity.description().asString(parameters)).config(configuration).build();
    final DataAdapterDto savedDataAdapterDto = dataAdapterService.save(dataAdapterDto);
    return NativeEntity.create(entity.id(), savedDataAdapterDto.id(), TYPE_V1, savedDataAdapterDto.title(), savedDataAdapterDto);
}
Also used : LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDataAdapterConfiguration(org.graylog2.plugin.lookup.LookupDataAdapterConfiguration)

Example 25 with EntityV1

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

the class PipelineFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(PipelineDao pipelineDao, EntityDescriptorIds entityDescriptorIds) {
    final Set<ValueReference> connectedStreams = connectedStreams(pipelineDao.id(), entityDescriptorIds);
    final PipelineEntity pipelineEntity = PipelineEntity.create(ValueReference.of(pipelineDao.title()), ValueReference.of(pipelineDao.description()), ValueReference.of(pipelineDao.source()), connectedStreams);
    final JsonNode data = objectMapper.convertValue(pipelineEntity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(pipelineDao.id(), ModelTypes.PIPELINE_V1))).type(ModelTypes.PIPELINE_V1).data(data).build();
}
Also used : PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Entity (org.graylog2.contentpacks.model.entities.Entity)82 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)78 Test (org.junit.Test)71 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)56 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)45 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)40 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)21 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)21 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)17 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)17 VisibleForTesting (com.google.common.annotations.VisibleForTesting)16 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)16 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 ModelId (org.graylog2.contentpacks.model.ModelId)14 HashMap (java.util.HashMap)12 InputEntity (org.graylog2.contentpacks.model.entities.InputEntity)11 Map (java.util.Map)10