Search in sources :

Example 21 with Orchestrator

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();
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Orchestrator(alien4cloud.model.orchestrators.Orchestrator)

Example 22 with Orchestrator

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();
    }
}
Also used : ArrayList(java.util.ArrayList) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) AlreadyExistException(alien4cloud.exception.AlreadyExistException) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 23 with Orchestrator

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));
}
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 24 with 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);
}
Also used : Orchestrator(alien4cloud.model.orchestrators.Orchestrator)

Example 25 with Orchestrator

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);
    }
}
Also used : LocationMatch(alien4cloud.model.deployment.matching.LocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

Orchestrator (alien4cloud.model.orchestrators.Orchestrator)28 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)7 Location (alien4cloud.model.orchestrators.locations.Location)6 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 ApiOperation (io.swagger.annotations.ApiOperation)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)3 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)3 Test (org.junit.Test)3 Audit (alien4cloud.audit.annotation.Audit)2 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)2 ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)2 LocationMatch (alien4cloud.model.deployment.matching.LocationMatch)2 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)2 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)2 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)2 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)2 LocationMatchingException (alien4cloud.paas.exception.LocationMatchingException)2 LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)2