Beispiel #1
0
        public static IList <RMNode> DeactivatedNodes(int racks, int nodesPerRack, Resource
                                                      perNode)
        {
            IList <RMNode> list = Lists.NewArrayList();

            for (int i = 0; i < racks; ++i)
            {
                for (int j = 0; j < nodesPerRack; ++j)
                {
                    NodeState[] allStates = NodeState.Values();
                    list.AddItem(NodeInfo(i, perNode, allStates[j % allStates.Length]));
                }
            }
            return(list);
        }
Beispiel #2
0
        /// <exception cref="System.Exception"/>
        public override int Run(string[] args)
        {
            Options opts = new Options();

            opts.AddOption(HelpCmd, false, "Displays help for all commands.");
            opts.AddOption(StatusCmd, true, "Prints the status report of the node.");
            opts.AddOption(ListCmd, false, "List all running nodes. " + "Supports optional use of -states to filter nodes "
                           + "based on node state, all -all to list all nodes.");
            Option nodeStateOpt = new Option(NodeStateCmd, true, "Works with -list to filter nodes based on input comma-separated list of node states."
                                             );

            nodeStateOpt.SetValueSeparator(',');
            nodeStateOpt.SetArgs(Option.UnlimitedValues);
            nodeStateOpt.SetArgName("States");
            opts.AddOption(nodeStateOpt);
            Option allOpt = new Option(NodeAll, false, "Works with -list to list all nodes.");

            opts.AddOption(allOpt);
            opts.GetOption(StatusCmd).SetArgName("NodeId");
            int         exitCode  = -1;
            CommandLine cliParser = null;

            try
            {
                cliParser = new GnuParser().Parse(opts, args);
            }
            catch (MissingArgumentException)
            {
                sysout.WriteLine("Missing argument for options");
                PrintUsage(opts);
                return(exitCode);
            }
            if (cliParser.HasOption("status"))
            {
                if (args.Length != 2)
                {
                    PrintUsage(opts);
                    return(exitCode);
                }
                PrintNodeStatus(cliParser.GetOptionValue("status"));
            }
            else
            {
                if (cliParser.HasOption("list"))
                {
                    ICollection <NodeState> nodeStates = new HashSet <NodeState>();
                    if (cliParser.HasOption(NodeAll))
                    {
                        foreach (NodeState state in NodeState.Values())
                        {
                            nodeStates.AddItem(state);
                        }
                    }
                    else
                    {
                        if (cliParser.HasOption(NodeStateCmd))
                        {
                            string[] types = cliParser.GetOptionValues(NodeStateCmd);
                            if (types != null)
                            {
                                foreach (string type in types)
                                {
                                    if (!type.Trim().IsEmpty())
                                    {
                                        nodeStates.AddItem(NodeState.ValueOf(StringUtils.ToUpperCase(type.Trim())));
                                    }
                                }
                            }
                        }
                        else
                        {
                            nodeStates.AddItem(NodeState.Running);
                        }
                    }
                    ListClusterNodes(nodeStates);
                }
                else
                {
                    if (cliParser.HasOption(HelpCmd))
                    {
                        PrintUsage(opts);
                        return(0);
                    }
                    else
                    {
                        syserr.WriteLine("Invalid Command Usage : ");
                        PrintUsage(opts);
                    }
                }
            }
            return(0);
        }