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 {
67  NOT_READY,
69  READY,
71  PENDING,
73  COMPLETED,
75  UNKNOWN
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 
142  WorkflowTask::State getState() const;
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 
158  enum InternalState {
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 
170  void setInternalState(WorkflowTask::InternalState);
171 
172  void setState(WorkflowTask::State);
173 
174  void setUpcomingState(WorkflowTask::State);
175 
176  WorkflowTask::State getUpcomingState() const;
177 
178  WorkflowTask::InternalState getInternalState() const;
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 
211  struct WorkflowTaskExecution {
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
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
unsigned long getMaxNumCores() const
Get the maximum number of cores that the task can use.
Definition: WorkflowTask.cpp:145
void addOutputFile(WorkflowFile *file)
Add an output file to the task.
Definition: WorkflowTask.cpp:86
unsigned long getMinNumCores() const
Get the minimum number of cores required for running the task.
Definition: WorkflowTask.cpp:136
A computational task in a Workflow.
Definition: WorkflowTask.h:26
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
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 getParallelEfficiency() const
Get the parallel efficiency of the task.
Definition: WorkflowTask.cpp:154
double getFlops() const
Get the number of flops of the task.
Definition: WorkflowTask.cpp:127
unsigned long getNumberOfParents() const
Get the number of parents of a task.
Definition: WorkflowTask.cpp:195
std::string getID() const
Get the id of the task.
Definition: WorkflowTask.cpp:118
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
Definition: Alarm.cpp:19