use of org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method location_resource_should_be_matched_only_if_capabilities_are_satisfied.
@Test
public void location_resource_should_be_matched_only_if_capabilities_are_satisfied() throws Exception {
// Given
CapabilityDefinition capabilityArchitecture = new CapabilityDefinition("tosca.capabilities.OperatingSystem");
computeNodeType.setCapabilities(Arrays.asList(capabilityArchitecture));
Capability capability = new Capability();
capability.setType("tosca.capabilities.OperatingSystem");
capability.setProperties(ImmutableMap.of("architecture", new ScalarPropertyValue("x86")));
computeNodeTemplate.setCapabilities(ImmutableMap.of("os", capability));
CapabilityType capabilityType = new CapabilityType();
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("string");
capabilityType.setElementId("tosca.capabilities.OperatingSystem");
capabilityType.setProperties(ImmutableMap.of("architecture", propertyDefinition));
locationResources.setCapabilityTypes(ImmutableMap.of("tosca.capabilities.OperatingSystem", capabilityType));
// Matching configuration
Map<String, MatchingConfiguration> capabilityFilterConfiguration = new HashMap<>();
MatchingConfiguration matchingConfiguration = new MatchingConfiguration();
MatchingFilterDefinition matchingFilterDefinition = new MatchingConfiguration();
matchingFilterDefinition.setProperties(ImmutableMap.of("architecture", Arrays.asList(new EqualConstraint())));
matchingConfiguration.setCapabilities(ImmutableMap.of("os", matchingFilterDefinition));
capabilityFilterConfiguration.put("org.alien4cloud.nodes.mock.aws.Compute", matchingConfiguration);
// When
NodeTemplate wantedNodeTemplate = new NodeTemplate();
wantedNodeTemplate.setType("tosca.nodes.Compute");
Capability wantedCapability = new Capability();
wantedCapability.setType("tosca.capabilities.OperatingSystem");
wantedCapability.setProperties(ImmutableMap.of("architecture", new ScalarPropertyValue("power_pc")));
wantedNodeTemplate.setCapabilities(ImmutableMap.of("os", wantedCapability));
NodeType nodeType = new NodeType();
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, nodeType, locationResources, capabilityFilterConfiguration);
// Then
assertThat(proposition).hasSize(0);
}
use of org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint in project alien4cloud by alien4cloud.
the class ToscaPropertyDefaultValueConstraintsValidatorTest method createEqualDefinition.
private PropertyDefinition createEqualDefinition(String propertyType, String constraintValue, String defaultValue) {
EqualConstraint constraint = new EqualConstraint();
constraint.setEqual(constraintValue);
return createDefinitions(propertyType, constraint, defaultValue);
}
use of org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint in project alien4cloud by alien4cloud.
the class ToscaSerializerUtilsTest method testRenderConstraint.
@Test
public void testRenderConstraint() {
GreaterOrEqualConstraint greaterOrEqualConstraint = new GreaterOrEqualConstraint();
Assert.assertEquals("greater_or_equal: null", utils.renderConstraint(greaterOrEqualConstraint));
greaterOrEqualConstraint.setGreaterOrEqual("1");
Assert.assertEquals("greater_or_equal: 1", utils.renderConstraint(greaterOrEqualConstraint));
GreaterThanConstraint greaterThanConstraint = new GreaterThanConstraint();
Assert.assertEquals("greater_than: null", utils.renderConstraint(greaterThanConstraint));
greaterThanConstraint.setGreaterThan("1");
Assert.assertEquals("greater_than: 1", utils.renderConstraint(greaterThanConstraint));
LessOrEqualConstraint lessOrEqualConstraint = new LessOrEqualConstraint();
Assert.assertEquals("less_or_equal: null", utils.renderConstraint(lessOrEqualConstraint));
lessOrEqualConstraint.setLessOrEqual("1");
Assert.assertEquals("less_or_equal: 1", utils.renderConstraint(lessOrEqualConstraint));
LessThanConstraint lessThanConstraint = new LessThanConstraint();
Assert.assertEquals("less_than: null", utils.renderConstraint(lessThanConstraint));
lessThanConstraint.setLessThan("1");
Assert.assertEquals("less_than: 1", utils.renderConstraint(lessThanConstraint));
LengthConstraint lengthConstraint = new LengthConstraint();
Assert.assertEquals("length: null", utils.renderConstraint(lengthConstraint));
lengthConstraint.setLength(1);
Assert.assertEquals("length: 1", utils.renderConstraint(lengthConstraint));
MaxLengthConstraint maxLengthConstraint = new MaxLengthConstraint();
Assert.assertEquals("max_length: null", utils.renderConstraint(maxLengthConstraint));
maxLengthConstraint.setMaxLength(1);
Assert.assertEquals("max_length: 1", utils.renderConstraint(maxLengthConstraint));
MinLengthConstraint minLengthConstraint = new MinLengthConstraint();
Assert.assertEquals("min_length: null", utils.renderConstraint(minLengthConstraint));
minLengthConstraint.setMinLength(1);
Assert.assertEquals("min_length: 1", utils.renderConstraint(minLengthConstraint));
PatternConstraint patternConstraint = new PatternConstraint();
Assert.assertEquals("pattern: null", utils.renderConstraint(patternConstraint));
patternConstraint.setPattern("a");
Assert.assertEquals("pattern: a", utils.renderConstraint(patternConstraint));
patternConstraint.setPattern("[.*]");
Assert.assertEquals("pattern: \"[.*]\"", utils.renderConstraint(patternConstraint));
EqualConstraint equalConstraint = new EqualConstraint();
Assert.assertEquals("equal: null", utils.renderConstraint(equalConstraint));
equalConstraint.setEqual("value");
Assert.assertEquals("equal: value", utils.renderConstraint(equalConstraint));
equalConstraint.setEqual(" value");
Assert.assertEquals("equal: \" value\"", utils.renderConstraint(equalConstraint));
InRangeConstraint inRangeConstraint = new InRangeConstraint();
Assert.assertEquals("in_range: []", utils.renderConstraint(inRangeConstraint));
List<String> inRange = Lists.newArrayList();
inRangeConstraint.setInRange(inRange);
Assert.assertEquals("in_range: []", utils.renderConstraint(inRangeConstraint));
inRange.add("1");
Assert.assertEquals("in_range: [1]", utils.renderConstraint(inRangeConstraint));
inRange.add("2");
Assert.assertEquals("in_range: [1, 2]", utils.renderConstraint(inRangeConstraint));
ValidValuesConstraint validValuesConstraint = new ValidValuesConstraint();
Assert.assertEquals("valid_values: []", utils.renderConstraint(validValuesConstraint));
List<String> validValues = Lists.newArrayList();
validValuesConstraint.setValidValues(validValues);
Assert.assertEquals("valid_values: []", utils.renderConstraint(validValuesConstraint));
validValues.add("value1");
Assert.assertEquals("valid_values: [value1]", utils.renderConstraint(validValuesConstraint));
validValues.add("value2 ");
Assert.assertEquals("valid_values: [value1, \"value2 \"]", utils.renderConstraint(validValuesConstraint));
validValues.add("value3,value4");
Assert.assertEquals("valid_values: [value1, \"value2 \", \"value3,value4\"]", utils.renderConstraint(validValuesConstraint));
// finally test an unknown constraint
AbstractPropertyConstraint abstractPropertyConstraint = new AbstractPropertyConstraint() {
@Override
public void validate(Object propertyValue) throws ConstraintViolationException {
}
@Override
public void initialize(IPropertyType<?> propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
}
};
Assert.assertEquals("", utils.renderConstraint(abstractPropertyConstraint));
}
use of org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint in project alien4cloud by alien4cloud.
the class DanglingRequirementService method setPropertiesFromFilter.
// TODO This is a workaround as right now matching does not use filter but properties.
private void setPropertiesFromFilter(NodeTemplate danglingTemplate, NodeType danglingNodeType) {
if (danglingTemplate.getNodeFilter() == null) {
return;
}
for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(danglingTemplate.getNodeFilter().getProperties()).entrySet()) {
if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(danglingNodeType.getProperties().get(constraintEntry.getKey()).getType())) {
danglingTemplate.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
}
}
for (Entry<String, FilterDefinition> capabilityFilter : safe(danglingTemplate.getNodeFilter().getCapabilities()).entrySet()) {
Capability capability = getCapability(danglingTemplate, capabilityFilter.getKey());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(capabilityFilter.getValue().getProperties()).entrySet()) {
if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(capabilityType.getProperties().get(constraintEntry.getKey()).getType())) {
capability.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint 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