Back to index

nordugrid-arc-nox  1.1.0~rc6
migrate_activity.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/message/SOAPEnvelope.h>
00006 #include <arc/ws-addressing/WSA.h>
00007 // #include "../../hed/acc/ARC1/AREXClient.h"
00008 #include "../../hed/libs/client/JobDescription.h"
00009 #include "job.h"
00010 
00011 #include "arex.h"
00012 
00013 namespace ARex {
00014 
00015 
00016 Arc::MCC_Status ARexService::MigrateActivity(ARexGMConfig& config,Arc::XMLNode in,Arc::XMLNode out,const std::string& clientid) {
00017   /*
00018   MigrateActivity
00019     ActivityIdentifier (wsa:EndpointReferenceType)
00020     ActivityDocument
00021       jsdl:JobDefinition
00022     ForceMigration
00023 
00024   MigrateActivityResponse
00025     ActivityIdentifier (wsa:EndpointReferenceType)
00026     ActivityDocument
00027       jsdl:JobDefinition
00028 
00029   NotAuthorizedFault
00030   NotAcceptingNewActivitiesFault
00031   UnsupportedFeatureFault
00032   InvalidRequestMessageFault
00033   */
00034   {
00035     std::string s;
00036     in.GetXML(s);
00037     logger_.msg(Arc::VERBOSE, "MigrateActivity: request = \n%s", s);
00038   };
00039   Arc::WSAEndpointReference id(in["ActivityIdentifier"]);
00040   if(!(Arc::XMLNode)id) {
00041     // Wrong request
00042     logger_.msg(Arc::ERROR, "MigrateActivitys: no ActivityIdentifier found");
00043     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find ActivityIdentifier element in request");
00044     InvalidRequestMessageFault(fault,"jsdl:ActivityIdentifier","Element is missing");
00045     out.Destroy();
00046     return Arc::MCC_Status();
00047   };
00048   std::string migrateid = Arc::WSAEndpointReference(id).Address() + "/" + (std::string)Arc::WSAEndpointReference(id).ReferenceParameters()["a-rex:JobID"];
00049   if(migrateid.empty()) {
00050     // EPR is wrongly formated or not an A-REX EPR
00051     logger_.msg(Arc::ERROR, "MigrateActivity: EPR contains no JobID");
00052     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find JobID element in ActivityIdentifier");
00053     InvalidRequestMessageFault(fault,"a-rex:JobID","Element is missing");
00054     out.Destroy();
00055     return Arc::MCC_Status();
00056   };
00057 
00058   // HPC Basic Profile 1.0 comply (these fault handlings are defined in the KnowARC standards 
00059   // conformance roadmap 2nd release)
00060 
00061  // End of the HPC BP 1.0 fault handling part
00062 
00063   std::string delegation;
00064   Arc::XMLNode delegated_token = in["deleg:DelegatedToken"];
00065   if(delegated_token) {
00066     // Client wants to delegate credentials
00067     if(!delegations_.DelegatedToken(delegation,delegated_token)) {
00068       // Failed to accept delegation (report as bad request)
00069       logger_.msg(Arc::ERROR, "MigrateActivity: Failed to accept delegation");
00070       Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Failed to accept delegation");
00071       InvalidRequestMessageFault(fault,"deleg:DelegatedToken","This token does not exist");
00072       out.Destroy();
00073       return Arc::MCC_Status();
00074     };
00075   };
00076 
00077   if( !(in["ActivityDocument"]["JobDefinition"])) {
00078     /*
00079     // First try to get job desc from old cluster
00080     logger_.msg(Arc::VERBOSE, "MigrateActivity: no job description found try to get it from old cluster");
00081     Arc::MCCConfig cfg;
00082     // TODO:
00083     //if (!proxyPath.empty())
00084     cfg.AddProxy(delegation);
00085     //if (!certificatePath.empty())
00086       //cfg.AddCertificate(certificatePath);
00087     //if (!keyPath.empty())
00088       //cfg.AddPrivateKey(keyPath);
00089     //if (!caCertificatesDir.empty())
00090       //cfg.AddCADir(caCertificatesDir);
00091     Arc::URL url(migrateid);
00092     Arc::PathIterator pi(url.Path(), true);
00093     url.ChangePath(*pi);
00094     Arc::AREXClient ac(url, cfg);
00095     Arc::NS ns;
00096     ns["a-rex"] = "http://www.nordugrid.org/schemas/a-rex";
00097     ns["bes-factory"] = "http://schemas.ggf.org/bes/2006/08/bes-factory";
00098     ns["wsa"] = "http://www.w3.org/2005/08/addressing";
00099     ns["jsdl"] = "http://schemas.ggf.org/jsdl/2005/11/jsdl";
00100     ns["jsdl-posix"] = "http://schemas.ggf.org/jsdl/2005/11/jsdl-posix";
00101     ns["jsdl-arc"] = "http://www.nordugrid.org/ws/schemas/jsdl-arc";
00102     ns["jsdl-hpcpa"] = "http://schemas.ggf.org/jsdl/2006/07/jsdl-hpcpa";
00103     Arc::XMLNode id(ns, "ActivityIdentifier");
00104     id.NewChild("wsa:Address") = url.str();
00105     id.NewChild("wsa:ReferenceParameters").NewChild("a-rex:JobID") = pi.Rest();
00106     std::string idstr;
00107     id.GetXML(idstr);
00108     std::string desc_str;
00109     if (ac.getdesc(idstr,desc_str)){
00110       Arc::JobDescription desc;
00111       desc.setSource(desc_str);
00112       if (desc.isValid()) {
00113         logger_.msg(Arc::INFO,"Valid job description obtained");
00114         if ( !( in["ActivityDocument"] ) ) in.NewChild("bes-factory:ActivityDocument");
00115         Arc::XMLNode XMLdesc;
00116         desc.getXML(XMLdesc);
00117         in["ActivityDocument"].NewChild(XMLdesc);
00118       } else {
00119         // Wrongly formatted job description
00120         logger_.msg(Arc::ERROR, "MigrateActivity: job description could not be fetch from old cluster");
00121         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find JobDefinition element in request");
00122         InvalidRequestMessageFault(fault,"jsdl:JobDefinition","Element is missing");
00123         out.Destroy();
00124         return Arc::MCC_Status();
00125       }
00126     }
00127     */
00128     //else {
00129       // Not able to get job description
00130       logger_.msg(Arc::ERROR, "MigrateActivity: no job description found");
00131       //logger_.msg(Arc::ERROR, "MigrateActivity: job description could not be fetch from old cluster");
00132       Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find JobDefinition element in request");
00133       InvalidRequestMessageFault(fault,"jsdl:JobDefinition","Element is missing");
00134       out.Destroy();
00135       return Arc::MCC_Status();
00136     //}
00137   };
00138 
00139   Arc::XMLNode jsdl = in["ActivityDocument"]["JobDefinition"];
00140 
00141   Arc::NS ns;
00142   // Creating migration XMLNode
00143   Arc::XMLNode migration(ns, "Migration");
00144   migration.NewChild("ActivityIdentifier") = migrateid;
00145   if( (bool)in["ForceMigration"]){
00146     migration.NewChild("ForceMigration") = (std::string)in["ForceMigration"];
00147   } else {
00148     migration.NewChild("ForceMigration") = "true";
00149   }
00150 
00151   std::string migrationStr;
00152   migration.GetDoc(migrationStr, true);
00153   logger_.msg(Arc::INFO, "Migration XML sent to AREXJob: %s", migrationStr);
00154 
00155   ARexJob job(jsdl,config,delegation,clientid,logger_,migration);
00156   if(!job) {
00157     ARexJobFailure failure_type = job;
00158     std::string failure = job.Failure();
00159     switch(failure_type) {
00160       case ARexJobDescriptionUnsupportedError: {
00161         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Unsupported feature in job description");
00162         UnsupportedFeatureFault(fault,failure);
00163       }; break;
00164       case ARexJobDescriptionMissingError: {
00165         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Missing needed element in job description");
00166         UnsupportedFeatureFault(fault,failure);
00167       }; break;
00168       case ARexJobDescriptionLogicalError: {
00169         std::string element;
00170         std::string::size_type pos = failure.find(' ');
00171         if(pos != std::string::npos) {
00172           element=failure.substr(0,pos);
00173           failure=failure.substr(pos+1);
00174         };
00175         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Logical error in job description");
00176         InvalidRequestMessageFault(fault,element,failure);
00177       }; break;
00178       default: {
00179         logger_.msg(Arc::ERROR, "MigrateActivity: Failed to migrate new job: %s",failure);
00180         // Failed to migrate new job (no corresponding BES fault defined - using generic SOAP error)
00181         logger_.msg(Arc::ERROR, "MigrateActivity: Failed to migrate new job");
00182         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,("Failed to migrate new activity: "+failure).c_str());
00183         GenericFault(fault);
00184       };
00185     };
00186     out.Destroy();
00187     return Arc::MCC_Status();
00188   };
00189 
00190   // Make SOAP response
00191   Arc::WSAEndpointReference identifier(out.NewChild("bes-factory:ActivityIdentifier"));
00192   // Make job's ID
00193   identifier.Address(config.Endpoint()); // address of service
00194   identifier.ReferenceParameters().NewChild("a-rex:JobID")=job.ID();
00195   identifier.ReferenceParameters().NewChild("a-rex:JobSessionDir")=config.Endpoint()+"/"+job.ID();
00196   out.NewChild(in["ActivityDocument"]);
00197   logger_.msg(Arc::VERBOSE, "MigrateActivity finished successfully");
00198   {
00199     std::string s;
00200     out.GetXML(s);
00201     logger_.msg(Arc::VERBOSE, "MigrateActivity: response = \n%s", s);
00202   };
00203   /* Needs to kill old job */
00204 
00205   return Arc::MCC_Status(Arc::STATUS_OK);
00206 }
00207 
00208 } // namespace ARex
00209