Search in sources :

Example 1 with MatchingFilterDefinition

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;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) List(java.util.List) MatchingFilterDefinition(alien4cloud.model.deployment.matching.MatchingFilterDefinition)

Example 2 with MatchingFilterDefinition

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);
}
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 3 with MatchingFilterDefinition

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

Aggregations

MatchingFilterDefinition (alien4cloud.model.deployment.matching.MatchingFilterDefinition)3 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)2 Capability (org.alien4cloud.tosca.model.templates.Capability)2 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)1 HashMap (java.util.HashMap)1 List (java.util.List)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 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1 Test (org.junit.Test)1