Search in sources :

Example 6 with MatchingConfiguration

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;
}
Also used : MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration)

Example 7 with MatchingConfiguration

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);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 8 with MatchingConfiguration

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);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) MatchingFilterDefinition(alien4cloud.model.deployment.matching.MatchingFilterDefinition) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) Test(org.junit.Test)

Example 9 with MatchingConfiguration

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();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 10 with MatchingConfiguration

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());
}
Also used : MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) Test(org.junit.Test)

Aggregations

MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)11 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 Test (org.junit.Test)7 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)6 HashMap (java.util.HashMap)6 MatchingFilterDefinition (alien4cloud.model.deployment.matching.MatchingFilterDefinition)2 INodeMatcherPlugin (alien4cloud.deployment.matching.plugins.INodeMatcherPlugin)1 MatchingConfigurations (alien4cloud.deployment.matching.services.nodes.MatchingConfigurations)1 InvalidArgumentException (alien4cloud.exception.InvalidArgumentException)1 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)1 ServiceResource (alien4cloud.model.service.ServiceResource)1 ParsingException (alien4cloud.tosca.parser.ParsingException)1 Path (java.nio.file.Path)1 List (java.util.List)1 Map (java.util.Map)1 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)1 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)1 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)1 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)1