internal Parameters(BalancingPolicy policy, double threshold, int maxIdleIteration , ICollection <string> nodesToBeExcluded, ICollection <string> nodesToBeIncluded) { // exclude the nodes in this set from balancing operations //include only these nodes in balancing operations this.policy = policy; this.threshold = threshold; this.maxIdleIteration = maxIdleIteration; this.nodesToBeExcluded = nodesToBeExcluded; this.nodesToBeIncluded = nodesToBeIncluded; }
/// <summary> /// Get all /// <see cref="BalancingPolicy"/> /// instances /// </summary> internal static BalancingPolicy Parse(string s) { BalancingPolicy[] all = new BalancingPolicy[] { BalancingPolicy.Node.Instance, BalancingPolicy.Pool .Instance }; foreach (BalancingPolicy p in all) { if (Sharpen.Runtime.EqualsIgnoreCase(p.GetName(), s)) { return(p); } } throw new ArgumentException("Cannot parse string \"" + s + "\""); }
/// <summary>Construct a balancer.</summary> /// <remarks> /// Construct a balancer. /// Initialize balancer. It sets the value of the threshold, and /// builds the communication proxies to /// namenode as a client and a secondary namenode and retry proxies /// when connection fails. /// </remarks> internal Balancer(NameNodeConnector theblockpool, Balancer.Parameters p, Configuration conf) { long movedWinWidth = conf.GetLong(DFSConfigKeys.DfsBalancerMovedwinwidthKey, DFSConfigKeys .DfsBalancerMovedwinwidthDefault); int moverThreads = conf.GetInt(DFSConfigKeys.DfsBalancerMoverthreadsKey, DFSConfigKeys .DfsBalancerMoverthreadsDefault); int dispatcherThreads = conf.GetInt(DFSConfigKeys.DfsBalancerDispatcherthreadsKey , DFSConfigKeys.DfsBalancerDispatcherthreadsDefault); int maxConcurrentMovesPerNode = conf.GetInt(DFSConfigKeys.DfsDatanodeBalanceMaxNumConcurrentMovesKey , DFSConfigKeys.DfsDatanodeBalanceMaxNumConcurrentMovesDefault); this.dispatcher = new Dispatcher(theblockpool, p.nodesToBeIncluded, p.nodesToBeExcluded , movedWinWidth, moverThreads, dispatcherThreads, maxConcurrentMovesPerNode, conf ); this.threshold = p.threshold; this.policy = p.policy; }
/// <summary>parse command line arguments</summary> internal static Balancer.Parameters Parse(string[] args) { BalancingPolicy policy = Balancer.Parameters.Default.policy; double threshold = Balancer.Parameters.Default.threshold; int maxIdleIteration = Balancer.Parameters.Default.maxIdleIteration; ICollection <string> nodesTobeExcluded = Balancer.Parameters.Default.nodesToBeExcluded; ICollection <string> nodesTobeIncluded = Balancer.Parameters.Default.nodesToBeIncluded; if (args != null) { try { for (int i = 0; i < args.Length; i++) { if (Sharpen.Runtime.EqualsIgnoreCase("-threshold", args[i])) { Preconditions.CheckArgument(++i < args.Length, "Threshold value is missing: args = " + Arrays.ToString(args)); try { threshold = double.ParseDouble(args[i]); if (threshold < 1 || threshold > 100) { throw new ArgumentException("Number out of range: threshold = " + threshold); } Log.Info("Using a threshold of " + threshold); } catch (ArgumentException e) { System.Console.Error.WriteLine("Expecting a number in the range of [1.0, 100.0]: " + args[i]); throw; } } else { if (Sharpen.Runtime.EqualsIgnoreCase("-policy", args[i])) { Preconditions.CheckArgument(++i < args.Length, "Policy value is missing: args = " + Arrays.ToString(args)); try { policy = BalancingPolicy.Parse(args[i]); } catch (ArgumentException e) { System.Console.Error.WriteLine("Illegal policy name: " + args[i]); throw; } } else { if (Sharpen.Runtime.EqualsIgnoreCase("-exclude", args[i])) { Preconditions.CheckArgument(++i < args.Length, "List of nodes to exclude | -f <filename> is missing: args = " + Arrays.ToString(args)); if (Sharpen.Runtime.EqualsIgnoreCase("-f", args[i])) { Preconditions.CheckArgument(++i < args.Length, "File containing nodes to exclude is not specified: args = " + Arrays.ToString(args)); nodesTobeExcluded = Dispatcher.Util.GetHostListFromFile(args[i], "exclude"); } else { nodesTobeExcluded = Dispatcher.Util.ParseHostList(args[i]); } } else { if (Sharpen.Runtime.EqualsIgnoreCase("-include", args[i])) { Preconditions.CheckArgument(++i < args.Length, "List of nodes to include | -f <filename> is missing: args = " + Arrays.ToString(args)); if (Sharpen.Runtime.EqualsIgnoreCase("-f", args[i])) { Preconditions.CheckArgument(++i < args.Length, "File containing nodes to include is not specified: args = " + Arrays.ToString(args)); nodesTobeIncluded = Dispatcher.Util.GetHostListFromFile(args[i], "include"); } else { nodesTobeIncluded = Dispatcher.Util.ParseHostList(args[i]); } } else { if (Sharpen.Runtime.EqualsIgnoreCase("-idleiterations", args[i])) { Preconditions.CheckArgument(++i < args.Length, "idleiterations value is missing: args = " + Arrays.ToString(args)); maxIdleIteration = System.Convert.ToInt32(args[i]); Log.Info("Using a idleiterations of " + maxIdleIteration); } else { throw new ArgumentException("args = " + Arrays.ToString(args)); } } } } } } Preconditions.CheckArgument(nodesTobeExcluded.IsEmpty() || nodesTobeIncluded.IsEmpty (), "-exclude and -include options cannot be specified together."); } catch (RuntimeException e) { PrintUsage(System.Console.Error); throw; } } return(new Balancer.Parameters(policy, threshold, maxIdleIteration, nodesTobeExcluded , nodesTobeIncluded)); }