use of org.graylog2.contentpacks.constraints.ConstraintChecker 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;
}
use of org.graylog2.contentpacks.constraints.ConstraintChecker in project graylog2-server by Graylog2.
the class GraylogVersionConstraintCheckerTest method checkConstraints.
@Test
public void checkConstraints() {
final GraylogVersionConstraintChecker constraintChecker = new GraylogVersionConstraintChecker("1.0.0");
final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^1.0.0").build();
final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
final Set<ConstraintCheckResult> result = constraintChecker.checkConstraints(requiredConstraints);
assertThat(result.stream().allMatch(c -> c.fulfilled())).isTrue();
}
use of org.graylog2.contentpacks.constraints.ConstraintChecker in project graylog2-server by Graylog2.
the class GraylogVersionConstraintCheckerTest method checkConstraintsFails.
@Test
public void checkConstraintsFails() {
final GraylogVersionConstraintChecker constraintChecker = new GraylogVersionConstraintChecker("1.0.0");
final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
final Set<ConstraintCheckResult> result = constraintChecker.checkConstraints(requiredConstraints);
assertThat(result.stream().allMatch(c -> !c.fulfilled())).isTrue();
}
use of org.graylog2.contentpacks.constraints.ConstraintChecker in project graylog2-server by Graylog2.
the class ContentPackServiceTest method setUp.
@Before
public void setUp() throws Exception {
final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = contentPackInstallService;
final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
pluginMetaData = new HashSet<>();
outputFactories = new HashMap<>();
outputFactories2 = new HashMap<>();
final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = ImmutableMap.of(ModelTypes.GROK_PATTERN_V1, new GrokPatternFacade(objectMapper, patternService), ModelTypes.STREAM_V1, new StreamFacade(objectMapper, streamService, streamRuleService, alertService, alarmCallbackConfigurationService, legacyAlertConditionMigration, indexSetService, userService), ModelTypes.OUTPUT_V1, new OutputFacade(objectMapper, outputService, pluginMetaData, outputFactories, outputFactories2));
contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
Map<String, String> entityData = new HashMap<>(2);
entityData.put("name", "NAME");
entityData.put("pattern", "\\w");
grokPattern = GrokPattern.builder().pattern("\\w").name("NAME").build();
JsonNode jsonData = objectMapper.convertValue(entityData, JsonNode.class);
EntityV1 entityV1 = EntityV1.builder().id(ModelId.of("12345")).type(ModelTypes.GROK_PATTERN_V1).data(jsonData).build();
ImmutableSet<Entity> entities = ImmutableSet.of(entityV1);
NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("12345"), "dead-beef1", ModelTypes.GROK_PATTERN_V1, "NAME");
nativeEntityDescriptors = ImmutableSet.of(nativeEntityDescriptor);
contentPack = ContentPackV1.builder().description("test").entities(entities).name("test").revision(1).summary("").vendor("").url(URI.create("http://graylog.com")).id(ModelId.of("dead-beef")).build();
contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("dead-beef")).contentPackRevision(1).entities(nativeEntityDescriptors).comment("Installed").parameters(ImmutableMap.copyOf(Collections.emptyMap())).createdAt(Instant.now()).createdBy("me").build();
}
use of org.graylog2.contentpacks.constraints.ConstraintChecker in project graylog2-server by Graylog2.
the class PluginVersionConstraintCheckerTest method checkConstraints.
@Test
public void checkConstraints() {
final TestPluginMetaData pluginMetaData = new TestPluginMetaData();
final PluginVersionConstraintChecker constraintChecker = new PluginVersionConstraintChecker(Collections.singleton(pluginMetaData));
final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
assertThat(constraintChecker.checkConstraints(requiredConstraints).stream().allMatch(c -> c.fulfilled())).isTrue();
}
Aggregations