Search in sources :

Example 1 with MatchingConfiguration

use of alien4cloud.model.deployment.matching.MatchingConfiguration in project yorc-a4c-plugin by ystia.

the class AbstractLocationConfigurer method getMatchingConfigurations.

public Map<String, MatchingConfiguration> getMatchingConfigurations(String matchingConfigRelativePath) {
    Path matchingConfigPath = selfContext.getPluginPath().resolve(matchingConfigRelativePath);
    MatchingConfigurations matchingConfigurations = null;
    try {
        matchingConfigurations = matchingConfigurationsParser.parseFile(matchingConfigPath).getResult();
    } catch (ParsingException e) {
        return Maps.newHashMap();
    }
    Map<String, MatchingConfiguration> ret = matchingConfigurations.getMatchingConfigurations();
    printMatchingConfigurations(ret);
    return ret;
}
Also used : Path(java.nio.file.Path) MatchingConfigurations(alien4cloud.deployment.matching.services.nodes.MatchingConfigurations) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) ParsingException(alien4cloud.tosca.parser.ParsingException)

Example 2 with MatchingConfiguration

use of alien4cloud.model.deployment.matching.MatchingConfiguration in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method unknown_type_from_topology_should_not_match_any_location_resource.

@Test
public void unknown_type_from_topology_should_not_match_any_location_resource() throws Exception {
    // Given
    Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
    // When
    NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Unknown");
    NodeType wantedNodeType = new NodeType();
    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 3 with MatchingConfiguration

use of alien4cloud.model.deployment.matching.MatchingConfiguration in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method real_world_location_resource_compute_should_be_able_to_match_an_abstract_compute_from_topology.

@Test
public void real_world_location_resource_compute_should_be_able_to_match_an_abstract_compute_from_topology() throws Exception {
    // Given
    Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
    // When
    NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Compute");
    NodeType wantedNodeType = new NodeType();
    List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
    // Then
    assertThat(proposition).hasSize(1);
}
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 4 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_2.

@Test
public void abstract_template_should_be_matched_if_service_is_available_2() throws Exception {
    // Given
    Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
    // When
    NodeTemplate wantedNodeTemplate = nodeTemplate("alien.service.MongoDB");
    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 5 with MatchingConfiguration

use of alien4cloud.model.deployment.matching.MatchingConfiguration in project alien4cloud by alien4cloud.

the class NodeMatcherService method match.

public Map<String, List<LocationResourceTemplate>> match(Map<String, NodeType> nodesTypes, Map<String, NodeTemplate> nodesToMatch, Location location, String environmentId) {
    Map<String, List<LocationResourceTemplate>> matchingResult = Maps.newHashMap();
    // fetch location resources
    LocationResources locationResources = locationResourceService.getLocationResources(location);
    // Authorization filtering of location resources
    filterOnAuthorization(locationResources.getNodeTemplates(), environmentId);
    // fetch service resources
    List<ServiceResource> services = serviceResourceService.searchByLocation(location.getId());
    // self filtering: remove managed service linked to this location
    filterSelfManagedService(services, environmentId);
    // Authorization filtering of location resources
    filterOnAuthorization(services, environmentId);
    // from serviceResource to locationResource
    populateLocationResourcesWithServiceResource(locationResources, services, location.getId());
    Map<String, MatchingConfiguration> matchingConfigurations = locationMatchingConfigurationService.getMatchingConfiguration(location);
    Set<String> typesManagedByLocation = Sets.newHashSet();
    for (NodeType nodeType : locationResources.getNodeTypes().values()) {
        typesManagedByLocation.add(nodeType.getElementId());
        typesManagedByLocation.addAll(nodeType.getDerivedFrom());
    }
    INodeMatcherPlugin nodeMatcherPlugin = getNodeMatcherPlugin();
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodesToMatch.entrySet()) {
        String nodeTemplateId = nodeTemplateEntry.getKey();
        NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
        if (typesManagedByLocation.contains(nodeTemplate.getType())) {
            NodeType nodeTemplateType = nodesTypes.get(nodeTemplate.getType());
            if (nodeTemplateType == null) {
                throw new InvalidArgumentException("The given node types map must contain the type of the node template");
            }
            matchingResult.put(nodeTemplateId, nodeMatcherPlugin.matchNode(nodeTemplate, nodeTemplateType, locationResources, matchingConfigurations));
        }
    }
    return matchingResult;
}
Also used : MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NodeType(org.alien4cloud.tosca.model.types.NodeType) List(java.util.List) ServiceResource(alien4cloud.model.service.ServiceResource) INodeMatcherPlugin(alien4cloud.deployment.matching.plugins.INodeMatcherPlugin) Map(java.util.Map)

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