Ejemplo n.º 1
0
        /// <summary>Displays format of commands.</summary>
        /// <param name="cmd">The command that is being executed.</param>
        private static void PrintUsage(string cmd, bool isHAEnabled)
        {
            StringBuilder usageBuilder = new StringBuilder();

            if (AdminUsage.Contains(cmd) || Usage.Contains(cmd))
            {
                BuildIndividualUsageMsg(cmd, usageBuilder);
            }
            else
            {
                BuildUsageMsg(usageBuilder, isHAEnabled);
            }
            System.Console.Error.WriteLine(usageBuilder);
            ToolRunner.PrintGenericCommandUsage(System.Console.Error);
        }
Ejemplo n.º 2
0
        /// <exception cref="System.Exception"/>
        public override int Run(string[] args)
        {
            // -directlyAccessNodeLabelStore is a additional option for node label
            // access, so just search if we have specified this option, and remove it
            IList <string> argsList = new AList <string>();

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("-directlyAccessNodeLabelStore"))
                {
                    directlyAccessNodeLabelStore = true;
                }
                else
                {
                    argsList.AddItem(args[i]);
                }
            }
            args = Sharpen.Collections.ToArray(argsList, new string[0]);
            YarnConfiguration yarnConf = GetConf() == null ? new YarnConfiguration() : new YarnConfiguration
                                             (GetConf());
            bool isHAEnabled = yarnConf.GetBoolean(YarnConfiguration.RmHaEnabled, YarnConfiguration
                                                   .DefaultRmHaEnabled);

            if (args.Length < 1)
            {
                PrintUsage(string.Empty, isHAEnabled);
                return(-1);
            }
            int    exitCode = -1;
            int    i_1      = 0;
            string cmd      = args[i_1++];

            exitCode = 0;
            if ("-help".Equals(cmd))
            {
                if (i_1 < args.Length)
                {
                    PrintUsage(args[i_1], isHAEnabled);
                }
                else
                {
                    PrintHelp(string.Empty, isHAEnabled);
                }
                return(exitCode);
            }
            if (Usage.Contains(cmd))
            {
                if (isHAEnabled)
                {
                    return(base.Run(args));
                }
                System.Console.Out.WriteLine("Cannot run " + cmd + " when ResourceManager HA is not enabled"
                                             );
                return(-1);
            }
            //
            // verify that we have enough command line parameters
            //
            if ("-refreshAdminAcls".Equals(cmd) || "-refreshQueues".Equals(cmd) || "-refreshNodes"
                .Equals(cmd) || "-refreshServiceAcl".Equals(cmd) || "-refreshUserToGroupsMappings"
                .Equals(cmd) || "-refreshSuperUserGroupsConfiguration".Equals(cmd))
            {
                if (args.Length != 1)
                {
                    PrintUsage(cmd, isHAEnabled);
                    return(exitCode);
                }
            }
            try
            {
                if ("-refreshQueues".Equals(cmd))
                {
                    exitCode = RefreshQueues();
                }
                else
                {
                    if ("-refreshNodes".Equals(cmd))
                    {
                        exitCode = RefreshNodes();
                    }
                    else
                    {
                        if ("-refreshUserToGroupsMappings".Equals(cmd))
                        {
                            exitCode = RefreshUserToGroupsMappings();
                        }
                        else
                        {
                            if ("-refreshSuperUserGroupsConfiguration".Equals(cmd))
                            {
                                exitCode = RefreshSuperUserGroupsConfiguration();
                            }
                            else
                            {
                                if ("-refreshAdminAcls".Equals(cmd))
                                {
                                    exitCode = RefreshAdminAcls();
                                }
                                else
                                {
                                    if ("-refreshServiceAcl".Equals(cmd))
                                    {
                                        exitCode = RefreshServiceAcls();
                                    }
                                    else
                                    {
                                        if ("-getGroups".Equals(cmd))
                                        {
                                            string[] usernames = Arrays.CopyOfRange(args, i_1, args.Length);
                                            exitCode = GetGroups(usernames);
                                        }
                                        else
                                        {
                                            if ("-addToClusterNodeLabels".Equals(cmd))
                                            {
                                                if (i_1 >= args.Length)
                                                {
                                                    System.Console.Error.WriteLine(NoLabelErrMsg);
                                                    exitCode = -1;
                                                }
                                                else
                                                {
                                                    exitCode = AddToClusterNodeLabels(args[i_1]);
                                                }
                                            }
                                            else
                                            {
                                                if ("-removeFromClusterNodeLabels".Equals(cmd))
                                                {
                                                    if (i_1 >= args.Length)
                                                    {
                                                        System.Console.Error.WriteLine(NoLabelErrMsg);
                                                        exitCode = -1;
                                                    }
                                                    else
                                                    {
                                                        exitCode = RemoveFromClusterNodeLabels(args[i_1]);
                                                    }
                                                }
                                                else
                                                {
                                                    if ("-replaceLabelsOnNode".Equals(cmd))
                                                    {
                                                        if (i_1 >= args.Length)
                                                        {
                                                            System.Console.Error.WriteLine(NoMappingErrMsg);
                                                            exitCode = -1;
                                                        }
                                                        else
                                                        {
                                                            exitCode = ReplaceLabelsOnNodes(args[i_1]);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        exitCode = -1;
                                                        System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": Unknown command"
                                                                                       );
                                                        PrintUsage(string.Empty, isHAEnabled);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (ArgumentException arge)
            {
                exitCode = -1;
                System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + arge.GetLocalizedMessage
                                                   ());
                PrintUsage(cmd, isHAEnabled);
            }
            catch (RemoteException e)
            {
                //
                // This is a error returned by hadoop server. Print
                // out the first line of the error mesage, ignore the stack trace.
                exitCode = -1;
                try
                {
                    string[] content;
                    content = e.GetLocalizedMessage().Split("\n");
                    System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + content
                                                   [0]);
                }
                catch (Exception ex)
                {
                    System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + ex.GetLocalizedMessage
                                                       ());
                }
            }
            catch (Exception e)
            {
                exitCode = -1;
                System.Console.Error.WriteLine(Sharpen.Runtime.Substring(cmd, 1) + ": " + e.GetLocalizedMessage
                                                   ());
            }
            if (null != localNodeLabelsManager)
            {
                localNodeLabelsManager.Stop();
            }
            return(exitCode);
        }