use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionService method updateTopologyVersion.
private void updateTopologyVersion(ApplicationEnvironment[] relatedEnvironments, ApplicationVersion oldVersion, ApplicationVersion newVersion) {
if (ArrayUtils.isEmpty(relatedEnvironments)) {
return;
}
Arrays.stream(relatedEnvironments).forEach(environment -> {
ApplicationTopologyVersion oldTopologyVersion = oldVersion.getTopologyVersions().get(environment.getTopologyVersion());
String newTopologyVersion = getTopologyVersion(newVersion.getVersion(), oldTopologyVersion.getQualifier());
applicationEnvironmentService.updateTopologyVersion(environment, environment.getTopologyVersion(), newVersion.getVersion(), newTopologyVersion, environment.getId());
});
}
use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionService method deleteVersion.
private void deleteVersion(ApplicationVersion version) {
// Call delete archive
for (Map.Entry<String, ApplicationTopologyVersion> topologyVersionEntry : version.getTopologyVersions().entrySet()) {
publisher.publishEvent(new BeforeApplicationTopologyVersionDeleted(this, version.getApplicationId(), version.getId(), topologyVersionEntry.getKey()));
csarService.deleteCsar(topologyVersionEntry.getValue().getArchiveId());
}
publisher.publishEvent(new BeforeApplicationVersionDeleted(this, version.getApplicationId(), version.getId()));
alienDAO.delete(ApplicationVersion.class, version.getId());
publisher.publishEvent(new AfterApplicationVersionDeleted(this, version.getApplicationId(), version.getId()));
for (Map.Entry<String, ApplicationTopologyVersion> topologyVersionEntry : version.getTopologyVersions().entrySet()) {
publisher.publishEvent(new AfterApplicationTopologyVersionDeleted(this, version.getApplicationId(), version.getId(), topologyVersionEntry.getKey()));
}
}
use of alien4cloud.model.application.ApplicationTopologyVersion 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();
}
use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionService method createTopologyVersion.
@SneakyThrows
private ApplicationTopologyVersion createTopologyVersion(String applicationId, String version, String qualifier, String description, Topology topology) {
String oldArchiveName = topology.getArchiveName();
String oldArchiveVersion = topology.getArchiveVersion();
// Every version of an application has a Cloud Service Archive
String delegateType = ArchiveDelegateType.APPLICATION.toString();
Csar csar = new Csar(applicationId, version);
csar.setWorkspace(APP_WORKSPACE_PREFIX + ":" + applicationId);
csar.setDelegateId(applicationId);
csar.setDelegateType(delegateType);
if (oldArchiveName != null && oldArchiveVersion != null) {
// Change all artifact references to the newly created archive if it's a copy
ArtifactUtil.changeTopologyArtifactReferences(topology, csar);
csar.setToscaDefinitionsVersion(csarService.getOrFail(new Csar(oldArchiveName, oldArchiveVersion).getId()).getToscaDefinitionsVersion());
} else {
csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
}
topology.setArchiveName(csar.getName());
topology.setArchiveVersion(csar.getVersion());
topology.setWorkspace(csar.getWorkspace());
// if the new version is a release, we have to ensure that all dependencies are released
if (!VersionUtil.isSnapshot(version)) {
checkTopologyReleasable(topology);
}
if (oldArchiveName != null && oldArchiveVersion != null) {
Path newTopologyTempPath = Files.createTempDirectory(tempDirPath, "a4c");
try {
// When it's a copy from other topology, we copy artifacts
Path originalTopologyArchive = archiveRepositry.getExpandedCSAR(oldArchiveName, oldArchiveVersion);
ArtifactUtil.copyCsarArtifacts(originalTopologyArchive, newTopologyTempPath);
archiveIndexer.importNewArchive(csar, topology, newTopologyTempPath);
} finally {
FileUtil.delete(newTopologyTempPath);
}
} else {
archiveIndexer.importNewArchive(csar, topology, null);
}
// Import the created archive and topology
ApplicationTopologyVersion applicationTopologyVersion = new ApplicationTopologyVersion();
applicationTopologyVersion.setArchiveId(csar.getId());
applicationTopologyVersion.setQualifier(qualifier);
applicationTopologyVersion.setDescription(description);
return applicationTopologyVersion;
}
use of alien4cloud.model.application.ApplicationTopologyVersion 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;
}
Aggregations