Search in sources :

Example 51 with Location

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;
}
Also used : Location(alien4cloud.model.orchestrators.locations.Location)

Example 52 with Location

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

Example 53 with Location

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;
}
Also used : ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) ArrayList(java.util.ArrayList) List(java.util.List) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Location(alien4cloud.model.orchestrators.locations.Location)

Example 54 with Location

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);
}
Also used : Location(alien4cloud.model.orchestrators.locations.Location)

Example 55 with Location

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;
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) PluginUsage(alien4cloud.plugin.model.PluginUsage) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

Location (alien4cloud.model.orchestrators.locations.Location)80 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 ApiOperation (io.swagger.annotations.ApiOperation)30 List (java.util.List)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)28 Audit (alien4cloud.audit.annotation.Audit)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)15 LocationService (alien4cloud.orchestrators.locations.services.LocationService)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 Application (alien4cloud.model.application.Application)12 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)12 RestResponse (alien4cloud.rest.model.RestResponse)12 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)12 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)12 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)12 Resource (javax.annotation.Resource)12 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)11 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)11 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)11