use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationService method getMultiple.
/**
* Get multiple locations from list of ids
*
* @param ids ids of location to get
* @return map of id to location
*/
public Map<String, Location> getMultiple(Collection<String> ids) {
List<Location> locations = alienDAO.findByIds(Location.class, ids.toArray(new String[ids.size()]));
Map<String, Location> locationMap = Maps.newHashMap();
for (Location location : locations) {
locationMap.put(location.getId(), location);
}
return locationMap;
}
use of alien4cloud.model.orchestrators.locations.Location 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;
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class PluginArchiveIndexer method getAllExposedArchivesIdsExluding.
/**
* Query for csars that are defined by locations.
*
* @return A maps of <csar_id, list of locations that uses the csar>.
*/
public Map<String, List<Location>> getAllExposedArchivesIdsExluding(Location excludedLocation) {
// exclude a location from the search
QueryBuilder query = QueryBuilders.boolQuery().mustNot(QueryBuilders.idsQuery(Location.class.getSimpleName().toLowerCase()).ids(excludedLocation.getId()));
List<Location> locations = alienDAO.customFindAll(Location.class, query);
Map<String, List<Location>> archiveIds = Maps.newHashMap();
if (locations != null) {
for (Location location : locations) {
ILocationConfiguratorPlugin configuratorPlugin = getConfiguratorPlugin(location);
List<PluginArchive> pluginArchives = configuratorPlugin.pluginArchives();
for (PluginArchive pluginArchive : safe(pluginArchives)) {
String archiveId = pluginArchive.getArchive().getArchive().getId();
List<Location> locationsPerArchive = archiveIds.get(archiveId);
if (locationsPerArchive == null) {
locationsPerArchive = Lists.newArrayList();
archiveIds.put(archiveId, locationsPerArchive);
}
locationsPerArchive.add(location);
}
}
}
return archiveIds;
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class OrchestratorService method delete.
/**
* Delete an existing orchestrator.
*
* @param id The id of the orchestrator to delete.
*/
public void delete(String id) {
// delete all locations for the orchestrator
Location[] locations = locationService.getOrchestratorLocations(id);
if (locations != null) {
for (Location location : locations) {
locationService.delete(id, location.getId());
}
}
// delete the orchestrator configuration
alienDAO.delete(OrchestratorConfiguration.class, id);
alienDAO.delete(Orchestrator.class, id);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class TopologyModifierPluginLinker method usage.
@Override
public List<PluginUsage> usage(String pluginId) {
// Get all modifiers associated with a location
GetMultipleDataResult<Location> locationData = alienDAO.buildQuery(Location.class).prepareSearch().search(0, Integer.MAX_VALUE);
List<PluginUsage> usages = Lists.newArrayList();
for (Location location : locationData.getData()) {
for (LocationModifierReference locationModifierReference : safe(location.getModifiers())) {
if (pluginId.equals(locationModifierReference.getPluginId())) {
usages.add(new PluginUsage(location.getId(), location.getName(), Location.class.getSimpleName()));
}
}
}
return usages;
}
Aggregations