Search in sources :

Example 6 with ILocationMatch

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

the class LocationMatchingService method match.

/**
 * Given a topology, return a list of locations on which the topo can be deployed
 *
 * @param topology The topology to match against the location matcher.
 * @param applicationEnvironment eventually the environment related to the topology to match.
 * @return A list of candidates Location Matches.
 */
public List<ILocationMatch> match(Topology topology, ApplicationEnvironment applicationEnvironment) {
    List<ILocationMatch> matches;
    // If no registered matcher id found later on, then match with the default matcher
    ILocationMatcher matcher = defaultLocationMatcher;
    // TODO Now we just take the first matcher found. To fix. Later, use the configured matcher
    Map<String, Map<String, ILocationMatcher>> instancesByPlugins = locationMatcherFactoriesRegistry.getInstancesByPlugins();
    if (MapUtils.isNotEmpty(instancesByPlugins)) {
        Map<String, ILocationMatcher> matchers = instancesByPlugins.values().iterator().next();
        if (MapUtils.isNotEmpty(matchers)) {
            matcher = matchers.values().iterator().next();
        }
    }
    matches = matcher.match(topology);
    // keep only the authorized ones
    authorizationFilter.filter(matches, applicationEnvironment);
    return CollectionUtils.isEmpty(matches) ? null : matches;
}
Also used : ILocationMatcher(alien4cloud.deployment.matching.plugins.ILocationMatcher) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) Map(java.util.Map)

Example 7 with ILocationMatch

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

the class MockLocationMatcher method match.

@Override
public List<ILocationMatch> match(Topology topology) throws LocationMatchingException {
    log.info("Mock location matcher <" + this.getClass().getName() + "> called!");
    List<ILocationMatch> matched = Lists.newArrayList();
    // get all enabled orchestrators
    try {
        List<Orchestrator> enabledOrchestrators = orchestratorService.getAllEnabledOrchestrators();
        if (CollectionUtils.isEmpty(enabledOrchestrators)) {
            return matched;
        }
        Map<String, Orchestrator> orchestratorMap = AlienUtils.fromListToMap(enabledOrchestrators, "id", true);
        List<Location> locations = locationService.getOrchestratorsLocations(orchestratorMap.keySet());
        for (Location location : locations) {
            matched.add(new LocationMatch(location, orchestratorMap.get(location.getOrchestratorId()), null));
        }
        new MockLocationMatchOrchestratorFilter(selfContext).filter(matched, topology);
        return matched;
    } catch (Exception e) {
        throw new LocationMatchingException("Failed to match topology <" + topology.getId() + "> against locations. ", e);
    }
}
Also used : LocationMatch(alien4cloud.model.deployment.matching.LocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)7 Location (alien4cloud.model.orchestrators.locations.Location)3 List (java.util.List)3 LocationMatch (alien4cloud.model.deployment.matching.LocationMatch)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 LocationMatchingException (alien4cloud.paas.exception.LocationMatchingException)2 ILocationMatcher (alien4cloud.deployment.matching.plugins.ILocationMatcher)1 Application (alien4cloud.model.application.Application)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Map (java.util.Map)1 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1