ARC SDK
Job.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_JOB_H__
4 #define __ARC_JOB_H__
5 
6 #include <string>
7 #include <set>
8 
9 #include <arc/DateTime.h>
10 #include <arc/URL.h>
11 #include <arc/compute/JobState.h>
12 
13 namespace Arc {
14 
15  class DataHandle;
16  class JobControllerPlugin;
17  class JobControllerPluginLoader;
18  class JobSupervisor;
19  class Logger;
20  class UserConfig;
21  class XMLNode;
22 
24 
33  class Job {
34  friend class JobSupervisor;
35  public:
36 
38 
41  Job();
42  ~Job();
43 
44  Job(const Job& job);
45  Job(XMLNode job);
46 
47  // Proposed mandatory attributes for ARC 3.0
48  std::string JobID;
49  std::string Name;
50  URL ServiceInformationURL;
51  std::string ServiceInformationInterfaceName;
52  URL JobStatusURL;
53  std::string JobStatusInterfaceName;
54  URL JobManagementURL;
55  std::string JobManagementInterfaceName;
56 
57  URL StageInDir;
58  URL StageOutDir;
59  URL SessionDir;
60 
61  std::string Type;
62  std::string IDFromEndpoint;
63 
64  std::string LocalIDFromManager;
66 
70  std::string JobDescription;
71 
73 
78 
79  JobState State;
80  JobState RestartState;
81  int ExitCode;
82  std::string ComputingManagerExitCode;
83  std::list<std::string> Error;
84  int WaitingPosition;
85  std::string UserDomain;
86  std::string Owner;
87  std::string LocalOwner;
88  Period RequestedTotalWallTime;
89  Period RequestedTotalCPUTime;
90  int RequestedSlots;
91  std::list<std::string> RequestedApplicationEnvironment;
92  std::string StdIn;
93  std::string StdOut;
94  std::string StdErr;
95  std::string LogDir;
96  std::list<std::string> ExecutionNode;
97  std::string Queue;
98  Period UsedTotalWallTime;
99  Period UsedTotalCPUTime;
100  int UsedMainMemory;
101  Time LocalSubmissionTime;
102  Time SubmissionTime;
103  Time ComputingManagerSubmissionTime;
104  Time StartTime;
105  Time ComputingManagerEndTime;
106  Time EndTime;
107  Time WorkingAreaEraseTime;
108  Time ProxyExpirationTime;
109  std::string SubmissionHost;
110  std::string SubmissionClientName;
111  Time CreationTime;
112  Period Validity;
113  std::list<std::string> OtherMessages;
114  //Associations
115  std::list<std::string> ActivityOldID;
116  std::map<std::string, std::string> LocalInputFiles;
121  std::list<std::string> DelegationID;
122 
123 
124  enum ResourceType {
125  STDIN,
126  STDOUT,
127  STDERR,
128  STAGEINDIR,
129  STAGEOUTDIR,
130  SESSIONDIR,
131  JOBLOG,
132  JOBDESCRIPTION
133  };
134 
136 
145  void SaveToStream(std::ostream& out, bool longlist) const;
146  void SaveToStreamJSON(std::ostream& out, bool longlist) const;
147 
149 
159  Job& operator=(XMLNode job);
160 
161  Job& operator=(const Job& job);
162 
163  int operator==(const Job& other);
164 
166 
173  void SetFromXML(XMLNode job);
174 
176 
184  void ToXML(XMLNode job) const;
185 
186  bool PrepareHandler(const UserConfig& uc);
187  bool Update();
188 
189  bool Clean();
190 
191  bool Cancel();
192 
193  bool Resume();
194 
195  bool Renew();
196 
197  bool GetURLToResource(ResourceType resource, URL& url) const;
198 
199  bool Retrieve(const UserConfig& uc, const URL& destination, bool force) const;
200 
201  static bool CopyJobFile(const UserConfig& uc, const URL& src, const URL& dst);
202  static bool ListFilesRecursive(const UserConfig& uc, const URL& dir, std::list<std::string>& files) { files.clear(); return ListFilesRecursive(uc, dir, files, ""); }
203 
204  static bool CompareJobID(const Job& a, const Job& b) { return a.JobID.compare(b.JobID) < 0; }
205  static bool CompareSubmissionTime(const Job& a, const Job& b) { return a.SubmissionTime < b.SubmissionTime; }
206  static bool CompareJobName(const Job& a, const Job& b) { return a.Name.compare(b.Name) < 0; }
207 
209 
226  static bool ReadJobIDsFromFile(const std::string& filename, std::list<std::string>& jobids, unsigned nTries = 10, unsigned tryInterval = 500000);
227 
229 
244  static bool WriteJobIDToFile(const std::string& jobid, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
245 
247 
262  static bool WriteJobIDsToFile(const std::list<std::string>& jobids, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
263 
264  static bool WriteJobIDsToFile(const std::list<Job>& jobs, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
265 
266  private:
267  static bool ListFilesRecursive(const UserConfig& uc, const URL& dir, std::list<std::string>& files, const std::string& prefix);
268 
269  JobControllerPlugin* jc;
270 
271  static JobControllerPluginLoader& getLoader();
272 
273  // Objects might be pointing to allocated memory upon termination, leave it as garbage.
274  static DataHandle *data_source, *data_destination;
275 
276  static Logger logger;
277  };
278 
279 } // namespace Arc
280 
281 #endif // __ARC_JOB_H__
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
Job & operator=(XMLNode job)
Set Job attributes from a XMLNode.
static bool WriteJobIDsToFile(const std::list< std::string > &jobids, const std::string &filename, unsigned nTries=10, unsigned tryInterval=500000)
Append list of URLs to a file.
User configuration class
Definition: UserConfig.h:196
std::string JobDescriptionDocument
Job description document describing job.
Definition: Job.h:77
Wrapper for LibXML library Tree interface.
Definition: XMLNode.h:61
A class for storing and manipulating times.
Definition: DateTime.h:125
std::list< std::string > DelegationID
Definition: Job.h:121
void SetFromXML(XMLNode job)
Set Job attributes from a XMLNode representing GLUE2 ComputingActivity.
static bool ReadJobIDsFromFile(const std::string &filename, std::list< std::string > &jobids, unsigned nTries=10, unsigned tryInterval=500000)
Read a list of Job IDs from a file, and append them to a list.
Job.
Definition: Job.h:33
void SaveToStream(std::ostream &out, bool longlist) const
Write job information to a std::ostream object.
Job()
Create a Job object.
JobSupervisor class.
Definition: JobSupervisor.h:48
static bool WriteJobIDToFile(const std::string &jobid, const std::string &filename, unsigned nTries=10, unsigned tryInterval=500000)
Append a jobID to a file.
void ToXML(XMLNode job) const
Add job information to a XMLNode.
A Period represents a length of time.
Definition: DateTime.h:48
Class to represent general URLs.
Definition: URL.h:88
Definition: JobState.h:42
std::string JobDescription
Language of job description describing job.
Definition: Job.h:70