Search in sources :

Example 11 with ApplicationTopologyVersion

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

the class ApplicationVersionService method createTopologyVersion.

/**
 * Create a new application topology version. If originalId is not null the topology will be created:
 * - From a topology template if originalIsVersion is false
 * - From a version of the application if
 *
 * @param applicationId The id of the application for which to create the new application topology version.
 * @param versionId The id of the version for which to create a new topology version.
 * @param qualifier The qualifier for this specific topology version.
 * @param description The description of the topology version.
 * @param originalId The id that points to a topology used to initialize the new application topology version.
 * @param originalIsVersion True if the originalId is the id of an application topology version, false if this is the id of a topology template.
 */
public void createTopologyVersion(String applicationId, String versionId, String qualifier, String description, String originalId, boolean originalIsVersion) {
    // validate the qualifier first if not null
    if (qualifier != null) {
        VersionUtil.isQualifierValidOrFail(qualifier);
    }
    // Get the version from elastic-search
    ApplicationVersion applicationVersion = getOrFail(versionId);
    Topology topology;
    if (originalId == null) {
        topology = new Topology();
    } else {
        if (originalIsVersion) {
            // we need to check that the version is indeed a previous version of this application
            ApplicationVersion originalVersion = getOrFailByArchiveId(originalId);
            if (!applicationId.equals(originalVersion.getApplicationId())) {
                throw new AuthorizationServiceException("Creating a new version of an application from the version of another application is not authorized.");
            }
            topology = topologyServiceCore.getOrFail(originalId);
        } else {
            topology = getTemplateTopology(originalId);
        }
    }
    String version = getTopologyVersion(applicationVersion.getVersion(), qualifier);
    if (applicationVersion.getTopologyVersions().get(version) != null) {
        throw new AlreadyExistException("The topology version [" + versionId + "] already exists for application [" + applicationId + "]");
    }
    // Create a new application version based on an existing topology.
    ApplicationTopologyVersion applicationTopologyVersion = createTopologyVersion(applicationId, version, qualifier, description, topology);
    applicationVersion.getTopologyVersions().put(version, applicationTopologyVersion);
    alienDAO.save(applicationVersion);
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) AuthorizationServiceException(org.springframework.security.access.AuthorizationServiceException) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 12 with ApplicationTopologyVersion

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

the class ApplicationVersionService method importTopologiesFromPreviousVersion.

private void importTopologiesFromPreviousVersion(ApplicationVersion newVersion, ApplicationVersion originalAppVersion) {
    // if the version is a release version we have to ensure that every sub-topology can be released
    Map<String, Topology> previousTopologies = Maps.newHashMap();
    // If the previous version was not a release and we want to create a release version then we have to check that all topologies can indeed be released.
    boolean mustCheckReleasable = newVersion.isReleased() && !originalAppVersion.isReleased();
    for (ApplicationTopologyVersion originalAppTopoVersion : originalAppVersion.getTopologyVersions().values()) {
        // Ensure that all versions can be created and does not exists already.
        csarService.ensureUniqueness(newVersion.getApplicationId(), newVersion.getVersion() + "-" + originalAppTopoVersion.getQualifier());
        // Cache the previous topology for duplication when creating the new version.
        Topology topology = alienDAO.findById(Topology.class, originalAppTopoVersion.getArchiveId());
        if (mustCheckReleasable) {
            // If the new version is a release, we have to ensure that all dependencies are released
            checkTopologyReleasable(topology);
        }
        previousTopologies.put(originalAppTopoVersion.getArchiveId(), topology);
    }
    for (ApplicationTopologyVersion originalAppTopoVersion : originalAppVersion.getTopologyVersions().values()) {
        String newTopologyVersion = getTopologyVersion(newVersion.getVersion(), originalAppTopoVersion.getQualifier());
        ApplicationTopologyVersion applicationTopologyVersion = createTopologyVersion(newVersion.getApplicationId(), newTopologyVersion, originalAppTopoVersion.getQualifier(), originalAppTopoVersion.getDescription(), previousTopologies.get(originalAppTopoVersion.getArchiveId()));
        // Add the newly created application version to the list.
        newVersion.getTopologyVersions().put(newTopologyVersion, applicationTopologyVersion);
    }
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 13 with ApplicationTopologyVersion

use of alien4cloud.model.application.ApplicationTopologyVersion 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 14 with ApplicationTopologyVersion

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

the class DeploymentTopologyController method updatePolicySubstitution.

/**
 * Update policy substitution.
 *
 * @param appId id of the application.
 * @param environmentId id of the environment.
 * @return response containing the deployment topology dto {@link DeploymentTopologyDTO}.
 */
@ApiOperation(value = "Substitute a specific policy by a location policy resource template in the topology of an application, given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/policies/{policyId}/substitution", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<DeploymentTopologyDTO> updatePolicySubstitution(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String policyId, @RequestParam String locationResourceTemplateId) {
    Application application = applicationService.getOrFail(appId);
    ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> policyMatchingSubstitutionService.updateSubstitution(application, environment, topology, policyId, locationResourceTemplateId));
    return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ApplicationTopologyVersion

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

the class DeploymentTopologyController method updatePolicySubstitutionProperty.

@ApiOperation(value = "Update policy substitution's property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/policies/{nodeId}/substitution/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updatePolicySubstitutionProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestBody UpdatePropertyRequest updateRequest) {
    try {
        Application application = applicationService.getOrFail(appId);
        ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
        ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
        Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
        DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedPolicyPropertiesConfigService.updateProperty(application, environment, topology, nodeId, updateRequest.getPropertyName(), updateRequest.getPropertyValue()));
        return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
    } catch (ConstraintTechnicalException e) {
        if (e.getCause() instanceof ConstraintFunctionalException) {
            return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue());
        }
        throw e;
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)18 Topology (org.alien4cloud.tosca.model.templates.Topology)12 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)11 Application (alien4cloud.model.application.Application)9 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)9 ApiOperation (io.swagger.annotations.ApiOperation)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)7 Audit (alien4cloud.audit.annotation.Audit)6 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)5 ConstraintFunctionalException (org.alien4cloud.tosca.exceptions.ConstraintFunctionalException)3 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)3 NotFoundException (alien4cloud.exception.NotFoundException)2 AfterApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted)2 BeforeApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted)2 AuthorizationServiceException (org.springframework.security.access.AuthorizationServiceException)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 Deployment (alien4cloud.model.deployment.Deployment)1 RestError (alien4cloud.rest.model.RestError)1