use of alien4cloud.common.ResourceUpdateInterceptor.TopologyVersionUpdated 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);
}
}
Aggregations