Exemple #1
0
            public void BeginDisableLoadBalancing()
            {
                try
                {
                    this._operationContext.RetryTime = TimeSpan.Zero;

                    this._serverContext = (ServerContext)_operationContext.Options.Parameters[0].Value;

                    var config = Helpers.GetConfigSettings(this._serverContext.WebFarm.Name);
                    var node   = Helpers.GetNodeName(this._serverContext.Address, config.TCPPort);

                    //if node is already disabled, complete the task
                    if (LoadBalancer.GetDisabledNodes(config).Contains(node))
                    {
                        this._serverContext.TraceWarning("Node {0} in pool {1} is already disabled.", node, config.PoolName);
                        base.SetComplete();
                    }
                    //if is forced stop or draining is disabled, complete the task
                    else if (_operationContext.Options.Force || !(config.DrainingPeriod > 0))
                    {
                        this._serverContext.TraceWarning("Draining skipped for node {0} in pool {1}. (Force={2}, DrainingPeriod={3})", node, config.PoolName, _operationContext.Options.Force, config.DrainingPeriod);
                        this.DrainNodeCompleteCallback(null);
                    }
                    else if (!LoadBalancer.GetDrainingNodes(config).Contains(node))
                    {
                        //start draining
                        DrainNodeGateContext.DrainNode(this._serverContext, new WaitCallback(this.DrainNodeCompleteCallback));
                    }
                }
                catch (Exception exception)
                {
                    this._lastException = exception;
                    base.SetComplete();
                }
            }
Exemple #2
0
        private static DrainNodeGateContext GetDrainNodeGateContext(WebFarmContext webFarmContext)
        {
            lock (sm_lock)
            {
                DrainNodeGateContext state = webFarmContext.StateTable.GetState <DrainNodeGateContext>();

                if (state == null)
                {
                    var config = Helpers.GetConfigSettings(webFarmContext.Name);

                    state = new DrainNodeGateContext(config);

                    webFarmContext.StateTable.SetState(state);
                }

                return(state);
            }
        }