Search in sources :

Example 46 with Application

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;
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application)

Example 47 with Application

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);
        }
    }
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Set(java.util.Set) SetMatchedNodeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedNodeModifier) EventListener(org.springframework.context.event.EventListener) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) FlowExecutor(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutor) AbstractComposedModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.AbstractComposedModifier) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) NodeMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingCompositeModifier) Topology(org.alien4cloud.tosca.model.templates.Topology) Set(java.util.Set) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 48 with Application

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);
    }
}
Also used : Usage(alien4cloud.model.common.Usage) ServiceResource(alien4cloud.model.service.ServiceResource) Application(alien4cloud.model.application.Application)

Example 49 with Application

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;
}
Also used : Application(alien4cloud.model.application.Application)

Example 50 with 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;
}
Also used : DeleteApplicationEnvironments(alien4cloud.application.ApplicationEnvironmentService.DeleteApplicationEnvironments) BeforeApplicationDeleted(org.alien4cloud.alm.events.BeforeApplicationDeleted) DeleteApplicationVersions(alien4cloud.application.ApplicationVersionService.DeleteApplicationVersions) Deployment(alien4cloud.model.deployment.Deployment) AfterApplicationDeleted(org.alien4cloud.alm.events.AfterApplicationDeleted) Application(alien4cloud.model.application.Application)

Aggregations

Application (alien4cloud.model.application.Application)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)45 ApiOperation (io.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)39 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)38 Audit (alien4cloud.audit.annotation.Audit)28 List (java.util.List)14 Topology (org.alien4cloud.tosca.model.templates.Topology)14 Set (java.util.Set)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)11 RestResponse (alien4cloud.rest.model.RestResponse)11 Collectors (java.util.stream.Collectors)11 Map (java.util.Map)10 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)9 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)9 Arrays (java.util.Arrays)9 When (cucumber.api.java.en.When)8 Deployment (alien4cloud.model.deployment.Deployment)7 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)7 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)7