예제 #1
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);
        }
예제 #2
0
 public static NodeState ConvertFromProtoFormat(YarnProtos.NodeStateProto e)
 {
     return(NodeState.ValueOf(e.ToString().Replace(NodeStatePrefix, string.Empty)));
 }
예제 #3
0
            protected override void Render(HtmlBlock.Block html)
            {
                html.(typeof(MetricsOverviewTable));
                ResourceScheduler sched       = rm.GetResourceScheduler();
                string            type        = $(YarnWebParams.NodeState);
                string            labelFilter = $(YarnWebParams.NodeLabel, CommonNodeLabelsManager.Any).Trim
                                                    ();

                Hamlet.TBODY <Hamlet.TABLE <Org.Apache.Hadoop.Yarn.Webapp.Hamlet.Hamlet> > tbody = html
                                                                                                   .Table("#nodes").Thead().Tr().Th(".nodelabels", "Node Labels").Th(".rack", "Rack"
                                                                                                                                                                     ).Th(".state", "Node State").Th(".nodeaddress", "Node Address").Th(".nodehttpaddress"
                                                                                                                                                                                                                                        , "Node HTTP Address").Th(".lastHealthUpdate", "Last health-update").Th(".healthReport"
                                                                                                                                                                                                                                                                                                                , "Health-report").Th(".containers", "Containers").Th(".mem", "Mem Used").Th(".mem"
                                                                                                                                                                                                                                                                                                                                                                                             , "Mem Avail").Th(".vcores", "VCores Used").Th(".vcores", "VCores Avail").Th(".nodeManagerVersion"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          , "Version").().().Tbody();
                NodeState stateFilter = null;

                if (type != null && !type.IsEmpty())
                {
                    stateFilter = NodeState.ValueOf(StringUtils.ToUpperCase(type));
                }
                ICollection <RMNode> rmNodes = this.rm.GetRMContext().GetRMNodes().Values;
                bool isInactive = false;

                if (stateFilter != null)
                {
                    switch (stateFilter)
                    {
                    case NodeState.Decommissioned:
                    case NodeState.Lost:
                    case NodeState.Rebooted:
                    {
                        rmNodes    = this.rm.GetRMContext().GetInactiveRMNodes().Values;
                        isInactive = true;
                        break;
                    }

                    default:
                    {
                        Log.Debug("Unexpected state filter for inactive RM node");
                        break;
                    }
                    }
                }
                foreach (RMNode ni in rmNodes)
                {
                    if (stateFilter != null)
                    {
                        NodeState state = ni.GetState();
                        if (!stateFilter.Equals(state))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // No filter. User is asking for all nodes. Make sure you skip the
                        // unhealthy nodes.
                        if (ni.GetState() == NodeState.Unhealthy)
                        {
                            continue;
                        }
                    }
                    // Besides state, we need to filter label as well.
                    if (!labelFilter.Equals(RMNodeLabelsManager.Any))
                    {
                        if (labelFilter.IsEmpty())
                        {
                            // Empty label filter means only shows nodes without label
                            if (!ni.GetNodeLabels().IsEmpty())
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (!ni.GetNodeLabels().Contains(labelFilter))
                            {
                                // Only nodes have given label can show on web page.
                                continue;
                            }
                        }
                    }
                    NodeInfo info            = new NodeInfo(ni, sched);
                    int      usedMemory      = (int)info.GetUsedMemory();
                    int      availableMemory = (int)info.GetAvailableMemory();
                    Hamlet.TR <Hamlet.TBODY <Hamlet.TABLE <Org.Apache.Hadoop.Yarn.Webapp.Hamlet.Hamlet> >
                               > row = tbody.Tr().Td(StringUtils.Join(",", info.GetNodeLabels())).Td(info.GetRack
                                                                                                         ()).Td(info.GetState()).Td(info.GetNodeId());
                    if (isInactive)
                    {
                        row.Td().("N/A").();
                    }
                    else
                    {
                        string httpAddress = info.GetNodeHTTPAddress();
                        row.Td().A("//" + httpAddress, httpAddress).();
                    }
                    row.Td().Br().$title(info.GetLastHealthUpdate().ToString()).().(Times.Format(info
                                                                                                 .GetLastHealthUpdate())).().Td(info.GetHealthReport()).Td(info.GetNumContainers(
                                                                                                                                                               ).ToString()).Td().Br().$title(usedMemory.ToString()).().(StringUtils.ByteDesc(usedMemory
                                                                                                                                                                                                                                              * BytesInMb)).().Td().Br().$title(availableMemory.ToString()).().(StringUtils.ByteDesc
                                                                                                                                                                                                                                                                                                                    (availableMemory * BytesInMb)).().Td(info.GetUsedVirtualCores().ToString()).Td(info
                                                                                                                                                                                                                                                                                                                                                                                                   .GetAvailableVirtualCores().ToString()).Td(ni.GetNodeManagerVersion()).();
                }
                tbody.().();
            }