Back to index

nordugrid-arc-nox  1.1.0~rc6
arcstat.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(), "arcstat");
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                             istring("The arcstat command is used for "
00034                                     "obtaining the status of jobs that have\n"
00035                                     "been submitted to grid enabled resources."),
00036                             istring("Argument to -c has the format "
00037                                     "Flavour:URL e.g.\n"
00038                                     "ARC0:ldap://grid.tsl.uu.se:2135/"
00039                                     "nordugrid-cluster-name=grid.tsl.uu.se,"
00040                                     "Mds-Vo-name=local,o=grid"));
00041 
00042   bool all = false;
00043   options.AddOption('a', "all",
00044                     istring("all jobs"),
00045                     all);
00046 
00047   std::string joblist;
00048   options.AddOption('j', "joblist",
00049                     istring("file containing a list of jobs"),
00050                     istring("filename"),
00051                     joblist);
00052 
00053   std::list<std::string> clusters;
00054   options.AddOption('c', "cluster",
00055                     istring("explicity select or reject a specific cluster"),
00056                     istring("[-]name"),
00057                     clusters);
00058 
00059   std::list<std::string> status;
00060   options.AddOption('s', "status",
00061                     istring("only select jobs whose status is statusstr"),
00062                     istring("statusstr"),
00063                     status);
00064 
00065   bool longlist = false;
00066   options.AddOption('l', "long",
00067                     istring("long format (more information)"),
00068                     longlist);
00069 
00070   int timeout = -1;
00071   options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
00072                     istring("seconds"), timeout);
00073 
00074   std::string conffile;
00075   options.AddOption('z', "conffile",
00076                     istring("configuration file (default ~/.arc/client.conf)"),
00077                     istring("filename"), conffile);
00078 
00079   std::string debug;
00080   options.AddOption('d', "debug",
00081                     istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"),
00082                     istring("debuglevel"), debug);
00083 
00084   bool version = false;
00085   options.AddOption('v', "version", istring("print version information"),
00086                     version);
00087 
00088   std::list<std::string> jobs = options.Parse(argc, argv);
00089 
00090   // If debug is specified as argument, it should be set before loading the configuration.
00091   if (!debug.empty())
00092     Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(debug));
00093 
00094   Arc::UserConfig usercfg(conffile, joblist);
00095   if (!usercfg) {
00096     logger.msg(Arc::ERROR, "Failed configuration initialization");
00097     return 1;
00098   }
00099 
00100   if (debug.empty() && !usercfg.Verbosity().empty())
00101     Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(usercfg.Verbosity()));
00102 
00103   if (timeout > 0)
00104     usercfg.Timeout(timeout);
00105 
00106 
00107   if (version) {
00108     std::cout << Arc::IString("%s version %s", "arcstat", VERSION)
00109               << std::endl;
00110     return 0;
00111   }
00112 
00113   if ((!joblist.empty() || !status.empty()) && jobs.empty() && clusters.empty())
00114     all = true;
00115 
00116   if (jobs.empty() && clusters.empty() && !all) {
00117     logger.msg(Arc::ERROR, "No jobs given");
00118     return 1;
00119   }
00120 
00121   if (!jobs.empty() || all)
00122     usercfg.ClearSelectedServices();
00123 
00124   if (!clusters.empty()) {
00125     usercfg.ClearSelectedServices();
00126     usercfg.AddServices(clusters, Arc::COMPUTING);
00127   }
00128 
00129   Arc::JobSupervisor jobmaster(usercfg, jobs);
00130   if (!jobmaster.JobsFound()) {
00131     std::cout << "No jobs" << std::endl;
00132     return 0;
00133   }
00134   std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
00135 
00136   if (jobcont.empty()) {
00137     logger.msg(Arc::ERROR, "No job controller plugins loaded");
00138     return 1;
00139   }
00140 
00141   int retval = 0;
00142   for (std::list<Arc::JobController*>::iterator it = jobcont.begin();
00143        it != jobcont.end(); it++) {
00144     if (!(*it)->PrintJobStatus(status, longlist))
00145       retval = 1;
00146   }
00147 
00148   return retval;
00149 }