Back to index

nordugrid-arc-nox  1.1.0~rc6
SubmitterBES.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 <string>
00008 #include <sstream>
00009 
00010 #include <arc/StringConv.h>
00011 #include <arc/UserConfig.h>
00012 #include <arc/client/ExecutionTarget.h>
00013 #include <arc/client/JobDescription.h>
00014 #include <arc/message/MCC.h>
00015 
00016 #include "SubmitterBES.h"
00017 #include "AREXClient.h"
00018 
00019 namespace Arc {
00020 
00021   Logger SubmitterBES::logger(Submitter::logger, "BES");
00022 
00023   static std::string char_to_hex(char v) {
00024     std::string s;
00025     unsigned int n;
00026     n = (unsigned int)((v & 0xf0) >> 4);
00027     if(n < 10) { s+=(char)('0'+n); } else { s+=(char)('a'+n-10); }
00028     n = (unsigned int)(v & 0x0f);
00029     if(n < 10) { s+=(char)('0'+n); } else { s+=(char)('a'+n-10); }
00030     return s;
00031   }
00032 
00033   static std::string disguise_id_into_url(const URL& u,const std::string& id) {
00034     std::string jobid = u.str();
00035     jobid+="#";
00036     for(std::string::size_type p = 0;p < id.length();++p) {
00037       jobid+=char_to_hex(id[p]);
00038     }
00039     return jobid;
00040   }
00041 
00042   SubmitterBES::SubmitterBES(const UserConfig& usercfg)
00043     : Submitter(usercfg, "BES") {}
00044 
00045   SubmitterBES::~SubmitterBES() {}
00046 
00047   Plugin* SubmitterBES::Instance(PluginArgument *arg) {
00048     SubmitterPluginArgument *subarg =
00049       dynamic_cast<SubmitterPluginArgument*>(arg);
00050     if (!subarg)
00051       return NULL;
00052     return new SubmitterBES(*subarg);
00053   }
00054 
00055   URL SubmitterBES::Submit(const JobDescription& jobdesc,
00056                             const ExecutionTarget& et) const {
00057     MCCConfig cfg;
00058     usercfg.ApplyToConfig(cfg);
00059     AREXClient ac(et.url, cfg, usercfg.Timeout(), false);
00060 
00061     std::string jobid;
00062     // !! TODO: ordinary JSDL is needed - keeping ARCJSDL so far
00063     if (!ac.submit(jobdesc.UnParse("ARCJSDL"), jobid, et.url.Protocol() == "https"))
00064       return URL();
00065 
00066     if (jobid.empty()) {
00067       logger.msg(INFO, "No job identifier returned by BES service");
00068       return URL();
00069     }
00070 
00071     XMLNode jobidx(jobid);
00072 
00073     JobDescription job(jobdesc);
00074 
00075     // Unfortunately Job handling framework somewhy want to have job
00076     // URL instead of identifier we have to invent one. So we disguise
00077     // XML blob inside URL path.
00078     URL jobid_url(disguise_id_into_url(et.url,jobid));
00079     AddJob(job, jobid_url, et.Cluster, et.url);
00080     return et.url;
00081   }
00082 
00083   URL SubmitterBES::Migrate(const URL& jobid, const JobDescription& jobdesc,
00084                              const ExecutionTarget& et,
00085                              bool forcemigration) const {
00086     logger.msg(INFO, "Trying to migrate to %s: Migration to a BES cluster is not supported.", et.url.str());
00087     return URL();
00088   }
00089 
00090   bool SubmitterBES::ModifyJobDescription(JobDescription& jobdesc, const ExecutionTarget& et) const {
00091     return true;
00092   }
00093 
00094 } // namespace Arc