use of alien4cloud.model.deployment.matching.MatchingConfiguration in project alien4cloud by alien4cloud.
the class AbstractTemplateMatcher method getMatchingConfiguration.
/**
* Get the matching configuration for the substitution candidate based on its type hierarchy.
*
* Meaning if a candidateType D derives from (in this order) C, B, A, then we will first look for a matching for D. <br>
* If not found, then look for the closest parent matching configuration, and so on until no more parent left.
*
* @param candidateType
* @param matchingConfigurations
* @return
*/
private MatchingConfiguration getMatchingConfiguration(T candidateType, Map<String, MatchingConfiguration> matchingConfigurations) {
MatchingConfiguration config = null;
if (MapUtils.isNotEmpty(matchingConfigurations)) {
List<String> typeHierarchy = Lists.newArrayList(candidateType.getElementId());
typeHierarchy.addAll(safe(candidateType.getDerivedFrom()));
Iterator<String> iter = typeHierarchy.iterator();
while (config == null && iter.hasNext()) {
config = matchingConfigurations.get(iter.next());
}
}
return config;
}
use of alien4cloud.model.deployment.matching.MatchingConfiguration in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method concrete_template_cannot_be_matched_even_if_service_is_available.
@Test
public void concrete_template_cannot_be_matched_even_if_service_is_available() throws Exception {
// Given
Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
// When
NodeTemplate wantedNodeTemplate = nodeTemplate("test.nodes.DB");
NodeType wantedNodeType = new NodeType();
wantedNodeType.setAbstract(false);
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
// Then
assertThat(proposition).hasSize(0);
}
use of alien4cloud.model.deployment.matching.MatchingConfiguration 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.MatchingConfiguration in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method abstract_template_should_be_matched_if_service_is_available.
@Test
public void abstract_template_should_be_matched_if_service_is_available() throws Exception {
// Given
Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
// When
NodeTemplate wantedNodeTemplate = nodeTemplate("test.nodes.DB");
NodeType wantedNodeType = new NodeType();
wantedNodeType.setAbstract(true);
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
// Then
assertThat(proposition).hasSize(1);
assertThat(proposition.get(0).isService()).isTrue();
}
use of alien4cloud.model.deployment.matching.MatchingConfiguration in project alien4cloud by alien4cloud.
the class MatchingConfigurationsParserTest method testParsing.
@Test()
public void testParsing() throws FileNotFoundException, ParsingException {
MatchingConfigurations configurations = parser.parseFile(Paths.get("src/test/resources/matching/mock-resources-matching-config.yml")).getResult();
Assert.assertEquals(1, configurations.getMatchingConfigurations().size());
MatchingConfiguration computeConf = configurations.getMatchingConfigurations().get("org.alien4cloud.nodes.mock.Compute");
Assert.assertNotNull(computeConf);
Assert.assertEquals(0, computeConf.getProperties().size());
Assert.assertEquals(2, computeConf.getCapabilities().size());
Assert.assertEquals(4, computeConf.getCapabilities().get("host").getProperties().size());
}
Aggregations