use of alien4cloud.model.orchestrators.Orchestrator in project alien4cloud by alien4cloud.
the class OrchestratorService method getLocationSupport.
/**
* Get the location support information for a given orchestrator.
*
* @param orchestratorId The id of the orchestrator for which to get location support information.
* @return location support information.
*/
public LocationSupport getLocationSupport(String orchestratorId) {
Orchestrator orchestrator = getOrFail(orchestratorId);
IOrchestratorPluginFactory orchestratorFactory = getPluginFactory(orchestrator);
return orchestratorFactory.getLocationSupport();
}
use of alien4cloud.model.orchestrators.Orchestrator in project alien4cloud by alien4cloud.
the class OrchestratorStateService method initialize.
/**
* Initialize all orchestrator that have a non-disabled state.
* Note: Each orchestrator initialization is down in it's own thread so it doesn't impact application startup or other orchestrator connection.
*
* @param callback the callback to be executed when initialize finish
*/
public ListenableFuture<?> initialize(FutureCallback callback) {
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
try {
List<ListenableFuture<?>> futures = new ArrayList<>();
// get all the orchestrator that are not disabled
final List<Orchestrator> enabledOrchestratorList = orchestratorService.getAllEnabledOrchestrators();
if (enabledOrchestratorList == null || enabledOrchestratorList.isEmpty()) {
return Futures.immediateFuture(null);
}
log.info("Initializing orchestrators");
for (final Orchestrator orchestrator : enabledOrchestratorList) {
// error in initialization and timeouts should not impact startup time of Alien 4 cloud and other PaaS Providers.
ListenableFuture<?> future = executorService.submit(new Runnable() {
@Override
public void run() {
try {
load(orchestrator);
} catch (AlreadyExistException e) {
log.info("Orchestrator was already loaded at initialization for {}.", orchestrator.getId());
} catch (Exception e) {
// we have to catch everything as we don't know what a plugin can do here and cannot interrupt startup.
// Any orchestrator that failed to load will be considered as DISABLED as the registration didn't occurred
log.error("Unexpected error in plugin", e);
orchestrator.setState(OrchestratorState.DISABLED);
alienDAO.save(orchestrator);
}
}
});
futures.add(future);
}
ListenableFuture<?> combinedFuture = Futures.allAsList(futures);
if (callback != null) {
Futures.addCallback(combinedFuture, callback);
}
Futures.addCallback(combinedFuture, new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
log.info("{} Orchestrators loaded", enabledOrchestratorList.size());
}
@Override
public void onFailure(Throwable t) {
log.error("Unable to load orchestrators", t);
}
});
return combinedFuture;
} finally {
executorService.shutdown();
}
}
use of alien4cloud.model.orchestrators.Orchestrator 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));
}
use of alien4cloud.model.orchestrators.Orchestrator in project alien4cloud by alien4cloud.
the class OrchestratorServiceTest method searchOrchestrator.
private List<Orchestrator> searchOrchestrator() {
Orchestrator cloud = new Orchestrator();
cloud.setId("id");
cloud.setName("name");
cloud.setState(OrchestratorState.CONNECTED);
cloud.setPluginId("paasPluginId");
cloud.setPluginBean("paasPluginBean");
return Lists.newArrayList(cloud);
}
use of alien4cloud.model.orchestrators.Orchestrator in project alien4cloud by alien4cloud.
the class MockLocationMatcher method match.
@Override
public List<ILocationMatch> match(Topology topology) throws LocationMatchingException {
log.info("Mock location matcher <" + this.getClass().getName() + "> called!");
List<ILocationMatch> matched = Lists.newArrayList();
// get all enabled orchestrators
try {
List<Orchestrator> enabledOrchestrators = orchestratorService.getAllEnabledOrchestrators();
if (CollectionUtils.isEmpty(enabledOrchestrators)) {
return matched;
}
Map<String, Orchestrator> orchestratorMap = AlienUtils.fromListToMap(enabledOrchestrators, "id", true);
List<Location> locations = locationService.getOrchestratorsLocations(orchestratorMap.keySet());
for (Location location : locations) {
matched.add(new LocationMatch(location, orchestratorMap.get(location.getOrchestratorId()), null));
}
new MockLocationMatchOrchestratorFilter(selfContext).filter(matched, topology);
return matched;
} catch (Exception e) {
throw new LocationMatchingException("Failed to match topology <" + topology.getId() + "> against locations. ", e);
}
}
Aggregations