Back to index

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