Search in sources :

Example 11 with Deployment

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();
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) Location(alien4cloud.model.orchestrators.locations.Location)

Example 12 with Deployment

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;
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) DeploymentSourceType(alien4cloud.model.deployment.DeploymentSourceType) IDeploymentSource(alien4cloud.model.deployment.IDeploymentSource) Location(alien4cloud.model.orchestrators.locations.Location)

Example 13 with Deployment

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

Example 14 with Deployment

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Deployment(alien4cloud.model.deployment.Deployment)

Example 15 with Deployment

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

Aggregations

Deployment (alien4cloud.model.deployment.Deployment)43 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)13 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)11 ApiOperation (io.swagger.annotations.ApiOperation)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 NotFoundException (alien4cloud.exception.NotFoundException)6 Application (alien4cloud.model.application.Application)6 Location (alien4cloud.model.orchestrators.locations.Location)6 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)3 Usage (alien4cloud.model.common.Usage)3 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)3 Date (java.util.Date)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 ServiceResource (alien4cloud.model.service.ServiceResource)2 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)2