Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestFailResultCodes()
        {
            Configuration conf = new YarnConfiguration();

            conf.SetClass("fs.file.impl", typeof(LocalFileSystem), typeof(FileSystem));
            LogCLIHelpers cliHelper = new LogCLIHelpers();

            cliHelper.SetConf(conf);
            YarnClient mockYarnClient = CreateMockYarnClient(YarnApplicationState.Finished);
            LogsCLI    dumper         = new TestLogsCLI.LogsCLIForTest(mockYarnClient);

            dumper.SetConf(conf);
            // verify dumping a non-existent application's logs returns a failure code
            int exitCode = dumper.Run(new string[] { "-applicationId", "application_0_0" });

            NUnit.Framework.Assert.IsTrue("Should return an error code", exitCode != 0);
            // verify dumping a non-existent container log is a failure code
            exitCode = cliHelper.DumpAContainersLogs("application_0_0", "container_0_0", "nonexistentnode:1234"
                                                     , "nobody");
            NUnit.Framework.Assert.IsTrue("Should return an error code", exitCode != 0);
        }
Пример #2
0
        /// <exception cref="System.Exception"/>
        public virtual int Run(string[] args)
        {
            Options opts = new Options();

            opts.AddOption(HelpCmd, false, "Displays help for all commands.");
            Option appIdOpt = new Option(ApplicationIdOption, true, "ApplicationId (required)"
                                         );

            appIdOpt.SetRequired(true);
            opts.AddOption(appIdOpt);
            opts.AddOption(ContainerIdOption, true, "ContainerId (must be specified if node address is specified)"
                           );
            opts.AddOption(NodeAddressOption, true, "NodeAddress in the format " + "nodename:port (must be specified if container id is specified)"
                           );
            opts.AddOption(AppOwnerOption, true, "AppOwner (assumed to be current user if not specified)"
                           );
            opts.GetOption(ApplicationIdOption).SetArgName("Application ID");
            opts.GetOption(ContainerIdOption).SetArgName("Container ID");
            opts.GetOption(NodeAddressOption).SetArgName("Node Address");
            opts.GetOption(AppOwnerOption).SetArgName("Application Owner");
            Options printOpts = new Options();

            printOpts.AddOption(opts.GetOption(HelpCmd));
            printOpts.AddOption(opts.GetOption(ContainerIdOption));
            printOpts.AddOption(opts.GetOption(NodeAddressOption));
            printOpts.AddOption(opts.GetOption(AppOwnerOption));
            if (args.Length < 1)
            {
                PrintHelpMessage(printOpts);
                return(-1);
            }
            if (args[0].Equals("-help"))
            {
                PrintHelpMessage(printOpts);
                return(0);
            }
            CommandLineParser parser         = new GnuParser();
            string            appIdStr       = null;
            string            containerIdStr = null;
            string            nodeAddress    = null;
            string            appOwner       = null;

            try
            {
                CommandLine commandLine = parser.Parse(opts, args, true);
                appIdStr       = commandLine.GetOptionValue(ApplicationIdOption);
                containerIdStr = commandLine.GetOptionValue(ContainerIdOption);
                nodeAddress    = commandLine.GetOptionValue(NodeAddressOption);
                appOwner       = commandLine.GetOptionValue(AppOwnerOption);
            }
            catch (ParseException e)
            {
                System.Console.Error.WriteLine("options parsing failed: " + e.Message);
                PrintHelpMessage(printOpts);
                return(-1);
            }
            if (appIdStr == null)
            {
                System.Console.Error.WriteLine("ApplicationId cannot be null!");
                PrintHelpMessage(printOpts);
                return(-1);
            }
            ApplicationId appId = null;

            try
            {
                appId = ConverterUtils.ToApplicationId(appIdStr);
            }
            catch (Exception)
            {
                System.Console.Error.WriteLine("Invalid ApplicationId specified");
                return(-1);
            }
            try
            {
                int resultCode = VerifyApplicationState(appId);
                if (resultCode != 0)
                {
                    System.Console.Out.WriteLine("Logs are not avaiable right now.");
                    return(resultCode);
                }
            }
            catch (Exception)
            {
                System.Console.Error.WriteLine("Unable to get ApplicationState." + " Attempting to fetch logs directly from the filesystem."
                                               );
            }
            LogCLIHelpers logCliHelper = new LogCLIHelpers();

            logCliHelper.SetConf(GetConf());
            if (appOwner == null || appOwner.IsEmpty())
            {
                appOwner = UserGroupInformation.GetCurrentUser().GetShortUserName();
            }
            int resultCode_1 = 0;

            if (containerIdStr == null && nodeAddress == null)
            {
                resultCode_1 = logCliHelper.DumpAllContainersLogs(appId, appOwner, System.Console.Out
                                                                  );
            }
            else
            {
                if ((containerIdStr == null && nodeAddress != null) || (containerIdStr != null &&
                                                                        nodeAddress == null))
                {
                    System.Console.Out.WriteLine("ContainerId or NodeAddress cannot be null!");
                    PrintHelpMessage(printOpts);
                    resultCode_1 = -1;
                }
                else
                {
                    resultCode_1 = logCliHelper.DumpAContainersLogs(appIdStr, containerIdStr, nodeAddress
                                                                    , appOwner);
                }
            }
            return(resultCode_1);
        }
