Back to index

nordugrid-arc-nox  1.1.0~rc6
arcinfo.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/client/TargetGenerator.h>
00019 #include <arc/UserConfig.h>
00020 
00021 int main(int argc, char **argv) {
00022 
00023   setlocale(LC_ALL, "");
00024 
00025   Arc::Logger logger(Arc::Logger::getRootLogger(), "arcinfo");
00026   Arc::LogStream logcerr(std::cerr);
00027   logcerr.setFormat(Arc::ShortFormat);
00028   Arc::Logger::getRootLogger().addDestination(logcerr);
00029   Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
00030 
00031   Arc::ArcLocation::Init(argv[0]);
00032 
00033   Arc::OptionParser options(istring("[cluster ...]"),
00034                             istring("The arcinfo command is used for "
00035                                     "obtaining the status of clusters\n"
00036                                     "on the grid."),
00037                             istring("Argument to -i has the format "
00038                                     "Flavour:URL e.g.\n"
00039                                     "ARC0:ldap://grid.tsl.uu.se:2135/"
00040                                     "mds-vo-name=sweden,O=grid\n"
00041                                     "CREAM:ldap://cream.grid.upjs.sk:2170/"
00042                                     "o=grid\n"
00043                                     "\n"
00044                                     "Argument to -c has the format "
00045                                     "Flavour:URL e.g.\n"
00046                                     "ARC0:ldap://grid.tsl.uu.se:2135/"
00047                                     "nordugrid-cluster-name=grid.tsl.uu.se,"
00048                                     "Mds-Vo-name=local,o=grid"));
00049 
00050   std::list<std::string> clusters;
00051   options.AddOption('c', "cluster",
00052                     istring("explicity select or reject a specific cluster"),
00053                     istring("[-]name"),
00054                     clusters);
00055 
00056   std::list<std::string> indexurls;
00057   options.AddOption('i', "index",
00058                     istring("explicity select or reject an index server"),
00059                     istring("[-]name"),
00060                     indexurls);
00061 
00062   bool longlist = false;
00063   options.AddOption('l', "long",
00064                     istring("long format (more information)"),
00065                     longlist);
00066 
00067   int timeout = -1;
00068   options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
00069                     istring("seconds"), timeout);
00070 
00071   std::string conffile;
00072   options.AddOption('z', "conffile",
00073                     istring("configuration file (default ~/.arc/client.conf)"),
00074                     istring("filename"), conffile);
00075 
00076   std::string debug;
00077   options.AddOption('d', "debug",
00078                     istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"),
00079                     istring("debuglevel"), debug);
00080 
00081   bool version = false;
00082   options.AddOption('v', "version", istring("print version information"),
00083                     version);
00084 
00085   {
00086     std::list<std::string> clusterstmp = options.Parse(argc, argv);
00087     clusters.insert(clusters.end(), clusterstmp.begin(), clusterstmp.end());
00088   }
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);
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", "arcinfo", VERSION)
00108               << std::endl;
00109     return 0;
00110   }
00111 
00112   if (!clusters.empty() || !indexurls.empty())
00113     usercfg.ClearSelectedServices();
00114 
00115   if (!clusters.empty())
00116     usercfg.AddServices(clusters, Arc::COMPUTING);
00117 
00118   if (!indexurls.empty())
00119     usercfg.AddServices(indexurls, Arc::INDEX);
00120 
00121 
00122   Arc::TargetGenerator targen(usercfg);
00123   targen.GetTargets(0, 1);
00124   targen.PrintTargetInfo(longlist);
00125   return 0;
00126 }