use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class NodeMatchingSubstitutionService method onCopyConfiguration.
// FIXME fix this, synch with org.alien4cloud.alm.deployment.configuration.services.PolicyMatchingSubstitutionService#onCopyConfiguration
@EventListener
// Process this after location matching copy (first element).
@Order(30)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
DeploymentMatchingConfiguration targetConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups()) || targetConfiguration == null || MapUtils.isEmpty(targetConfiguration.getLocationGroups())) {
// Nothing to copy
return;
}
// We have to execute a piece of the deployment flow to find out matching candidates so we copy only required inputs
Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
Application application = applicationService.getOrFail(target.getApplicationId());
FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, target));
flowExecutor.execute(topology, getMatchingFlow(), executionContext);
Map<String, Set<String>> locResTemplateIdsPerNodeIds = (Map<String, Set<String>>) executionContext.getExecutionCache().get(FlowExecutionContext.SELECTED_MATCH_NODE_LOCATION_TEMPLATE_BY_NODE_ID_MAP);
// Update the substitution on the target if available substitution is always compatible
Map<String, String> validOnNewEnvSubstitutedNodes = safe(sourceConfiguration.getMatchedLocationResources()).entrySet().stream().filter(entry -> locResTemplateIdsPerNodeIds.containsKey(entry.getKey()) && locResTemplateIdsPerNodeIds.get(entry.getKey()).contains(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(validOnNewEnvSubstitutedNodes)) {
if (targetConfiguration.getMatchedLocationResources() == null) {
targetConfiguration.setMatchedLocationResources(Maps.newHashMap());
}
validOnNewEnvSubstitutedNodes.forEach((key, value) -> {
targetConfiguration.getMatchedLocationResources().put(key, value);
// Copy properties set on the node to the new one
targetConfiguration.getMatchedNodesConfiguration().put(key, safe(sourceConfiguration.getMatchedNodesConfiguration()).get(key));
});
deploymentConfigurationDao.save(targetConfiguration);
}
}
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesService method onCopyConfiguration.
@EventListener
// This is one of the last elements to process to place it's order quite far, after location match copy anyway.
@Order(40)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentMatchingConfiguration sourceMatchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (sourceMatchingConfiguration == null || MapUtils.isEmpty(sourceMatchingConfiguration.getLocationIds())) {
return;
}
DeploymentMatchingConfiguration targetMatchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (targetMatchingConfiguration == null || MapUtils.isEmpty(targetMatchingConfiguration.getLocationIds()) || !sourceMatchingConfiguration.getOrchestratorId().equals(targetMatchingConfiguration.getOrchestratorId())) {
// If the target does not have the same orchestrator as the source then don't copy the inputs
return;
}
OrchestratorDeploymentProperties sourceProperties = deploymentConfigurationDao.findById(OrchestratorDeploymentProperties.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (sourceProperties == null || MapUtils.isEmpty(sourceProperties.getProviderDeploymentProperties())) {
return;
}
OrchestratorDeploymentProperties targetProperties = new OrchestratorDeploymentProperties(target.getTopologyVersion(), target.getId(), sourceProperties.getOrchestratorId());
targetProperties.setProviderDeploymentProperties(sourceProperties.getProviderDeploymentProperties());
deploymentConfigurationDao.save(targetProperties);
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class DeployService method generateOrchestratorDeploymentId.
/**
* Generate the human readable deployment id for the orchestrator.
*
* @param envId Id of the deployed environment.
* @param orchestratorId Id of the orchestrator on which the deployment is performed.
* @return The orchestrator deployment id.
* @throws alien4cloud.paas.exception.OrchestratorDeploymentIdConflictException
*/
private String generateOrchestratorDeploymentId(String envId, String orchestratorId) throws OrchestratorDeploymentIdConflictException {
log.debug("Generating deployment paaS Id...");
log.debug("All spaces will be replaced by an \"_\" charactr. You might consider it while naming your applications.");
ApplicationEnvironment env = applicationEnvironmentService.getOrFail(envId);
Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
String namePattern = orchestrator.getDeploymentNamePattern();
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(namePattern);
String orchestratorDeploymentId = (String) exp.getValue(new OrchestratorIdContext(env, applicationService.getOrFail(env.getApplicationId()), namePattern.contains("metaProperties[")));
// ensure that the id is not used by another deployment.
if (deploymentService.isActiveDeployment(orchestratorId, orchestratorDeploymentId)) {
throw new OrchestratorDeploymentIdConflictException("Conflict detected with the generated paasId <" + orchestratorDeploymentId + ">.");
}
return orchestratorDeploymentId;
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentService method getEnvironmentByIdOrDefault.
/**
* Get a environment for and application
*
* @param applicationId
* @param applicationEnvironmentId
* @return
*/
public ApplicationEnvironment getEnvironmentByIdOrDefault(String applicationId, String applicationEnvironmentId) {
ApplicationEnvironment environment = null;
if (applicationEnvironmentId == null) {
ApplicationEnvironment[] applicationEnvironments = getByApplicationId(applicationId);
environment = applicationEnvironments[0];
} else {
environment = getOrFail(applicationEnvironmentId);
}
return environment;
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentService method checkAndGetApplicationEnvironment.
/**
* Check rights on the related application and get the application environment
* If no roles mentioned, all {@link ApplicationRole} values will be used
*
* @param applicationEnvironmentId application's environment id
* @param roles {@link ApplicationRole} to check right on the underlying application
* @return the corresponding application environment
*/
public ApplicationEnvironment checkAndGetApplicationEnvironment(String applicationEnvironmentId, IResourceRoles... roles) {
ApplicationEnvironment applicationEnvironment = getOrFail(applicationEnvironmentId);
// Is the user allowed access (application, environment) level ?
if (AuthorizationUtil.hasAuthorization(applicationEnvironment, Role.ADMIN, roles)) {
return applicationEnvironment;
}
// is the user allowed to access at the application level
applicationService.checkAndGetApplication(applicationEnvironment.getApplicationId(), roles);
return applicationEnvironment;
}
Aggregations