public async Task <ILoadBalancer> Get(string serviceName, LoadBalancerMode _loadBalancer = LoadBalancerMode.RoundRobin)
        {
            try
            {
                if (_loadBalancers.TryGetValue(serviceName, out var loadBalancer))
                {
                    loadBalancer = _loadBalancers[serviceName];
                    if (serviceName != loadBalancer.GetType().Name)
                    {
                        loadBalancer = await _factory.Get(serviceName, _loadBalancer);

                        AddLoadBalancer(serviceName, loadBalancer);
                    }
                    return(loadBalancer);
                }

                loadBalancer = await _factory.Get(serviceName, _loadBalancer);

                AddLoadBalancer(serviceName, loadBalancer);
                return(loadBalancer);
            }
            catch (Exception ex)
            {
                throw new KeyNotFoundException($"unabe to find load balancer for {serviceName} exception is {ex}");
            }
        }
        private IOfferOperations ExecuteRemoteWithLoadBalancer(LoadBalancerMode mode, Action <IOfferRemoteOperations> remote, List <ServerConfig> servers, string farm)
        {
            var lbExecutor = GetLoadBalancer(mode, servers);

            var errorDuringLoadBalancing = false;

            foreach (var server in lbExecutor.GetServerExecutionOrder(servers, _settings, _token))
            {
                try
                {
                    lbExecutor.BringOffline(server, _settings, _token);

                    if (!server.LoadBalancerState.PreventDeployment)
                    {
                        ExecuteOperation(remote, server);
                    }
                }
                catch
                {
                    errorDuringLoadBalancing = true;
                    throw;
                }
                finally
                {
                    if (!errorDuringLoadBalancing && !_settings.Options.StopAfterMarkedServer)
                    {
                        lbExecutor.BringOnline(server, _settings, _token);
                    }
                }
            }
            return(this);
        }
Exemple #3
0
        public async Task <ILoadBalancer> Get(string serviceName, LoadBalancerMode loadBalancer = LoadBalancerMode.RoundRobin)
        {
            switch (loadBalancer)
            {
            case LoadBalancerMode.Random:
                return(new RandomLoadBalancer(_service, serviceName));

            case LoadBalancerMode.RoundRobin:
                return(new RoundRobinLoadBalancer(_service, serviceName));

            default:
                return(new NoLoadBalancer(_service));
            }
        }
Exemple #4
0
        public async Task <ILoadBalancer> Get(string serviceName, LoadBalancerMode loadBalancer = LoadBalancerMode.RoundRobin)
        {
            switch (loadBalancer)
            {
            case LoadBalancerMode.Random:
                return(new RandomSelector(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            case LoadBalancerMode.RoundRobin:
                return(new RoundRobinSelector(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            case LoadBalancerMode.LeastConnection:
                return(new LeastConnectionSelector(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            default:
                return(new NoLoadBalancerSelector(await _serviceProvider.FindServiceInstancesAsync(serviceName)));
            }
        }
Exemple #5
0
        private LoadBalancerExecutorBase GetLoadBalancer(LoadBalancerMode mode, IList <ServerConfig> servers)
        {
            LoadBalancerExecutorBase lbExecutor = null;
            var loadBalancer = _loadBalancerLocator.GetLoadBalancer();

            switch (mode)
            {
            case LoadBalancerMode.RoundRobin:
                lbExecutor = new RoundRobinLoadBalancerExecutor(servers, loadBalancer);
                break;

            case LoadBalancerMode.Sticky:
                lbExecutor = new StickyLoadBalancerExecutor(loadBalancer);
                break;

            default:
                throw new ConDepLoadBalancerException("Load balancer mode not supported");
            }
            return(lbExecutor);
        }
 public IOfferOperations LoadBalance(LoadBalancerMode mode, string tier, string farm, Action <IOfferRemoteOperations, ServerConfig> remote)
 {
     return(ExecuteRemoteWithLoadBalancer(mode, remote, _settings.Config.Servers.ToList(), farm));
 }