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;
456  std::string QueueName;
457  SoftwareRequirement RunTimeEnvironment;
458  };
459 
464  class SourceType: public URL {
465  public:
466  SourceType() {};
467  SourceType(const URL& u):URL(u) {};
468  SourceType(const std::string& s):URL(s) {};
469  SourceType& operator=(const URL& u) { URL::operator=(u); return *this; };
470  SourceType& operator=(const std::string& s) { URL::operator=(s); return *this; };
471  std::string DelegationID;
472  };
473 
475 
479  class TargetType: public URL {
480  public:
482 
489  UseIfFailure(false),
490  UseIfCancel(false),
491  UseIfSuccess(true) {};
493 
496  TargetType(const URL& u) :
497  URL(u),
499  UseIfFailure(false),
500  UseIfCancel(false),
501  UseIfSuccess(true) {};
503 
506  TargetType(const std::string& s) :
507  URL(s),
509  UseIfFailure(false),
510  UseIfCancel(false),
511  UseIfSuccess(true) {};
512 
514 
517  std::string DelegationID;
518 
524  };
525 
527 
532 
534 
539 
541 
546 
548 
553  };
554 
560  public:
561  InputFileType() : Name(""), IsExecutable(false), FileSize(-1) {};
562  std::string Name;
563  bool IsExecutable;
564  long FileSize;
566 
570  std::string Checksum;
571  std::list<SourceType> Sources;
572  };
573 
575 
580  public:
581  OutputFileType() : Name("") {};
583  std::string Name;
585  std::list<TargetType> Targets;
586  };
587 
589 
594  public:
596 
598  std::list<InputFileType> InputFiles;
600  std::list<OutputFileType> OutputFiles;
601  };
602 
603 
610  public:
611  JobDescriptionResult(bool r):res(r) { };
612  JobDescriptionResult(bool r, const std::string& s):res(r),desc(s) { };
613  operator bool(void) { return res; };
614  bool operator!(void) { return !res; };
615  const std::string& str(void) { return desc; };
616  private:
617  bool res;
618  std::string desc;
619  };
620 
640  public:
641  friend class JobDescriptionParserPlugin;
642  JobDescription() : alternatives(), current(alternatives.begin()) {};
643 
644  JobDescription(const JobDescription& j, bool withAlternatives = true);
645 
646  // Language wrapper constructor
647  JobDescription(const long int& ptraddr);
648 
649  ~JobDescription() {}
650 
651  JobDescription& operator=(const JobDescription& j);
652 
653  void AddAlternative(const JobDescription& j);
654 
655  bool HasAlternatives() const { return !alternatives.empty(); }
656  const std::list<JobDescription>& GetAlternatives() const { return alternatives; }
657  std::list<JobDescription>& GetAlternatives() { return alternatives; }
658  std::list<JobDescription> GetAlternativesCopy() const { return alternatives; }
659  bool UseAlternative();
660  void UseOriginal();
661 
662  void RemoveAlternatives();
663 
665 
684  static JobDescriptionResult Parse(const std::string& source, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
685 
686  static JobDescriptionResult ParseFromFile(const std::string& filename, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
687 
689 
696  JobDescriptionResult UnParse(std::string& product, std::string language, const std::string& dialect = "") const;
697 
699 
707  const std::string& GetSourceLanguage() const { return sourceLanguage; }
708 
710 
726  JobDescriptionResult SaveToStream(std::ostream& out, const std::string& format) const;
727 
729 
760  bool Prepare(const ExecutionTarget& et) { return Prepare(&et); }
761 
762  bool Prepare() { return Prepare(NULL); }
763 
764  static bool GetTestJob(int testid, JobDescription& jobdescription);
765 
767 
772 
774 
778 
780 
785 
787 
792 
794 
803  std::map<std::string, std::string> OtherAttributes;
804 
805  private:
806  bool Prepare(const ExecutionTarget* et);
807 
808  void Set(const JobDescription& j);
809 
810  std::string sourceLanguage;
811 
812  std::list<JobDescription> alternatives;
813  std::list<JobDescription>::iterator current;
814 
815  static Glib::Mutex jdpl_lock;
817 
818  static Logger logger;
819  };
820 
821 } // namespace Arc
822 
823 #endif // __ARC_JOBDESCRIPTION_H__