Back to index

nordugrid-arc-nox  1.1.0~rc6
terminate_activities.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::TerminateActivities(ARexGMConfig& config,Arc::XMLNode in,Arc::XMLNode out) {
00015   /*
00016   TerminateActivities
00017     ActivityIdentifier (wsa:EndpointReferenceType, unbounded)
00018 
00019   TerminateActivitiesResponse
00020     Response (unbounded)
00021       ActivityIdentifier
00022       Terminated (boolean)
00023       Fault (soap:Fault)
00024 
00025   */
00026   {
00027     std::string s;
00028     in.GetXML(s);
00029     logger_.msg(Arc::VERBOSE, "TerminateActivities: request = \n%s", s);
00030   };
00031   for(int n = 0;;++n) {
00032     Arc::XMLNode id = in["ActivityIdentifier"][n];
00033     if(!id) break;
00034     // Create place for response
00035     Arc::XMLNode resp = out.NewChild("bes-factory:Response");
00036     resp.NewChild(id);
00037     std::string jobid = Arc::WSAEndpointReference(id).ReferenceParameters()["a-rex:JobID"];
00038     if(jobid.empty()) {
00039       // EPR is wrongly formated or not an A-REX EPR
00040       logger_.msg(Arc::ERROR, "TerminateActivities: non-ARex job requested");
00041       Arc::SOAPFault fault(resp,Arc::SOAPFault::Sender,"Missing a-rex:JobID in ActivityIdentifier");
00042       UnknownActivityIdentifierFault(fault,"Unrecognized EPR in ActivityIdentifier");
00043       continue;
00044     };
00045     // Look for obtained ID
00046     ARexJob job(jobid,config,logger_);
00047     if(!job) {
00048       // There is no such job
00049       logger_.msg(Arc::ERROR, "TerminateActivities: job %s - %s", jobid, job.Failure());
00050       Arc::SOAPFault fault(resp,Arc::SOAPFault::Sender,"No corresponding activity found");
00051       UnknownActivityIdentifierFault(fault,("No activity "+jobid+" found: "+job.Failure()).c_str());
00052       continue;
00053     };
00054     /*
00055     // Check permissions on that ID
00056     */
00057     // Cancel job (put a mark)
00058     bool result = job.Cancel();
00059     if(result) {
00060       resp.NewChild("bes-factory:Terminated")="true";
00061     } else {
00062       resp.NewChild("bes-factory:Terminated")="false";
00063       // Or should it be a fault?
00064     };
00065   };
00066   {
00067     std::string s;
00068     out.GetXML(s);
00069     logger_.msg(Arc::VERBOSE, "TerminateActivities: response = \n%s", s);
00070   };
00071   return Arc::MCC_Status(Arc::STATUS_OK);
00072 }
00073 
00074 } // namespace ARex
00075