Search in sources :

Example 1 with ILocationConfiguratorPlugin

use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.

the class LocationResourceService method getLocationResourcesFromOrchestrator.

/*
     * (non-Javadoc)
     * 
     * @see
     * alien4cloud.orchestrators.locations.services.ILocationResourceService#getLocationResourcesFromOrchestrator(alien4cloud.model.orchestrators.locations.
     * Location)
     */
@Override
public LocationResources getLocationResourcesFromOrchestrator(Location location) {
    LocationResources locationResources = new LocationResources();
    Orchestrator orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
    IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    fillLocationResourceTypes(configuratorPlugin.getResourcesTypes(), locationResources, location.getDependencies());
    fillPoliciesLocationResourceTypes(configuratorPlugin.getPoliciesTypes(), locationResources, location.getDependencies());
    // add LocationResourceTemplate
    List<LocationResourceTemplate> locationResourceTemplates = getResourcesTemplates(location.getId());
    setLocationRessource(locationResourceTemplates, locationResources);
    // add PolicyLocationResourceTemplate
    locationResources.getPolicyTemplates().addAll(getPoliciesResourcesTemplates(location.getId()));
    return locationResources;
}
Also used : LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 2 with ILocationConfiguratorPlugin

use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method getConfiguratorPlugin.

private ILocationConfiguratorPlugin getConfiguratorPlugin(Location location) {
    ILocationConfiguratorPlugin configuratorPlugin;
    try {
        IOrchestratorPlugin<Object> orchestratorInstance = orchestratorPluginService.getOrFail(location.getOrchestratorId());
        configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    } catch (OrchestratorDisabledException e) {
        IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestratorService.getOrFail(location.getOrchestratorId()));
        IOrchestratorPlugin<Object> orchestratorInstance = orchestratorFactory.newInstance();
        configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
        orchestratorFactory.destroy(orchestratorInstance);
    }
    return configuratorPlugin;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 3 with ILocationConfiguratorPlugin

use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.

the class LocationMatchingConfigurationService method getMatchingConfiguration.

/**
 * Get the matching configuration for a given location.
 *
 * @param location The location for which to get the configuration.
 * @return A map nodetype, matching configuration to be used for matching.
 */
public Map<String, MatchingConfiguration> getMatchingConfiguration(Location location) {
    Orchestrator orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
    IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.get(orchestrator.getId());
    if (orchestratorInstance == null) {
        return null;
    }
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    return configuratorPlugin.getMatchingConfigurations();
}
Also used : ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 4 with ILocationConfiguratorPlugin

use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.

the class LocationService method autoConfigure.

/**
 * This method calls the orchestrator plugin to try to auto-configure the
 *
 * @param orchestrator The orchestrator for which to auto-configure a location.
 * @param location The location to auto-configure
 * @return the List of {@link LocationResourceTemplate} generated from the location auto-configuration call, null is a valid answer.
 */
private List<LocationResourceTemplate> autoConfigure(Orchestrator orchestrator, Location location) throws UnsupportedOperationException {
    // get the orchestrator plugin instance
    IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    ILocationResourceAccessor accessor = locationResourceService.accessor(location.getId());
    // let's try to auto-configure the location
    List<LocationResourceTemplate> templates = configuratorPlugin.instances(accessor);
    if (templates != null) {
        // save the instances
        for (LocationResourceTemplate template : templates) {
            // initialize the instances from data.
            template.setId(UUID.randomUUID().toString());
            template.setLocationId(location.getId());
            template.setGenerated(true);
            template.setEnabled(true);
            NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, template.getTemplate().getType(), location.getDependencies());
            nodeType.getDerivedFrom().add(0, template.getTemplate().getType());
            template.setTypes(nodeType.getDerivedFrom());
            LocationTemplateCreated event = new LocationTemplateCreated(this);
            event.setTemplate(template);
            event.setLocation(location);
            event.setToscaType(nodeType);
            applicationContext.publishEvent(event);
        }
        alienDAO.save(templates.toArray(new LocationResourceTemplate[templates.size()]));
        alienDAO.save(location);
    }
    return templates;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationTemplateCreated(alien4cloud.events.LocationTemplateCreated) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 5 with ILocationConfiguratorPlugin

use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin 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

ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)7 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)3 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)3 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 Location (alien4cloud.model.orchestrators.locations.Location)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Csar (org.alien4cloud.tosca.model.Csar)2 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1 LocationTemplateCreated (alien4cloud.events.LocationTemplateCreated)1 Usage (alien4cloud.model.common.Usage)1 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)1 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)1 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)1 ILocationResourceAccessor (alien4cloud.orchestrators.plugin.ILocationResourceAccessor)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1