Search in sources :

Example 6 with ApplicationVersion

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

the class ApplicationVersionService method delete.

/**
 * Delete a specific application version.
 *
 * @param applicationVersionId The id of the specific version to delete.
 */
public void delete(String applicationVersionId) {
    ApplicationVersion applicationVersion = getOrFail(applicationVersionId);
    deleteCheck(applicationVersion);
    deleteVersion(applicationVersion);
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion)

Example 7 with ApplicationVersion

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

the class ApplicationVersionService method update.

/**
 * Update an application version and all it's topology versions.
 *
 * @param applicationVersionId The application version for which to update all versions.
 * @param newVersion The updated version number.
 * @param newDescription The new description.
 */
public void update(String applicationId, String applicationVersionId, String newVersion, String newDescription) {
    ApplicationVersion applicationVersion = getOrFail(applicationVersionId);
    if (!applicationId.equals(applicationVersion.getApplicationId())) {
        throw new AuthorizationServiceException("It is not authorize to change an application with a wrong application id: request application id [" + applicationId + "] version application id: [" + applicationVersion.getApplicationId() + "]");
    }
    if (newDescription != null) {
        applicationVersion.setDescription(newDescription);
    }
    if (newVersion != null && !applicationVersion.getVersion().equals(newVersion)) {
        // if the version is a release it is not possible to change it's version number
        if (applicationVersion.isReleased()) {
            throw new UpdateApplicationVersionException("The application version " + applicationVersion.getId() + " is released and cannot be update.");
        }
        if (applicationVersionNameExists(applicationVersion.getApplicationId(), newVersion)) {
            throw new AlreadyExistException("An application version already exist for this application with the version :" + newVersion);
        }
        ApplicationEnvironment[] relatedEnvironments = findAllApplicationVersionUsage(applicationVersion.getApplicationId(), applicationVersion.getVersion());
        if (ArrayUtils.isNotEmpty(relatedEnvironments)) {
            // should fal the update if linked to deployed environment
            failIfAnyEnvironmentDeployed(relatedEnvironments);
            // Should fail the update if exposed as a service
            failIfAnyEnvironmentExposedAsService(applicationId, relatedEnvironments);
        }
        // When changing the version number we actually perform a full version creation and then delete the previous one.
        ApplicationVersion newApplicationVersion = new ApplicationVersion();
        newApplicationVersion.setVersion(newVersion);
        newApplicationVersion.setNestedVersion(VersionUtil.parseVersion(newVersion));
        newApplicationVersion.setDescription(applicationVersion.getDescription());
        newApplicationVersion.setApplicationId(applicationVersion.getApplicationId());
        newApplicationVersion.setReleased(!VersionUtil.isSnapshot(newVersion));
        newApplicationVersion.setTopologyVersions(Maps.newHashMap());
        importTopologiesFromPreviousVersion(newApplicationVersion, applicationVersion);
        // save the new version
        alienDAO.save(newApplicationVersion);
        resourceUpdateInterceptor.runOnTopologyVersionReleased(new TopologyVersionUpdated(applicationVersion, newApplicationVersion));
        // update topology versions on related objects: (environments, deploymentTopologies)
        updateTopologyVersion(relatedEnvironments, applicationVersion, newApplicationVersion);
        // delete the previous version
        deleteVersion(applicationVersion);
    } else {
        // save the new version
        alienDAO.save(applicationVersion);
    }
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) TopologyVersionUpdated(alien4cloud.common.ResourceUpdateInterceptor.TopologyVersionUpdated) AuthorizationServiceException(org.springframework.security.access.AuthorizationServiceException) UpdateApplicationVersionException(alien4cloud.utils.version.UpdateApplicationVersionException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 8 with ApplicationVersion

use of alien4cloud.model.application.ApplicationVersion 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 9 with ApplicationVersion

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

the class ApplicationVersionService method createApplicationVersion.

/**
 * Create a new version for an application. The new application version can be created from an exiting application version of not.
 * When created from an existing application version all topology versions from the original version will be created in the new application version.
 *
 * @param applicationId The id of the application for which to create the version.
 * @param version The new version.
 * @param description The description.
 * @param originalId The version (application version or topology) from witch to create the new application version.
 * @param originalIsAppVersion True if the originalId is the id of an application version id, false if it is the id of a topology id.
 */
public ApplicationVersion createApplicationVersion(String applicationId, String version, String description, String originalId, boolean originalIsAppVersion) {
    if (isVersionNameExist(applicationId, version)) {
        throw new AlreadyExistException("A version " + version + " already exists for application " + applicationId + ".");
    }
    ApplicationVersion appVersion = new ApplicationVersion();
    appVersion.setDelegateId(applicationId);
    appVersion.setVersion(version);
    appVersion.setNestedVersion(VersionUtil.parseVersion(version));
    appVersion.setReleased(!VersionUtil.isSnapshot(version));
    appVersion.setDescription(description);
    appVersion.setTopologyVersions(Maps.newHashMap());
    // Create all topology versions based on the previous version configuration
    if (originalIsAppVersion && originalId != null) {
        ApplicationVersion originalAppVersion = getOrFail(originalId);
        // Ensure that the id of the original application version is indeed the same as the one of the application
        if (!applicationId.equals(originalAppVersion.getApplicationId())) {
            throw new AuthorizationServiceException("Creating a new version of an application from the version of another application is not authorized.");
        }
        // if the version is a release version we have to ensure that every sub-topology can be released
        importTopologiesFromPreviousVersion(appVersion, originalAppVersion);
    } else {
        // Don't create the application version from an existing version but from either a topology template or start a blank topology
        Topology topology;
        if (originalId == null) {
            topology = new Topology();
        } else {
            topology = getTemplateTopology(originalId);
        }
        // Create a default topology version for this application version.
        ApplicationTopologyVersion applicationTopologyVersion = createTopologyVersion(applicationId, version, null, "default topology", topology);
        appVersion.getTopologyVersions().put(version, applicationTopologyVersion);
    }
    // Save the version object
    alienDAO.save(appVersion);
    return appVersion;
}
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 10 with ApplicationVersion

use of alien4cloud.model.application.ApplicationVersion 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)

Aggregations

ApplicationVersion (alien4cloud.model.application.ApplicationVersion)19 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)5 Audit (alien4cloud.audit.annotation.Audit)4 Test (org.junit.Test)4 Application (alien4cloud.model.application.Application)3 Deployment (alien4cloud.model.deployment.Deployment)3 AuthorizationServiceException (org.springframework.security.access.AuthorizationServiceException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Topology (org.alien4cloud.tosca.model.templates.Topology)2 TopologyVersionUpdated (alien4cloud.common.ResourceUpdateInterceptor.TopologyVersionUpdated)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 TestUtils.nullAsString (alien4cloud.it.utils.TestUtils.nullAsString)1 UpdateApplicationVersionException (alien4cloud.utils.version.UpdateApplicationVersionException)1 Date (java.util.Date)1 Set (java.util.Set)1 AfterApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted)1