Back to index

nordugrid-arc-nox  1.1.0~rc6
SubmitterCREAM.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 <arc/GUID.h>
00008 #include <arc/StringConv.h>
00009 #include <arc/UserConfig.h>
00010 #include <arc/client/ExecutionTarget.h>
00011 #include <arc/client/JobDescription.h>
00012 #include <arc/message/MCC.h>
00013 
00014 #include "CREAMClient.h"
00015 #include "SubmitterCREAM.h"
00016 
00017 namespace Arc {
00018 
00019   SubmitterCREAM::SubmitterCREAM(const UserConfig& usercfg)
00020     : Submitter(usercfg, "CREAM") {}
00021 
00022   SubmitterCREAM::~SubmitterCREAM() {}
00023 
00024   Plugin* SubmitterCREAM::Instance(PluginArgument *arg) {
00025     SubmitterPluginArgument *subarg =
00026       dynamic_cast<SubmitterPluginArgument*>(arg);
00027     if (!subarg)
00028       return NULL;
00029     return new SubmitterCREAM(*subarg);
00030   }
00031 
00032   URL SubmitterCREAM::Submit(const JobDescription& jobdesc,
00033                              const ExecutionTarget& et) const {
00034     MCCConfig cfg;
00035     usercfg.ApplyToConfig(cfg);
00036     std::string delegationid = UUID();
00037     URL delegationurl(et.url);
00038     delegationurl.ChangePath(delegationurl.Path() + "/gridsite-delegation");
00039     CREAMClient gLiteClientDelegation(delegationurl, cfg, usercfg.Timeout());
00040     if (!gLiteClientDelegation.createDelegation(delegationid, usercfg.ProxyPath())) {
00041       logger.msg(INFO, "Failed creating singed delegation certificate");
00042       return URL();
00043     }
00044     URL submissionurl(et.url);
00045     submissionurl.ChangePath(submissionurl.Path() + "/CREAM2");
00046     CREAMClient gLiteClientSubmission(submissionurl, cfg, usercfg.Timeout());
00047     gLiteClientSubmission.setDelegationId(delegationid);
00048 
00049     JobDescription job(jobdesc);
00050     if (!ModifyJobDescription(job, et)) {
00051       logger.msg(INFO, "Failed adapting job description to target resources");
00052       return URL();
00053     }
00054 
00055     std::string jobdescstring = job.UnParse("JDL");
00056     creamJobInfo jobInfo;
00057     if (!gLiteClientSubmission.registerJob(jobdescstring, jobInfo)) {
00058       logger.msg(INFO, "Failed registering job");
00059       return URL();
00060     }
00061 
00062     if (!PutFiles(job, jobInfo.ISB_URI)) {
00063       logger.msg(INFO, "Failed uploading local input files");
00064       return URL();
00065     }
00066 
00067     if (!gLiteClientSubmission.startJob(jobInfo.jobId)) {
00068       logger.msg(INFO, "Failed starting job");
00069       return URL();
00070     }
00071 
00072     std::map<std::string, std::string> additionalInfo;
00073     additionalInfo["ISB"] = jobInfo.ISB_URI;
00074     additionalInfo["OSB"] = jobInfo.OSB_URI;
00075 
00076     AddJob(job, submissionurl.str() + '/' + jobInfo.jobId, et.Cluster,
00077            delegationurl.str() + '/' + delegationid, additionalInfo);
00078 
00079     return submissionurl.str() + '/' + jobInfo.jobId;
00080   }
00081 
00082   URL SubmitterCREAM::Migrate(const URL& jobid, const JobDescription& jobdesc,
00083                               const ExecutionTarget& et,
00084                               bool forcemigration) const {
00085     logger.msg(INFO, "Trying to migrate to %s: Migration to a CREAM cluster is not supported.", et.url.str());
00086     return URL();
00087   }
00088 
00089   bool SubmitterCREAM::ModifyJobDescription(JobDescription& jobdesc, const ExecutionTarget& et) const {
00090     if (jobdesc.JDL_elements.find("BatchSystem") == jobdesc.JDL_elements.end() &&
00091         !et.ManagerProductName.empty())
00092       jobdesc.JDL_elements["BatchSystem"] = et.ManagerProductName;
00093 
00094     if (jobdesc.Resources.CandidateTarget.empty()) {
00095       ResourceTargetType candidateTarget;
00096       candidateTarget.EndPointURL = URL();
00097       candidateTarget.QueueName = et.ComputingShareName;
00098       jobdesc.Resources.CandidateTarget.push_back(candidateTarget);
00099     }
00100 
00101     return true;
00102   }
00103 } // namespace Arc