コード例 #1
0
        // gets the config merged with the arguments
        /// <exception cref="System.Exception"/>
        private ConfigExtractor GetTestConfig(bool sleep)
        {
            ArgumentParser parser = new ArgumentParser(GetTestArgs(sleep));

            ArgumentParser.ParsedOutput @out = parser.Parse();
            NUnit.Framework.Assert.IsTrue([email protected]());
            ConfigMerger    merge     = new ConfigMerger();
            Configuration   cfg       = merge.GetMerged(@out, GetBaseConfig());
            ConfigExtractor extractor = new ConfigExtractor(cfg);

            return(extractor);
        }
コード例 #2
0
ファイル: SliveTest.cs プロジェクト: orf53975/hadoop.net
        public virtual int Run(string[] args)
        {
            ArgumentParser.ParsedOutput parsedOpts = null;
            try
            {
                ArgumentParser argHolder = new ArgumentParser(args);
                parsedOpts = argHolder.Parse();
                if (parsedOpts.ShouldOutputHelp())
                {
                    parsedOpts.OutputHelp();
                    return(1);
                }
            }
            catch (Exception e)
            {
                Log.Error("Unable to parse arguments due to error: ", e);
                return(1);
            }
            Log.Info("Running with option list " + Helper.StringifyArray(args, " "));
            ConfigExtractor config = null;

            try
            {
                ConfigMerger  cfgMerger = new ConfigMerger();
                Configuration cfg       = cfgMerger.GetMerged(parsedOpts, new Configuration(@base));
                if (cfg != null)
                {
                    config = new ConfigExtractor(cfg);
                }
            }
            catch (Exception e)
            {
                Log.Error("Unable to merge config due to error: ", e);
                return(1);
            }
            if (config == null)
            {
                Log.Error("Unable to merge config & options!");
                return(1);
            }
            try
            {
                Log.Info("Options are:");
                ConfigExtractor.DumpOptions(config);
            }
            catch (Exception e)
            {
                Log.Error("Unable to dump options due to error: ", e);
                return(1);
            }
            bool jobOk = false;

            try
            {
                Log.Info("Running job:");
                RunJob(config);
                jobOk = true;
            }
            catch (Exception e)
            {
                Log.Error("Unable to run job due to error: ", e);
            }
            if (jobOk)
            {
                try
                {
                    Log.Info("Reporting on job:");
                    WriteReport(config);
                }
                catch (Exception e)
                {
                    Log.Error("Unable to report on job due to error: ", e);
                }
            }
            // attempt cleanup (not critical)
            bool cleanUp = GetBool(parsedOpts.GetValue(ConfigOption.Cleanup.GetOpt()));

            if (cleanUp)
            {
                try
                {
                    Log.Info("Cleaning up job:");
                    Cleanup(config);
                }
                catch (Exception e)
                {
                    Log.Error("Unable to cleanup job due to error: ", e);
                }
            }
            // all mostly worked
            if (jobOk)
            {
                return(0);
            }
            // maybe didn't work
            return(1);
        }