Search in sources :

Example 11 with Constraint

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

the class PluginVersionConstraintChecker method ensureConstraints.

@Override
public Set<Constraint> ensureConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<Constraint> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof PluginVersionConstraint) {
            final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            for (Semver pluginVersion : pluginVersions) {
                if (requiredVersion.isSatisfiedBy(pluginVersion)) {
                    fulfilledConstraints.add(constraint);
                }
            }
        }
    }
    return fulfilledConstraints.build();
}
Also used : 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 12 with Constraint

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

the class LookupCacheFacade method exportNativeEntity.

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

Example 13 with Constraint

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

the class GraylogVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof GraylogVersionConstraint) {
            final GraylogVersionConstraint versionConstraint = (GraylogVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            final ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, requiredVersion.isSatisfiedBy(graylogVersion.withClearedSuffixAndBuild()));
            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) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)

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