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 
35  class JobDescriptionParserPluginLoader;
36  class ExecutionTarget;
37 
42  template<class T>
43  class OptIn {
44  public:
45  OptIn<T>() : optIn(false) {}
46  OptIn<T>(const T& t) : v(t), optIn(false) {}
47  OptIn<T>(const T& t, bool o) : v(t), optIn(o) {}
48  OptIn<T>(const OptIn<T>& ot) : v(ot.v), optIn(ot.optIn) {}
49 
50  OptIn<T>& operator=(const OptIn<T>& ot) { v = ot.v; optIn = ot.optIn; return *this; }
51  OptIn<T>& operator=(const T& t) { v = t; optIn = false; return *this; }
52 
53  operator T() const { return v; }
54 
55  T v;
56  bool optIn;
57  };
58 
63  template<class T>
64  class Range {
65  public:
66  Range<T>() : min(0), max(0) {}
67  Range<T>(const T& t) : min(t), max(t) {}
68  operator T(void) const { return max; }
69 
70  Range<T>& operator=(const Range<T>& t) { min = t.min; max = t.max; return *this; };
71  Range<T>& operator=(const T& t) { max = t; return *this; };
72 
73  T min;
74  T max;
75  };
76 
81  template<class T>
82  class ScalableTime {
83  public:
84  ScalableTime<T>() : benchmark("", -1.) {}
85  ScalableTime<T>(const T& t) : range(t) {}
86 
87  std::pair<std::string, double> benchmark;
88  Range<T> range;
89  };
90 
95  template<>
96  class ScalableTime<int> {
97  public:
98  ScalableTime<int>() : benchmark("", -1.) {}
99  ScalableTime<int>(const int& t) : range(t) {}
100 
101  std::pair<std::string, double> benchmark;
102  Range<int> range;
103 
104  int scaleMin(double s) const { return (int)(range.min*benchmark.second/s); }
105  int scaleMax(double s) const { return (int)(range.max*benchmark.second/s); }
106  };
107 
109 
119  class JobIdentificationType {
120  public:
121  JobIdentificationType() :
122  JobName(""), Description(""), Type("") {}
124 
131  std::string JobName;
132 
134 
141  std::string Description;
142 
144 
151  std::string Type;
152 
154 
160  std::list<std::string> Annotation;
161 
163 
172  std::list<std::string> ActivityOldID;
173  };
174 
176 
186  class ExecutableType {
187  public:
188  ExecutableType() : Path(""), SuccessExitCode(false, 0) {}
189 
191 
198  std::string Path;
199 
201 
207  std::list<std::string> Argument;
208 
210 
221  std::pair<bool, int> SuccessExitCode;
222  };
223 
225 
232  class RemoteLoggingType {
233  public:
234  RemoteLoggingType() : optional(false) {}
235 
237 
245  std::string ServiceType;
246 
248 
254  URL Location;
255 
257 
264  bool optional;
265  };
266 
271  class NotificationType {
272  public:
273  NotificationType() {}
274 
278  std::string Email;
279 
283  std::list<std::string> States;
284  };
285 
290  class ApplicationType {
291  public:
292  ApplicationType() :
293  Rerun(-1),
294  ExpirationTime(-1),
296  Priority (-1),
297  DryRun(false)
298  {}
299  ApplicationType& operator=(const ApplicationType&);
301 
307  ExecutableType Executable;
308 
310 
316  std::string Input;
317 
319 
326  std::string Output;
327 
329 
335  std::string Error;
340  std::list< std::pair<std::string, std::string> > Environment;
341 
343 
351  std::list<ExecutableType> PreExecutable;
352 
354 
362  std::list<ExecutableType> PostExecutable;
363 
365 
371  std::string LogDir;
372 
378  std::list<RemoteLoggingType> RemoteLogging;
383  int Rerun;
384 
389 
394 
398  int Priority;
399 
400  std::list<NotificationType> Notification;
401 
405  std::list<URL> CredentialService;
406 
411 
415  bool DryRun;
416  };
417 
422  class SlotRequirementType {
423  public:
425  NumberOfSlots(-1),
426  SlotsPerHost(-1),
427  ExclusiveExecution(EE_DEFAULT) {}
431  int NumberOfSlots; // Range?
432 
436  int SlotsPerHost; // Range?
437 
442  EE_DEFAULT,
443  EE_TRUE,
444  EE_FALSE
445  } ExclusiveExecution;
446  };
447 
452  class DiskSpaceRequirementType {
453  public:
454  DiskSpaceRequirementType() :
455  DiskSpace(-1),
456  CacheDiskSpace(-1),
457  SessionDiskSpace(-1) {}
463  Range<int> DiskSpace;
470  int CacheDiskSpace;
477  int SessionDiskSpace;
478  };
479 
484  enum SessionDirectoryAccessMode {
485  SDAM_NONE = 0,
486  SDAM_RO = 1,
487  SDAM_RW = 2
488  };
489 
494  enum NodeAccessType {
495  NAT_NONE = 0,
496  NAT_INBOUND = 1,
497  NAT_OUTBOUND = 2,
498  NAT_INOUTBOUND = 3
499  };
500 
505  class ParallelEnvironmentType {
506  public:
507  ParallelEnvironmentType() :
508  ProcessesPerSlot(-1),
509  ThreadsPerProcess(-1) {}
510 
514  std::string Type;
515 
519  std::string Version;
520 
524  int ProcessesPerSlot; // Range?
525 
529  int ThreadsPerProcess; // Range?
530 
534  std::multimap<std::string, std::string> Options;
535  };
536 
538 
543  class ResourcesType {
544  public:
545  ResourcesType() :
548  SessionLifeTime(-1),
549  SessionDirectoryAccess(SDAM_NONE),
550  IndividualCPUTime(-1),
551  TotalCPUTime(-1),
552  IndividualWallTime(-1),
553  TotalWallTime(IndividualWallTime),
554  NodeAccess(NAT_NONE) {}
555  ResourcesType& operator=(const ResourcesType&);
556 
558 
561  SoftwareRequirement OperatingSystem;
562 
566  std::string Platform;
567 
571  std::string NetworkInfo;
572 
577 
582 
583  DiskSpaceRequirementType DiskSpaceRequirement;
584 
589 
593  SessionDirectoryAccessMode SessionDirectoryAccess;
594 
599 
604 
609 
610  ScalableTime<int>& TotalWallTime;
611 
615  NodeAccessType NodeAccess;
616 
618 
624 
625  SlotRequirementType SlotRequirement;
626  ParallelEnvironmentType ParallelEnvironment;
627 
632 
634 
637  std::string QueueName;
638 
640 
647  };
648 
653  class SourceType: public URL {
654  public:
655  SourceType() {};
656  SourceType(const URL& u):URL(u) {};
657  SourceType(const std::string& s):URL(s) {};
658  SourceType& operator=(const URL& u) { URL::operator=(u); return *this; };
659  SourceType& operator=(const std::string& s) { URL::operator=(s); return *this; };
660  std::string DelegationID;
661  };
662 
668  class TargetType: public URL {
669  public:
671 
676  TargetType() :
678  UseIfFailure(false),
679  UseIfCancel(false),
680  UseIfSuccess(true) {};
682 
685  TargetType(const URL& u) :
686  URL(u),
688  UseIfFailure(false),
689  UseIfCancel(false),
690  UseIfSuccess(true) {};
692 
695  TargetType(const std::string& s) :
696  URL(s),
698  UseIfFailure(false),
699  UseIfCancel(false),
700  UseIfSuccess(true) {};
701 
703 
706  std::string DelegationID;
707 
709  CFE_DEFAULT,
710  CFE_OVERWRITE,
711  CFE_APPEND,
713  };
714 
721 
727  bool UseIfFailure;
728 
734  bool UseIfCancel;
735 
741  bool UseIfSuccess;
742  };
743 
748  class InputFileType {
749  public:
750  InputFileType() : Name(""), IsExecutable(false), FileSize(-1) {};
751  std::string Name;
757  bool IsExecutable;
758 
759  long FileSize;
765  std::string Checksum;
766  std::list<SourceType> Sources;
767  };
768 
774  class OutputFileType {
775  public:
776  OutputFileType() : Name("") {};
778  std::string Name;
780  std::list<TargetType> Targets;
781  };
782 
788  class DataStagingType {
789  public:
790  DataStagingType() {};
791 
793  std::list<InputFileType> InputFiles;
795  std::list<OutputFileType> OutputFiles;
796  };
797 
798 
800 
809  class JobDescriptionResult {
810  public:
811  JobDescriptionResult(bool r):res(r) { };
812  JobDescriptionResult(bool r, const std::string& s):res(r),desc(s) { };
814  operator bool(void) { return res; };
816  bool operator!(void) { return !res; };
818  const std::string& str(void) { return desc; };
819  private:
820  bool res;
821  std::string desc;
822  };
823 
842  class JobDescription {
843  public:
844  friend class JobDescriptionParserPlugin;
845  JobDescription() : alternatives(), current(alternatives.begin()) {};
846 
847  JobDescription(const JobDescription& j, bool withAlternatives = true);
848 
849  // Language wrapper constructor
850  JobDescription(const long int& ptraddr);
851 
852  ~JobDescription() {}
853 
855  JobDescription& operator=(const JobDescription& j);
856 
858 
862  void AddAlternative(const JobDescription& j);
864 
867  bool HasAlternatives() const { return !alternatives.empty(); }
873  const std::list<JobDescription>& GetAlternatives() const { return alternatives; }
879  std::list<JobDescription>& GetAlternatives() { return alternatives; }
881 
884  std::list<JobDescription> GetAlternativesCopy() const { return alternatives; }
886 
892  bool UseAlternative();
893  void UseOriginal();
894 
895  void RemoveAlternatives();
896 
898 
917  static JobDescriptionResult Parse(const std::string& source, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
918 
919  static JobDescriptionResult ParseFromFile(const std::string& filename, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
920 
922 
929  JobDescriptionResult UnParse(std::string& product, std::string language, const std::string& dialect = "") const;
930 
932 
940  const std::string& GetSourceLanguage() const { return sourceLanguage; }
941 
943 
959  JobDescriptionResult SaveToStream(std::ostream& out, const std::string& format) const;
960 
962 
993  bool Prepare(const ExecutionTarget& et) { return Prepare(&et); }
994 
995  bool Prepare() { return Prepare(NULL); }
996 
997  static bool GetTestJob(int testid, JobDescription& jobdescription);
998 
1005 
1007 
1011 
1018 
1025 
1027 
1038  std::map<std::string, std::string> OtherAttributes;
1039 
1040  private:
1041  bool Prepare(const ExecutionTarget* et);
1042 
1043  void Set(const JobDescription& j);
1044 
1045  std::string sourceLanguage;
1046 
1047  std::list<JobDescription> alternatives;
1048  std::list<JobDescription>::iterator current;
1049 
1050  static Glib::Mutex jdpl_lock;
1051  static JobDescriptionParserPluginLoader *jdpl;
1052 
1053  static Logger logger;
1054  };
1055 
1056 } // namespace Arc
1057 
1058 #endif // __ARC_JOBDESCRIPTION_H__