ARC SDK
JobDescription.h
Go to the documentation of this file.
1 #ifndef __ARC_JOBDESCRIPTION_H__
2 #define __ARC_JOBDESCRIPTION_H__
3 
8 #include <list>
9 #include <vector>
10 #include <string>
11 
12 #include <arc/DateTime.h>
13 #include <arc/XMLNode.h>
14 #include <arc/URL.h>
15 #include <arc/compute/Software.h>
16 
17 
18 namespace Arc {
19 
28  class JobDescriptionParserPluginLoader;
29  class ExecutionTarget;
30 
35  template<class T>
36  class OptIn {
37  public:
38  OptIn<T>() : optIn(false) {}
39  OptIn<T>(const T& t) : v(t), optIn(false) {}
40  OptIn<T>(const T& t, bool o) : v(t), optIn(o) {}
41  OptIn<T>(const OptIn<T>& ot) : v(ot.v), optIn(ot.optIn) {}
42 
43  OptIn<T>& operator=(const OptIn<T>& ot) { v = ot.v; optIn = ot.optIn; return *this; }
44  OptIn<T>& operator=(const T& t) { v = t; optIn = false; return *this; }
45 
46  operator T() const { return v; }
47 
48  T v;
49  bool optIn;
50  };
51 
56  template<class T>
57  class Range {
58  public:
59  Range<T>() : min(0), max(0) {}
60  Range<T>(const T& t) : min(t), max(t) {}
61  operator T(void) const { return max; }
62 
63  Range<T>& operator=(const Range<T>& t) { min = t.min; max = t.max; return *this; };
64  Range<T>& operator=(const T& t) { max = t; return *this; };
65 
66  T min;
67  T max;
68  };
69 
74  template<class T>
75  class ScalableTime {
76  public:
77  ScalableTime<T>() : benchmark("", -1.) {}
78  ScalableTime<T>(const T& t) : range(t) {}
79 
80  std::pair<std::string, double> benchmark;
81  Range<T> range;
82  };
83 
88  template<>
89  class ScalableTime<int> {
90  public:
91  ScalableTime<int>() : benchmark("", -1.) {}
92  ScalableTime<int>(const int& t) : range(t) {}
93 
94  std::pair<std::string, double> benchmark;
95  Range<int> range;
96 
97  int scaleMin(double s) const { return (int)(range.min*benchmark.second/s); }
98  int scaleMax(double s) const { return (int)(range.max*benchmark.second/s); }
99  };
100 
102 
113  public:
115  JobName(""), Description(""), Type("") {}
117 
122  std::string JobName;
123 
125 
130  std::string Description;
131 
133 
138  std::string Type;
139 
141 
145  std::list<std::string> Annotation;
146 
148 
155  std::list<std::string> ActivityOldID;
156  };
157 
159 
170  public:
171  ExecutableType() : Path(""), SuccessExitCode(false, 0) {}
172 
174 
179  std::string Path;
180 
182 
186  std::list<std::string> Argument;
187 
189 
198  std::pair<bool, int> SuccessExitCode;
199  };
200 
202 
210  public:
211  RemoteLoggingType() : optional(false) {}
212 
214 
220  std::string ServiceType;
221 
223 
228 
230 
235  bool optional;
236  };
237 
243  public:
244  NotificationType() {}
245  std::string Email;
246  std::list<std::string> States;
247  };
248 
254  public:
255  ApplicationType() :
256  Rerun(-1),
257  ExpirationTime(-1),
258  ProcessingStartTime(-1),
259  Priority (-1),
260  DryRun(false)
261  {}
262  ApplicationType& operator=(const ApplicationType&);
264 
271 
273 
277  std::string Input;
278 
280 
285  std::string Output;
286 
288 
292  std::string Error;
293 
294  std::list< std::pair<std::string, std::string> > Environment;
295 
297 
303  std::list<ExecutableType> PreExecutable;
304 
306 
312  std::list<ExecutableType> PostExecutable;
313 
315 
319  std::string LogDir;
320 
322 
326  std::list<RemoteLoggingType> RemoteLogging;
327 
328  int Rerun;
329  Time ExpirationTime;
330  Time ProcessingStartTime;
331  int Priority;
332  std::list<NotificationType> Notification;
333  std::list<URL> CredentialService;
334  XMLNode AccessControl;
335  bool DryRun;
336  };
337 
343  public:
345  NumberOfSlots(-1),
346  SlotsPerHost(-1),
347  ExclusiveExecution(EE_DEFAULT) {}
348  int NumberOfSlots; // Range?
349  int SlotsPerHost; // Range?
350  enum ExclusiveExecutionType {
351  EE_DEFAULT,
352  EE_TRUE,
353  EE_FALSE
354  } ExclusiveExecution;
355  };
356 
362  public:
364  DiskSpace(-1),
365  CacheDiskSpace(-1),
366  SessionDiskSpace(-1) {}
381  };
382 
387  enum SessionDirectoryAccessMode {
388  SDAM_NONE = 0,
389  SDAM_RO = 1,
390  SDAM_RW = 2
391  };
392 
397  enum NodeAccessType {
398  NAT_NONE = 0,
399  NAT_INBOUND = 1,
400  NAT_OUTBOUND = 2,
401  NAT_INOUTBOUND = 3
402  };
403 
409  public:
411  ProcessesPerSlot(-1),
412  ThreadsPerProcess(-1) {}
413  std::string Type;
414  std::string Version;
415  int ProcessesPerSlot; // Range?
416  int ThreadsPerProcess; // Range?
417  std::multimap<std::string, std::string> Options;
418  };
419 
425  public:
426  ResourcesType() :
427  IndividualPhysicalMemory(-1),
428  IndividualVirtualMemory(-1),
429  SessionLifeTime(-1),
430  SessionDirectoryAccess(SDAM_NONE),
431  IndividualCPUTime(-1),
432  TotalCPUTime(-1),
433  IndividualWallTime(-1),
434  TotalWallTime(IndividualWallTime),
435  NodeAccess(NAT_NONE) {}
436  ResourcesType& operator=(const ResourcesType&);
437 
438  SoftwareRequirement OperatingSystem;
439  std::string Platform;
440  std::string NetworkInfo;
441  Range<int> IndividualPhysicalMemory;
442  Range<int> IndividualVirtualMemory;
443  DiskSpaceRequirementType DiskSpaceRequirement;
444  Period SessionLifeTime;
445  SessionDirectoryAccessMode SessionDirectoryAccess;
446  ScalableTime<int> IndividualCPUTime;
447  ScalableTime<int> TotalCPUTime;
448  ScalableTime<int> IndividualWallTime;
449  ScalableTime<int>& TotalWallTime;
450  NodeAccessType NodeAccess;
451  SoftwareRequirement CEType;
452  SlotRequirementType SlotRequirement;
453  ParallelEnvironmentType ParallelEnvironment;
454  OptIn<std::string> Coprocessor;
455  std::string QueueName;
456  SoftwareRequirement RunTimeEnvironment;
457  };
458 
463  class SourceType: public URL {
464  public:
465  SourceType() {};
466  SourceType(const URL& u):URL(u) {};
467  SourceType(const std::string& s):URL(s) {};
468  SourceType& operator=(const URL& u) { URL::operator=(u); return *this; };
469  SourceType& operator=(const std::string& s) { URL::operator=(s); return *this; };
470  std::string DelegationID;
471  };
472 
477  class TargetType: public URL {
478  public:
479  TargetType() :
480  CreationFlag(CFE_DEFAULT),
481  UseIfFailure(false),
482  UseIfCancel(false),
483  UseIfSuccess(true) {};
484  TargetType(const URL& u) :
485  URL(u),
486  CreationFlag(CFE_DEFAULT),
487  UseIfFailure(false),
488  UseIfCancel(false),
489  UseIfSuccess(true) {};
490  TargetType(const std::string& s) :
491  URL(s),
492  CreationFlag(CFE_DEFAULT),
493  UseIfFailure(false),
494  UseIfCancel(false),
495  UseIfSuccess(true) {};
496  std::string DelegationID;
497  enum CreationFlagEnumeration {
498  CFE_DEFAULT,
499  CFE_OVERWRITE,
500  CFE_APPEND,
501  CFE_DONTOVERWRITE
502  };
503  CreationFlagEnumeration CreationFlag;
504  bool UseIfFailure;
505  bool UseIfCancel;
506  bool UseIfSuccess;
507  };
508 
514  public:
515  InputFileType() : Name(""), IsExecutable(false), FileSize(-1) {};
516  std::string Name;
517  bool IsExecutable;
518  long FileSize;
520 
524  std::string Checksum;
525  std::list<SourceType> Sources;
526  };
527 
533  public:
534  OutputFileType() : Name("") {};
535  std::string Name;
536  std::list<TargetType> Targets;
537  };
538 
544  public:
545  DataStagingType() {};
546  std::list<InputFileType> InputFiles;
547  std::list<OutputFileType> OutputFiles;
548  };
549 
550 
557  public:
558  JobDescriptionResult(bool r):res(r) { };
559  JobDescriptionResult(bool r, const std::string& s):res(r),desc(s) { };
560  operator bool(void) { return res; };
561  bool operator!(void) { return !res; };
562  const std::string& str(void) { return desc; };
563  private:
564  bool res;
565  std::string desc;
566  };
567 
587  public:
588  friend class JobDescriptionParserPlugin;
589  JobDescription() : alternatives(), current(alternatives.begin()) {};
590 
591  JobDescription(const JobDescription& j, bool withAlternatives = true);
592 
593  JobIdentificationType Identification;
594  ApplicationType Application;
595  ResourcesType Resources;
596  DataStagingType DataStaging;
597 
598  JobDescription& operator=(const JobDescription& j);
599 
600  // Language wrapper constructor
601  JobDescription(const long int& ptraddr);
602 
603  ~JobDescription() {}
604 
605  void AddAlternative(const JobDescription& j);
606 
607  bool HasAlternatives() const { return !alternatives.empty(); }
608  const std::list<JobDescription>& GetAlternatives() const { return alternatives; }
609  std::list<JobDescription>& GetAlternatives() { return alternatives; }
610  std::list<JobDescription> GetAlternativesCopy() const { return alternatives; }
611  bool UseAlternative();
612  void UseOriginal();
613 
614  void RemoveAlternatives();
615 
617 
636  static JobDescriptionResult Parse(const std::string& source, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
637 
638  static JobDescriptionResult ParseFromFile(const std::string& filename, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
639 
641 
648  JobDescriptionResult UnParse(std::string& product, std::string language, const std::string& dialect = "") const;
649 
650 
652 
660  const std::string& GetSourceLanguage() const { return sourceLanguage; }
661 
663 
679  JobDescriptionResult SaveToStream(std::ostream& out, const std::string& format) const;
680 
682 
713  bool Prepare(const ExecutionTarget& et) { return Prepare(&et); }
714 
715  bool Prepare() { return Prepare(NULL); }
716 
717  static bool GetTestJob(int testid, JobDescription& jobdescription);
718 
720 
729  std::map<std::string, std::string> OtherAttributes;
730 
731  private:
732  bool Prepare(const ExecutionTarget* et);
733 
734  void Set(const JobDescription& j);
735 
736  std::string sourceLanguage;
737 
738  std::list<JobDescription> alternatives;
739  std::list<JobDescription>::iterator current;
740 
741  static Glib::Mutex jdpl_lock;
743 
744  static Logger logger;
745  };
746 
747 } // namespace Arc
748 
749 #endif // __ARC_JOBDESCRIPTION_H__