Back to index

nordugrid-arc-nox  1.1.0~rc6
JobControllerBES.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 <glib.h>
00008 
00009 #include <arc/StringConv.h>
00010 #include <arc/UserConfig.h>
00011 #include <arc/XMLNode.h>
00012 #include <arc/client/JobDescription.h>
00013 #include <arc/data/DataMover.h>
00014 #include <arc/data/DataHandle.h>
00015 #include <arc/data/URLMap.h>
00016 #include <arc/message/MCC.h>
00017 
00018 #include "AREXClient.h"
00019 #include "JobControllerBES.h"
00020 
00021 namespace Arc {
00022 
00023   Logger JobControllerBES::logger(JobController::logger, "BES");
00024 
00025   static char hex_to_char(const char* v) {
00026     char r = 0;
00027     if((*v >= '0') && (*v <= '9')) { r |= *v  - '0'; }
00028     else if((*v >= 'a') && (*v <= 'f')) { r |= *v  - 'a' + 10; }
00029     else if((*v >= 'A') && (*v <= 'F')) { r |= *v  - 'A' + 10; }
00030     r <<= 4; ++v;
00031     if((*v >= '0') && (*v <= '9')) { r |= *v  - '0'; }
00032     else if((*v >= 'a') && (*v <= 'f')) { r |= *v  - 'a' + 10; }
00033     else if((*v >= 'A') && (*v <= 'F')) { r |= *v  - 'A' + 10; }
00034     return r;
00035   }
00036 
00037   static std::string extract_job_id(const URL& u) {
00038     std::string jobid = u.Path();
00039     if(jobid.empty()) return jobid;
00040     std::string::size_type p = jobid.find('#');
00041     if(p == std::string::npos) { p=0; } else { ++p; }
00042     std::string s;
00043     for(;p < jobid.length();p+=2) {
00044       char r = hex_to_char(jobid.c_str() + p);
00045       if(r == 0) { s.resize(0); break; }
00046       s += r;
00047     }
00048     return s;
00049   }
00050 
00051   JobControllerBES::JobControllerBES(const UserConfig& usercfg)
00052     : JobController(usercfg, "BES") {}
00053 
00054   JobControllerBES::~JobControllerBES() {}
00055 
00056   Plugin* JobControllerBES::Instance(PluginArgument *arg) {
00057     JobControllerPluginArgument *jcarg =
00058       dynamic_cast<JobControllerPluginArgument*>(arg);
00059     if (!jcarg)
00060       return NULL;
00061     return new JobControllerBES(*jcarg);
00062   }
00063 
00064   void JobControllerBES::GetJobInformation() {
00065     MCCConfig cfg;
00066     usercfg.ApplyToConfig(cfg);
00067 
00068     for (std::list<Job>::iterator iter = jobstore.begin();
00069          iter != jobstore.end(); iter++) {
00070       AREXClient ac(iter->Cluster, cfg, usercfg.Timeout(),false);
00071       std::string idstr = extract_job_id(iter->JobID);
00072       if (!ac.stat(idstr, *iter))
00073         logger.msg(INFO, "Failed retrieving job status information");
00074     }
00075   }
00076 
00077   bool JobControllerBES::GetJob(const Job& job,
00078                                  const std::string& downloaddir) {
00079     logger.msg(INFO, "Getting BES jobs is not supported");
00080     return false;
00081   }
00082 
00083   bool JobControllerBES::CleanJob(const Job& job, bool force) {
00084     logger.msg(INFO, "Cleaning of BES jobs is not supported");
00085     return false;
00086   }
00087 
00088   bool JobControllerBES::CancelJob(const Job& job) {
00089     MCCConfig cfg;
00090     usercfg.ApplyToConfig(cfg);
00091     AREXClient ac(job.Cluster, cfg, usercfg.Timeout(), false);
00092     std::string idstr = extract_job_id(job.JobID);
00093     return ac.kill(idstr);
00094   }
00095 
00096   bool JobControllerBES::RenewJob(const Job& job) {
00097     logger.msg(INFO, "Renewal of BES jobs is not supported");
00098     return false;
00099   }
00100 
00101   bool JobControllerBES::ResumeJob(const Job& job) {
00102     logger.msg(INFO, "Resuming BES jobs is not supported");
00103     return false;
00104   }
00105 
00106   bool JobControllerBES::GetJobDescription(const Job& job, std::string& desc_str) {
00107     MCCConfig cfg;
00108     usercfg.ApplyToConfig(cfg);
00109     AREXClient ac(job.Cluster, cfg, usercfg.Timeout(), false);
00110     std::string idstr = extract_job_id(job.JobID);
00111     if (ac.getdesc(idstr, desc_str)) {
00112       JobDescription desc;
00113       desc.Parse(desc_str);
00114       if (desc)
00115       return true;
00116     }
00117 
00118     logger.msg(ERROR, "Failed retrieving job description for job: %s", job.JobID.str());
00119     return false;
00120   }
00121 
00122   URL JobControllerBES::GetFileUrlForJob(const Job& job, const std::string& whichfile) {
00123     return URL();
00124   }
00125 
00126 } // namespace Arc