use of alien4cloud.topology.task.NodeFilterToSatisfy.Violations in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validatePropertyFilters.
private List<Violations> validatePropertyFilters(Map<String, List<PropertyConstraint>> propertyFilters, Map<String, AbstractPropertyValue> propertyValues, Map<String, PropertyDefinition> propertyDefinitionMap, boolean skipInputs) {
List<Violations> violations = Lists.newArrayList();
for (Map.Entry<String, List<PropertyConstraint>> propertyEntry : propertyFilters.entrySet()) {
Violations violation = new Violations(propertyEntry.getKey());
List<NodeFilterConstraintViolation> violatedConstraints = Lists.newArrayList();
violation.violatedConstraints = violatedConstraints;
AbstractPropertyValue value = propertyValues.get(propertyEntry.getKey());
String propertyValue = null;
if (value == null) {
propertyValue = null;
} else if (value instanceof ScalarPropertyValue) {
propertyValue = ((ScalarPropertyValue) value).getValue();
} else {
if (skipInputs) {
continue;
}
if (FunctionEvaluator.isGetInput((FunctionPropertyValue) value)) {
violation.relatedInput = ((FunctionPropertyValue) value).getElementNameToFetch();
}
}
for (PropertyConstraint constraint : propertyEntry.getValue()) {
if (!propertyDefinitionMap.containsKey(propertyEntry.getKey())) {
continue;
}
// the constraint need to be initiazed with the type of the property (to check that actual value type matches the definition type).
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinitionMap.get(propertyEntry.getKey()).getType());
try {
constraint.initialize(toscaType);
constraint.validate(toscaType, propertyValue);
} catch (ConstraintViolationException e) {
violatedConstraints.add(new NodeFilterConstraintViolation(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR, e.getMessage(), e.getConstraintInformation()));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
violatedConstraints.add(new NodeFilterConstraintViolation(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR, e.getMessage(), null));
}
}
if (!violatedConstraints.isEmpty()) {
violations.add(violation);
}
}
return violations;
}
use of alien4cloud.topology.task.NodeFilterToSatisfy.Violations in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validateNodeFilterCapabilities.
private void validateNodeFilterCapabilities(NodeFilter nodeFilter, NodeTemplate target, NodeType targetType, Map<String, CapabilityType> capabilityTypes, NodeFilterToSatisfy nodeFilterToSatisfy, boolean skipInputs) {
if (nodeFilter.getCapabilities() == null || nodeFilter.getCapabilities().isEmpty()) {
return;
}
Map<String, FilterDefinition> capabilities = nodeFilter.getCapabilities();
for (Map.Entry<String, FilterDefinition> filterDefinitionEntry : capabilities.entrySet()) {
String capabilityName = filterDefinitionEntry.getKey();
CapabilityDefinition definition = getCapabilityDefinition(targetType, capabilityName);
if (definition == null) {
nodeFilterToSatisfy.getMissingCapabilities().add(capabilityName);
continue;
}
CapabilityType capabilityType = capabilityTypes.get(definition.getType());
List<Violations> violations = validatePropertyFilters(filterDefinitionEntry.getValue().getProperties(), target.getCapabilities().get(definition.getId()).getProperties(), capabilityType.getProperties(), skipInputs);
violations.forEach(violation -> violation.capabilityName = capabilityName);
if (nodeFilterToSatisfy.getViolations() == null) {
nodeFilterToSatisfy.setViolations(violations);
} else {
nodeFilterToSatisfy.getViolations().addAll(violations);
}
}
}
Aggregations