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 {
64  };
65 
70  std::shared_ptr<CompoundJob> getSharedPtr() { return this->shared_from_this(); }
71 
72  std::set<std::shared_ptr<Action>> getActions();
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 
133  bool hasFailed();
134 
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::CompoundJob::addCustomAction
std::shared_ptr< CustomAction > addCustomAction(std::string name, double ram, unsigned long num_cores, const std::function< void(std::shared_ptr< ActionExecutor > action_executor)> &lambda_execute, const std::function< void(std::shared_ptr< ActionExecutor > action_executor)> &lambda_terminate)
Add a custom action to the job.
Definition: CompoundJob.cpp:248
wrench::CompoundJob::getChildrenJobs
std::set< std::shared_ptr< CompoundJob > > getChildrenJobs()
Get the job's children.
Definition: CompoundJob.cpp:341
wrench::CompoundJob::SUBMITTED
@ SUBMITTED
Job has been submitted to a JobManager.
Definition: CompoundJob.h:56
wrench::CompoundJob::State
State
Compound job states.
Definition: CompoundJob.h:52
wrench::CompoundJob::printTaskMap
void printTaskMap()
Print the task map.
Definition: CompoundJob.cpp:401
wrench::CompoundJob::getParents
std::set< std::shared_ptr< CompoundJob > > & getParents()
Returns the job's parent jobs, if any.
Definition: CompoundJob.cpp:490
wrench::CompoundJob::getState
CompoundJob::State getState()
Get the state of the standard job.
Definition: CompoundJob.cpp:56
wrench::CompoundJob::addSleepAction
std::shared_ptr< SleepAction > addSleepAction(std::string name, double sleep_time)
Add a sleep action to the job.
Definition: CompoundJob.cpp:95
wrench::CompoundJob::addFileReadAction
std::shared_ptr< FileReadAction > addFileReadAction(std::string name, std::shared_ptr< DataFile >file, std::shared_ptr< FileLocation > file_location)
Add a file read action to the job.
Definition: CompoundJob.cpp:132
wrench::CompoundJob::getStateAsString
std::string getStateAsString()
Get the state of the standard job.
Definition: CompoundJob.cpp:64
wrench::Job
Abstraction of a job used for executing tasks in a Workflow.
Definition: Job.h:34
wrench::CompoundJob::NOT_SUBMITTED
@ NOT_SUBMITTED
Job hasn't been submitted yet.
Definition: CompoundJob.h:54
wrench::CompoundJob::getMinimumRequiredMemory
double getMinimumRequiredMemory()
Get the minimum required amount of memory to run the job.
Definition: CompoundJob.cpp:559
wrench::CompoundJob::setPriority
void setPriority(double priority) override
Set the job's priority (the higher the priority value, the higher the priority)
Definition: CompoundJob.cpp:84
wrench::CompoundJob::addActionDependency
void addActionDependency(const std::shared_ptr< Action > &parent, const std::shared_ptr< Action > &child)
Add a dependency between two actions (does nothing if dependency already exists)
Definition: CompoundJob.cpp:277
wrench::JobManager
A helper daemon (co-located with and explicitly started by an execution controller),...
Definition: JobManager.h:56
wrench::CompoundJob::getMinimumRequiredNumCores
unsigned long getMinimumRequiredNumCores()
Get the minimum required num cores to run the job.
Definition: CompoundJob.cpp:547
wrench::CompoundJob::addFileCopyAction
std::shared_ptr< FileCopyAction > addFileCopyAction(std::string name, std::shared_ptr< DataFile >file, std::shared_ptr< FileLocation > src_file_location, std::shared_ptr< FileLocation > dst_file_location)
Add a file copy action to the job.
Definition: CompoundJob.cpp:181
wrench::CompoundJob::setAllActionsFailed
void setAllActionsFailed(const std::shared_ptr< FailureCause > &cause)
Set all actions to FAILED for the same failure cause (e.g., a job-level failure)
Definition: CompoundJob.cpp:434
wrench::CompoundJob::addParentJob
void addParentJob(const std::shared_ptr< CompoundJob > &parent)
Add a parent job to this job (be careful not to add circular dependencies, which may lead to deadlock...
Definition: CompoundJob.cpp:301
wrench::BareMetalComputeService
A compute service that manages a set of multi-core compute hosts and provides access to their resourc...
Definition: BareMetalComputeService.h:45
wrench
Definition: Action.cpp:28
wrench::CompoundJob::getSharedPtr
std::shared_ptr< CompoundJob > getSharedPtr()
Get the shared pointer for this object.
Definition: CompoundJob.h:70
wrench::Job::name
std::string name
The job's name.
Definition: Job.h:93
wrench::Job::job_manager
std::shared_ptr< JobManager > job_manager
The Job Manager in charge of this job.
Definition: Job.h:86
wrench::CompoundJob::hasAction
bool hasAction(const std::string &name)
Determine whether an action with a given name exists in job.
Definition: CompoundJob.cpp:539
wrench::CompoundJob::addFileRegistryDeleteEntryAction
std::shared_ptr< FileRegistryDeleteEntryAction > addFileRegistryDeleteEntryAction(std::shared_ptr< FileRegistryService > file_registry, std::shared_ptr< DataFile >file, std::shared_ptr< FileLocation > file_location)
Add a file registry add entry action.
Definition: CompoundJob.cpp:231
wrench::CompoundJob::addComputeAction
std::shared_ptr< ComputeAction > addComputeAction(std::string name, double flops, double ram, unsigned long min_num_cores, unsigned long max_num_cores, std::shared_ptr< ParallelModel > parallel_model)
Add a compute action to the job.
Definition: CompoundJob.cpp:111
wrench::CompoundJob::getParentJobs
std::set< std::shared_ptr< CompoundJob > > getParentJobs()
Get the job's parents.
Definition: CompoundJob.cpp:333
wrench::CompoundJob::getActions
std::set< std::shared_ptr< Action > > getActions()
Get the job's actions.
Definition: CompoundJob.cpp:48
wrench::CompoundJob::addFileDeleteAction
std::shared_ptr< FileDeleteAction > addFileDeleteAction(std::string name, std::shared_ptr< DataFile >file, std::shared_ptr< FileLocation > file_location)
Add a file delete action to the job.
Definition: CompoundJob.cpp:199
wrench::CompoundJob::addFileRegistryAddEntryAction
std::shared_ptr< FileRegistryAddEntryAction > addFileRegistryAddEntryAction(std::shared_ptr< FileRegistryService > file_registry, std::shared_ptr< DataFile >file, std::shared_ptr< FileLocation > file_location)
Add a file registry add entry action.
Definition: CompoundJob.cpp:214
wrench::CompoundJob::hasSuccessfullyCompleted
bool hasSuccessfullyCompleted()
Return whether the job has terminated and has done so successfully.
Definition: CompoundJob.cpp:394
wrench::CompoundJob::removeAction
void removeAction(std::shared_ptr< Action > &action)
Remove an action from the job.
Definition: CompoundJob.cpp:498
wrench::CompoundJob::getChildren
std::set< std::shared_ptr< CompoundJob > > & getChildren()
Returns the job's child jobs, if any.
Definition: CompoundJob.cpp:482
wrench::CompoundJob::DISCONTINUED
@ DISCONTINUED
Job has finished executing but not all actions were successfully completed. Actions may have failed,...
Definition: CompoundJob.h:63
wrench::CompoundJob::updateStateActionMap
void updateStateActionMap(const std::shared_ptr< Action > &action, Action::State old_state, Action::State new_state)
Update the internal State-Action map.
Definition: CompoundJob.cpp:365
wrench::Action
An abstract class that implements the concept of an action.
Definition: Action.h:28
wrench::CompoundJob::CompoundJob
CompoundJob(std::string name, std::shared_ptr< JobManager > job_manager)
Constructor.
Definition: CompoundJob.cpp:37
wrench::CompoundJob::hasFailed
bool hasFailed()
Return whether the job has terminated and has done so with some tasks having failed.
Definition: CompoundJob.cpp:422
wrench::CompoundJob::addFileWriteAction
std::shared_ptr< FileWriteAction > addFileWriteAction(std::string name, std::shared_ptr< DataFile >file, std::shared_ptr< FileLocation > file_location)
Add a file write action to the job.
Definition: CompoundJob.cpp:164
wrench::CompoundJob::printActionDependencies
void printActionDependencies()
Print the list of actions with their children and parents.
Definition: CompoundJob.cpp:515
wrench::CompoundJob::COMPLETED
@ COMPLETED
Job has finished executing and all actions were successfully completed.
Definition: CompoundJob.h:58
wrench::CompoundJob::isReady
bool isReady()
Get the readiness of the job.
Definition: CompoundJob.cpp:350
wrench::CompoundJob
A compound job.
Definition: CompoundJob.h:47
wrench::Action::State
State
Action states.
Definition: Action.h:33
wrench::CompoundJob::addChildJob
void addChildJob(const std::shared_ptr< CompoundJob > &child)
Add a child job to this job (be careful not to add circular dependencies, which may lead to deadlocks...
Definition: CompoundJob.cpp:317
wrench::CompoundJob::usesScratch
bool usesScratch()
Determine whether the job uses scratch.
Definition: CompoundJob.cpp:571