GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
job.h
Go to the documentation of this file.
1 #ifndef JOB_H_
2 #define JOB_H_
3 
4 #include <string>
5 #include <unordered_set>
6 #include <sstream>
7 #include <chrono>
8 #include <iostream>
9 
10 #include "utils.h"
11 #include "interfaces.h"
12 #include "software.h"
13 
14 class User;
15 
17 
20 template <class Idable>
21 struct IdLess
22 {
23  bool operator()(Idable* const & lhs, Idable* const & rhs) const
24  {
25  return lhs->GetId() < rhs->GetId();
26  }
27 };
28 
29 typedef std::unordered_set<Software, Software::Hash> SoftwareSet;
30 
32 
35 class Job : public ISave, public IUpdate, public IPrint
36 {
37 public:
39 
42  struct PriorityLess
43  {
44  bool operator()(Job* const & lhs, Job* const & rhs) const
45  {
46  return (lhs->_priority > rhs->_priority) || // Organize Jobs by priority
47  ((lhs->_priority == rhs->_priority) && (lhs->_id < rhs->_id)); // If priorities are equal organize by id
48  }
49  };
50 
54  Job(const std::string& name, uint8 priority, double requiredRAM, double requiredDiskSpace, uint executionTime);
55 
56  uint GetId() const { return _id;}
57  void SetId(uint val) { _id = val; }
58  const std::string& GetName() const { return _name; }
59  uint8 GetPriority() const { return _priority; }
60  void SetPriority(uint8 val) { _priority = val; }
61  double GetRequiredRAM() const { return _requiredRAM; }
62  double GetRequiredDiskSpace() const { return _requiredDiskSpace; }
64  uint GetElapsedTime() const { return _elapsedTime; }
65 
66  double GetPrice() const { return 0.05 * _requiredRAM; }
67 
68  bool Finished() const { return _totalExecutionTime <= _elapsedTime; }
70 
71  bool Save(ByteBuffer& bb) const override;
72  static Job* Load(ByteBuffer& bb);
73 
74  void Update(uint32 diff);
75 
76  void Print(std::ostream& os = std::cout) const override;
77  void PrintWithId(std::ostream& os = std::cout) const;
78  static void PrintHeader(std::ostream& os = std::cout, bool withId = false);
79 
80  void AddRequiredSoftware(const Software& sw) { _requiredSoftware.insert(sw); }
81 
82  bool IsRequiredSoftware(const Software& sw) const { return _requiredSoftware.find(sw) != _requiredSoftware.end(); }
84 
85 private:
86  const double _requiredRAM;
87  const double _requiredDiskSpace;
93 
94  const std::string _name;
96 
98 
99 private: // no copying
100  Job(const Job&);
101  Job& operator=(Job const&);
102 };
103 
104 
105 
106 #endif // JOB_H_