Back to index

nordugrid-arc-nox  1.1.0~rc6
arcresume.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <iostream>
00008 #include <list>
00009 #include <string>
00010 
00011 #include <arc/ArcLocation.h>
00012 #include <arc/IString.h>
00013 #include <arc/Logger.h>
00014 #include <arc/OptionParser.h>
00015 #include <arc/StringConv.h>
00016 #include <arc/client/JobController.h>
00017 #include <arc/client/JobSupervisor.h>
00018 #include <arc/UserConfig.h>
00019 
00020 int main(int argc, char **argv) {
00021 
00022   setlocale(LC_ALL, "");
00023 
00024   Arc::Logger logger(Arc::Logger::getRootLogger(), "arcresume");
00025   Arc::LogStream logcerr(std::cerr);
00026   logcerr.setFormat(Arc::ShortFormat);
00027   Arc::Logger::getRootLogger().addDestination(logcerr);
00028   Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
00029 
00030   Arc::ArcLocation::Init(argv[0]);
00031 
00032   Arc::OptionParser options(istring("[job ...]"));
00033 
00034   bool all = false;
00035   options.AddOption('a', "all",
00036                     istring("all jobs"),
00037                     all);
00038 
00039   std::string joblist;
00040   options.AddOption('j', "joblist",
00041                     istring("file containing a list of jobs"),
00042                     istring("filename"),
00043                     joblist);
00044 
00045   std::list<std::string> clusters;
00046   options.AddOption('c', "cluster",
00047                     istring("explicity select or reject a specific cluster"),
00048                     istring("[-]name"),
00049                     clusters);
00050 
00051   std::list<std::string> status;
00052   options.AddOption('s', "status",
00053                     istring("only select jobs whose status is statusstr"),
00054                     istring("statusstr"),
00055                     status);
00056 
00057   int timeout = -1;
00058   options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
00059                     istring("seconds"), timeout);
00060 
00061   std::string conffile;
00062   options.AddOption('z', "conffile",
00063                     istring("configuration file (default ~/.arc/client.conf)"),
00064                     istring("filename"), conffile);
00065 
00066   std::string debug;
00067   options.AddOption('d', "debug",
00068                     istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"),
00069                     istring("debuglevel"), debug);
00070 
00071   bool version = false;
00072   options.AddOption('v', "version", istring("print version information"),
00073                     version);
00074 
00075   std::list<std::string> jobs = options.Parse(argc, argv);
00076 
00077   // If debug is specified as argument, it should be set before loading the configuration.
00078   if (!debug.empty())
00079     Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(debug));
00080 
00081   Arc::UserConfig usercfg(conffile, joblist);
00082   if (!usercfg) {
00083     logger.msg(Arc::ERROR, "Failed configuration initialization");
00084     return 1;
00085   }
00086 
00087   if (debug.empty() && !usercfg.Verbosity().empty())
00088     Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(usercfg.Verbosity()));
00089 
00090   if (timeout > 0)
00091     usercfg.Timeout(timeout);
00092 
00093   if (version) {
00094     std::cout << Arc::IString("%s version %s", "arcresume", VERSION)
00095               << std::endl;
00096     return 0;
00097   }
00098 
00099   if ((!joblist.empty() || !status.empty()) && jobs.empty() && clusters.empty())
00100     all = true;
00101 
00102   if (jobs.empty() && clusters.empty() && !all) {
00103     logger.msg(Arc::ERROR, "No jobs given");
00104     return 1;
00105   }
00106 
00107   if (!jobs.empty() || all)
00108     usercfg.ClearSelectedServices();
00109 
00110   if (!clusters.empty()) {
00111     usercfg.ClearSelectedServices();
00112     usercfg.AddServices(clusters, Arc::COMPUTING);
00113   }
00114 
00115   Arc::JobSupervisor jobmaster(usercfg, jobs);
00116   if (!jobmaster.JobsFound()) {
00117     std::cout << "No jobs" << std::endl;
00118     return 0;
00119   }
00120   std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
00121 
00122   // If the user specified a joblist on the command line joblist equals
00123   // usercfg.JobListFile(). If not use the default, ie. usercfg.JobListFile().
00124   if (jobcont.empty()) {
00125     logger.msg(Arc::ERROR, "No job controller plugins loaded");
00126     return 1;
00127   }
00128 
00129   int retval = 0;
00130   for (std::list<Arc::JobController*>::iterator it = jobcont.begin();
00131        it != jobcont.end(); it++)
00132     if (!(*it)->Resume(status))
00133       retval = 1;
00134 
00135   if (retval = 0)
00136     std::cout << "All jobs were resumed" << std::endl;
00137   return retval;
00138 }