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;
117 
118 
119  enum ResourceType {
120  STDIN,
121  STDOUT,
122  STDERR,
123  STAGEINDIR,
124  STAGEOUTDIR,
125  SESSIONDIR,
126  JOBLOG,
127  JOBDESCRIPTION
128  };
129 
131 
140  void SaveToStream(std::ostream& out, bool longlist) const;
141 
143 
153  Job& operator=(XMLNode job);
154 
155  Job& operator=(const Job& job);
156 
157  int operator==(const Job& other);
158 
160 
167  void SetFromXML(XMLNode job);
168 
170 
178  void ToXML(XMLNode job) const;
179 
180  bool PrepareHandler(const UserConfig& uc);
181  bool Update();
182 
183  bool Clean();
184 
185  bool Cancel();
186 
187  bool Resume();
188 
189  bool Renew();
190 
191  bool GetURLToResource(ResourceType resource, URL& url) const;
192 
193  bool Retrieve(const UserConfig& uc, const URL& destination, bool force) const;
194 
195  static bool CopyJobFile(const UserConfig& uc, const URL& src, const URL& dst);
196  static bool ListFilesRecursive(const UserConfig& uc, const URL& dir, std::list<std::string>& files) { files.clear(); return ListFilesRecursive(uc, dir, files, ""); }
197 
198  static bool CompareJobID(const Job& a, const Job& b) { return a.JobID.compare(b.JobID) < 0; }
199  static bool CompareSubmissionTime(const Job& a, const Job& b) { return a.SubmissionTime < b.SubmissionTime; }
200  static bool CompareJobName(const Job& a, const Job& b) { return a.Name.compare(b.Name) < 0; }
201 
203 
220  static bool ReadJobIDsFromFile(const std::string& filename, std::list<std::string>& jobids, unsigned nTries = 10, unsigned tryInterval = 500000);
221 
223 
238  static bool WriteJobIDToFile(const std::string& jobid, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
239 
241 
256  static bool WriteJobIDsToFile(const std::list<std::string>& jobids, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
257 
258  static bool WriteJobIDsToFile(const std::list<Job>& jobs, const std::string& filename, unsigned nTries = 10, unsigned tryInterval = 500000);
259 
260  private:
261  static bool ListFilesRecursive(const UserConfig& uc, const URL& dir, std::list<std::string>& files, const std::string& prefix);
262 
263  JobControllerPlugin* jc;
264 
265  static JobControllerPluginLoader& getLoader();
266 
267  // Objects might be pointing to allocated memory upon termination, leave it as garbage.
268  static DataHandle *data_source, *data_destination;
269 
270  static Logger logger;
271  };
272 
273 } // namespace Arc
274 
275 #endif // __ARC_JOB_H__