Search in sources :

Example 1 with EntityDescriptorIds

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

the class EventDefinitionFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Optional<EventDefinitionDto> eventDefinition = eventDefinitionService.get(modelId.id());
    if (!eventDefinition.isPresent()) {
        LOG.debug("Couldn't find event definition {}", entityDescriptor);
        return Optional.empty();
    }
    return Optional.of(exportNativeEntity(eventDefinition.get(), entityDescriptorIds));
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 2 with EntityDescriptorIds

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

the class NotificationFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Optional<NotificationDto> notificationDto = notificationService.get(modelId.id());
    if (!notificationDto.isPresent()) {
        LOG.debug("Couldn't find notification {}", entityDescriptor);
        return Optional.empty();
    }
    final NotificationEntity entity = (NotificationEntity) notificationDto.get().toContentPackEntity(entityDescriptorIds);
    final JsonNode data = objectMapper.convertValue(entity, JsonNode.class);
    return Optional.of(EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(notificationDto.get().id(), ModelTypes.NOTIFICATION_V1))).type(ModelTypes.NOTIFICATION_V1).data(data).build());
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 3 with EntityDescriptorIds

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

the class InputFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(InputWithExtractors inputWithExtractors, EntityDescriptorIds entityDescriptorIds) {
    final Input input = inputWithExtractors.input();
    // TODO: Create independent representation of entity?
    final Map<String, ValueReference> staticFields = input.getStaticFields().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, kv -> ValueReference.of(kv.getValue())));
    final ReferenceMap configuration = toReferenceMap(input.getConfiguration());
    final List<ExtractorEntity> extractors = inputWithExtractors.extractors().stream().map(this::encodeExtractor).collect(Collectors.toList());
    final InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), configuration, staticFields, ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractors);
    final JsonNode data = objectMapper.convertValue(inputEntity, JsonNode.class);
    final Set<Constraint> constraints = versionConstraints(input);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(input.getId(), ModelTypes.INPUT_V1))).type(ModelTypes.INPUT_V1).data(data).constraints(ImmutableSet.copyOf(constraints)).build();
}
Also used : Extractor(org.graylog2.plugin.inputs.Extractor) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Tools(org.graylog2.plugin.Tools) InputService(org.graylog2.inputs.InputService) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) LoggerFactory(org.slf4j.LoggerFactory) ModelType(org.graylog2.contentpacks.model.ModelType) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) InputRegistry(org.graylog2.shared.inputs.InputRegistry) MessageInputFactory(org.graylog2.shared.inputs.MessageInputFactory) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ImmutableSet(com.google.common.collect.ImmutableSet) ModelId(org.graylog2.contentpacks.model.ModelId) GrokPatternService(org.graylog2.grok.GrokPatternService) ImmutableMap(com.google.common.collect.ImmutableMap) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) Set(java.util.Set) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) ServerStatus(org.graylog2.plugin.ServerStatus) ReferenceMapUtils.toReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) List(java.util.List) Stream(java.util.stream.Stream) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) PluginMetaData(org.graylog2.plugin.PluginMetaData) Optional(java.util.Optional) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) Configuration(org.graylog2.plugin.configuration.Configuration) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Converter(org.graylog2.plugin.inputs.Converter) Entity(org.graylog2.contentpacks.model.entities.Entity) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) DBLookupTableService(org.graylog2.lookup.db.DBLookupTableService) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Input(org.graylog2.inputs.Input) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) NotFoundException(org.graylog2.database.NotFoundException) ReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMap) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) Ints(com.google.common.primitives.Ints) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Message(org.graylog2.plugin.Message) ReferenceMapUtils.toValueMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toValueMap) Graph(com.google.common.graph.Graph) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) ReferenceMapUtils.toReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap) ReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ReferenceMapUtils.toReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap) ReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMap) ReferenceMapUtils.toValueMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toValueMap) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with EntityDescriptorIds

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

the class LookupTableFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(LookupTableDto lookupTableDto, EntityDescriptorIds entityDescriptorIds) {
    final String tableId = entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.id(), ModelTypes.LOOKUP_TABLE_V1)).orElseThrow(() -> new ContentPackException("Couldn't find lookup table entity " + lookupTableDto.id()));
    final String cacheId = entityDescriptorIds.get(cacheDescriptor(lookupTableDto.cacheId())).orElseThrow(() -> new ContentPackException("Couldn't find lookup cache entity " + lookupTableDto.cacheId()));
    final String adapterId = entityDescriptorIds.get(adapterDescriptor(lookupTableDto.dataAdapterId())).orElseThrow(() -> new ContentPackException("Couldn't find lookup data adapter entity " + lookupTableDto.dataAdapterId()));
    final LookupTableEntity lookupTableEntity = LookupTableEntity.create(ValueReference.of(lookupTableDto.name()), ValueReference.of(lookupTableDto.title()), ValueReference.of(lookupTableDto.description()), ValueReference.of(cacheId), ValueReference.of(adapterId), ValueReference.of(lookupTableDto.defaultSingleValue()), ValueReference.of(lookupTableDto.defaultSingleValueType()), ValueReference.of(lookupTableDto.defaultMultiValue()), ValueReference.of(lookupTableDto.defaultMultiValueType()));
    final JsonNode data = objectMapper.convertValue(lookupTableEntity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(tableId)).type(ModelTypes.LOOKUP_TABLE_V1).data(data).build();
}
Also used : ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with EntityDescriptorIds

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

the class ContentPackService method collectEntities.

public ImmutableSet<Entity> collectEntities(Collection<EntityDescriptor> resolvedEntities) {
    // It's important to only compute the EntityDescriptor IDs once per #collectEntities call! Otherwise we
    // will get broken references between the entities.
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(resolvedEntities);
    final ImmutableSet.Builder<Entity> entities = ImmutableSet.builder();
    for (EntityDescriptor entityDescriptor : resolvedEntities) {
        if (EntityDescriptorIds.isSystemStreamDescriptor(entityDescriptor)) {
            continue;
        }
        final EntityWithExcerptFacade<?, ?> facade = entityFacades.getOrDefault(entityDescriptor.type(), UnsupportedEntityFacade.INSTANCE);
        facade.exportEntity(entityDescriptor, entityDescriptorIds).ifPresent(entities::add);
    }
    return entities.build();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) ImmutableSet(com.google.common.collect.ImmutableSet)

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