use of org.alien4cloud.tosca.model.definitions.constraints.IMatchPropertyConstraint in project alien4cloud by alien4cloud.
the class AbstractTemplateMatcher method isValidTemplatePropertiesMatch.
/**
* Add filters ent/ICSARRepositorySearchService.java from the matching configuration to the node filter that will be applied for matching only if a value is
* specified on the configuration template.
*
* @param templatePropertyValues The properties values from the template to match.
* @param candidatePropertyValues The values defined on the Location Template.
* @param propertyDefinitions The properties definitions associated with the node.
* @param configuredFilters The filtering map (based on constraints) from matching configuration, other properties fall backs to an equal constraint/filter.
*/
protected boolean isValidTemplatePropertiesMatch(Map<String, AbstractPropertyValue> templatePropertyValues, Map<String, AbstractPropertyValue> candidatePropertyValues, Map<String, PropertyDefinition> propertyDefinitions, Map<String, List<IMatchPropertyConstraint>> configuredFilters) {
// We perform matching on every property that is defined on the candidate (admin node) and that has a value defined in the topology.
for (Map.Entry<String, AbstractPropertyValue> candidateValueEntry : safe(candidatePropertyValues).entrySet()) {
List<IMatchPropertyConstraint> filter = safe(configuredFilters).get(candidateValueEntry.getKey());
AbstractPropertyValue templatePropertyValue = templatePropertyValues.get(candidateValueEntry.getKey());
// For now we support matching only on scalar properties.
if (candidateValueEntry.getValue() != null && candidateValueEntry.getValue() instanceof ScalarPropertyValue && templatePropertyValue != null && templatePropertyValue instanceof ScalarPropertyValue) {
try {
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinitions.get(candidateValueEntry.getKey()).getType());
if (filter == null) {
// If no filter is defined then process matching using an equal constraint.
filter = Lists.newArrayList(new EqualConstraint());
}
// set the constraint value and add it to the node filter
for (IMatchPropertyConstraint constraint : filter) {
constraint.setConstraintValue(toscaType, ((ScalarPropertyValue) candidateValueEntry.getValue()).getValue());
try {
constraint.validate(toscaType, ((ScalarPropertyValue) templatePropertyValue).getValue());
} catch (ConstraintViolationException e) {
return false;
}
}
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
log.debug("The value of property for a constraint is not valid.", e);
}
}
}
return true;
}
use of org.alien4cloud.tosca.model.definitions.constraints.IMatchPropertyConstraint in project yorc-a4c-plugin by ystia.
the class AbstractLocationConfigurer method printProperties.
private void printProperties(Map<String, List<IMatchPropertyConstraint>> props) {
for (String kprop : props.keySet()) {
List<IMatchPropertyConstraint> lc = props.get(kprop);
for (IMatchPropertyConstraint mpc : lc) {
if (mpc instanceof LessOrEqualConstraint) {
LessOrEqualConstraint cons = (LessOrEqualConstraint) mpc;
log.debug(" " + kprop + " <= " + cons.getLessOrEqual());
} else if (mpc instanceof EqualConstraint) {
EqualConstraint cons = (EqualConstraint) mpc;
log.debug(" " + kprop + " == " + cons.getEqual());
} else if (mpc instanceof GreaterOrEqualConstraint) {
GreaterOrEqualConstraint cons = (GreaterOrEqualConstraint) mpc;
log.debug(" " + kprop + " >= " + cons.getGreaterOrEqual());
} else if (mpc instanceof GreaterThanConstraint) {
GreaterThanConstraint cons = (GreaterThanConstraint) mpc;
log.debug(" " + kprop + " > " + cons.getGreaterThan());
} else if (mpc instanceof LessThanConstraint) {
LessThanConstraint cons = (LessThanConstraint) mpc;
log.debug(" " + kprop + " < " + cons.getLessThan());
} else {
log.debug(" " + kprop + " " + mpc.toString());
}
}
}
}
Aggregations