use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentController method getRelatedLocationsSummaries.
private Map<String, Location> getRelatedLocationsSummaries(Deployment[] deployments) {
Set<String> locationIds = Sets.newHashSet();
for (Deployment deployment : deployments) {
if (ArrayUtils.isNotEmpty(deployment.getLocationIds())) {
locationIds.addAll(Sets.newHashSet(deployment.getLocationIds()));
}
}
Map<String, Location> locations = null;
if (!locationIds.isEmpty()) {
locations = locationService.findByIds(FetchContext.SUMMARY, locationIds.toArray(new String[locationIds.size()]));
}
return locations != null ? locations : Maps.newHashMap();
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentController method buildDeploymentsDTOS.
private List<DeploymentDTO> buildDeploymentsDTOS(boolean includeSourceSummary, Deployment... deployments) {
List<DeploymentDTO> dtos = Lists.newArrayList();
if (ArrayUtils.isEmpty(deployments)) {
return dtos;
}
Map<String, ? extends IDeploymentSource> sources = Maps.newHashMap();
// get the app summaries if true
if (includeSourceSummary) {
DeploymentSourceType sourceType = deployments[0].getSourceType();
String[] sourceIds = getSourceIdsFromDeployments(deployments);
if (sourceIds[0] != null) {
// can have no application deployed
switch(sourceType) {
case APPLICATION:
Map<String, ? extends IDeploymentSource> appSources = applicationService.findByIdsIfAuthorized(FetchContext.SUMMARY, sourceIds);
if (appSources != null) {
sources = appSources;
}
}
}
}
Map<String, Location> locationsSummariesMap = getRelatedLocationsSummaries(deployments);
for (Object object : deployments) {
Deployment deployment = (Deployment) object;
IDeploymentSource source = sources.get(deployment.getSourceId());
if (source == null) {
source = new DeploymentSourceDTO(deployment.getSourceId(), deployment.getSourceName());
}
List<Location> locationsSummaries = getLocations(deployment.getLocationIds(), locationsSummariesMap);
DeploymentDTO dto = new DeploymentDTO(deployment, source, locationsSummaries);
dtos.add(dto);
}
return dtos;
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class WorkflowEventHandler method checkDeploymentAuthorization.
private void checkDeploymentAuthorization(Authentication authentication, User a4cUser, String deploymentId) {
Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
switch(deployment.getSourceType()) {
case APPLICATION:
// check if the user has right for the environment associated with the deployment.
ApplicationEnvironment environment = alienDAO.findById(ApplicationEnvironment.class, deployment.getEnvironmentId());
if (environment == null) {
log.error("Environment with id [{}] do not exist any more for deployment [{}]", deployment.getEnvironmentId(), deployment.getId());
throw new NotFoundException("Environment with id [" + deployment.getEnvironmentId() + "] do not exist any more for deployment [" + deployment.getId() + "]");
}
AuthorizationUtil.checkAuthorization(a4cUser, environment, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.values());
break;
case CSAR:
AuthorizationUtil.checkHasOneRoleIn(authentication, Role.COMPONENTS_MANAGER);
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentService method getOrchestratorDeploymentIdsByOrchestratorId.
/**
* For a given environment get all deployments that have been and compute a map of deployment orchestrator ids by orchestrator id.
*
* @param applicationEnvironmentId The id of the application environment for which to get the map or pas deployment
* @return A map of orchestrator deployment ids by orchestrator ids.
*/
public Map<String, Set<String>> getOrchestratorDeploymentIdsByOrchestratorId(String applicationEnvironmentId) {
Map<String, Set<String>> result = new HashMap<>();
GetMultipleDataResult<Deployment> dataResult = alienDao.search(Deployment.class, null, FilterUtil.fromKeyValueCouples("environmentId", applicationEnvironmentId), Integer.MAX_VALUE);
if (dataResult.getData() != null && dataResult.getData().length > 0) {
for (Deployment deployment : dataResult.getData()) {
if (!result.containsKey(deployment.getOrchestratorId())) {
result.put(deployment.getOrchestratorId(), new HashSet<String>());
}
result.get(deployment.getOrchestratorId()).add(deployment.getOrchestratorDeploymentId());
}
}
return result;
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentService method getActiveDeployment.
/**
* Get a topology for a given cloud / topology
*
* @param orchestratorId targeted orchestrator id
* @param topologyId id of the topology to deploy
* @return a deployment
*/
public Deployment getActiveDeployment(String orchestratorId, String topologyId) {
Deployment deployment = null;
Map<String, String[]> activeDeploymentFilters = MapUtil.newHashMap(new String[] { "orchestratorId", "topologyId", "endDate" }, new String[][] { new String[] { orchestratorId }, new String[] { topologyId }, new String[] { null } });
GetMultipleDataResult<Deployment> dataResult = alienDao.search(Deployment.class, null, activeDeploymentFilters, 1);
if (dataResult.getData() != null && dataResult.getData().length > 0) {
deployment = dataResult.getData()[0];
}
return deployment;
}
Aggregations