Пример #3
0
        /// <exception cref="System.Exception"/>
        public virtual int Run(string[] argv)
        {
            int exitCode = -1;

            if (argv.Length < 1)
            {
                DisplayUsage(string.Empty);
                return(exitCode);
            }
            // process arguments
            string      cmd              = argv[0];
            string      submitJobFile    = null;
            string      jobid            = null;
            string      taskid           = null;
            string      historyFile      = null;
            string      counterGroupName = null;
            string      counterName      = null;
            JobPriority jp                      = null;
            string      taskType                = null;
            string      taskState               = null;
            int         fromEvent               = 0;
            int         nEvents                 = 0;
            bool        getStatus               = false;
            bool        getCounter              = false;
            bool        killJob                 = false;
            bool        listEvents              = false;
            bool        viewHistory             = false;
            bool        viewAllHistory          = false;
            bool        listJobs                = false;
            bool        listAllJobs             = false;
            bool        listActiveTrackers      = false;
            bool        listBlacklistedTrackers = false;
            bool        displayTasks            = false;
            bool        killTask                = false;
            bool        failTask                = false;
            bool        setJobPriority          = false;
            bool        logs                    = false;

            if ("-submit".Equals(cmd))
            {
                if (argv.Length != 2)
                {
                    DisplayUsage(cmd);
                    return(exitCode);
                }
                submitJobFile = argv[1];
            }
            else
            {
                if ("-status".Equals(cmd))
                {
                    if (argv.Length != 2)
                    {
                        DisplayUsage(cmd);
                        return(exitCode);
                    }
                    jobid     = argv[1];
                    getStatus = true;
                }
                else
                {
                    if ("-counter".Equals(cmd))
                    {
                        if (argv.Length != 4)
                        {
                            DisplayUsage(cmd);
                            return(exitCode);
                        }
                        getCounter       = true;
                        jobid            = argv[1];
                        counterGroupName = argv[2];
                        counterName      = argv[3];
                    }
                    else
                    {
                        if ("-kill".Equals(cmd))
                        {
                            if (argv.Length != 2)
                            {
                                DisplayUsage(cmd);
                                return(exitCode);
                            }
                            jobid   = argv[1];
                            killJob = true;
                        }
                        else
                        {
                            if ("-set-priority".Equals(cmd))
                            {
                                if (argv.Length != 3)
                                {
                                    DisplayUsage(cmd);
                                    return(exitCode);
                                }
                                jobid = argv[1];
                                try
                                {
                                    jp = JobPriority.ValueOf(argv[2]);
                                }
                                catch (ArgumentException iae)
                                {
                                    Log.Info(iae);
                                    DisplayUsage(cmd);
                                    return(exitCode);
                                }
                                setJobPriority = true;
                            }
                            else
                            {
                                if ("-events".Equals(cmd))
                                {
                                    if (argv.Length != 4)
                                    {
                                        DisplayUsage(cmd);
                                        return(exitCode);
                                    }
                                    jobid      = argv[1];
                                    fromEvent  = System.Convert.ToInt32(argv[2]);
                                    nEvents    = System.Convert.ToInt32(argv[3]);
                                    listEvents = true;
                                }
                                else
                                {
                                    if ("-history".Equals(cmd))
                                    {
                                        if (argv.Length != 2 && !(argv.Length == 3 && "all".Equals(argv[1])))
                                        {
                                            DisplayUsage(cmd);
                                            return(exitCode);
                                        }
                                        viewHistory = true;
                                        if (argv.Length == 3 && "all".Equals(argv[1]))
                                        {
                                            viewAllHistory = true;
                                            historyFile    = argv[2];
                                        }
                                        else
                                        {
                                            historyFile = argv[1];
                                        }
                                    }
                                    else
                                    {
                                        if ("-list".Equals(cmd))
                                        {
                                            if (argv.Length != 1 && !(argv.Length == 2 && "all".Equals(argv[1])))
                                            {
                                                DisplayUsage(cmd);
                                                return(exitCode);
                                            }
                                            if (argv.Length == 2 && "all".Equals(argv[1]))
                                            {
                                                listAllJobs = true;
                                            }
                                            else
                                            {
                                                listJobs = true;
                                            }
                                        }
                                        else
                                        {
                                            if ("-kill-task".Equals(cmd))
                                            {
                                                if (argv.Length != 2)
                                                {
                                                    DisplayUsage(cmd);
                                                    return(exitCode);
                                                }
                                                killTask = true;
                                                taskid   = argv[1];
                                            }
                                            else
                                            {
                                                if ("-fail-task".Equals(cmd))
                                                {
                                                    if (argv.Length != 2)
                                                    {
                                                        DisplayUsage(cmd);
                                                        return(exitCode);
                                                    }
                                                    failTask = true;
                                                    taskid   = argv[1];
                                                }
                                                else
                                                {
                                                    if ("-list-active-trackers".Equals(cmd))
                                                    {
                                                        if (argv.Length != 1)
                                                        {
                                                            DisplayUsage(cmd);
                                                            return(exitCode);
                                                        }
                                                        listActiveTrackers = true;
                                                    }
                                                    else
                                                    {
                                                        if ("-list-blacklisted-trackers".Equals(cmd))
                                                        {
                                                            if (argv.Length != 1)
                                                            {
                                                                DisplayUsage(cmd);
                                                                return(exitCode);
                                                            }
                                                            listBlacklistedTrackers = true;
                                                        }
                                                        else
                                                        {
                                                            if ("-list-attempt-ids".Equals(cmd))
                                                            {
                                                                if (argv.Length != 4)
                                                                {
                                                                    DisplayUsage(cmd);
                                                                    return(exitCode);
                                                                }
                                                                jobid        = argv[1];
                                                                taskType     = argv[2];
                                                                taskState    = argv[3];
                                                                displayTasks = true;
                                                                if (!taskTypes.Contains(StringUtils.ToUpperCase(taskType)))
                                                                {
                                                                    System.Console.Out.WriteLine("Error: Invalid task-type: " + taskType);
                                                                    DisplayUsage(cmd);
                                                                    return(exitCode);
                                                                }
                                                                if (!taskStates.Contains(StringUtils.ToLowerCase(taskState)))
                                                                {
                                                                    System.Console.Out.WriteLine("Error: Invalid task-state: " + taskState);
                                                                    DisplayUsage(cmd);
                                                                    return(exitCode);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if ("-logs".Equals(cmd))
                                                                {
                                                                    if (argv.Length == 2 || argv.Length == 3)
                                                                    {
                                                                        logs  = true;
                                                                        jobid = argv[1];
                                                                        if (argv.Length == 3)
                                                                        {
                                                                            taskid = argv[2];
                                                                        }
                                                                        else
                                                                        {
                                                                            taskid = null;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        DisplayUsage(cmd);
                                                                        return(exitCode);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    DisplayUsage(cmd);
                                                                    return(exitCode);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // initialize cluster
            cluster = CreateCluster();
            // Submit the request
            try
            {
                if (submitJobFile != null)
                {
                    Job job = Job.GetInstance(new JobConf(submitJobFile));
                    job.Submit();
                    System.Console.Out.WriteLine("Created job " + job.GetJobID());
                    exitCode = 0;
                }
                else
                {
                    if (getStatus)
                    {
                        Job job = cluster.GetJob(JobID.ForName(jobid));
                        if (job == null)
                        {
                            System.Console.Out.WriteLine("Could not find job " + jobid);
                        }
                        else
                        {
                            Counters counters = job.GetCounters();
                            System.Console.Out.WriteLine();
                            System.Console.Out.WriteLine(job);
                            if (counters != null)
                            {
                                System.Console.Out.WriteLine(counters);
                            }
                            else
                            {
                                System.Console.Out.WriteLine("Counters not available. Job is retired.");
                            }
                            exitCode = 0;
                        }
                    }
                    else
                    {
                        if (getCounter)
                        {
                            Job job = cluster.GetJob(JobID.ForName(jobid));
                            if (job == null)
                            {
                                System.Console.Out.WriteLine("Could not find job " + jobid);
                            }
                            else
                            {
                                Counters counters = job.GetCounters();
                                if (counters == null)
                                {
                                    System.Console.Out.WriteLine("Counters not available for retired job " + jobid);
                                    exitCode = -1;
                                }
                                else
                                {
                                    System.Console.Out.WriteLine(GetCounter(counters, counterGroupName, counterName));
                                    exitCode = 0;
                                }
                            }
                        }
                        else
                        {
                            if (killJob)
                            {
                                Job job = cluster.GetJob(JobID.ForName(jobid));
                                if (job == null)
                                {
                                    System.Console.Out.WriteLine("Could not find job " + jobid);
                                }
                                else
                                {
                                    JobStatus jobStatus = job.GetStatus();
                                    if (jobStatus.GetState() == JobStatus.State.Failed)
                                    {
                                        System.Console.Out.WriteLine("Could not mark the job " + jobid + " as killed, as it has already failed."
                                                                     );
                                        exitCode = -1;
                                    }
                                    else
                                    {
                                        if (jobStatus.GetState() == JobStatus.State.Killed)
                                        {
                                            System.Console.Out.WriteLine("The job " + jobid + " has already been killed.");
                                            exitCode = -1;
                                        }
                                        else
                                        {
                                            if (jobStatus.GetState() == JobStatus.State.Succeeded)
                                            {
                                                System.Console.Out.WriteLine("Could not kill the job " + jobid + ", as it has already succeeded."
                                                                             );
                                                exitCode = -1;
                                            }
                                            else
                                            {
                                                job.KillJob();
                                                System.Console.Out.WriteLine("Killed job " + jobid);
                                                exitCode = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (setJobPriority)
                                {
                                    Job job = cluster.GetJob(JobID.ForName(jobid));
                                    if (job == null)
                                    {
                                        System.Console.Out.WriteLine("Could not find job " + jobid);
                                    }
                                    else
                                    {
                                        job.SetPriority(jp);
                                        System.Console.Out.WriteLine("Changed job priority.");
                                        exitCode = 0;
                                    }
                                }
                                else
                                {
                                    if (viewHistory)
                                    {
                                        ViewHistory(historyFile, viewAllHistory);
                                        exitCode = 0;
                                    }
                                    else
                                    {
                                        if (listEvents)
                                        {
                                            ListEvents(cluster.GetJob(JobID.ForName(jobid)), fromEvent, nEvents);
                                            exitCode = 0;
                                        }
                                        else
                                        {
                                            if (listJobs)
                                            {
                                                ListJobs(cluster);
                                                exitCode = 0;
                                            }
                                            else
                                            {
                                                if (listAllJobs)
                                                {
                                                    ListAllJobs(cluster);
                                                    exitCode = 0;
                                                }
                                                else
                                                {
                                                    if (listActiveTrackers)
                                                    {
                                                        ListActiveTrackers(cluster);
                                                        exitCode = 0;
                                                    }
                                                    else
                                                    {
                                                        if (listBlacklistedTrackers)
                                                        {
                                                            ListBlacklistedTrackers(cluster);
                                                            exitCode = 0;
                                                        }
                                                        else
                                                        {
                                                            if (displayTasks)
                                                            {
                                                                DisplayTasks(cluster.GetJob(JobID.ForName(jobid)), taskType, taskState);
                                                                exitCode = 0;
                                                            }
                                                            else
                                                            {
                                                                if (killTask)
                                                                {
                                                                    TaskAttemptID taskID = TaskAttemptID.ForName(taskid);
                                                                    Job           job    = cluster.GetJob(taskID.GetJobID());
                                                                    if (job == null)
                                                                    {
                                                                        System.Console.Out.WriteLine("Could not find job " + jobid);
                                                                    }
                                                                    else
                                                                    {
                                                                        if (job.KillTask(taskID, false))
                                                                        {
                                                                            System.Console.Out.WriteLine("Killed task " + taskid);
                                                                            exitCode = 0;
                                                                        }
                                                                        else
                                                                        {
                                                                            System.Console.Out.WriteLine("Could not kill task " + taskid);
                                                                            exitCode = -1;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (failTask)
                                                                    {
                                                                        TaskAttemptID taskID = TaskAttemptID.ForName(taskid);
                                                                        Job           job    = cluster.GetJob(taskID.GetJobID());
                                                                        if (job == null)
                                                                        {
                                                                            System.Console.Out.WriteLine("Could not find job " + jobid);
                                                                        }
                                                                        else
                                                                        {
                                                                            if (job.KillTask(taskID, true))
                                                                            {
                                                                                System.Console.Out.WriteLine("Killed task " + taskID + " by failing it");
                                                                                exitCode = 0;
                                                                            }
                                                                            else
                                                                            {
                                                                                System.Console.Out.WriteLine("Could not fail task " + taskid);
                                                                                exitCode = -1;
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (logs)
                                                                        {
                                                                            try
                                                                            {
                                                                                JobID         jobID         = JobID.ForName(jobid);
                                                                                TaskAttemptID taskAttemptID = TaskAttemptID.ForName(taskid);
                                                                                LogParams     logParams     = cluster.GetLogParams(jobID, taskAttemptID);
                                                                                LogCLIHelpers logDumper     = new LogCLIHelpers();
                                                                                logDumper.SetConf(GetConf());
                                                                                exitCode = logDumper.DumpAContainersLogs(logParams.GetApplicationId(), logParams.
                                                                                                                         GetContainerId(), logParams.GetNodeId(), logParams.GetOwner());
                                                                            }
                                                                            catch (IOException e)
                                                                            {
                                                                                if (e is RemoteException)
                                                                                {
                                                                                    throw;
                                                                                }
                                                                                System.Console.Out.WriteLine(e.Message);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (RemoteException re)
            {
                IOException unwrappedException = re.UnwrapRemoteException();
                if (unwrappedException is AccessControlException)
                {
                    System.Console.Out.WriteLine(unwrappedException.Message);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                cluster.Close();
            }
            return(exitCode);
        }