Back to index

nordugrid-arc-nox  1.1.0~rc6
arcclean.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(), "arcclean");
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 arcclean command removes a job "
00034                                     "from the remote cluster."),
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   bool force = false;
00065   options.AddOption('f', "force",
00066                     istring("remove the job from the local list of jobs "
00067                             "even if the job is not found in the infosys"),
00068                     force);
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   if (version) {
00107     std::cout << Arc::IString("%s version %s", "arcclean", VERSION)
00108               << std::endl;
00109     return 0;
00110   }
00111 
00112   if ((!joblist.empty() || !status.empty()) && jobs.empty() && clusters.empty())
00113     all = true;
00114 
00115   if (jobs.empty() && clusters.empty() && !all) {
00116     logger.msg(Arc::ERROR, "No jobs given");
00117     return 1;
00118   }
00119 
00120   if (!jobs.empty() || all)
00121     usercfg.ClearSelectedServices();
00122 
00123   if (!clusters.empty()) {
00124     usercfg.ClearSelectedServices();
00125     usercfg.AddServices(clusters, Arc::COMPUTING);
00126   }
00127 
00128   Arc::JobSupervisor jobmaster(usercfg, jobs);
00129   if (!jobmaster.JobsFound()) {
00130     std::cout << "No jobs" << std::endl;
00131     return 0;
00132   }
00133   std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
00134 
00135   // If the user specified a joblist on the command line joblist equals
00136   // usercfg.JobListFile(). If not use the default, ie. usercfg.JobListFile().
00137   if (jobcont.empty()) {
00138     logger.msg(Arc::ERROR, "No job controller plugins loaded");
00139     return 1;
00140   }
00141 
00142   int retval = 0;
00143   for (std::list<Arc::JobController*>::iterator it = jobcont.begin();
00144        it != jobcont.end(); it++)
00145     if (!(*it)->Clean(status, force))
00146       retval = 1;
00147 
00148   return retval;
00149 }