Back to index

nordugrid-arc-nox  1.1.0~rc6
create_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 "job.h"
00008 
00009 #include "arex.h"
00010 
00011 namespace ARex {
00012 
00013 
00014 Arc::MCC_Status ARexService::CreateActivity(ARexGMConfig& config,Arc::XMLNode in,Arc::XMLNode out,const std::string& clientid) {
00015   /*
00016   CreateActivity
00017     ActivityDocument
00018       jsdl:JobDefinition
00019 
00020   CreateActivityResponse
00021     ActivityIdentifier (wsa:EndpointReferenceType)
00022     ActivityDocument
00023       jsdl:JobDefinition
00024 
00025   NotAuthorizedFault
00026   NotAcceptingNewActivitiesFault
00027   UnsupportedFeatureFault
00028   InvalidRequestMessageFault
00029   */
00030   {
00031     std::string s;
00032     in.GetXML(s);
00033     logger_.msg(Arc::VERBOSE, "CreateActivity: request = \n%s", s);
00034   };
00035   Arc::XMLNode jsdl = in["ActivityDocument"]["JobDefinition"];
00036   if(!jsdl) {
00037     // Wrongly formated request
00038     logger_.msg(Arc::ERROR, "CreateActivity: no job description found");
00039     Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Can't find JobDefinition element in request");
00040     InvalidRequestMessageFault(fault,"jsdl:JobDefinition","Element is missing");
00041     out.Destroy();
00042     return Arc::MCC_Status();
00043   };
00044 
00045   // HPC Basic Profile 1.0 comply (these fault handlings are defined in the KnowARC standards 
00046   // conformance roadmap 2nd release)
00047 
00048  // End of the HPC BP 1.0 fault handling part
00049 
00050   std::string delegation;
00051   Arc::XMLNode delegated_token = in["deleg:DelegatedToken"];
00052   if(delegated_token) {
00053     // Client wants to delegate credentials
00054     if(!delegations_.DelegatedToken(delegation,delegated_token)) {
00055       // Failed to accept delegation (report as bad request)
00056       logger_.msg(Arc::ERROR, "CreateActivity: Failed to accept delegation");
00057       Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Failed to accept delegation");
00058       InvalidRequestMessageFault(fault,"deleg:DelegatedToken","This token does not exist");
00059       out.Destroy();
00060       return Arc::MCC_Status();
00061     };
00062   };
00063   ARexJob job(jsdl,config,delegation,clientid,logger_);
00064   if(!job) {
00065     ARexJobFailure failure_type = job;
00066     std::string failure = job.Failure();
00067     switch(failure_type) {
00068       case ARexJobDescriptionUnsupportedError: {
00069         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Unsupported feature in job description");
00070         UnsupportedFeatureFault(fault,failure);
00071       }; break;
00072       case ARexJobDescriptionMissingError: {
00073         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Missing needed element in job description");
00074         UnsupportedFeatureFault(fault,failure);
00075       }; break;
00076       case ARexJobDescriptionLogicalError: {
00077         std::string element;
00078         std::string::size_type pos = failure.find(' ');
00079         if(pos != std::string::npos) {
00080           element=failure.substr(0,pos);
00081           failure=failure.substr(pos+1);
00082         };
00083         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,"Logical error in job description");
00084         InvalidRequestMessageFault(fault,element,failure);
00085       }; break;
00086       default: {
00087         logger_.msg(Arc::ERROR, "CreateActivity: Failed to create new job: %s",failure);
00088         // Failed to create new job (no corresponding BES fault defined - using generic SOAP error)
00089         logger_.msg(Arc::ERROR, "CreateActivity: Failed to create new job");
00090         Arc::SOAPFault fault(out.Parent(),Arc::SOAPFault::Sender,("Failed to create new activity: "+failure).c_str());
00091         GenericFault(fault);
00092       };
00093     };
00094     out.Destroy();
00095     return Arc::MCC_Status();
00096   };
00097   // Make SOAP response
00098   Arc::WSAEndpointReference identifier(out.NewChild("bes-factory:ActivityIdentifier"));
00099   // Make job's ID
00100   identifier.Address(config.Endpoint()); // address of service
00101   identifier.ReferenceParameters().NewChild("a-rex:JobID")=job.ID();
00102   identifier.ReferenceParameters().NewChild("a-rex:JobSessionDir")=config.Endpoint()+"/"+job.ID();
00103   out.NewChild(in["ActivityDocument"]);
00104   logger_.msg(Arc::VERBOSE, "CreateActivity finished successfully");
00105   {
00106     std::string s;
00107     out.GetXML(s);
00108     logger_.msg(Arc::VERBOSE, "CreateActivity: response = \n%s", s);
00109   };
00110   return Arc::MCC_Status(Arc::STATUS_OK);
00111 }
00112 
00113 } // namespace ARex
00114