Commit 82eb91e2 authored by Aleksandr Konstantinov's avatar Aleksandr Konstantinov
Browse files

Moving messages printing in gm-jobs to logger. Adding possibility to control logging level.

parent 96fce453
Pipeline #1761 failed with stage
in 95 minutes and 41 seconds
......@@ -22,6 +22,8 @@
using namespace ARex;
static Arc::Logger logger(Arc::Logger::getRootLogger(), "gm-jobs");
/** Fill maps with shares taken from data staging states log */
static void get_data_staging_shares(const GMConfig& config,
std::map<std::string, int>& share_preparing,
......@@ -31,7 +33,7 @@ static void get_data_staging_shares(const GMConfig& config,
// get DTR configuration
StagingConfig staging_conf(config);
if (!staging_conf) {
std::cout<<"Could not read data staging configuration from "<<config.ConfigFile()<<std::endl;
logger.msg(Arc::ERROR, "Could not read data staging configuration from %s", config.ConfigFile());
return;
}
std::string dtr_log = staging_conf.get_dtr_log();
......@@ -39,7 +41,7 @@ static void get_data_staging_shares(const GMConfig& config,
// read DTR state info
std::list<std::string> data;
if (!Arc::FileRead(dtr_log, data)) {
std::cout<<"Can't read transfer states from "<<dtr_log<<". Perhaps A-REX is not running?"<<std::endl;
logger.msg(Arc::ERROR, "Can't read transfer states from %s. Perhaps A-REX is not running?", dtr_log);
return;
}
// format DTR_ID state priority share [destination]
......@@ -88,6 +90,7 @@ int main(int argc, char* argv[]) {
// stderr destination for error messages
Arc::LogStream logcerr(std::cerr);
logcerr.setFormat(Arc::EmptyFormat);
Arc::Logger::getRootLogger().addDestination(logcerr);
Arc::Logger::getRootLogger().setThreshold(Arc::DEBUG);
......@@ -180,9 +183,18 @@ int main(int argc, char* argv[]) {
istring("output requested elements (jobs list, delegation ids and tokens) to file"),
istring("file name"), output_file);
std::string debug;
options.AddOption('x', "debug",
istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"),
istring("debuglevel"), debug);
std::list<std::string> params = options.Parse(argc, argv);
// If debug is specified as argument, it should be set as soon as possible
if (!debug.empty())
Arc::Logger::getRootLogger().setThreshold(Arc::istring_to_level(debug));
if(show_share) { // Why?
notshow_jobs=true;
notshow_states=true;
......@@ -192,7 +204,7 @@ int main(int argc, char* argv[]) {
if (!conf_file.empty())
config.SetConfigFile(conf_file);
std::cout << "Using configuration at " << config.ConfigFile() << std::endl;
logger.msg(Arc::VERBOSE, "Using configuration at %s", config.ConfigFile());
if(!config.Load()) exit(1);
if (!control_dir.empty()) config.SetControlDir(control_dir);
......@@ -213,7 +225,7 @@ int main(int argc, char* argv[]) {
if(!output_file.empty()) {
outf.open(output_file.c_str());
if(!outf.is_open()) {
std::cerr<<"Failed to open output file '"<<output_file<<"'"<<std::endl;
logger.msg(Arc::ERROR, "Failed to open output file '%s'", output_file);
return -1;
};
outs = &outf;
......@@ -222,7 +234,7 @@ int main(int argc, char* argv[]) {
if((!notshow_jobs) || (!notshow_states) || (show_share) ||
(cancel_users.size() > 0) || (clean_users.size() > 0) ||
(cancel_jobs.size() > 0) || (clean_jobs.size() > 0)) {
std::cout << "Looking for current jobs" << std::endl;
logger.msg(Arc::VERBOSE, "Looking for current jobs");
}
bool service_alive = false;
......@@ -259,7 +271,7 @@ int main(int argc, char* argv[]) {
if(!i) continue;
job_state_t new_state = job_state_read_file(i->get_id(), config, pending);
if (new_state == JOB_STATE_UNDEFINED) {
std::cout<<"Job: "<<i->get_id()<<" : ERROR : Unrecognizable state"<<std::endl;
logger.msg(Arc::ERROR, "Job: %s : ERROR : Unrecognizable state", i->get_id());
continue;
}
Arc::Time job_time(job_state_time(i->get_id(), config));
......@@ -268,7 +280,7 @@ int main(int argc, char* argv[]) {
if (pending) counters_pending[new_state]++;
JobLocalDescription& job_desc = *(i->GetLocalDescription(config));
if (&job_desc == NULL) {
std::cout<<"Job: "<<i->get_id()<<" : ERROR : No local information."<<std::endl;
logger.msg(Arc::ERROR, "Job: %s : ERROR : No local information.", i->get_id());
continue;
}
if(match_list(job_desc.DN,cancel_users)) {
......@@ -285,7 +297,7 @@ int main(int argc, char* argv[]) {
}
// Printing information
if((filter_users.size() > 0) && (!match_list(job_desc.DN,filter_users))) continue;
if((!show_share) && (!notshow_jobs)) std::cout << "Job: "<<i->get_id();
if((!show_share) && (!notshow_jobs)) *outs << "Job: "<<i->get_id();
if(!notshow_jobs) {
if (!long_list) {
*outs<<" : "<<GMJob::get_state_name(new_state)<<" : "<<job_desc.DN<<" : "<<job_time.str()<<std::endl;
......@@ -327,7 +339,7 @@ int main(int argc, char* argv[]) {
if (share_preparing[i->first] == 0)
*outs<<" 0/"<<share_preparing_pending[i->first]<<"\t\t\t"<<i->first<<std::endl;
}
std::cout<<"\n Finishing/Pending files\tTransfer share"<<std::endl;
*outs<<"\n Finishing/Pending files\tTransfer share"<<std::endl;
for (std::map<std::string, int>::iterator i = share_finishing.begin(); i != share_finishing.end(); i++) {
*outs<<" "<<i->second<<"/"<<share_finishing_pending[i->first]<<"\t\t\t"<<i->first<<std::endl;
}
......@@ -429,9 +441,9 @@ int main(int argc, char* argv[]) {
for(std::list<GMJob*>::iterator job = cancel_jobs_list.begin();
job != cancel_jobs_list.end(); ++job) {
if(!job_cancel_mark_put(**job, config)) {
std::cout<<"Job: "<<(*job)->get_id()<<" : ERROR : Failed to put cancel mark"<<std::endl;
logger.msg(Arc::ERROR, "Job: %s : ERROR : Failed to put cancel mark", (*job)->get_id());
} else {
std::cout<<"Job: "<<(*job)->get_id()<<" : Cancel request put"<<std::endl;
logger.msg(Arc::INFO, "Job: %s : Cancel request put", (*job)->get_id());
}
}
}
......@@ -441,9 +453,9 @@ int main(int argc, char* argv[]) {
// Do not clean job directly because it may have delegations locked.
// Instead put clean mark and let A-REX do cleaning properly.
if(!job_clean_mark_put(**job, config)) {
std::cout<<"Job: "<<(*job)->get_id()<<" : ERROR : Failed to put clean mark"<<std::endl;
logger.msg(Arc::ERROR, "Job: %s : ERROR : Failed to put clean mark", (*job)->get_id());
} else {
std::cout<<"Job: "<<(*job)->get_id()<<" : Clean request put"<<std::endl;
logger.msg(Arc::INFO, "Job: %s : Clean request put", (*job)->get_id());
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment