use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class ManagedServiceResourceService method checkAndGetApplicationEnvironment.
/**
* Get application environment, checks for DEPLOYMENT_MANAGEMENT rights on it.
*
* @param environmentId
* @return the environment if the current user has the proper rights on it
* @throws java.nio.file.AccessDeniedException if the current user doesn't have proper rights on the requested environment
*/
private ApplicationEnvironment checkAndGetApplicationEnvironment(String environmentId) {
ApplicationEnvironment environment = environmentService.getOrFail(environmentId);
Application application = applicationService.getOrFail(environment.getApplicationId());
// Only a user with deployment rĂ´le on the environment can create an associated service.
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
return environment;
}
use of alien4cloud.model.application.Application 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.Application in project alien4cloud by alien4cloud.
the class ApplicationVersionService method failIfAnyEnvironmentExposedAsService.
private void failIfAnyEnvironmentExposedAsService(String applicationId, ApplicationEnvironment[] environments) {
Application application = applicationService.getOrFail(applicationId);
Usage[] usages = Arrays.stream(environments).map(environment -> {
Usage usage = null;
ServiceResource service = alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("environmentId", environment.getId())).prepareSearch().find();
if (service != null) {
String usageName = service.getName() + " [App (" + application.getName() + "), Env (" + environment.getName() + ")]";
usage = new Usage(usageName, "Service", service.getId(), null);
}
return usage;
}).filter(Objects::nonNull).toArray(Usage[]::new);
if (ArrayUtils.isNotEmpty(usages)) {
throw new ReferencedResourceException("Application versions exposed as a service cannot be updated", usages);
}
}
use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class ApplicationService method checkAndGetApplication.
/**
* Check if the connected user has at least one application role on the related application with a fail when applicationId is not valid
* If no roles mentioned, all {@link ApplicationRole} values will be used (one at least required)
*
* @param applicationId
* @return the related application
*/
public Application checkAndGetApplication(String applicationId, IResourceRoles... roles) {
Application application = getOrFail(applicationId);
roles = ArrayUtils.isEmpty(roles) ? ApplicationRole.values() : roles;
AuthorizationUtil.checkAuthorizationForApplication(application, roles);
return application;
}
use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class ApplicationService method delete.
/**
* Delete an existing application from it's id. This method ensures first that there is no running deployment of the application.
*
* @param applicationId The id of the application to remove.
* @return True if the application has been removed, false if not.
*/
public boolean delete(String applicationId) {
// Removal of a deployed application is not authorized
if (alienDAO.count(Deployment.class, null, fromKeyValueCouples("sourceId", applicationId, "endDate", null)) > 0) {
return false;
}
// Ensure that application related resources can be removed.
Application application = getOrFail(applicationId);
DeleteApplicationVersions deleteApplicationVersions = applicationVersionService.prepareDeleteByApplication(applicationId);
DeleteApplicationEnvironments deleteApplicationEnvironments = applicationEnvironmentService.prepareDeleteByApplication(applicationId);
// Delete the application.
deleteApplicationVersions.delete();
deleteApplicationEnvironments.delete();
publisher.publishEvent(new BeforeApplicationDeleted(this, applicationId));
alienDAO.delete(Application.class, applicationId);
if (application != null && StringUtils.isNotBlank(application.getImageId())) {
imageDAO.deleteAll(application.getImageId());
}
publisher.publishEvent(new AfterApplicationDeleted(this, applicationId));
return true;
}
Aggregations