Search in sources :

Example 41 with ApplicationEnvironment

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

the class ApplicationEnvironmentService method getTopologyId.

/**
 * Get the topology id linked to the environment
 *
 * @param applicationEnvironmentId The id of the environment.
 * @return a topology id or null
 */
@Deprecated
public String getTopologyId(String applicationEnvironmentId) {
    ApplicationEnvironment applicationEnvironment = getOrFail(applicationEnvironmentId);
    ApplicationVersion applicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), applicationEnvironment.getTopologyVersion()));
    ApplicationTopologyVersion topologyVersion = applicationVersion == null ? null : applicationVersion.getTopologyVersions().get(applicationEnvironment.getTopologyVersion());
    return topologyVersion == null ? null : topologyVersion.getArchiveId();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 42 with ApplicationEnvironment

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

the class ApplicationEnvironmentService method delete.

/**
 * Delete a version and the related topologies.
 *
 * @param id The id of the version to delete.
 */
public void delete(String id) {
    ApplicationEnvironment environment = getOrFail(id);
    deleteCheck(environment);
    deleteEnvironment(environment);
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 43 with ApplicationEnvironment

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

the class ApplicationVersionService method deleteTopologyVersion.

/**
 * Delete an Application Topology version from a given application version.
 *
 * @param applicationId The application Id.
 * @param versionId The version id of the application version.
 * @param topologyVersion The version (not archive id) of the topology version.
 */
public void deleteTopologyVersion(String applicationId, String versionId, String topologyVersion) {
    ApplicationVersion applicationVersion = getOrFail(versionId);
    ApplicationTopologyVersion applicationTopologyVersion = applicationVersion.getTopologyVersions().get(topologyVersion);
    if (applicationTopologyVersion == null) {
        throw new NotFoundException("Topology version [" + topologyVersion + "] does not exist in the application version [" + versionId + "] for application [" + applicationId + "]");
    }
    if (applicationVersion.getTopologyVersions().size() == 1) {
        throw new DeleteLastApplicationVersionException("Application topology version [" + topologyVersion + "] for application version [" + versionId + "] can't be be deleted as it is the last topology version for this application version.");
    }
    ApplicationEnvironment usage = findAnyApplicationTopologyVersionUsage(applicationId, topologyVersion);
    if (usage != null) {
        throw new DeleteReferencedObjectException("Application topology version with id [" + topologyVersion + "] could not be deleted as it is used by environment [" + usage.getName() + "]");
    }
    ApplicationTopologyVersion deleted = applicationVersion.getTopologyVersions().remove(topologyVersion);
    publisher.publishEvent(new BeforeApplicationTopologyVersionDeleted(this, applicationVersion.getApplicationId(), applicationVersion.getId(), topologyVersion));
    csarService.deleteCsar(deleted.getArchiveId());
    alienDAO.save(applicationVersion);
    publisher.publishEvent(new AfterApplicationTopologyVersionDeleted(this, applicationVersion.getApplicationId(), applicationVersion.getId(), topologyVersion));
}
Also used : AfterApplicationTopologyVersionDeleted(org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted) ApplicationVersion(alien4cloud.model.application.ApplicationVersion) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) BeforeApplicationTopologyVersionDeleted(org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 44 with ApplicationEnvironment

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

the class ResourcePermissionService method grantAuthorizedEnvironmentsAndEnvTypesPerApplication.

public void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd, String[] environmentTypesToAdd) {
    List<String> envIds = Lists.newArrayList();
    IResourceSaver noSave = null;
    if (ArrayUtils.isNotEmpty(applicationsToAdd)) {
        grantPermission(resource, noSave, Subject.APPLICATION, applicationsToAdd);
        // when an app is added, all eventual existing env authorizations are removed
        for (String applicationToAddId : applicationsToAdd) {
            ApplicationEnvironment[] aes = applicationEnvironmentService.getByApplicationId(applicationToAddId);
            for (ApplicationEnvironment ae : aes) {
                envIds.add(ae.getId());
            }
        }
        if (!envIds.isEmpty()) {
            revokePermission(resource, noSave, Subject.ENVIRONMENT, envIds.toArray(new String[envIds.size()]));
        }
        // remove all all eventual existing env type authorizations
        Set<String> envTypes = Sets.newHashSet();
        for (String applicationToAddId : applicationsToAdd) {
            for (EnvironmentType envType : EnvironmentType.values()) {
                envTypes.add(applicationToAddId + ":" + envType.toString());
            }
        }
        if (!envTypes.isEmpty()) {
            revokePermission(resource, noSave, Subject.ENVIRONMENT_TYPE, envTypes.toArray(new String[envTypes.size()]));
        }
    }
    if (ArrayUtils.isNotEmpty(environmentsToAdd)) {
        List<String> envToAddSet = Arrays.stream(environmentsToAdd).filter(env -> !envIds.contains(env)).collect(Collectors.toList());
        grantPermission(resource, noSave, Subject.ENVIRONMENT, envToAddSet.toArray(new String[envToAddSet.size()]));
    }
    if (ArrayUtils.isNotEmpty(environmentTypesToAdd)) {
        grantPermission(resource, noSave, Subject.ENVIRONMENT_TYPE, environmentTypesToAdd);
    }
    alienDAO.save(resource);
}
Also used : BeforePermissionRevokedEvent(org.alien4cloud.alm.events.BeforePermissionRevokedEvent) Lists(org.elasticsearch.common.collect.Lists) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) Subject(alien4cloud.security.Subject) AbstractSecurityEnabledResource(alien4cloud.security.AbstractSecurityEnabledResource) ArrayUtils(org.apache.commons.lang3.ArrayUtils) User(alien4cloud.security.model.User) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) MapUtils(org.apache.commons.collections4.MapUtils) Permission(alien4cloud.security.Permission) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Resource(javax.annotation.Resource) Set(java.util.Set) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IAlienGroupDao(alien4cloud.security.groups.IAlienGroupDao) IAlienUserDao(alien4cloud.security.users.IAlienUserDao) List(java.util.List) ISecurityEnabledResource(alien4cloud.security.ISecurityEnabledResource) Group(alien4cloud.security.model.Group) EnvironmentType(alien4cloud.model.application.EnvironmentType) AllArgsConstructor(lombok.AllArgsConstructor) Comparator(java.util.Comparator) AfterPermissionRevokedEvent(org.alien4cloud.alm.events.AfterPermissionRevokedEvent) NoArgsConstructor(lombok.NoArgsConstructor) EnvironmentType(alien4cloud.model.application.EnvironmentType) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 45 with ApplicationEnvironment

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

