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;
}
Aggregations