Search in sources :

Example 6 with IOrchestratorPluginFactory

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

the class OrchestratorStateService method unloadAllOrchestrators.

/**
 * Unload all orchestrators from JVM memory, it's typically to refresh/reload code
 */
public void unloadAllOrchestrators() {
    List<Orchestrator> enabledOrchestratorList = orchestratorService.getAllEnabledOrchestrators();
    if (enabledOrchestratorList != null && !enabledOrchestratorList.isEmpty()) {
        log.info("Unloading orchestrators");
        for (final Orchestrator orchestrator : enabledOrchestratorList) {
            // un-register the orchestrator.
            IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.unregister(orchestrator.getId());
            if (orchestratorInstance != null) {
                IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
                orchestratorFactory.destroy(orchestratorInstance);
            }
        }
        log.info("{} Orchestrators Unloaded", enabledOrchestratorList.size());
    }
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 7 with IOrchestratorPluginFactory

use of alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory 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 8 with IOrchestratorPluginFactory

use of alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory 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 9 with IOrchestratorPluginFactory

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

the class OrchestratorDeploymentService method getDeploymentPropertyDefinitions.

public Map<String, PropertyDefinition> getDeploymentPropertyDefinitions(String orchestratorId) {
    Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    return orchestratorFactory.getDeploymentPropertyDefinitions();
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Orchestrator(alien4cloud.model.orchestrators.Orchestrator)

Example 10 with IOrchestratorPluginFactory

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

the class OrchestratorService method create.

/**
 * Creates an orchestrator.
 *
 * @param name The unique name that defines the orchestrator from user point of view.
 * @param pluginId The id of the plugin used to communicate with the orchestrator.
 * @param pluginBean The bean in the plugin that is indeed managing communication.
 * @return The generated identifier for the orchestrator.
 */
public synchronized String create(String name, String pluginId, String pluginBean) {
    Orchestrator orchestrator = new Orchestrator();
    // generate an unique id
    orchestrator.setId(UUID.randomUUID().toString());
    orchestrator.setName(name);
    orchestrator.setPluginId(pluginId);
    orchestrator.setPluginBean(pluginBean);
    // by default clouds are disabled as it should be configured before being enabled.
    orchestrator.setState(OrchestratorState.DISABLED);
    // get default configuration for the orchestrator.
    IOrchestratorPluginFactory orchestratorFactory = getPluginFactory(orchestrator);
    OrchestratorConfiguration configuration = new OrchestratorConfiguration(orchestrator.getId(), orchestratorFactory.getDefaultConfiguration());
    ensureNameUnicityAndSave(orchestrator);
    alienDAO.save(configuration);
    return orchestrator.getId();
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration)

Aggregations

IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)13 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)7 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)6 OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)4 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)3 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 Usage (alien4cloud.model.common.Usage)2 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1 LocationTemplateCreated (alien4cloud.events.LocationTemplateCreated)1 Deployment (alien4cloud.model.deployment.Deployment)1 Location (alien4cloud.model.orchestrators.locations.Location)1 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)1 ILocationAutoConfigurer (alien4cloud.orchestrators.plugin.ILocationAutoConfigurer)1 ILocationResourceAccessor (alien4cloud.orchestrators.plugin.ILocationResourceAccessor)1 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 ArrayList (java.util.ArrayList)1