Search in sources :

Example 51 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class ApplicationService method findByIdsIfAuthorized.

/**
 * Retrieve applications given a list of ids, and a specific context
 * Only retrieves the authorized ones.
 *
 * @param fetchContext The fetch context to recover only the required field (Note that this should be simplified to directly use the given field...).
 * @param ids array of id of the applications to find
 * @return Map of Applications that has the given ids and for which the user is authorized (key is application Id), or null if no application matching the
 *         request is found.
 */
public Map<String, Application> findByIdsIfAuthorized(String fetchContext, String... ids) {
    List<Application> apps = alienDAO.findByIdsWithContext(Application.class, fetchContext, ids);
    if (apps == null) {
        return null;
    }
    Map<String, Application> applications = Maps.newHashMap();
    Iterator<Application> iterator = apps.iterator();
    while (iterator.hasNext()) {
        Application app = iterator.next();
        if (!AuthorizationUtil.hasAuthorizationForApplication(app, ApplicationRole.values())) {
            iterator.remove();
            continue;
        }
        applications.put(app.getId(), app);
    }
    return applications.isEmpty() ? null : applications;
}
Also used : Application(alien4cloud.model.application.Application)

Example 52 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class PolicyMatchingSubstitutionService method onCopyConfiguration.

// FIXME fix this, synch with org.alien4cloud.alm.deployment.configuration.services.MatchingSubstitutionService#onCopyConfiguration
// @EventListener
// @Order(30) // Process this after location matching copy (first element).
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) PolicyMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingCompositeModifier) PolicyMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingConfigAutoSelectModifier) 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) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Set(java.util.Set) SetMatchedPolicyModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier) 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) 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)

Example 53 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class CsarService method getCsarRelatedResourceList.

/**
 * Get the list of resources that are using the given archive.
 *
 * @param csar The archive for which to get usage.
 * @return The list of usage of the archive.
 */
public List<Usage> getCsarRelatedResourceList(Csar csar) {
    if (csar == null) {
        log.debug("You have requested a resource list for a invalid csar object : <" + csar + ">");
        return Lists.newArrayList();
    }
    ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, csar.getName(), csar.getVersion());
    // Archive from applications are used by the application.
    if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
        // The CSAR is from an application's topology
        Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
        archiveUsageRequestEvent.addUsage(new Usage(application.getName(), Application.class.getSimpleName().toLowerCase(), csar.getDelegateId(), csar.getWorkspace()));
    }
    // a csar that is a dependency of another csar can not be deleted
    Csar[] relatedCsars = getDependantCsars(csar.getName(), csar.getVersion());
    if (ArrayUtils.isNotEmpty(relatedCsars)) {
        archiveUsageRequestEvent.addUsages(generateCsarsInfo(relatedCsars));
    }
    // check if some of the nodes are used in topologies.
    Topology[] topologies = getDependantTopologies(csar.getName(), csar.getVersion());
    if (topologies != null && topologies.length > 0) {
        archiveUsageRequestEvent.addUsages(generateTopologiesInfo(topologies));
    }
    // a csar that is a dependency of location can not be deleted
    Location[] relatedLocations = getDependantLocations(csar.getName(), csar.getVersion());
    if (relatedLocations != null && relatedLocations.length > 0) {
        archiveUsageRequestEvent.addUsages(generateLocationsInfo(relatedLocations));
    }
    publisher.publishEvent(archiveUsageRequestEvent);
    return archiveUsageRequestEvent.getUsages();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) ArchiveUsageRequestEvent(org.alien4cloud.tosca.catalog.events.ArchiveUsageRequestEvent) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) Location(alien4cloud.model.orchestrators.locations.Location)

Example 54 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class CsarService method generateCsarsInfo.

/**
 * Generate resources related to a csar list
 *
 * @param csars
 * @return
 */
public List<Usage> generateCsarsInfo(Csar[] csars) {
    String resourceName;
    String resourceId;
    List<Usage> resourceList = Lists.newArrayList();
    for (Csar csar : csars) {
        if (ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) {
            Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
            resourceName = application.getName();
        } else {
            resourceName = csar.getName();
        }
        Usage temp = new Usage(resourceName, Csar.class.getSimpleName().toLowerCase(), csar.getId(), csar.getWorkspace());
        resourceList.add(temp);
    }
    return resourceList;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) Application(alien4cloud.model.application.Application)

Example 55 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class InputsMappingFileVariableResolverTest method setUp.

@Before
public void setUp() throws Exception {
    inputsPropertyDefinitions = Maps.newHashMap();
    inputsPropertyDefinitions.put("int_input", buildPropDef(ToscaTypes.INTEGER));
    inputsPropertyDefinitions.put("float_input", buildPropDef(ToscaTypes.FLOAT));
    inputsPropertyDefinitions.put("string_input", buildPropDef(ToscaTypes.STRING));
    inputsPropertyDefinitions.put("complex_input", buildPropDef("datatype.complex_input_entry"));
    Resource yamlApp = new FileSystemResource("src/test/resources/alien/variables/variables_app_test.yml");
    Resource yamlEnvType = new FileSystemResource("src/test/resources/alien/variables/variables_env_type_test.yml");
    Resource yamlEnv = new FileSystemResource("src/test/resources/alien/variables/variables_env_test.yml");
    AlienContextVariables alienContextVariables = new AlienContextVariables();
    Application application = new Application();
    application.setName("originalAppName");
    alienContextVariables.setApplication(application);
    inputsMappingFileVariableResolverConfigured = configure(PropertiesYamlParser.ToProperties.from(yamlApp), PropertiesYamlParser.ToProperties.from(yamlEnvType), PropertiesYamlParser.ToProperties.from(yamlEnv), alienContextVariables);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Application(alien4cloud.model.application.Application) Before(org.junit.Before)

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