Search in sources :

Example 1 with BeforeApplicationTopologyVersionDeleted

use of org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted 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()));
    }
}
Also used : AfterApplicationTopologyVersionDeleted(org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted) AfterApplicationVersionDeleted(org.alien4cloud.alm.events.AfterApplicationVersionDeleted) BeforeApplicationVersionDeleted(org.alien4cloud.alm.events.BeforeApplicationVersionDeleted) Map(java.util.Map) BeforeApplicationTopologyVersionDeleted(org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 2 with BeforeApplicationTopologyVersionDeleted

use of org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted 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)

Aggregations

ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)2 AfterApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted)2 BeforeApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)1 Map (java.util.Map)1 AfterApplicationVersionDeleted (org.alien4cloud.alm.events.AfterApplicationVersionDeleted)1 BeforeApplicationVersionDeleted (org.alien4cloud.alm.events.BeforeApplicationVersionDeleted)1