Search in sources :

Example 1 with Constraint

use of org.graylog2.contentpacks.model.constraints.Constraint 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 2 with Constraint

use of org.graylog2.contentpacks.model.constraints.Constraint in project graylog2-server by Graylog2.

the class ContentPackService method checkConstraintsV1.

private Set<ConstraintCheckResult> checkConstraintsV1(ContentPackV1 contentPackV1) {
    Set<Constraint> requiredConstraints = contentPackV1.constraints();
    final Set<ConstraintCheckResult> fulfilledConstraints = new HashSet<>();
    for (ConstraintChecker constraintChecker : constraintCheckers) {
        fulfilledConstraints.addAll(constraintChecker.checkConstraints(requiredConstraints));
    }
    return fulfilledConstraints;
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) ConstraintChecker(org.graylog2.contentpacks.constraints.ConstraintChecker) HashSet(java.util.HashSet)

Example 3 with Constraint

use of org.graylog2.contentpacks.model.constraints.Constraint in project graylog2-server by Graylog2.

the class PluginVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof PluginVersionConstraint) {
            final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            boolean result = false;
            for (Semver pluginVersion : pluginVersions) {
                if (requiredVersion.isSatisfiedBy(pluginVersion)) {
                    result = true;
                }
            }
            ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, result);
            fulfilledConstraints.add(constraintCheckResult);
        }
    }
    return fulfilledConstraints.build();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Requirement(com.vdurmont.semver4j.Requirement) ImmutableSet(com.google.common.collect.ImmutableSet) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Semver(com.vdurmont.semver4j.Semver)

Example 4 with Constraint

use of org.graylog2.contentpacks.model.constraints.Constraint in project graylog2-server by Graylog2.

the class OutputFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(Output output, EntityDescriptorIds entityDescriptorIds) {
    final OutputEntity outputEntity = OutputEntity.create(ValueReference.of(output.getTitle()), ValueReference.of(output.getType()), toReferenceMap(output.getConfiguration()));
    final JsonNode data = objectMapper.convertValue(outputEntity, JsonNode.class);
    final Set<Constraint> constraints = versionConstraints(output);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(output.getId(), ModelTypes.OUTPUT_V1))).type(ModelTypes.OUTPUT_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
Also used : Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Constraint

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

Aggregations

Constraint (org.graylog2.contentpacks.model.constraints.Constraint)13 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)10 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ConstraintCheckResult (org.graylog2.contentpacks.model.constraints.ConstraintCheckResult)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Requirement (com.vdurmont.semver4j.Requirement)4 Test (org.junit.Test)4 Semver (com.vdurmont.semver4j.Semver)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Graph (com.google.common.graph.Graph)1 GraphBuilder (com.google.common.graph.GraphBuilder)1 ImmutableGraph (com.google.common.graph.ImmutableGraph)1 MutableGraph (com.google.common.graph.MutableGraph)1 Ints (com.google.common.primitives.Ints)1 Collection (java.util.Collection)1