hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCECommonTask.hpp
Go to the documentation of this file.
1 
14 #ifndef DRCE_COMMON_TASK_HPP
15 #define DRCE_COMMON_TASK_HPP
16 
17 #include <Poco/Task.h>
18 #include <Poco/Timestamp.h>
19 #include <vector>
20 
21 #include "DRCENodeOptions.hpp"
22 #include "CustomMessage.hpp"
23 #include "CommandExecutor.hpp"
24 #include "DRCEFilesList.hpp"
25 #include "DRCEResultData.hpp"
27 #include "DRCEAsyncTasksQueue.hpp"
28 #include "DRCEResourceMonitor.hpp"
29 #include "Process.hpp"
30 #include "DRCEError.hpp"
31 #include "DRCEInputJsonMessage.hpp"
32 
33 namespace HCE
34 {
35 namespace drce
36 {
37 class DRCEAsyncTasksQueue;
38 //-----------------------------------------------------------------------------
39 class DRCECommonTask : public Poco::Task
40 {
41 public:
42  typedef std::vector<std::pair<unsigned int, SessionOptions::CleanupFlag> > SubtasksList;
43 public:
45  {
46  public:
47  ApplyPidHandler(DRCEAsyncTasksQueue& asyncTasksQueue_,
48  AsyncTasks& asyncTask_,
49  DRCETaskRequest::TaskState allowedTaskState_,
50  SessionOptions::ThreadMode threadMode_);
52 
53  void operator()(pid_t pid);
54  private:
55  DRCEAsyncTasksQueue& asyncTasksQueue;
56  AsyncTasks& asyncTask;
57  DRCETaskRequest::TaskState allowedTaskState;
58  SessionOptions::ThreadMode threadMode;
59  };
60 public:
61  DRCECommonTask(const std::string& taskName_, DRCENodeOptions& nodeOptions_, CustomMessage& message_,
62  const DRCETaskRequestSetExecute& taskRequestSetExecute_, DRCEAsyncTasksQueue& asyncTasksQueue_,
63  DRCEResourceMonitor& resourceMonitor_, const DRCEInputJsonMessage& inputJsonMessage, unsigned int parentTaskId_);
64 
65  virtual void runTask(void) = 0;
66  virtual DRCEResultDataItem execute(Process::CallbackFunction fn) throw (Poco::Exception) = 0;
67 
68 
69  void updateTasks(DRCEResultDataItem& resultDataItem, unsigned int& progressCount);
70  static void updateTasks(DRCEResultDataItem& resultDataItem,
74  unsigned int& progressCount,
75  DRCECommonTask* pCommonTask=nullptr);
76 
77  void makeFilesBefore(DRCEFilesList& filesList) throw (Poco::Exception);
78  void makeFilesAfter(DRCEFilesList& filesList, DRCEResultDataItem& resultDataItem);
79 
80  static size_t getElapsedTimeMsec(const Poco::Timestamp& tsStart); // return msec
81 
82  unsigned int getParentTaskId(void) const {return parentTaskId;}
83 
84  void saveRequestData(void);
85  void saveResultData(DRCEResultDataItem& resultDataItem);
86 protected:
93  unsigned int parentTaskId;
94 public:
95  void executeSubtasks(DRCEResultDataItem& resultDataItem);
96  void cleanup(bool needCleanup=false);
98 
99  static DRCEInputJsonMessage getRequestData(unsigned int taskId,
102 
103  static void waitUpdateAllTasks(unsigned int taskId,
107  Poco::Task* pTask=nullptr);
108 
111  Poco::Task* pTask=nullptr);
112 
113  static void cleanup(unsigned int taskId,
116  bool needCleanup=false);
117 
121  bool needCleanup=false);
122 
126 
127  static void saveRequest(unsigned int taskId,
130 
134 
135  static void saveResultData(DRCEResultDataItem& resultDataItem,
139 
144  DRCETaskRequest::TaskState taskState,
145  unsigned int errorCode=NO_ERROR,
146  const std::string& errorMessage="",
147  unsigned int pid=0,
148  size_t timeElapsed=0,
149  unsigned int exitStatus=0);
150 
151  static unsigned int getHostParentTaskId(unsigned int taskId,
153 
157 
161 
162  static void safeCleanup(const std::string& path);
163  static DRCEResultDataItem extractResultDataItem(const std::string& fileName);
164 private:
165  typedef Poco::Task inherited;
166 };
167 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
169 } // end namespace drce
170 } // end namespace HCE
171 
172 #endif // DRCE_COMMON_TASK_HPP