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