WorkflowTask.h
1 
10 #ifndef WRENCH_WORKFLOWTASK_H
11 #define WRENCH_WORKFLOWTASK_H
12 
13 #include <map>
14 #include <stack>
15 #include <lemon/list_graph.h>
16 #include <set>
17 
18 #include "wrench/workflow/job/WorkflowJob.h"
19 #include "wrench/workflow/WorkflowFile.h"
20 
21 namespace wrench {
22 
26  class WorkflowTask {
27 
28  public:
29  std::string getID() const;
30 
31  double getFlops() const;
32 
33  unsigned long getMinNumCores() const;
34 
35  unsigned long getMaxNumCores() const;
36 
37  double getParallelEfficiency() const;
38 
39  double getMemoryRequirement() const;
40 
41  unsigned long getNumberOfChildren() const;
42  std::vector<WorkflowTask *> getChildren() const;
43 
44  unsigned long getNumberOfParents() const;
45  std::vector<WorkflowTask *> getParents() const;
46 
47  void addInputFile(WorkflowFile *file);
48 
49  void addOutputFile(WorkflowFile *file);
50 
51  unsigned int getFailureCount();
52 
53  /***********************/
55  /***********************/
56 
57 // /** @brief Task types */
58 // enum TaskType {
59 // COMPUTE,
60 // AUXILIARY,
61 // TRANSFER
62 // };
63 
65  enum State {
76  };
77 
78  static std::string stateToString(WorkflowTask::State state);
79 
80  WorkflowJob *getJob() const;
81 
82  Workflow *getWorkflow() const;
83 
84  std::string getClusterID() const;
85 
86  void setClusterID(std::string);
87 
88 // void setTaskType(TaskType);
89 //
90 // TaskType getTaskType() const;
91 
92  void setPriority(long);
93 
94  unsigned long getPriority() const;
95 
96  void setAverageCPU(double);
97 
98  double getAverageCPU() const;
99 
100  void setBytesRead(unsigned long);
101 
102  unsigned long getBytesRead() const;
103 
104  void setBytesWritten(unsigned long);
105 
106  unsigned long getBytesWritten() const;
107 
108  std::set<WorkflowFile *> getInputFiles();
109 
110  std::set<WorkflowFile *> getOutputFiles();
111 
112  unsigned long getTopLevel();
113 
114  double getStartDate();
115 
116  double getEndDate();
117 
118  double getFailureDate();
119 
120  double getTerminationDate();
121 
122  double getReadInputStartDate();
123 
124  double getReadInputEndDate();
125 
126  double getComputationStartDate();
127 
128  double getComputationEndDate();
129 
130  double getWriteOutputStartDate();
131 
132  double getWriteOutputEndDate();
133 
134  unsigned long getNumCoresAllocated();
135 
136  struct WorkflowTaskExecution;
137 
138  std::stack<WorkflowTaskExecution> getExecutionHistory();
139 
140  std::string getExecutionHost();
141 
143 
144 // void addSrcDest(WorkflowFile *, const std::string &, const std::string &);
145 //
146 // std::map<WorkflowFile *, std::pair<std::string, std::string>> getFileTransfers() const;
147 
148  /***********************/
150  /***********************/
151 
152 
153  /***********************/
155  /***********************/
156 
159  TASK_NOT_READY,
160  TASK_READY,
161  TASK_RUNNING,
162  TASK_COMPLETED,
163  TASK_FAILED
164  };
165 
166  static std::string stateToString(WorkflowTask::InternalState state);
167 
168  unsigned long updateTopLevel();
169 
171 
173 
175 
177 
179 
180  void setJob(WorkflowJob *job);
181 
182  void setStartDate(double date);
183 
184  void setEndDate(double date);
185 
186  void setReadInputStartDate(double date);
187 
188  void setReadInputEndDate(double date);
189 
190  void setComputationStartDate(double date);
191 
192  void setComputationEndDate(double date);
193 
194  void setWriteOutputStartDate(double date);
195 
196  void setWriteOutputEndDate(double date);
197 
198  void setFailureDate(double date);
199 
200  void setTerminationDate(double date);
201 
202  void incrementFailureCount();
203 
204  void setExecutionHost(std::string hostname);
205 
206  void setNumCoresAllocated(unsigned long num_cores);
207 
213  double task_start = -1.0;
215  double read_input_start = -1.0;
217  double read_input_end = -1.0;
219  double computation_start = -1.0;
221  double computation_end = -1.0;
223  double write_output_start = -1.0;
225  double write_output_end = -1.0;
227  double task_end = -1.0;
229  double task_failed = -1.0;
231  double task_terminated = -1.0;
232 
234  std::string execution_host = "";
236  unsigned long num_cores_allocated = 0;
237 
243  WorkflowTaskExecution(double task_start) : task_start(task_start) { }
244 
245  };
246 
247  /***********************/
249  /***********************/
250 
251  private:
252  friend class Workflow;
253 
254  std::string id; // Task ID
255  std::string cluster_id; // ID for clustered task
256 // TaskType task_type; // Task type
257  double flops; // Number of flops
258  double average_cpu = -1; // Average CPU utilization
259  unsigned long bytes_read = -1; // Total bytes read in KB
260  unsigned long bytes_written = -1; // Total bytes written in KB
261  unsigned long min_num_cores;
262  unsigned long max_num_cores;
263  double parallel_efficiency;
264  double memory_requirement;
265  unsigned long priority = 0; // Task priority
266  unsigned long toplevel; // 0 if entry task
267  unsigned int failure_count = 0; // Number of times the tasks has failed
268  std::string execution_host; // Host on which the task executed ("" if not executed successfully - yet)
269  State visible_state; // To be exposed to developer level
270  State upcoming_visible_state; // A visible state that will become active once a WMS has process a previously sent workflow execution event
271  InternalState internal_state; // Not to be exposed to developer level
272 
273  Workflow *workflow; // Containing workflow
274  lemon::ListDigraph *DAG; // Containing workflow
275  lemon::ListDigraph::Node DAG_node; // pointer to the underlying DAG node
276  std::map<std::string, WorkflowFile *> output_files; // List of output files
277  std::map<std::string, WorkflowFile *> input_files; // List of input files
278 // std::map<WorkflowFile *, std::pair<std::string, std::string>> fileTransfers; // Map of transfer files and hosts
279 
280  // Private constructor (called by Workflow)
281  WorkflowTask(std::string id,
282  double t,
283  unsigned long min_num_cores,
284  unsigned long max_num_cores,
285  double parallel_efficiency,
286  double memory_requirement);
287 
288  // Containing job
289  WorkflowJob *job;
290 
291  // Private helper function
292 // void addFileToMap(std::map<std::string, WorkflowFile *> &map_to_insert,
293 // std::map<std::string, WorkflowFile *> &map_to_check,
294 // WorkflowFile *f);
295 
296  std::stack<WorkflowTaskExecution> execution_history;
297  };
298 };
299 
300 #endif //WRENCH_WORKFLOWTASK_H
void setBytesRead(unsigned long)
Set the number of bytes read by the task.
Definition: WorkflowTask.cpp:442
Workflow * getWorkflow() const
Get the workflow that contains the task.
Definition: WorkflowTask.cpp:291
Some Unknown state (should not happen)
Definition: WorkflowTask.h:75
double getComputationEndDate()
Get the task&#39;s most recent computation end date.
Definition: WorkflowTask.cpp:682
double task_terminated
Task&#39;s terminated time.
Definition: WorkflowTask.h:231
Pending (has been submitted to a compute service)
Definition: WorkflowTask.h:71
double getMemoryRequirement() const
Get the memory requirement of the task.
Definition: WorkflowTask.cpp:163
std::vector< WorkflowTask * > getParents() const
Get the parents of a task.
Definition: WorkflowTask.cpp:208
std::string getClusterID() const
Get the cluster Id for the task.
Definition: WorkflowTask.cpp:385
unsigned long getMaxNumCores() const
Get the maximum number of cores that the task can use.
Definition: WorkflowTask.cpp:145
Not ready (parents have not completed)
Definition: WorkflowTask.h:67
Completed (successfully completed)
Definition: WorkflowTask.h:73
void setReadInputStartDate(double date)
Set the date when the read input portion of a WorkflowTask has begun.
Definition: WorkflowTask.cpp:521
void setStartDate(double date)
Set the task&#39;s start date.
Definition: WorkflowTask.cpp:467
void addOutputFile(WorkflowFile *file)
Add an output file to the task.
Definition: WorkflowTask.cpp:86
void incrementFailureCount()
Increment the failure count of a task.
Definition: WorkflowTask.cpp:624
unsigned long getMinNumCores() const
Get the minimum number of cores required for running the task.
Definition: WorkflowTask.cpp:136
void setTerminationDate(double date)
Set the date when the task was terminated.
Definition: WorkflowTask.cpp:594
A computational task in a Workflow.
Definition: WorkflowTask.h:26
void setNumCoresAllocated(unsigned long num_cores)
Sets the number of cores allocated for this task.
Definition: WorkflowTask.cpp:800
double write_output_start
Task&#39;s write output start time.
Definition: WorkflowTask.h:223
void setInternalState(WorkflowTask::InternalState)
Set the internal state of the task.
Definition: WorkflowTask.cpp:300
void setComputationStartDate(double date)
Set the date when the computation portion of a WorkflowTask has begun.
Definition: WorkflowTask.cpp:491
double getReadInputStartDate()
Get the task&#39;s most recent read input start date.
Definition: WorkflowTask.cpp:690
unsigned int getFailureCount()
Get the number of times a task has failed.
Definition: WorkflowTask.cpp:617
std::vector< WorkflowTask * > getChildren() const
Get the children of a task.
Definition: WorkflowTask.cpp:186
void setAverageCPU(double)
Set the task average CPU usage.
Definition: WorkflowTask.cpp:426
void setExecutionHost(std::string hostname)
Sets the host on which this task is running.
Definition: WorkflowTask.cpp:787
void setWriteOutputStartDate(double date)
Set the date when the write output portion of a WorkflowTask has begun.
Definition: WorkflowTask.cpp:551
double read_input_end
Task&#39;s read input end time.
Definition: WorkflowTask.h:217
Abstraction of a job used for executing tasks in a Workflow.
Definition: WorkflowJob.h:34
void setFailureDate(double date)
Set the date when the task has failed.
Definition: WorkflowTask.cpp:580
InternalState
Task state enum.
Definition: WorkflowTask.h:158
double getWriteOutputEndDate()
Get the task&#39;s most recent write output end date.
Definition: WorkflowTask.cpp:714
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26
A workflow (to be executed by a WMS)
Definition: Workflow.h:30
double task_end
Task&#39;s end time.
Definition: WorkflowTask.h:227
void setWriteOutputEndDate(double date)
Set the date when the write output portion of a WorkflowTask has completed.
Definition: WorkflowTask.cpp:566
WorkflowTask::State getState() const
Get the state of the task.
Definition: WorkflowTask.cpp:217
double getParallelEfficiency() const
Get the parallel efficiency of the task.
Definition: WorkflowTask.cpp:154
double task_failed
Task&#39;s failed time.
Definition: WorkflowTask.h:229
double read_input_start
Task&#39;s read input start time.
Definition: WorkflowTask.h:215
WorkflowTask::InternalState getInternalState() const
Get the state of the task (as known to the "internal" layer)
Definition: WorkflowTask.cpp:236
unsigned long getNumCoresAllocated()
Returns the number of cores allocated for this task&#39;s most recent execution or 0 if an execution atte...
Definition: WorkflowTask.cpp:778
A data structure that keeps track of a task&#39;s execution event times.
Definition: WorkflowTask.h:211
double getFailureDate()
Get the task&#39;s most recent failure date.
Definition: WorkflowTask.cpp:722
WorkflowJob * getJob() const
Get the task&#39;s containing job.
Definition: WorkflowTask.cpp:377
double computation_start
Task&#39;s computation start time.
Definition: WorkflowTask.h:219
unsigned long getTopLevel()
Returns the task&#39;s top level (max number of hops on a reverse path up to an entry task...
Definition: WorkflowTask.cpp:761
void setComputationEndDate(double date)
Set the date when the computation portion of a WorkflowTask has ended.
Definition: WorkflowTask.cpp:506
double computation_end
Task&#39;s computation end time.
Definition: WorkflowTask.h:221
double getFlops() const
Get the number of flops of the task.
Definition: WorkflowTask.cpp:127
void setEndDate(double date)
Set the task&#39;s end date.
Definition: WorkflowTask.cpp:477
unsigned long num_cores_allocated
Task&#39;s number of allocated cores.
Definition: WorkflowTask.h:236
unsigned long getNumberOfParents() const
Get the number of parents of a task.
Definition: WorkflowTask.cpp:195
Ready (parents have completed)
Definition: WorkflowTask.h:69
WorkflowTask::State getUpcomingState() const
Get the state of the task.
Definition: WorkflowTask.cpp:226
WorkflowTaskExecution(double task_start)
Constructor.
Definition: WorkflowTask.h:243
double getEndDate()
Get the task&#39;s most recent end date.
Definition: WorkflowTask.cpp:666
std::string getID() const
Get the id of the task.
Definition: WorkflowTask.cpp:118
unsigned long getBytesWritten() const
Get the number of bytes written by the task.
Definition: WorkflowTask.cpp:450
double getComputationStartDate()
Get the tasks&#39;s most recent computation start date.
Definition: WorkflowTask.cpp:674
State
Task types.
Definition: WorkflowTask.h:65
unsigned long getBytesRead() const
Get the number of bytes read by the task.
Definition: WorkflowTask.cpp:434
void setReadInputEndDate(double date)
Set the date when the read input portion of a WorkflowTask has completed.
Definition: WorkflowTask.cpp:536
std::set< WorkflowFile * > getInputFiles()
Get the set of input WorkflowFile objects for the task.
Definition: WorkflowTask.cpp:632
void setClusterID(std::string)
Set the cluster id for the task.
Definition: WorkflowTask.cpp:394
unsigned long updateTopLevel()
Update the task&#39;s top level (looking only at the parents, and updating children)
Definition: WorkflowTask.cpp:738
unsigned long getNumberOfChildren() const
Get the number of children of a task.
Definition: WorkflowTask.cpp:173
void addInputFile(WorkflowFile *file)
Add an input file to the task.
Definition: WorkflowTask.cpp:56
void setState(WorkflowTask::State)
Set the visible state of the task.
Definition: WorkflowTask.cpp:310
unsigned long getPriority() const
Get the task priority. By default, priority is 0.
Definition: WorkflowTask.cpp:402
double getReadInputEndDate()
Get the task&#39;s most recent read input end date.
Definition: WorkflowTask.cpp:698
void setBytesWritten(unsigned long)
Set the number of bytes written by the task.
Definition: WorkflowTask.cpp:458
void setJob(WorkflowJob *job)
Set the task&#39;s containing job.
Definition: WorkflowTask.cpp:369
double getAverageCPU() const
Get the task average CPU usage.
Definition: WorkflowTask.cpp:418
static std::string stateToString(WorkflowTask::State state)
Convert task state to a string (useful for output, debugging, logging, etc.)
Definition: WorkflowTask.cpp:245
void setUpcomingState(WorkflowTask::State)
Set the upcoming visible state of the task.
Definition: WorkflowTask.cpp:360
std::string execution_host
Task&#39;s execution host.
Definition: WorkflowTask.h:234
double getWriteOutputStartDate()
Get the task&#39;s most recent write output start date.
Definition: WorkflowTask.cpp:706
std::stack< WorkflowTaskExecution > getExecutionHistory()
Get the execution history of this task.
Definition: WorkflowTask.cpp:608
Definition: Alarm.cpp:19
double getTerminationDate()
Get the tasks&#39;s most recent termination date (when it was explicitly requested to be terminated by th...
Definition: WorkflowTask.cpp:730
double getStartDate()
Get the task&#39;s most recent start date.
Definition: WorkflowTask.cpp:658
void setPriority(long)
Set the task priority.
Definition: WorkflowTask.cpp:410
double task_start
Task&#39;s start time.
Definition: WorkflowTask.h:213
std::set< WorkflowFile * > getOutputFiles()
Get the set of output WorkflowFile objects for the task.
Definition: WorkflowTask.cpp:645
std::string getExecutionHost()
Returns the name of the host on which the task has most recently been executed, or "" if the task has...
Definition: WorkflowTask.cpp:770
double write_output_end
Task&#39;s write output end time.
Definition: WorkflowTask.h:225