Back to index

nordugrid-arc-nox  1.1.0~rc6
SubmitterUNICORE.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 
00009 #include <arc/StringConv.h>
00010 #include <arc/UserConfig.h>
00011 #include <arc/client/ExecutionTarget.h>
00012 #include <arc/client/JobDescription.h>
00013 #include <arc/message/MCC.h>
00014 #include <arc/ws-addressing/WSA.h>
00015 
00016 #include "SubmitterUNICORE.h"
00017 #include "UNICOREClient.h"
00018 
00019 namespace Arc {
00020 
00021   Logger SubmitterUNICORE::logger(Submitter::logger, "UNICORE");
00022 
00023   SubmitterUNICORE::SubmitterUNICORE(const UserConfig& usercfg)
00024     : Submitter(usercfg, "UNICORE") {}
00025 
00026   SubmitterUNICORE::~SubmitterUNICORE() {}
00027 
00028   Plugin* SubmitterUNICORE::Instance(PluginArgument *arg) {
00029     SubmitterPluginArgument *subarg =
00030       dynamic_cast<SubmitterPluginArgument*>(arg);
00031     if (!subarg)
00032       return NULL;
00033     return new SubmitterUNICORE(*subarg);
00034   }
00035 
00036   URL SubmitterUNICORE::Submit(const JobDescription& jobdesc,
00037                                const ExecutionTarget& et) const {
00038     MCCConfig cfg;
00039     usercfg.ApplyToConfig(cfg);
00040 
00041     //new code to use the UNICOREClient
00042     UNICOREClient uc(et.url, cfg, usercfg.Timeout());
00043 
00044     XMLNode id;
00045 
00046     if (uc.submit(jobdesc, id)){
00047     }
00048     else {
00049       return URL();
00050     }
00051     //end new code
00052 
00053 
00054 /*
00055     logger.msg(INFO, "Creating client chain for UNICORE BES service");
00056     ClientSOAP client(cfg, submissionEndpoint);
00057     //if((!client) || (!(*client))) {
00058     //   logger.msg(ERROR,"Failed to create client for SOAP exchange");
00059     //   return URL();
00060     //}
00061 
00062     // Prepare BES request
00063     logger.msg(INFO, "Creating and sending request");
00064 
00065     // Create job request
00066 
00067     //   bes-factory:CreateActivity
00068     //     bes-factory:ActivityDocument
00069     //       jsdl:JobDefinition
00070 
00071     NS ns;
00072     ns["bes-factory"] = "http://schemas.ggf.org/bes/2006/08/bes-factory";
00073     ns["wsa"] = "http://www.w3.org/2005/08/addressing";
00074     ns["jsdl"] = "http://schemas.ggf.org/jsdl/2005/11/jsdl";
00075     PayloadSOAP req(ns);
00076     XMLNode op = req.NewChild("bes-factory:CreateActivity");
00077     XMLNode act_doc = op.NewChild("bes-factory:ActivityDocument");
00078     WSAHeader(req).Action("http://schemas.ggf.org/bes/2006/08/bes-factory/BESFactoryPortType/CreateActivity");
00079     WSAHeader(req).To(submissionEndpoint.str());
00080     std::string jsdl_str = jobdesc.UnParse("ARCJSDL");
00081     act_doc.NewChild(XMLNode(jsdl_str));
00082     //act_doc.Child(0).Namespaces(arex_ns); // Unify namespaces
00083     PayloadSOAP *resp = NULL;
00084     act_doc.GetXML(jsdl_str);
00085     logger.msg(DEBUG, "Job description to be sent: %s", jsdl_str);
00086     MCC_Status status =
00087       client.process("http://schemas.ggf.org/bes/2006/08/bes-factory/"
00088                      "BESFactoryPortType/CreateActivity", &req, &resp);
00089     if (!status) {
00090       logger.msg(ERROR, "Submission request failed");
00091       return URL();
00092     }
00093     if (resp == NULL) {
00094       logger.msg(ERROR, "There was no SOAP response");
00095       return URL();
00096     }
00097 
00098     SOAPFault fs(*resp);
00099     if (fs) {
00100       std::string faultstring = fs.Reason();
00101       std::string s;
00102       resp->GetXML(s);
00103       // delete resp;
00104       logger.msg(DEBUG, "Submission returned failure: %s", s);
00105       logger.msg(ERROR, "Submission failed, service returned: %s", faultstring);
00106       return URL();
00107     }
00108     XMLNode id;
00109     (*resp)["CreateActivityResponse"]["ActivityIdentifier"].New(id);
00110     std::string jobid;
00111     id.GetDoc(jobid);
00112     // delete resp;
00113     if (jobid.empty()) {
00114       logger.msg(ERROR, "Service returned no job identifier");
00115       return URL();
00116     }*/
00117 
00118     std::string jobid;
00119     id.GetDoc(jobid);
00120 
00121     std::map<std::string, std::string> additional_info;
00122     additional_info["AuxInfo"] = jobid;
00123     AddJob(jobdesc, (std::string)id["Address"], et.Cluster, et.url, additional_info);
00124 
00125     return (std::string)id["Address"];
00126   }
00127 
00128   URL SubmitterUNICORE::Migrate(const URL& jobid,
00129                                 const JobDescription& jobdesc,
00130                                 const ExecutionTarget& et,
00131                                 bool forcemigration) const {
00132     logger.msg(INFO, "Trying to migrate to %s: Migration to a UNICORE cluster is not supported.", et.url.str());
00133     return URL();
00134   }
00135 
00136   bool SubmitterUNICORE::ModifyJobDescription(JobDescription& jobdesc, const ExecutionTarget& et) const {
00137     return true;
00138   }
00139 } // namespace Arc