use of alien4cloud.model.deployment.matching.MatchingFilterDefinition in project alien4cloud by alien4cloud.
the class DefaultNodeMatcher method typeSpecificMatching.
@Override
protected boolean typeSpecificMatching(NodeTemplate abstractTemplate, LocationResourceTemplate candidate, NodeType candidateType, LocationResources locationResources, MatchingConfiguration matchingConfiguration) {
for (Entry<String, Capability> candidateCapability : safe(candidate.getTemplate().getCapabilities()).entrySet()) {
MatchingFilterDefinition configuredFilterDefinition = matchingConfiguration == null ? null : safe(matchingConfiguration.getCapabilities()).get(candidateCapability.getKey());
Map<String, List<IMatchPropertyConstraint>> configuredFilters = configuredFilterDefinition == null ? null : configuredFilterDefinition.getProperties();
CapabilityType capabilityType = locationResources.getCapabilityTypes().get(candidateCapability.getValue().getType());
// Ignore scalable capabiltiy for matching.
if (!ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
Capability templateCapability = safe(abstractTemplate.getCapabilities()).get(candidateCapability.getKey());
if (templateCapability != null && !isValidTemplatePropertiesMatch(templateCapability.getProperties(), candidateCapability.getValue().getProperties(), capabilityType.getProperties(), configuredFilters)) {
return false;
}
}
}
return true;
}
use of alien4cloud.model.deployment.matching.MatchingFilterDefinition 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 alien4cloud.model.deployment.matching.MatchingFilterDefinition in project yorc-a4c-plugin by ystia.
the class AbstractLocationConfigurer method printMatchingConfigurations.
private void printMatchingConfigurations(Map<String, MatchingConfiguration> mcm) {
for (String key : mcm.keySet()) {
log.debug("MatchingConfiguration for " + key);
MatchingConfiguration mc = mcm.get(key);
log.debug("Sort ordering: " + mc.getSortOrdering());
// capabilities
Map<String, MatchingFilterDefinition> cap = mc.getCapabilities();
if (cap != null) {
for (String kcap : cap.keySet()) {
log.debug("Capability " + kcap);
MatchingFilterDefinition mfd = cap.get(kcap);
printProperties(mfd.getProperties());
}
}
log.debug("Properties");
printProperties(mc.getProperties());
}
}
Aggregations