Search in sources :

Example 1 with LocationResources

use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.

the class LocationResourceService method getLocationResourcesFromOrchestrator.

/*
     * (non-Javadoc)
     * 
     * @see
     * alien4cloud.orchestrators.locations.services.ILocationResourceService#getLocationResourcesFromOrchestrator(alien4cloud.model.orchestrators.locations.
     * Location)
     */
@Override
public LocationResources getLocationResourcesFromOrchestrator(Location location) {
    LocationResources locationResources = new LocationResources();
    Orchestrator orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
    IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    fillLocationResourceTypes(configuratorPlugin.getResourcesTypes(), locationResources, location.getDependencies());
    fillPoliciesLocationResourceTypes(configuratorPlugin.getPoliciesTypes(), locationResources, location.getDependencies());
    // add LocationResourceTemplate
    List<LocationResourceTemplate> locationResourceTemplates = getResourcesTemplates(location.getId());
    setLocationRessource(locationResourceTemplates, locationResources);
    // add PolicyLocationResourceTemplate
    locationResources.getPolicyTemplates().addAll(getPoliciesResourcesTemplates(location.getId()));
    return locationResources;
}
Also used : LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 2 with LocationResources

use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.

the class LocationResourceService method getLocationResources.

/*
     * (non-Javadoc)
     *
     * @see alien4cloud.orchestrators.locations.services.ILocationResourceService#getLocationResources(alien4cloud.model.orchestrators.locations.Location)
     */
@Override
public LocationResources getLocationResources(Location location) {
    Orchestrator orchestrator = orchestratorService.get(location.getOrchestratorId());
    Optional<LocationResources> locationResourcesFromOrchestrator = Optional.empty();
    if (orchestrator != null && orchestratorPluginService.get(orchestrator.getId()) != null) {
        locationResourcesFromOrchestrator = Optional.ofNullable(getLocationResourcesFromOrchestrator(location));
    }
    // Also get resource templates from outside of the orchestrator definition - eg custom resources
    List<LocationResourceTemplate> locationResourceTemplates = getResourcesTemplates(location.getId());
    LocationResources locationResources = new LocationResources(getLocationResourceTypes(locationResourceTemplates));
    // process policies types also
    List<PolicyLocationResourceTemplate> policyLocationResourceTemplates = getPoliciesResourcesTemplates(location.getId());
    locationResources.addFrom(getPoliciesLocationResourceTypes(policyLocationResourceTemplates));
    /*
         * If the orchestrator is present, take node types computed from the resources template
         * as "Custom resources types". If not, consider this is an orchestrator-free location.
         */
    locationResourcesFromOrchestrator.ifPresent(orchestratorResources -> {
        locationResources.getCapabilityTypes().putAll(orchestratorResources.getCapabilityTypes());
        locationResources.getConfigurationTypes().putAll(orchestratorResources.getConfigurationTypes());
        locationResources.getNodeTypes().putAll(orchestratorResources.getNodeTypes());
        locationResources.getProvidedTypes().addAll(orchestratorResources.getNodeTypes().keySet());
        locationResources.getAllNodeTypes().putAll(orchestratorResources.getAllNodeTypes());
        locationResources.getOnDemandTypes().putAll(orchestratorResources.getOnDemandTypes());
        locationResources.getPolicyTypes().putAll(orchestratorResources.getPolicyTypes());
    });
    setLocationRessource(locationResourceTemplates, locationResources);
    locationResources.getPolicyTemplates().addAll(policyLocationResourceTemplates);
    return locationResources;
}
Also used : LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)

Example 3 with LocationResources

use of alien4cloud.model.orchestrators.locations.LocationResources 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)

Example 4 with LocationResources

use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.

the class PolicyMatcherService method match.

/**
 * Perform matching of policies from a topology.
 *
 * @param policyTemplates The policy templates to match.
 * @param location The location against which to match policies.
 * @return A Map of available matches for every policy template.
 */
public Map<String, List<PolicyLocationResourceTemplate>> match(Map<String, PolicyTemplate> policyTemplates, Map<String, PolicyType> policyTypes, Location location, String environmentId) {
    if (MapUtils.isEmpty(policyTemplates)) {
        return Maps.newHashMap();
    }
    Map<String, List<PolicyLocationResourceTemplate>> matches = Maps.newHashMap();
    // fetch location resources
    LocationResources locationResources = locationResourceService.getLocationResources(location);
    // Authorization filtering of location resources
    locationResources.getPolicyTemplates().removeIf(securedResource -> !locationSecurityService.isAuthorised(securedResource, environmentId));
    for (Entry<String, PolicyTemplate> policyTemplateEntry : policyTemplates.entrySet()) {
        PolicyType policyType = policyTypes.get(policyTemplateEntry.getValue().getType());
        matches.put(policyTemplateEntry.getKey(), policyMatcher.match(policyTemplateEntry.getValue(), policyType, locationResources.getPolicyTemplates(), locationResources.getPolicyTypes(), locationResources, null));
    }
    return matches;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) List(java.util.List) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 5 with LocationResources

use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method setUp.

@Before
public void setUp() throws Exception {
    this.nodeMatcher = new DefaultNodeMatcher();
    this.computeNodeType = nodeType("org.alien4cloud.nodes.mock.aws.Compute", "tosca.nodes.Compute");
    this.computeNodeTemplate = nodeTemplate("org.alien4cloud.nodes.mock.aws.Compute");
    NodeType mongoDbNodeType = nodeType("alien.service.MongoDB", "", "tosca.service.ServiceType", "test.nodes.DB");
    NodeTemplate mongoDbNodeTemplate = nodeTemplate("alien.service.MongoDB");
    LocationResourceTemplate mongoDbLocationTemplate = locationResourceTemplate(mongoDbNodeTemplate);
    mongoDbLocationTemplate.setService(true);
    locationResources = new LocationResources();
    // 
    locationResources.setNodeTemplates(// 
    Arrays.asList(// 
    locationResourceTemplate(computeNodeTemplate), // 
    mongoDbLocationTemplate));
    // 
    locationResources.setNodeTypes(// 
    ImmutableMap.of(// 
    computeNodeType.getElementId(), // 
    computeNodeType, // 
    mongoDbNodeType.getElementId(), // 
    mongoDbNodeType));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Before(org.junit.Before)

Aggregations

LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)5 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)3 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)2 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)2 List (java.util.List)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 INodeMatcherPlugin (alien4cloud.deployment.matching.plugins.INodeMatcherPlugin)1 InvalidArgumentException (alien4cloud.exception.InvalidArgumentException)1 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)1 ServiceResource (alien4cloud.model.service.ServiceResource)1 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)1 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)1 Map (java.util.Map)1 PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)1 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)1 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)1 Before (org.junit.Before)1