Search in sources :

Example 1 with OrchestratorConfiguration

use of alien4cloud.model.orchestrators.OrchestratorConfiguration in project alien4cloud by alien4cloud.

the class OrchestratorServiceTest method testInitializeConfigurableOrchestratorValidConfig.

@SuppressWarnings("unchecked")
@Test
public void testInitializeConfigurableOrchestratorValidConfig() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, PluginConfigurationException, ExecutionException, InterruptedException, IOException {
    initializeMockedOrchestratorService();
    IOrchestratorPluginFactory orchestratorPluginFactory = Mockito.mock(IOrchestratorPluginFactory.class);
    IOrchestratorPlugin orchestratorPlugin = Mockito.mock(IOrchestratorPlugin.class);
    List<Orchestrator> enabledOrchestrators = searchOrchestrator();
    Orchestrator orchestrator = enabledOrchestrators.get(0);
    OrchestratorConfiguration configuration = new OrchestratorConfiguration(orchestrator.getId(), DEFAULT_CLOUD_CONFIGURATION);
    initSearch(enabledOrchestrators);
    Mockito.when(orchestratorService.getPluginFactory(orchestrator)).thenReturn(orchestratorPluginFactory);
    Mockito.when(orchestratorPluginFactory.newInstance()).thenReturn(orchestratorPlugin);
    Mockito.when(orchestratorPluginFactory.getConfigurationType()).thenReturn(String.class);
    Mockito.when(orchestratorPluginFactory.getDefaultConfiguration()).thenReturn(DEFAULT_CLOUD_CONFIGURATION);
    Mockito.when(orchestratorConfigurationService.configurationAsValidObject(orchestrator.getId(), configuration.getConfiguration())).thenReturn(DEFAULT_CLOUD_CONFIGURATION);
    Mockito.when(orchestratorConfigurationService.getConfigurationOrFail(orchestrator.getId())).thenReturn(configuration);
    initializeAndWait();
    Mockito.verify(orchestratorPlugin, Mockito.times(1)).setConfiguration(orchestrator.getId(), configuration.getConfiguration());
    Mockito.verify(orchestratorPluginService, Mockito.times(1)).register(orchestrator.getId(), orchestratorPlugin);
    IOrchestratorPluginFactory fatory = orchestratorService.getPluginFactory(orchestrator);
    Mockito.verify(archiveIndexer, Mockito.times(1)).indexOrchestratorArchives(fatory, fatory.newInstance());
    ;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Test(org.junit.Test)

Example 2 with OrchestratorConfiguration

use of alien4cloud.model.orchestrators.OrchestratorConfiguration in project alien4cloud by alien4cloud.

the class OrchestratorConfigurationService method updateConfiguration.

/**
 * Update the configuration for the given cloud.
 *
 * @param id Id of the orchestrator for which to update the configuration.
 * @param newConfiguration The new configuration.
 */
public synchronized void updateConfiguration(String id, Object newConfiguration) throws PluginConfigurationException, IOException {
    OrchestratorConfiguration configuration = alienDAO.findById(OrchestratorConfiguration.class, id);
    if (configuration == null) {
        throw new NotFoundException("No configuration exists for cloud [" + id + "].");
    }
    Object newConfigurationObj = configurationAsValidObject(id, newConfiguration);
    Object oldConfiguration = configuration.getConfiguration();
    Object oldConfigurationObj = configurationAsValidObject(id, oldConfiguration);
    Map<String, Object> oldConfAsMap = JsonUtil.toMap(JsonUtil.toString(oldConfigurationObj));
    Map<String, Object> newConfAsMap = (Map<String, Object>) newConfiguration;
    // merge the config so that old values are preserved
    ReflectionUtil.mergeObject(newConfigurationObj, oldConfigurationObj, false, Sets.difference(oldConfAsMap.keySet(), newConfAsMap.keySet()));
    configuration.setConfiguration(oldConfigurationObj);
    // Trigger update of the orchestrator's configuration if enabled.
    IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.get(id);
    if (orchestratorInstance != null) {
        orchestratorInstance.setConfiguration(id, oldConfigurationObj);
    }
    alienDAO.save(configuration);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration) Map(java.util.Map) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 3 with OrchestratorConfiguration

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

Example 4 with OrchestratorConfiguration

use of alien4cloud.model.orchestrators.OrchestratorConfiguration in project alien4cloud by alien4cloud.

the class OrchestratorStateService method load.

/**
 * Load and connect the given orchestrator.
 *
 * @param orchestrator the orchestrator to load and connect.
 */
private void load(Orchestrator orchestrator) throws PluginConfigurationException {
    log.info("Loading and connecting orchestrator {} (id: {})", orchestrator.getName(), orchestrator.getId());
    // check that the orchestrator is not already loaded.
    if (orchestratorPluginService.get(orchestrator.getId()) != null) {
        throw new AlreadyExistException("Plugin is already loaded.");
    }
    // switch the state to connecting
    orchestrator.setState(OrchestratorState.CONNECTING);
    alienDAO.save(orchestrator);
    // TODO move below in a thread to perform plugin loading and connection asynchronously
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    IOrchestratorPlugin<Object> orchestratorInstance = orchestratorFactory.newInstance();
    // Set the configuration for the provider
    OrchestratorConfiguration orchestratorConfiguration = orchestratorConfigurationService.getConfigurationOrFail(orchestrator.getId());
    try {
        Object configuration = orchestratorConfigurationService.configurationAsValidObject(orchestrator.getId(), orchestratorConfiguration.getConfiguration());
        orchestratorInstance.setConfiguration(orchestrator.getId(), configuration);
    } catch (IOException e) {
        throw new PluginConfigurationException("Failed convert configuration json in object.", e);
    }
    // index the archive in alien catalog
    archiveIndexer.indexOrchestratorArchives(orchestratorFactory, orchestratorInstance);
    // connect the orchestrator
    orchestratorInstance.init(deploymentService.getCloudActiveDeploymentContexts(orchestrator.getId()));
    // register the orchestrator instance to be polled for updates
    orchestratorPluginService.register(orchestrator.getId(), orchestratorInstance);
    orchestrator.setState(OrchestratorState.CONNECTED);
    alienDAO.save(orchestrator);
    if (orchestratorInstance instanceof ILocationAutoConfigurer) {
        // trigger locations auto-configurations
        locationService.autoConfigure(orchestrator, (ILocationAutoConfigurer) orchestratorInstance);
    }
    indexLocationsArchives(orchestrator);
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationAutoConfigurer(alien4cloud.orchestrators.plugin.ILocationAutoConfigurer) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration)

Example 5 with OrchestratorConfiguration

use of alien4cloud.model.orchestrators.OrchestratorConfiguration in project alien4cloud by alien4cloud.

the class OrchestratorServiceTest method testInitializeConfigurableOrchstratorInvalidConfig.

@SuppressWarnings("unchecked")
@Test
public void testInitializeConfigurableOrchstratorInvalidConfig() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, PluginConfigurationException, ExecutionException, InterruptedException, IOException {
    initializeMockedOrchestratorService();
    IOrchestratorPluginFactory orchestratorPluginFactory = Mockito.mock(IOrchestratorPluginFactory.class);
    IOrchestratorPlugin orchestratorPlugin = Mockito.mock(IOrchestratorPlugin.class);
    List<Orchestrator> enabledOrchestrators = searchOrchestrator();
    Orchestrator orchestrator = enabledOrchestrators.get(0);
    OrchestratorConfiguration configuration = new OrchestratorConfiguration(orchestrator.getId(), DEFAULT_CLOUD_CONFIGURATION);
    initSearch(enabledOrchestrators);
    Mockito.when(orchestratorService.getPluginFactory(orchestrator)).thenReturn(orchestratorPluginFactory);
    Mockito.when(orchestratorPluginFactory.newInstance()).thenReturn(orchestratorPlugin);
    Mockito.when(orchestratorPluginFactory.getConfigurationType()).thenReturn(String.class);
    Mockito.when(orchestratorPluginFactory.getDefaultConfiguration()).thenReturn(DEFAULT_CLOUD_CONFIGURATION);
    Mockito.when(orchestratorConfigurationService.getConfigurationOrFail(orchestrator.getId())).thenReturn(configuration);
    Mockito.when(orchestratorConfigurationService.configurationAsValidObject(orchestrator.getId(), configuration.getConfiguration())).thenReturn(DEFAULT_CLOUD_CONFIGURATION);
    Mockito.doThrow(PluginConfigurationException.class).when(orchestratorPlugin).setConfiguration(orchestrator.getId(), configuration.getConfiguration());
    initializeAndWait();
    Mockito.verify(orchestratorPluginService, Mockito.times(0)).register(orchestrator.getId(), orchestratorPlugin);
    orchestrator = (Orchestrator) searchOrchestrator().get(0);
    orchestrator.setState(OrchestratorState.DISABLED);
    Mockito.verify(alienDAO, Mockito.times(2)).save(Mockito.refEq(orchestrator));
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Test(org.junit.Test)

Aggregations

OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)5 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)4 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)3 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)3 Test (org.junit.Test)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 ILocationAutoConfigurer (alien4cloud.orchestrators.plugin.ILocationAutoConfigurer)1 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)1 IOException (java.io.IOException)1 Map (java.util.Map)1