Search in sources :

Example 1 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project yorc-a4c-plugin by ystia.

the class AbstractLocationConfigurer method addToAchive.

protected void addToAchive(List<PluginArchive> archives, String path) throws ParsingException {
    Path archivePath = selfContext.getPluginPath().resolve(path);
    // Parse the archives
    ParsingResult<ArchiveRoot> result = archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
    PluginArchive pluginArchive = new PluginArchive(result.getResult(), archivePath);
    archives.add(pluginArchive);
}
Also used : Path(java.nio.file.Path) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive)

Example 2 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project alien4cloud by alien4cloud.

the class MockAmazonLocationConfigurer method addToAchive.

private void addToAchive(List<PluginArchive> archives, String path) throws ParsingException {
    Path archivePath = selfContext.getPluginPath().resolve(path);
    // Parse the archives
    ParsingResult<ArchiveRoot> result = archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
    PluginArchive pluginArchive = new PluginArchive(result.getResult(), archivePath);
    archives.add(pluginArchive);
}
Also used : Path(java.nio.file.Path) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive)

Example 3 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project alien4cloud by alien4cloud.

the class ArchiveProviderPluginCallBack method deleteArchives.

private Map<Csar, List<Usage>> deleteArchives(Collection<PluginArchive> pluginArchives) {
    Map<Csar, List<Usage>> usages = Maps.newHashMap();
    for (PluginArchive pluginArchive : safe(pluginArchives)) {
        Csar csar = pluginArchive.getArchive().getArchive();
        List<Usage> csarUsage = csarService.deleteCsarWithElements(csar);
        // TODO push delete event
        if (CollectionUtils.isNotEmpty(csarUsage)) {
            usages.put(csar, csarUsage);
        }
    }
    return usages.isEmpty() ? null : usages;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) List(java.util.List)

Example 4 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive 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 5 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive 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)

Aggregations

PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)10 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)6 Path (java.nio.file.Path)5 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)3 List (java.util.List)3 Csar (org.alien4cloud.tosca.model.Csar)3 Usage (alien4cloud.model.common.Usage)2 Location (alien4cloud.model.orchestrators.locations.Location)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ParsingException (alien4cloud.tosca.parser.ParsingException)2 ArrayList (java.util.ArrayList)2 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)1 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)1 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 PluginArchiveException (alien4cloud.plugin.exception.PluginArchiveException)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1