00001 #ifndef __ARC_JOBDESCRIPTION_H__
00002 #define __ARC_JOBDESCRIPTION_H__
00003
00004 #include <list>
00005 #include <vector>
00006 #include <string>
00007
00008 #include <arc/DateTime.h>
00009 #include <arc/XMLNode.h>
00010 #include <arc/URL.h>
00011 #include <arc/client/Software.h>
00012
00013
00014 namespace Arc {
00015
00016 class JobDescriptionParserLoader;
00017 class ExecutionTarget;
00018
00019 template<class T>
00020 class OptIn {
00021 public:
00022 OptIn<T>() : optIn(false) {}
00023 OptIn<T>(const T& t) : v(t), optIn(false) {}
00024 OptIn<T>(const T& t, bool o) : v(t), optIn(o) {}
00025 OptIn<T>(const OptIn<T>& ot) : v(ot.v), optIn(ot.optIn) {}
00026
00027 OptIn<T>& operator=(const OptIn<T>& ot) { v = ot.v; optIn = ot.optIn; return *this; }
00028 OptIn<T>& operator=(const T& t) { v = t; optIn = false; return *this; }
00029
00030 operator T() const { return v; }
00031
00032 T v;
00033 bool optIn;
00034 };
00035
00036 template<class T>
00037 class Range {
00038 public:
00039 Range<T>() : min(0), max(0) {}
00040 Range<T>(const T& t) : min(t), max(t) {}
00041 operator T(void) const { return max; }
00042
00043 Range<T>& operator=(const Range<T>& t) { min = t.min; max = t.max; return *this; };
00044 Range<T>& operator=(const T& t) { max = t; return *this; };
00045
00046 T min;
00047 T max;
00048 };
00049
00050 template<class T>
00051 class ScalableTime {
00052 public:
00053 ScalableTime<T>() : benchmark("", -1.) {}
00054 ScalableTime<T>(const T& t) : range(t) {}
00055
00056 std::pair<std::string, double> benchmark;
00057 Range<T> range;
00058 };
00059
00060 template<>
00061 class ScalableTime<int> {
00062 public:
00063 ScalableTime<int>() : benchmark("", -1.) {}
00064 ScalableTime<int>(const int& t) : range(t) {}
00065
00066 std::pair<std::string, double> benchmark;
00067 Range<int> range;
00068
00069 int scaleMin(double s) const { return (int)(range.min*benchmark.second/s); }
00070 int scaleMax(double s) const { return (int)(range.max*benchmark.second/s); }
00071 };
00072
00074
00081 class JobIdentificationType {
00082 public:
00083 JobIdentificationType() :
00084 JobName(""), Description(""), Type("") {}
00086
00091 std::string JobName;
00092
00094
00099 std::string Description;
00100
00102
00107 std::string Type;
00108
00110
00114 std::list<std::string> Annotation;
00115
00117
00124 std::list<std::string> ActivityOldID;
00125 };
00126
00128
00135 class ExecutableType {
00136 public:
00137 ExecutableType() : Path(""), SuccessExitCode(false, 0) {}
00138
00140
00145 std::string Path;
00146
00148
00152 std::list<std::string> Argument;
00153
00155
00164 std::pair<bool, int> SuccessExitCode;
00165 };
00166
00168
00172 class RemoteLoggingType {
00173 public:
00174 RemoteLoggingType() : optional(false) {}
00175
00177
00183 std::string ServiceType;
00184
00186
00190 URL Location;
00191
00193
00198 bool optional;
00199 };
00200
00201 class NotificationType {
00202 public:
00203 NotificationType() {}
00204 std::string Email;
00205 std::list<std::string> States;
00206 };
00207
00208 class ApplicationType {
00209 public:
00210 ApplicationType() :
00211 Rerun(-1),
00212 ExpirationTime(-1),
00213 ProcessingStartTime(-1),
00214 Priority (-1),
00215 DryRun(false)
00216 {}
00218
00224 ExecutableType Executable;
00225
00227
00231 std::string Input;
00232
00234
00239 std::string Output;
00240
00242
00246 std::string Error;
00247
00248 std::list< std::pair<std::string, std::string> > Environment;
00249
00251
00257 std::list<ExecutableType> PreExecutable;
00258
00260
00266 std::list<ExecutableType> PostExecutable;
00267
00269
00273 std::string LogDir;
00274
00276
00280 std::list<RemoteLoggingType> RemoteLogging;
00281
00282 int Rerun;
00283 Time ExpirationTime;
00284 Time ProcessingStartTime;
00285 int Priority;
00286 std::list<NotificationType> Notification;
00287 std::list<URL> CredentialService;
00288 XMLNode AccessControl;
00289 bool DryRun;
00290 };
00291
00292 class SlotRequirementType {
00293 public:
00294 SlotRequirementType() :
00295 NumberOfSlots(-1),
00296 SlotsPerHost(-1),
00297 ExclusiveExecution(EE_DEFAULT) {}
00298 int NumberOfSlots;
00299 int SlotsPerHost;
00300 enum ExclusiveExecutionType {
00301 EE_DEFAULT,
00302 EE_TRUE,
00303 EE_FALSE
00304 } ExclusiveExecution;
00305 };
00306
00307 class DiskSpaceRequirementType {
00308 public:
00309 DiskSpaceRequirementType() :
00310 DiskSpace(-1),
00311 CacheDiskSpace(-1),
00312 SessionDiskSpace(-1) {}
00316 Range<int> DiskSpace;
00321 int CacheDiskSpace;
00326 int SessionDiskSpace;
00327 };
00328
00329 enum SessionDirectoryAccessMode {
00330 SDAM_NONE = 0,
00331 SDAM_RO = 1,
00332 SDAM_RW = 2
00333 };
00334
00335 enum NodeAccessType {
00336 NAT_NONE = 0,
00337 NAT_INBOUND = 1,
00338 NAT_OUTBOUND = 2,
00339 NAT_INOUTBOUND = 3
00340 };
00341
00342 class ParallelEnvironmentType {
00343 public:
00344 ParallelEnvironmentType() :
00345 ProcessesPerSlot(-1),
00346 ThreadsPerProcess(-1) {}
00347 std::string Type;
00348 std::string Version;
00349 int ProcessesPerSlot;
00350 int ThreadsPerProcess;
00351 std::multimap<std::string, std::string> Options;
00352 };
00353
00354 class ResourcesType {
00355 public:
00356 ResourcesType() :
00357 IndividualPhysicalMemory(-1),
00358 IndividualVirtualMemory(-1),
00359 SessionLifeTime(-1),
00360 SessionDirectoryAccess(SDAM_NONE),
00361 IndividualCPUTime(-1),
00362 TotalCPUTime(-1),
00363 IndividualWallTime(-1),
00364 TotalWallTime(-1),
00365 NodeAccess(NAT_NONE) {}
00366 SoftwareRequirement OperatingSystem;
00367 std::string Platform;
00368 std::string NetworkInfo;
00369 Range<int> IndividualPhysicalMemory;
00370 Range<int> IndividualVirtualMemory;
00371 DiskSpaceRequirementType DiskSpaceRequirement;
00372 Period SessionLifeTime;
00373 SessionDirectoryAccessMode SessionDirectoryAccess;
00374 ScalableTime<int> IndividualCPUTime;
00375 ScalableTime<int> TotalCPUTime;
00376 ScalableTime<int> IndividualWallTime;
00377 ScalableTime<int> TotalWallTime;
00378 NodeAccessType NodeAccess;
00379 SoftwareRequirement CEType;
00380 SlotRequirementType SlotRequirement;
00381 ParallelEnvironmentType ParallelEnvironment;
00382 OptIn<std::string> Coprocessor;
00383 std::string QueueName;
00384 SoftwareRequirement RunTimeEnvironment;
00385 };
00386
00387 class SourceType: public URL {
00388 public:
00389 SourceType() {};
00390 SourceType(const URL& u):URL(u) {};
00391 SourceType(const std::string& s):URL(s) {};
00392 SourceType& operator=(const URL& u) { URL::operator=(u); return *this; };
00393 SourceType& operator=(const std::string& s) { URL::operator=(s); return *this; };
00394 std::string DelegationID;
00395 };
00396
00397 class TargetType: public URL {
00398 public:
00399 TargetType() :
00400 CreationFlag(CFE_DEFAULT),
00401 UseIfFailure(false),
00402 UseIfCancel(false),
00403 UseIfSuccess(true) {};
00404 TargetType(const URL& u) :
00405 URL(u),
00406 CreationFlag(CFE_DEFAULT),
00407 UseIfFailure(false),
00408 UseIfCancel(false),
00409 UseIfSuccess(true) {};
00410 TargetType(const std::string& s) :
00411 URL(s),
00412 CreationFlag(CFE_DEFAULT),
00413 UseIfFailure(false),
00414 UseIfCancel(false),
00415 UseIfSuccess(true) {};
00416 std::string DelegationID;
00417 enum CreationFlagEnumeration {
00418 CFE_DEFAULT,
00419 CFE_OVERWRITE,
00420 CFE_APPEND,
00421 CFE_DONTOVERWRITE
00422 };
00423 CreationFlagEnumeration CreationFlag;
00424 bool UseIfFailure;
00425 bool UseIfCancel;
00426 bool UseIfSuccess;
00427 };
00428
00429 class InputFileType {
00430 public:
00431 InputFileType() : Name(""), IsExecutable(false), FileSize(-1) {};
00432 std::string Name;
00433 bool IsExecutable;
00434 long FileSize;
00436
00440 std::string Checksum;
00441 std::list<SourceType> Sources;
00442 };
00443
00444 class OutputFileType {
00445 public:
00446 OutputFileType() : Name("") {};
00447 std::string Name;
00448 std::list<TargetType> Targets;
00449 };
00450
00451 class DataStagingType {
00452 public:
00453 DataStagingType() {};
00454 std::list<InputFileType> InputFiles;
00455 std::list<OutputFileType> OutputFiles;
00456 };
00457
00458
00459 class JobDescriptionResult {
00460 public:
00461 JobDescriptionResult(bool r):res(r) { };
00462 JobDescriptionResult(bool r, const std::string& s):res(r),desc(s) { };
00463 operator bool(void) { return res; };
00464 bool operator!(void) { return !res; };
00465 const std::string& str(void) { return desc; };
00466 private:
00467 bool res;
00468 std::string desc;
00469 };
00470
00485 class JobDescription {
00486 public:
00487 friend class JobDescriptionParser;
00488 JobDescription() : alternatives(), current(alternatives.begin()) {};
00489
00490 JobDescription(const JobDescription& j, bool withAlternatives = true);
00491
00492 JobIdentificationType Identification;
00493 ApplicationType Application;
00494 ResourcesType Resources;
00495 DataStagingType DataStaging;
00496
00497 JobDescription& operator=(const JobDescription& j);
00498
00499
00500 JobDescription(const long int& ptraddr);
00501
00502 ~JobDescription() {}
00503
00504 void AddAlternative(const JobDescription& j);
00505
00506 bool HasAlternatives() const { return !alternatives.empty(); }
00507 const std::list<JobDescription>& GetAlternatives() const { return alternatives; }
00508 std::list<JobDescription>& GetAlternatives() { return alternatives; }
00509 std::list<JobDescription> GetAlternativesCopy() const { return alternatives; }
00510 bool UseAlternative();
00511 void UseOriginal();
00512
00513 void RemoveAlternatives();
00514
00516
00535 static JobDescriptionResult Parse(const std::string& source, std::list<JobDescription>& jobdescs, const std::string& language = "", const std::string& dialect = "");
00536
00538
00545 JobDescriptionResult UnParse(std::string& product, std::string language, const std::string& dialect = "") const;
00546
00547
00549
00557 const std::string& GetSourceLanguage() const { return sourceLanguage; }
00558
00560
00576 JobDescriptionResult SaveToStream(std::ostream& out, const std::string& format) const;
00577
00579
00610 bool Prepare(const ExecutionTarget& et);
00611
00612 static bool GetTestJob(int testid, JobDescription& jobdescription);
00613
00615
00622 std::map<std::string, std::string> OtherAttributes;
00623
00624 private:
00625 void Set(const JobDescription& j);
00626
00627 std::string sourceLanguage;
00628
00629 std::list<JobDescription> alternatives;
00630 std::list<JobDescription>::iterator current;
00631
00632 static Glib::Mutex jdpl_lock;
00633 static JobDescriptionParserLoader *jdpl;
00634
00635 static Logger logger;
00636 };
00637
00638 }
00639
00640 #endif // __ARC_JOBDESCRIPTION_H__