the class DeploymentTopologyDTOBuilder method build.

/**
 * Create a deployment topology dto from the context of the execution of a deployment flow.
 *
 * @param executionContext The deployment flow execution context.
 * @return The deployment topology.
 */
private DeploymentTopologyDTO build(FlowExecutionContext executionContext) {
    // re-create the deployment topology object for api compatibility purpose
    DeploymentTopology deploymentTopology = new DeploymentTopology();
    ReflectionUtil.mergeObject(executionContext.getTopology(), deploymentTopology);
    deploymentTopology.setInitialTopologyId(executionContext.getTopology().getId());
    deploymentTopology.setEnvironmentId(executionContext.getEnvironmentContext().get().getEnvironment().getId());
    deploymentTopology.setVersionId(executionContext.getEnvironmentContext().get().getEnvironment().getTopologyVersion());
    DeploymentTopologyDTO deploymentTopologyDTO = new DeploymentTopologyDTO();
    topologyDTOBuilder.initTopologyDTO(deploymentTopology, deploymentTopologyDTO);
    // Convert log result to validation result.
    TopologyValidationResult validationResult = new TopologyValidationResult();
    for (AbstractTask task : executionContext.getLog().getInfos()) {
        validationResult.addInfo(task);
    }
    for (AbstractTask task : executionContext.getLog().getWarnings()) {
        validationResult.addWarning(task);
    }
    for (AbstractTask task : executionContext.getLog().getErrors()) {
        validationResult.addTask(task);
    }
    validationResult.setValid(validationResult.getTaskList() == null || validationResult.getTaskList().isEmpty());
    deploymentTopologyDTO.setValidation(validationResult);
    Optional<PreconfiguredInputsConfiguration> preconfiguredInputsConfiguration = executionContext.getConfiguration(PreconfiguredInputsConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!preconfiguredInputsConfiguration.isPresent()) {
        deploymentTopology.setPreconfiguredInputProperties(Maps.newHashMap());
    } else {
        deploymentTopology.setPreconfiguredInputProperties(preconfiguredInputsConfiguration.get().getInputs());
    }
    Optional<DeploymentInputs> inputsOptional = executionContext.getConfiguration(DeploymentInputs.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!inputsOptional.isPresent()) {
        deploymentTopology.setDeployerInputProperties(Maps.newHashMap());
        deploymentTopology.setUploadedInputArtifacts(Maps.newHashMap());
    } else {
        deploymentTopology.setDeployerInputProperties(inputsOptional.get().getInputs());
        deploymentTopology.setUploadedInputArtifacts(inputsOptional.get().getInputArtifacts());
    }
    Optional<DeploymentMatchingConfiguration> matchingConfigurationOptional = executionContext.getConfiguration(DeploymentMatchingConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!matchingConfigurationOptional.isPresent()) {
        return deploymentTopologyDTO;
    }
    DeploymentMatchingConfiguration matchingConfiguration = matchingConfigurationOptional.get();
    deploymentTopology.setOrchestratorId(matchingConfiguration.getOrchestratorId());
    deploymentTopology.setLocationGroups(matchingConfiguration.getLocationGroups());
    deploymentTopologyDTO.setLocationPolicies(matchingConfiguration.getLocationIds());
    // Good enough approximation as it doesn't contains just the location dependencies.
    deploymentTopology.setLocationDependencies(executionContext.getTopology().getDependencies());
    DeploymentSubstitutionConfiguration substitutionConfiguration = new DeploymentSubstitutionConfiguration();
    substitutionConfiguration.setSubstitutionTypes(new LocationResourceTypes());
    // fill DTO with policies substitution stuffs
    fillDTOWithPoliciesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
    // fill DTO with nodes substitution stuffs
    fillDTOWithNodesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
    deploymentTopologyDTO.setAvailableSubstitutions(substitutionConfiguration);
    ApplicationEnvironment environment = executionContext.getEnvironmentContext().get().getEnvironment();
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = executionContext.getConfiguration(OrchestratorDeploymentProperties.class, this.getClass().getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), matchingConfiguration.getOrchestratorId()));
    deploymentTopology.setProviderDeploymentProperties(orchestratorDeploymentProperties.getProviderDeploymentProperties());
    deploymentTopologyDTO.setSecretCredentialInfos((List<SecretCredentialInfo>) executionContext.getExecutionCache().get(FlowExecutionContext.SECRET_CREDENTIAL));
    return deploymentTopologyDTO;
}
Also used : AbstractTask(alien4cloud.topology.task.AbstractTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) DeploymentSubstitutionConfiguration(alien4cloud.deployment.model.DeploymentSubstitutionConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties) TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) LocationResourceTypes(alien4cloud.orchestrators.locations.services.LocationResourceTypes) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)82 ApiOperation (io.swagger.annotations.ApiOperation)42 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 Application (alien4cloud.model.application.Application)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)35 Audit (alien4cloud.audit.annotation.Audit)27 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)15 RestResponse (alien4cloud.rest.model.RestResponse)15 Topology (org.alien4cloud.tosca.model.templates.Topology)15 Set (java.util.Set)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)13 NotFoundException (alien4cloud.exception.NotFoundException)13 Map (java.util.Map)13 Resource (javax.annotation.Resource)12 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)11 Deployment (alien4cloud.model.deployment.Deployment)11 Arrays (java.util.Arrays)11 Location (alien4cloud.model.orchestrators.locations.Location)10