Search in sources :

Example 1 with IOrchestratorPlugin

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

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin 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 3 with IOrchestratorPlugin

use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin 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 4 with IOrchestratorPlugin

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

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

the class OrchestratorStateService method disable.

/**
 * Disable an orchestrator.
 *
 * @param orchestrator The orchestrator to disable.
 * @param force If true the orchestrator is disabled even if some deployments are currently running.
 */
public synchronized List<Usage> disable(Orchestrator orchestrator, boolean force) {
    if (!force) {
        // If there is at least one active deployment.
        GetMultipleDataResult<Deployment> result = alienDAO.buildQuery(Deployment.class).setFilters(MapUtil.newHashMap(new String[] { "orchestratorId", "endDate" }, new String[][] { new String[] { orchestrator.getId() }, new String[] { null } })).prepareSearch().setFieldSort("_timestamp", true).search(0, 1);
        // TODO place a lock to avoid deployments during the disabling of the orchestrator.
        if (result.getData().length > 0) {
            List<Usage> usages = generateDeploymentUsages(result.getData());
            return usages;
        }
    }
    try {
        // unregister the orchestrator.
        IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.unregister(orchestrator.getId());
        if (orchestratorInstance != null) {
            IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
            orchestratorFactory.destroy(orchestratorInstance);
        }
    } catch (Exception e) {
        log.info("Unable to destroy orchestrator, it may not be created yet", e);
    } finally {
        // Mark the orchestrator as disabled
        orchestrator.setState(OrchestratorState.DISABLED);
        alienDAO.save(orchestrator);
    }
    return null;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment) AlreadyExistException(alien4cloud.exception.AlreadyExistException) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Aggregations

IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)22 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)6 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)6 Deployment (alien4cloud.model.deployment.Deployment)5 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)5 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)5 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)5 Location (alien4cloud.model.orchestrators.locations.Location)4 OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)3 IPaaSCallback (alien4cloud.paas.IPaaSCallback)3 PaaSTopologyDeploymentContext (alien4cloud.paas.model.PaaSTopologyDeploymentContext)3 Map (java.util.Map)3 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 Test (org.junit.Test)2 DeploymentCreatedEvent (alien4cloud.events.DeploymentCreatedEvent)1 LocationTemplateCreated (alien4cloud.events.LocationTemplateCreated)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Usage (alien4cloud.model.common.Usage)1