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();
}
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());
}
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);
}
}
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());
}
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());
}
Aggregations