WRENCH  1.11
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
CompoundJob.h
1 
10 #ifndef WRENCH_COMPOUNDJOB_H
11 #define WRENCH_COMPOUNDJOB_H
12 
13 #include <map>
14 #include <set>
15 #include <vector>
16 #include <memory>
17 
18 #include <wrench/action/Action.h>
19 
20 #include "Job.h"
21 
22 namespace wrench {
23 
24  /***********************/
26  /***********************/
27 
28  class Action;
29  class SleepAction;
30  class ComputeAction;
31  class FileReadAction;
32  class FileWriteAction;
33  class FileCopyAction;
34  class FileDeleteAction;
35  class FileRegistryService;
36  class FileRegistryAddEntryAction;
37  class FileRegistryDeleteEntryAction;
38  class ParallelModel;
39  class CustomAction;
40  class ActionExecutor;
41 
42  class DataFile;
43 
47 class CompoundJob : public Job, public std::enable_shared_from_this<CompoundJob> {
48 
49  public:
50 
52  enum State {
54  NOT_SUBMITTED,
56  SUBMITTED,
58  COMPLETED,
63  DISCONTINUED
64  };
65 
70  std::shared_ptr<CompoundJob> getSharedPtr() { return this->shared_from_this(); }
71 
72  std::set<std::shared_ptr<Action>> getActions();
73  CompoundJob::State getState();
74  std::string getStateAsString();
75  void setPriority(double priority) override;
76 
77  std::shared_ptr<SleepAction> addSleepAction(std::string name, double sleep_time);
78 
79  std::shared_ptr<FileReadAction> addFileReadAction(std::string name,
80  std::shared_ptr<DataFile>file,
81  std::shared_ptr<FileLocation> file_location);
82 
83  std::shared_ptr<FileReadAction> addFileReadAction(std::string name,
84  std::shared_ptr<DataFile>file,
85  std::vector<std::shared_ptr<FileLocation>> file_locations);
86 
87  std::shared_ptr<FileWriteAction> addFileWriteAction(std::string name,
88  std::shared_ptr<DataFile>file,
89  std::shared_ptr<FileLocation> file_location);
90 
91  std::shared_ptr<FileCopyAction> addFileCopyAction(std::string name,
92  std::shared_ptr<DataFile>file,
93  std::shared_ptr<FileLocation> src_file_location,
94  std::shared_ptr<FileLocation> dst_file_location);
95 
96  std::shared_ptr<FileDeleteAction> addFileDeleteAction(std::string name,
97  std::shared_ptr<DataFile>file,
98  std::shared_ptr<FileLocation> file_location);
99 
100  std::shared_ptr<FileRegistryAddEntryAction> addFileRegistryAddEntryAction(std::shared_ptr<FileRegistryService> file_registry, std::shared_ptr<DataFile>file,
101  std::shared_ptr<FileLocation> file_location);
102 
103  std::shared_ptr<FileRegistryDeleteEntryAction> addFileRegistryDeleteEntryAction(std::shared_ptr<FileRegistryService> file_registry, std::shared_ptr<DataFile>file,
104  std::shared_ptr<FileLocation> file_location);
105 
106  std::shared_ptr<ComputeAction> addComputeAction(std::string name,
107  double flops,
108  double ram,
109  unsigned long min_num_cores,
110  unsigned long max_num_cores,
111  std::shared_ptr<ParallelModel> parallel_model);
112 
113  std::shared_ptr<CustomAction> addCustomAction(std::string name,
114  double ram,
115  unsigned long num_cores,
116  const std::function<void (std::shared_ptr<ActionExecutor> action_executor)> &lambda_execute,
117  const std::function<void (std::shared_ptr<ActionExecutor> action_executor)> &lambda_terminate);
118 
119  void removeAction(std::shared_ptr<Action> &action);
120 
121  void addActionDependency(const std::shared_ptr<Action>& parent, const std::shared_ptr<Action>& child);
122 
123  void addParentJob(const std::shared_ptr<CompoundJob>& parent);
124  void addChildJob(const std::shared_ptr<CompoundJob>& child);
125 
126  std::set<std::shared_ptr<CompoundJob>> getParentJobs();
127  std::set<std::shared_ptr<CompoundJob>> getChildrenJobs();
128 
129 // void setServiceSpecificArgs(std::map<std::string, std::string> service_specific_args);
130 // const std::map<std::string, std::string> & getServiceSpecificArgs();
131 
132  bool hasSuccessfullyCompleted();
133  bool hasFailed();
134 
135  void printActionDependencies();
136 
137  void printTaskMap();
138 
139  unsigned long getMinimumRequiredNumCores();
140 
141  double getMinimumRequiredMemory();
142 
143  bool usesScratch();
144 
145  /***********************/
147  /***********************/
148 
149  /***********************/
151  /***********************/
152 
153  protected:
154 
155  friend class BareMetalComputeService;
156  friend class JobManager;
157  friend class Action;
158 
159  CompoundJob(std::string name, std::shared_ptr<JobManager> job_manager);
160 
161  bool isReady();
162 
163 // std::shared_ptr<CompoundJob> shared_this; // Set by the Job Manager
164  std::set<std::shared_ptr<Action>> actions;
165  std::map<std::string, std::shared_ptr<Action>> name_map;
166 
167  State state;
168  double priority;
169 
170  void updateStateActionMap(const std::shared_ptr<Action>& action, Action::State old_state, Action::State new_state);
171 
172  void setAllActionsFailed(const std::shared_ptr<FailureCause>& cause);
173 
174  bool hasAction(const std::string &name);
175 
176  std::set<std::shared_ptr<CompoundJob>> &getChildren();
177  std::set<std::shared_ptr<CompoundJob>> &getParents();
178 
179  private:
180 
181  double pre_job_overhead;
182  double post_job_overhead;
183 
184  void assertJobNotSubmitted();
185  void assertActionNameDoesNotAlreadyExist(const std::string &name);
186 
187  void addAction(const std::shared_ptr<Action>& action);
188 
189  bool pathExists(const std::shared_ptr<Action>& a, const std::shared_ptr<Action> &b);
190  bool pathExists(const std::shared_ptr<CompoundJob>& a, const std::shared_ptr<CompoundJob> &b);
191 
192  std::set<std::shared_ptr<CompoundJob>> parents;
193  std::set<std::shared_ptr<CompoundJob>> children;
194 
195  std::map<std::string, std::string> service_specific_args;
196 
197  std::unordered_map<Action::State, std::set<std::shared_ptr<Action>>> state_task_map;
198 
199  };
200 
201 
202  /***********************/
204  /***********************/
205 
206 };
207 
208 #endif //WRENCH_COMPOUNDJOB_H
wrench
Definition: Action.cpp:28
wrench::Action::State
State
Action states.
Definition: Action.h:33