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 
148 
158  Job& operator=(XMLNode job);
159 
160  Job& operator=(const Job& job);
161 
162  int operator==(const Job& other);
163 
165 
172  void SetFromXML(XMLNode job);
173 
175 
183  void ToXML(XMLNode job) const;
184 
185  bool PrepareHandler(const UserConfig& uc);
186  bool Update();
187 
188  bool Clean();
189 
190  bool Cancel();
191 
192  bool Resume();
193 
194  bool Renew();
195 
196  bool GetURLToResource(ResourceType resource, URL& url) const;
197 
198  bool Retrieve(const UserConfig& uc, const URL& destination, bool force) const;
199 
200  static bool CopyJobFile(const UserConfig& uc, const URL& src, const URL& dst);
201  static bool ListFilesRecursive(const UserConfig& uc, const URL& dir, std::list<std::string>& files) { files.clear(); return ListFilesRecursive(uc, dir, files, ""); }
202 
203  static bool CompareJobID(const Job& a, const Job& b) { return a.JobID.compare(b.JobID) < 0; }
204  static bool CompareSubmissionTime(const Job& a, const Job& b) { return a.SubmissionTime < b.SubmissionTime; }
205  static bool CompareJobName(const Job& a, const Job& b) { return a.Name.compare(b.Name) < 0; }
206 
208 
225  static bool ReadJobIDsFromFile(const std::string& filename, std::list<std::string>& jobids, unsigned nTries = 10, unsigned tryInterval = 500000);
226 
228 
243  static bool WriteJobIDToFile(const std::string& jobid, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
244 
246 
261  static bool WriteJobIDsToFile(const std::list<std::string>& jobids, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
262 
263  static bool WriteJobIDsToFile(const std::list<Job>& jobs, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
264 
265  private:
266  static bool ListFilesRecursive(const UserConfig& uc, const URL& dir, std::list<std::string>& files, const std::string& prefix);
267 
268  JobControllerPlugin* jc;
269 
270  static JobControllerPluginLoader& getLoader();
271 
272  // Objects might be pointing to allocated memory upon termination, leave it as garbage.
273  static DataHandle *data_source, *data_destination;
274 
275  static Logger logger;
276  };
277 
278 } // namespace Arc
279 
280 #endif // __ARC_JOB_H__