Back to index

nordugrid-arc-nox  1.1.0~rc6
JobRecord.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <istream>
00006 #include <sstream>
00007 
00008 #include <arc/XMLNode.h>
00009 
00010 #include "../grid-manager/conf/conf.h"
00011 
00012 namespace ARex {
00013 
00014 static void split(const std::string& str, const std::string delim, Arc::XMLNode& root, const std::string& name) {
00015   std::string::size_type offset = 0;
00016   std::string::size_type delimIndex = 0;
00017 
00018   delimIndex = str.find(delim, offset);
00019 
00020   while (delimIndex != std::string::npos) {
00021     root.NewChild(name) = str.substr(offset, delimIndex - offset);
00022     offset += delimIndex - offset + delim.length();
00023     delimIndex = str.find(delim, offset);
00024   }
00025 
00026   root.NewChild(name) = str.substr(offset);
00027 }
00028 
00029 class JobRecord: public Arc::XMLNode {
00030  private:
00031   bool valid;
00032   void set(std::istream& i);
00033  public:
00034   std::string url;
00035   operator bool(void) { return valid; };
00036   bool operator!(void) { return !valid; };
00037   JobRecord(std::istream& i);
00038   JobRecord(const std::string& s);
00039   JobRecord(XMLNode& xml);
00040   JobRecord(const JobRecord& j);
00041   ~JobRecord(void);
00042 };
00043 
00044 JobRecord::JobRecord(const JobRecord& j) {
00045   valid=j.valid;
00046   url=j.url; // ???
00047   j.New(*this);
00048 }
00049 
00050 JobRecord::JobRecord(XMLNode& xml) {
00051   valid=true; // !!!
00052   xml.New(*this);
00053 }
00054 
00055 void JobRecord::set(std::istream& i) {
00056   valid=false;
00057   Arc::NS ns;
00058   ns[""]="http://www.nordugrid.org/ws/schemas/ARCLoggerV2";
00059   Arc::XMLNode x(ns,"UsageRecord");
00060   x.New(*this);
00061   for(;;) {
00062     if(i.fail()) goto error;
00063     if(i.eof()) break;
00064     std::string value;
00065     std::string key = config_read_line(i,value,'=');
00066     if(key=="loggerurl") { url=value; }
00067     else if(key=="ngjobid") { NewChild("globaljobid")=value; }
00068     else if(key=="usersn") { NewChild("globaluserid")=value; }
00069     else if(key=="usersn") { NewChild("globaluserid")=value; }
00070     else if(key=="cluster") { NewChild("cluster")=value; }
00071     else if(key=="description") { NewChild("jobdescription")=value; }
00072     else if(key=="projectname") { NewChild("projectname")=value; }
00073     else if(key=="jobname") { NewChild("jobname")=value; }
00074     else if(key=="clienthost") { NewChild("submithost")=value; }
00075     else if(key=="requestedcputime") { NewChild("requestedcputime")=value; }
00076     else if(key=="requestedwalltime") { NewChild("requestedwalltime")=value; }
00077     else if(key=="requestedmemory") { NewChild("requestedmemory")=value; }
00078     else if(key=="requesteddisk") { NewChild("requesteddisk")=value; }
00079     else if(key=="submissiontime") { NewChild("submissiontime")=value; }
00080     else if(key=="localuser") { NewChild("localuserid")=value; }
00081     else if(key=="queue") { NewChild("queue")=value; }
00082     else if(key=="lrms") { NewChild("lrms")=value; }
00083     else if(key=="localjobid") { NewChild("localjobid")=value; }
00084     else if(key=="lrmssubmissiontime") { NewChild("lrmssubmissiontime")=value; }
00085     else if(key=="lrmsendtime") { NewChild("lrmsendtime")=value; }
00086     else if(key=="nodename") { split(value, ",", *this, "nodename"); }
00087     else if(key=="nodecount") { NewChild("nodecount")=value; }
00088     else if(key=="processors") { NewChild("processors")=value; }
00089     else if(key=="exitcode") { NewChild("exitcode")=value; }
00090     else if(key=="failurestring") { NewChild("failurestring")=value; }
00091     else if(key=="usedcputime") { NewChild("usedcputime")=value; }
00092     else if(key=="usedwalltime") { NewChild("usedwalltime")=value; }
00093     else if(key=="usedmemory") { NewChild("usedmemory")=value; }
00094     else if(key=="useddisk") { NewChild("useddisk")=value; }
00095     else if(key=="status") { NewChild("status")=value; }
00096     else if(key=="endtime") { NewChild("endtime")=value; }
00097     else if(key=="downloadtime") { NewChild("downloadtime")=value; }
00098     else if(key=="uploadtime") { NewChild("uploadtime")=value; }
00099     else if(key=="processid") { split(value, ",", *this, "processid"); }
00100     else if(key=="charge") { NewChild("charge")=value; }
00101     else if(key=="network") { NewChild("network")=value; }
00102     else if(key=="stageindata") { NewChild("stageindata")=value; }
00103     else if(key=="stageoutdata") { NewChild("stageoutdata")=value; }
00104     else if(key=="usedswap") { NewChild("usedswap")=value; }
00105     else if(key=="servicelevel") { NewChild("servicelevel")=value; }
00106     else if(key=="runtimeenvironment") { split(value, ",", *this, "runtimeenvironment"); }
00107   };
00108   valid=true;
00109 error:
00110   return;
00111 }
00112 
00113 JobRecord::JobRecord(std::istream& i) {
00114   set(i);
00115 }
00116 
00117 JobRecord::JobRecord(const std::string& s) {
00118   std::istringstream i(s);
00119   set(i);
00120 }
00121 
00122 JobRecord::~JobRecord(void) {
00123 }
00124 
00125 }
00126