Search in sources :

Example 1 with LocationArchiveDeleteRequested

use of alien4cloud.events.LocationArchiveDeleteRequested in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method deleteArchives.

/**
 * Delete all archives related to a location, if not exposed or used by another location
 *
 * @param location
 * @return Map of usages per archives if found (that means the deletion wasn't performed successfully), null if everything went well.
 */
public Map<Csar, List<Usage>> deleteArchives(Orchestrator orchestrator, Location location) {
    ILocationConfiguratorPlugin configuratorPlugin = getConfiguratorPlugin(location);
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    List<PluginArchive> pluginArchives = configuratorPlugin.pluginArchives();
    // abort if no archive is exposed by this location
    if (CollectionUtils.isEmpty(pluginArchives)) {
        return null;
    }
    Map<String, List<Location>> allExposedArchivesIds = getAllExposedArchivesIdsExluding(location);
    Map<Csar, List<Usage>> usages = Maps.newHashMap();
    for (PluginArchive pluginArchive : pluginArchives) {
        Csar csar = pluginArchive.getArchive().getArchive();
        List<Location> locationsExposingArchive = allExposedArchivesIds.get(csar.getId());
        LocationArchiveDeleteRequested e = new LocationArchiveDeleteRequested(this);
        e.setCsar(csar);
        e.setLocation(location);
        e.setOrchestratorFactory(orchestratorFactory);
        e.setLocationsExposingArchive(locationsExposingArchive);
        // only delete if no other location exposed this archive
        if (locationsExposingArchive == null) {
            List<Usage> csarUsage = csarService.deleteCsarWithElements(csar);
            if (CollectionUtils.isNotEmpty(csarUsage)) {
                usages.put(csar, csarUsage);
            }
            e.setDeleted(true);
        } else {
            e.setDeleted(false);
        }
        applicationContext.publishEvent(e);
    }
    return usages.isEmpty() ? null : usages;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) LocationArchiveDeleteRequested(alien4cloud.events.LocationArchiveDeleteRequested) Usage(alien4cloud.model.common.Usage) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ArrayList(java.util.ArrayList) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1 Usage (alien4cloud.model.common.Usage)1 Location (alien4cloud.model.orchestrators.locations.Location)1 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Csar (org.alien4cloud.tosca.model.Csar)1