/// <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); }
/// <exception cref="System.Exception"/> public override int Run(string[] args) { Options opts = new Options(); string title = null; if (args.Length > 0 && Sharpen.Runtime.EqualsIgnoreCase(args[0], Application)) { title = Application; opts.AddOption(StatusCmd, true, "Prints the status of the application."); opts.AddOption(ListCmd, false, "List applications. " + "Supports optional use of -appTypes to filter applications " + "based on application type, " + "and -appStates to filter applications based on application state." ); opts.AddOption(KillCmd, true, "Kills the application."); opts.AddOption(MoveToQueueCmd, true, "Moves the application to a " + "different queue." ); opts.AddOption(QueueCmd, true, "Works with the movetoqueue command to" + " specify which queue to move an application to." ); opts.AddOption(HelpCmd, false, "Displays help for all commands."); Option appTypeOpt = new Option(AppTypeCmd, true, "Works with -list to " + "filter applications based on " + "input comma-separated list of application types."); appTypeOpt.SetValueSeparator(','); appTypeOpt.SetArgs(Option.UnlimitedValues); appTypeOpt.SetArgName("Types"); opts.AddOption(appTypeOpt); Option appStateOpt = new Option(AppStateCmd, true, "Works with -list " + "to filter applications based on input comma-separated list of " + "application states. " + GetAllValidApplicationStates()); appStateOpt.SetValueSeparator(','); appStateOpt.SetArgs(Option.UnlimitedValues); appStateOpt.SetArgName("States"); opts.AddOption(appStateOpt); opts.GetOption(KillCmd).SetArgName("Application ID"); opts.GetOption(MoveToQueueCmd).SetArgName("Application ID"); opts.GetOption(QueueCmd).SetArgName("Queue Name"); opts.GetOption(StatusCmd).SetArgName("Application ID"); } else { if (args.Length > 0 && Sharpen.Runtime.EqualsIgnoreCase(args[0], ApplicationAttempt )) { title = ApplicationAttempt; opts.AddOption(StatusCmd, true, "Prints the status of the application attempt."); opts.AddOption(ListCmd, true, "List application attempts for aplication."); opts.AddOption(HelpCmd, false, "Displays help for all commands."); opts.GetOption(StatusCmd).SetArgName("Application Attempt ID"); opts.GetOption(ListCmd).SetArgName("Application ID"); } else { if (args.Length > 0 && Sharpen.Runtime.EqualsIgnoreCase(args[0], Container)) { title = Container; opts.AddOption(StatusCmd, true, "Prints the status of the container."); opts.AddOption(ListCmd, true, "List containers for application attempt."); opts.AddOption(HelpCmd, false, "Displays help for all commands."); opts.GetOption(StatusCmd).SetArgName("Container ID"); opts.GetOption(ListCmd).SetArgName("Application Attempt ID"); } } } int exitCode = -1; CommandLine cliParser = null; try { cliParser = new GnuParser().Parse(opts, args); } catch (MissingArgumentException) { sysout.WriteLine("Missing argument for options"); PrintUsage(title, opts); return(exitCode); } if (cliParser.HasOption(StatusCmd)) { if (args.Length != 3) { PrintUsage(title, opts); return(exitCode); } if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Application)) { exitCode = PrintApplicationReport(cliParser.GetOptionValue(StatusCmd)); } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[0], ApplicationAttempt)) { exitCode = PrintApplicationAttemptReport(cliParser.GetOptionValue(StatusCmd)); } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Container)) { exitCode = PrintContainerReport(cliParser.GetOptionValue(StatusCmd)); } } } return(exitCode); } else { if (cliParser.HasOption(ListCmd)) { if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Application)) { allAppStates = false; ICollection <string> appTypes = new HashSet <string>(); if (cliParser.HasOption(AppTypeCmd)) { string[] types = cliParser.GetOptionValues(AppTypeCmd); if (types != null) { foreach (string type in types) { if (!type.Trim().IsEmpty()) { appTypes.AddItem(StringUtils.ToUpperCase(type).Trim()); } } } } EnumSet <YarnApplicationState> appStates = EnumSet.NoneOf <YarnApplicationState>(); if (cliParser.HasOption(AppStateCmd)) { string[] states = cliParser.GetOptionValues(AppStateCmd); if (states != null) { foreach (string state in states) { if (!state.Trim().IsEmpty()) { if (Sharpen.Runtime.EqualsIgnoreCase(state.Trim(), AllstatesOption)) { allAppStates = true; break; } try { appStates.AddItem(YarnApplicationState.ValueOf(StringUtils.ToUpperCase(state).Trim ())); } catch (ArgumentException) { sysout.WriteLine("The application state " + state + " is invalid."); sysout.WriteLine(GetAllValidApplicationStates()); return(exitCode); } } } } } ListApplications(appTypes, appStates); } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[0], ApplicationAttempt)) { if (args.Length != 3) { PrintUsage(title, opts); return(exitCode); } ListApplicationAttempts(cliParser.GetOptionValue(ListCmd)); } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Container)) { if (args.Length != 3) { PrintUsage(title, opts); return(exitCode); } ListContainers(cliParser.GetOptionValue(ListCmd)); } } } } else { if (cliParser.HasOption(KillCmd)) { if (args.Length != 3) { PrintUsage(title, opts); return(exitCode); } try { KillApplication(cliParser.GetOptionValue(KillCmd)); } catch (ApplicationNotFoundException) { return(exitCode); } } else { if (cliParser.HasOption(MoveToQueueCmd)) { if (!cliParser.HasOption(QueueCmd)) { PrintUsage(title, opts); return(exitCode); } MoveApplicationAcrossQueues(cliParser.GetOptionValue(MoveToQueueCmd), cliParser.GetOptionValue (QueueCmd)); } else { if (cliParser.HasOption(HelpCmd)) { PrintUsage(title, opts); return(0); } else { syserr.WriteLine("Invalid Command Usage : "); PrintUsage(title, opts); } } } } } return(0); }
/// <summary>Parse command line options</summary> /// <param name="args">Parsed command line options</param> /// <returns>Whether the init was successful to run the client</returns> /// <exception cref="Org.Apache.Commons.Cli.ParseException"/> public virtual bool Init(string[] args) { CommandLine cliParser = new GnuParser().Parse(opts, args); if (args.Length == 0) { throw new ArgumentException("No args specified for client to initialize"); } if (cliParser.HasOption("log_properties")) { string log4jPath = cliParser.GetOptionValue("log_properties"); try { Log4jPropertyHelper.UpdateLog4jConfiguration(typeof(Org.Apache.Hadoop.Yarn.Applications.Distributedshell.Client ), log4jPath); } catch (Exception e) { Log.Warn("Can not set up custom log4j properties. " + e); } } if (cliParser.HasOption("help")) { PrintUsage(); return(false); } if (cliParser.HasOption("debug")) { debugFlag = true; } if (cliParser.HasOption("keep_containers_across_application_attempts")) { Log.Info("keep_containers_across_application_attempts"); keepContainers = true; } appName = cliParser.GetOptionValue("appname", "DistributedShell"); amPriority = System.Convert.ToInt32(cliParser.GetOptionValue("priority", "0")); amQueue = cliParser.GetOptionValue("queue", "default"); amMemory = System.Convert.ToInt32(cliParser.GetOptionValue("master_memory", "10") ); amVCores = System.Convert.ToInt32(cliParser.GetOptionValue("master_vcores", "1")); if (amMemory < 0) { throw new ArgumentException("Invalid memory specified for application master, exiting." + " Specified memory=" + amMemory); } if (amVCores < 0) { throw new ArgumentException("Invalid virtual cores specified for application master, exiting." + " Specified virtual cores=" + amVCores); } if (!cliParser.HasOption("jar")) { throw new ArgumentException("No jar file specified for application master"); } appMasterJar = cliParser.GetOptionValue("jar"); if (!cliParser.HasOption("shell_command") && !cliParser.HasOption("shell_script")) { throw new ArgumentException("No shell command or shell script specified to be executed by application master" ); } else { if (cliParser.HasOption("shell_command") && cliParser.HasOption("shell_script")) { throw new ArgumentException("Can not specify shell_command option " + "and shell_script option at the same time" ); } else { if (cliParser.HasOption("shell_command")) { shellCommand = cliParser.GetOptionValue("shell_command"); } else { shellScriptPath = cliParser.GetOptionValue("shell_script"); } } } if (cliParser.HasOption("shell_args")) { shellArgs = cliParser.GetOptionValues("shell_args"); } if (cliParser.HasOption("shell_env")) { string[] envs = cliParser.GetOptionValues("shell_env"); foreach (string env in envs) { env = env.Trim(); int index = env.IndexOf('='); if (index == -1) { shellEnv[env] = string.Empty; continue; } string key = Sharpen.Runtime.Substring(env, 0, index); string val = string.Empty; if (index < (env.Length - 1)) { val = Sharpen.Runtime.Substring(env, index + 1); } shellEnv[key] = val; } } shellCmdPriority = System.Convert.ToInt32(cliParser.GetOptionValue("shell_cmd_priority" , "0")); containerMemory = System.Convert.ToInt32(cliParser.GetOptionValue("container_memory" , "10")); containerVirtualCores = System.Convert.ToInt32(cliParser.GetOptionValue("container_vcores" , "1")); numContainers = System.Convert.ToInt32(cliParser.GetOptionValue("num_containers", "1")); if (containerMemory < 0 || containerVirtualCores < 0 || numContainers < 1) { throw new ArgumentException("Invalid no. of containers or container memory/vcores specified," + " exiting." + " Specified containerMemory=" + containerMemory + ", containerVirtualCores=" + containerVirtualCores + ", numContainer=" + numContainers); } nodeLabelExpression = cliParser.GetOptionValue("node_label_expression", null); clientTimeout = System.Convert.ToInt32(cliParser.GetOptionValue("timeout", "600000" )); attemptFailuresValidityInterval = long.Parse(cliParser.GetOptionValue("attempt_failures_validity_interval" , "-1")); log4jPropFile = cliParser.GetOptionValue("log_properties", string.Empty); // Get timeline domain options if (cliParser.HasOption("domain")) { domainId = cliParser.GetOptionValue("domain"); toCreateDomain = cliParser.HasOption("create"); if (cliParser.HasOption("view_acls")) { viewACLs = cliParser.GetOptionValue("view_acls"); } if (cliParser.HasOption("modify_acls")) { modifyACLs = cliParser.GetOptionValue("modify_acls"); } } return(true); }