Search in sources :

Example 1 with ILocationMatch

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

the class TopologyLocationMatchingController method match.

@ApiOperation(value = "Retrieve the list of locations on which the current user can deploy the topology.")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<List<ILocationMatch>> match(@PathVariable String topologyId, @RequestParam(required = false) String environmentId) {
    List<ILocationMatch> matchedLocation;
    if (StringUtils.isNotBlank(environmentId)) {
        ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(environmentId);
        Application application = applicationService.getOrFail(environment.getApplicationId());
        AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.DEPLOYMENT_MANAGER);
        matchedLocation = locationMatchingService.match(topologyId, environment);
    } else {
        matchedLocation = locationMatchingService.match(topologyId, null);
    }
    return RestResponseBuilder.<List<ILocationMatch>>builder().data(matchedLocation).build();
}
Also used : ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) List(java.util.List) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ILocationMatch

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

the class LocationMatchingModifier method processLocationMatching.

private void processLocationMatching(Topology topology, FlowExecutionContext context) {
    // The configuration has already been loaded by a previous topology modifier.
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        return;
    }
    DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
    // If some of the locations defined does not exist anymore then just reset the deployment matching configuration
    Map<String, String> locationIds = matchingConfiguration.getLocationIds();
    if (MapUtils.isEmpty(locationIds)) {
        return;
    }
    // returns null if at least one of the expected location is missing.
    Map<String, Location> locations = getLocations(locationIds);
    if (locations == null) {
        // TODO Add an info log to explain that previous location does not exist anymore
        // Reset and save the configuration
        resetMatchingConfiguration(context);
        return;
    }
    context.getExecutionCache().put(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY, locations);
    // Now we must check that the selected locations are still valid choices for deployment
    // Somehow if the initial topology and none of the previous modifiers had changed then we could assume that the choice is still valid.
    // We had an approximation for that in the past that was not correct enough as we checked only initial topology and location. Actually inputs and
    // potential snapshot substitution merged through composition may also impact this. We know always re-process location matching here.
    // We have to fetch valid location matches anyway to know if the location is a potential valid match.
    List<ILocationMatch> locationMatches = locationMatchingService.match(topology, context.getEnvironmentContext().get().getEnvironment());
    context.getExecutionCache().put(FlowExecutionContext.LOCATION_MATCH_CACHE_KEY, locationMatches);
    Map<String, ILocationMatch> locationMatchMap = Maps.newHashMap();
    // Check that current choices exist in actual location matches
    for (ILocationMatch match : safe(locationMatches)) {
        locationMatchMap.put(match.getLocation().getId(), match);
    }
    for (String locationId : locationIds.values()) {
        if (!locationMatchMap.containsKey(locationId)) {
            // A matched location is not a valid choice anymore.
            resetMatchingConfiguration(context);
            // TODO info log the reason why the location is no more a valid match
            return;
        }
    }
    // update the TOSCA context with the new dependencies so that next step runs with an up-to-date context
    ToscaContext.get().resetDependencies(topology.getDependencies());
}
Also used : ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Location(alien4cloud.model.orchestrators.locations.Location)

Example 3 with ILocationMatch

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

the class DefaultLocationMatcher method match.

@Override
public List<ILocationMatch> match(Topology topology) throws LocationMatchingException {
    List<ILocationMatch> matched = Lists.newArrayList();
    try {
        // get all enabled orchestrators
        List<Orchestrator> enabledOrchestrators = orchestratorService.getAll();
        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));
        }
        // filter on supported artifacts
        locationMatchNodeFilter.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)

Example 4 with ILocationMatch

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

the class NodeMatchingReplaceModifier method init.

/**
 * Add locations dependencies
 */
@Override
protected void init(Topology topology, FlowExecutionContext context) {
    List<ILocationMatch> locations = (List<ILocationMatch>) context.getExecutionCache().get(FlowExecutionContext.LOCATION_MATCH_CACHE_KEY);
    for (ILocationMatch location : locations) {
        // FIXME manage conflicting dependencies by fetching types from latest version
        topology.getDependencies().addAll(location.getLocation().getDependencies());
    }
    ToscaContext.get().resetDependencies(topology.getDependencies());
}
Also used : ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) List(java.util.List)

Example 5 with ILocationMatch

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

the class PolicyMatchingReplaceModifier method init.

/**
 * Add locations dependencies
 */
@Override
protected void init(Topology topology, FlowExecutionContext context) {
    List<ILocationMatch> locations = (List<ILocationMatch>) context.getExecutionCache().get(FlowExecutionContext.LOCATION_MATCH_CACHE_KEY);
    for (ILocationMatch location : locations) {
        // FIXME manage conflicting dependencies by fetching types from latest version
        topology.getDependencies().addAll(location.getLocation().getDependencies());
    }
    ToscaContext.get().resetDependencies(topology.getDependencies());
}
Also used : ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) List(java.util.List)

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