Search in sources :

Example 1 with INodeMatcherPlugin

use of alien4cloud.deployment.matching.plugins.INodeMatcherPlugin 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

INodeMatcherPlugin (alien4cloud.deployment.matching.plugins.INodeMatcherPlugin)1 InvalidArgumentException (alien4cloud.exception.InvalidArgumentException)1 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)1 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)1 ServiceResource (alien4cloud.model.service.ServiceResource)1 List (java.util.List)1 Map (java.util.Map)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1