1
// -*- indent-tabs-mode: nil -*-
12
#include <arc/ArcLocation.h>
13
#include <arc/IString.h>
14
#include <arc/Logger.h>
15
#include <arc/UserConfig.h>
16
#include <arc/client/JobSupervisor.h>
20
int RUNMAIN(arcstat)(int argc, char **argv) {
22
setlocale(LC_ALL, "");
24
Arc::Logger logger(Arc::Logger::getRootLogger(), "arcstat");
25
Arc::LogStream logcerr(std::cerr);
26
logcerr.setFormat(Arc::ShortFormat);
27
Arc::Logger::getRootLogger().addDestination(logcerr);
28
Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
30
Arc::ArcLocation::Init(argv[0]);
32
ClientOptions opt(ClientOptions::CO_STAT,
34
istring("The arcstat command is used for "
35
"obtaining the status of jobs that have\n"
36
"been submitted to Grid enabled resources."));
38
std::list<std::string> jobidentifiers = opt.Parse(argc, argv);
40
if (opt.showversion) {
41
std::cout << Arc::IString("%s version %s", "arcstat", VERSION)
46
// If debug is specified as argument, it should be set before loading the configuration.
47
if (!opt.debug.empty())
48
Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(opt.debug));
50
if (opt.show_plugins) {
51
std::list<std::string> types;
52
types.push_back("HED:JobControllerPlugin");
53
showplugins("arcstat", types, logger);
57
Arc::UserConfig usercfg(opt.conffile, opt.joblist);
59
logger.msg(Arc::ERROR, "Failed configuration initialization");
63
if (opt.debug.empty() && !usercfg.Verbosity().empty())
64
Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(usercfg.Verbosity()));
66
for (std::list<std::string>::const_iterator it = opt.jobidinfiles.begin(); it != opt.jobidinfiles.end(); it++) {
67
if (!Arc::Job::ReadJobIDsFromFile(*it, jobidentifiers)) {
68
logger.msg(Arc::WARNING, "Cannot read specified jobid file: %s", *it);
73
usercfg.Timeout(opt.timeout);
75
if (!opt.sort.empty() && !opt.rsort.empty()) {
76
logger.msg(Arc::ERROR, "The 'sort' and 'rsort' flags cannot be specified at the same time.");
80
if (!opt.rsort.empty()) {
84
typedef bool (*JobSorting)(const Arc::Job&, const Arc::Job&);
85
std::map<std::string, JobSorting> orderings;
86
orderings["jobid"] = &Arc::Job::CompareJobID;
87
orderings["submissiontime"] = &Arc::Job::CompareSubmissionTime;
88
orderings["jobname"] = &Arc::Job::CompareJobName;
90
if (!opt.sort.empty() && orderings.find(opt.sort) == orderings.end()) {
91
std::cerr << "Jobs cannot be sorted by \"" << opt.sort << "\", the following orderings are supported:" << std::endl;
92
for (std::map<std::string, JobSorting>::const_iterator it = orderings.begin();
93
it != orderings.end(); it++)
94
std::cerr << it->first << std::endl;
98
if ((!opt.joblist.empty() || !opt.status.empty()) && jobidentifiers.empty() && opt.clusters.empty())
101
if (jobidentifiers.empty() && opt.clusters.empty() && !opt.all) {
102
logger.msg(Arc::ERROR, "No jobs given");
106
std::list<std::string> selectedURLs;
107
if (!opt.clusters.empty()) {
108
selectedURLs = getSelectedURLsFromUserConfigAndCommandLine(usercfg, opt.clusters);
110
std::list<std::string> rejectManagementURLs = getRejectManagementURLsFromUserConfigAndCommandLine(usercfg, opt.rejectmanagement);
111
std::list<Arc::Job> jobs;
112
if (!Arc::Job::ReadJobsFromFile(usercfg.JobListFile(), jobs, jobidentifiers, opt.all, selectedURLs, rejectManagementURLs)) {
113
logger.msg(Arc::ERROR, "Unable to read job information from file (%s)", usercfg.JobListFile());
117
for (std::list<std::string>::const_iterator itJIDAndName = jobidentifiers.begin();
118
itJIDAndName != jobidentifiers.end(); ++itJIDAndName) {
119
std::cout << Arc::IString("Warning: Job not found in job list: %s", *itJIDAndName) << std::endl;
122
Arc::JobSupervisor jobmaster(usercfg, jobs);
124
jobmaster.SelectValid();
125
if (!opt.status.empty()) {
126
jobmaster.SelectByStatus(opt.status);
128
jobs = jobmaster.GetSelectedJobs();
131
std::cout << Arc::IString("No jobs") << std::endl;
135
std::vector<Arc::Job> jobsSortable(jobs.begin(), jobs.end());
137
if (!opt.sort.empty()) {
138
opt.rsort.empty() ? std::sort(jobsSortable.begin(), jobsSortable.end(), orderings[opt.sort]) :
139
std::sort(jobsSortable.rbegin(), jobsSortable.rend(), orderings[opt.sort]);
142
for (std::vector<Arc::Job>::const_iterator it = jobsSortable.begin();
143
it != jobsSortable.end(); it++) {
144
// Option 'long' (longlist) takes precedence over option 'print-jobids' (printids)
145
if (opt.longlist || !opt.printids) {
146
it->SaveToStream(std::cout, opt.longlist);
149
std::cout << it->JobID.fullstr() << std::endl;