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());
;
}
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;
}
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;
}
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);
}
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;
}
Aggregations