WMS.h
1 
10 #ifndef WRENCH_WMS_H
11 #define WRENCH_WMS_H
12 
13 #include <wrench/managers/EnergyMeterService.h>
14 #include "wrench/services/Service.h"
15 #include "wrench/wms/DynamicOptimization.h"
16 #include "wrench/wms/StaticOptimization.h"
17 #include "wrench/wms/scheduler/PilotJobScheduler.h"
18 #include "wrench/wms/scheduler/StandardJobScheduler.h"
19 #include "wrench/services/compute/cloud/CloudComputeService.h"
20 #include "wrench/workflow/execution_events/StandardJobCompletedEvent.h"
21 #include "wrench/workflow/execution_events/StandardJobFailedEvent.h"
22 #include "wrench/workflow/execution_events/PilotJobStartedEvent.h"
23 #include "wrench/workflow/execution_events/PilotJobExpiredEvent.h"
24 #include "wrench/workflow/execution_events/FileCopyCompletedEvent.h"
25 #include "wrench/workflow/execution_events/FileCopyFailedEvent.h"
26 #include "wrench/workflow/execution_events/TimerEvent.h"
27 #include "wrench/workflow/Workflow.h"
28 
29 namespace wrench {
30 
31  class Simulation;
32  class ComputeService;
33  class CloudComputeService;
34  class VirtualizedClusterComputeService;
35  class StorageService;
36  class NetworkProximityService;
37  class FileRegistryService;
38 
42  class WMS : public Service {
43 
44  public:
45  void addWorkflow(Workflow *workflow, double start_time = 0);
49 
50  void addStaticOptimization(std::unique_ptr<StaticOptimization>);
51 
52  void addDynamicOptimization(std::unique_ptr<DynamicOptimization>);
53 
54 
55  protected:
56 
57  /***********************/
59  /***********************/
60 
61  WMS(std::unique_ptr<StandardJobScheduler> standard_job_scheduler,
62  std::unique_ptr<PilotJobScheduler> pilot_job_scheduler,
63  const std::set<std::shared_ptr<ComputeService>> &compute_services,
64  const std::set<std::shared_ptr<StorageService>> &storage_services,
65  const std::set<std::shared_ptr<NetworkProximityService>> &network_proximity_services,
66  std::shared_ptr<FileRegistryService> file_registry_service,
67  const std::string &hostname,
68  const std::string suffix);
69 
70 
71  void checkDeferredStart();
72 
73  void setTimer(double date, std::string message);
74 
75  std::shared_ptr<JobManager> createJobManager();
76  std::shared_ptr<DataMovementManager> createDataMovementManager();
77  std::shared_ptr<EnergyMeterService> createEnergyMeter(const std::map<std::string, double> &measurement_periods);
78  std::shared_ptr<EnergyMeterService> createEnergyMeter(const std::vector<std::string> &hostnames, double measurement_period);
79 
81 
83 
89  template <class T>
90  std::set<std::shared_ptr<T>> getAvailableComputeServices() {
91  bool is_cloud = (std::type_index(typeid(T)) == std::type_index(typeid(CloudComputeService)));
92  std::set<std::shared_ptr<T>> to_return;
93  for (auto const &h : this->compute_services) {
94  if (not is_cloud) {
95  auto shared_ptr = std::dynamic_pointer_cast<T>(h);
96  if (shared_ptr) {
97  to_return.insert(shared_ptr);
98  }
99  } else {
100  auto shared_ptr_cloud = std::dynamic_pointer_cast<T>(h);
101  auto shared_ptr_vc = std::dynamic_pointer_cast<VirtualizedClusterComputeService>(h);
102  if (shared_ptr_cloud and (not shared_ptr_vc)) {
103  to_return.insert(shared_ptr_cloud);
104  }
105  }
106  }
107  return to_return;
108  }
109 
110  // The template specialization below does not compile with gcc, hence the above method!
111 
112 // /**
113 // * @brief Obtain the list of compute services available to the WMS
114 // * @tparam CloudComputeService
115 // * @return a set of compute services
116 // * @return
117 // */
118 // template <>
119 // std::set<std::shared_ptr<CloudComputeService>> getAvailableComputeServices<CloudComputeService>() {
120 // std::set<std::shared_ptr<CloudComputeService>> to_return;
121 // for (auto const &h : this->compute_services) {
122 // auto shared_ptr_cloud = std::dynamic_pointer_cast<CloudComputeService>(h);
123 // auto shared_ptr_vc = std::dynamic_pointer_cast<VirtualizedClusterComputeService>(h);
124 // if (shared_ptr_cloud and (not shared_ptr_vc)) {
125 // to_return.insert(shared_ptr_cloud);
126 // }
127 // }
128 // return to_return;
129 // }
130 
131 
132  std::set<std::shared_ptr<StorageService>> getAvailableStorageServices();
133  std::set<std::shared_ptr<NetworkProximityService>> getAvailableNetworkProximityServices();
134  std::shared_ptr<FileRegistryService> getAvailableFileRegistryService();
135 
137  bool waitForAndProcessNextEvent(double timeout);
138  std::shared_ptr<WorkflowExecutionEvent> waitForNextEvent();
139  std::shared_ptr<WorkflowExecutionEvent> waitForNextEvent(double timeout);
140  virtual void processEventStandardJobCompletion(std::shared_ptr<StandardJobCompletedEvent>);
141 
142  virtual void processEventStandardJobFailure(std::shared_ptr<StandardJobFailedEvent>);
143 
144  virtual void processEventPilotJobStart(std::shared_ptr<PilotJobStartedEvent>);
145 
146  virtual void processEventPilotJobExpiration(std::shared_ptr<PilotJobExpiredEvent>);
147 
148  virtual void processEventFileCopyCompletion(std::shared_ptr<FileCopyCompletedEvent>);
149 
150  virtual void processEventFileCopyFailure(std::shared_ptr<FileCopyFailedEvent>);
151 
152  virtual void processEventTimer(std::shared_ptr<TimerEvent>);
153 
154  /***********************/
156  /***********************/
157 
158  /***********************/
160  /***********************/
161 
162  private:
163  friend class Simulation;
164  friend class DataMovementManager;
165  friend class JobManager;
166 
168  Workflow *workflow;
170  double start_time;
172  std::set<std::shared_ptr<ComputeService>> compute_services;
174  std::set<std::shared_ptr<StorageService>> storage_services;
176  std::set<std::shared_ptr<NetworkProximityService>> network_proximity_services;
178  std::shared_ptr<FileRegistryService> file_registry_service;
179 
181  std::shared_ptr<StandardJobScheduler> standard_job_scheduler;
183  std::shared_ptr<PilotJobScheduler> pilot_job_scheduler;
184 
186  std::vector<std::unique_ptr<DynamicOptimization>> dynamic_optimizations;
188  std::vector<std::unique_ptr<StaticOptimization>> static_optimizations;
189 
190  /***********************/
192  /***********************/
193 
194  private:
195  virtual int main() = 0;
196 
197  };
198 
199 };
200 
201 
202 #endif //WRENCH_WMS_H
void setTimer(double date, std::string message)
Sets a timer (which, when it goes off, will generate a TimerEvent)
Definition: WMS.cpp:415
virtual void processEventStandardJobCompletion(std::shared_ptr< StandardJobCompletedEvent >)
Process a standard job completion event.
Definition: WMS.cpp:222
std::shared_ptr< DataMovementManager > createDataMovementManager()
Instantiate and start a data movement manager.
Definition: WMS.cpp:342
virtual void processEventPilotJobStart(std::shared_ptr< PilotJobStartedEvent >)
Process a pilot job start event.
Definition: WMS.cpp:241
std::set< std::shared_ptr< StorageService > > getAvailableStorageServices()
Obtain the list of storage services available to the WMS.
Definition: WMS.cpp:136
void addStaticOptimization(std::unique_ptr< StaticOptimization >)
Add a static optimization to the list of optimizations. Optimizations are executed in order of insert...
Definition: WMS.cpp:76
WMS(std::unique_ptr< StandardJobScheduler > standard_job_scheduler, std::unique_ptr< PilotJobScheduler > pilot_job_scheduler, const std::set< std::shared_ptr< ComputeService >> &compute_services, const std::set< std::shared_ptr< StorageService >> &storage_services, const std::set< std::shared_ptr< NetworkProximityService >> &network_proximity_services, std::shared_ptr< FileRegistryService > file_registry_service, const std::string &hostname, const std::string suffix)
Constructor: a WMS with a workflow instance, a scheduler implementation, and a list of compute servic...
Definition: WMS.cpp:42
PilotJobScheduler * getPilotJobScheduler()
Get the WMS's pilot scheduler.
Definition: WMS.cpp:397
A helper daemon (co-located with and explicitly started by a WMS), which is used to handle all job ex...
Definition: JobManager.h:40
std::set< std::shared_ptr< NetworkProximityService > > getAvailableNetworkProximityServices()
Obtain the list of network proximity services available to the WMS.
Definition: WMS.cpp:145
StandardJobScheduler * getStandardJobScheduler()
Get the WMS's pilot scheduler.
Definition: WMS.cpp:406
virtual void processEventPilotJobExpiration(std::shared_ptr< PilotJobExpiredEvent >)
Process a pilot job expiration event.
Definition: WMS.cpp:250
A cloud-based compute service that manages a set of physical hosts and controls access to their resou...
Definition: CloudComputeService.h:37
Definition: Alarm.cpp:20
A workflow (to be executed by a WMS)
Definition: Workflow.h:33
std::shared_ptr< EnergyMeterService > createEnergyMeter(const std::map< std::string, double > &measurement_periods)
Instantiate and start an energy meter.
Definition: WMS.cpp:368
void addWorkflow(Workflow *workflow, double start_time=0)
Assign a workflow to the WMS.
Definition: WMS.cpp:288
A helper daemon (co-located with a WMS) that handles data movement operations.
Definition: DataMovementManager.h:31
virtual void processEventTimer(std::shared_ptr< TimerEvent >)
Process a timer event.
Definition: WMS.cpp:277
std::set< std::shared_ptr< T > > getAvailableComputeServices()
Obtain the list of compute services available to the WMS.
Definition: WMS.h:90
void addDynamicOptimization(std::unique_ptr< DynamicOptimization >)
Add a dynamic optimization to the list of optimizations. Optimizations are executed in order of inser...
Definition: WMS.cpp:66
std::shared_ptr< WorkflowExecutionEvent > waitForNextEvent()
Wait for a workflow execution event.
Definition: WMS.cpp:213
virtual void processEventStandardJobFailure(std::shared_ptr< StandardJobFailedEvent >)
Process a standard job failure event.
Definition: WMS.cpp:232
virtual void processEventFileCopyCompletion(std::shared_ptr< FileCopyCompletedEvent >)
Process a file copy completion event.
Definition: WMS.cpp:259
std::shared_ptr< JobManager > createJobManager()
Instantiate and start a job manager.
Definition: WMS.cpp:321
virtual void processEventFileCopyFailure(std::shared_ptr< FileCopyFailedEvent >)
Process a file copy failure event.
Definition: WMS.cpp:268
A (mostly virtual) base class for implementing PilotJob scheduling algorithms to be used by a WMS.
Definition: PilotJobScheduler.h:26
Workflow * getWorkflow()
Get the workflow that was assigned to the WMS.
Definition: WMS.cpp:313
std::shared_ptr< FileRegistryService > getAvailableFileRegistryService()
Obtain the file registry service available to the WMS.
Definition: WMS.cpp:154
void waitForAndProcessNextEvent()
Wait for a workflow execution event and then call the associated function to process that event.
Definition: WMS.cpp:161
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:45
A (mostly virtual) base class for implementing StandardJob scheduling algorithms to be used by a WMS.
Definition: StandardJobScheduler.h:31
void checkDeferredStart()
Check whether the WMS has a deferred start simulation time (likely the first call in the main() routi...
Definition: WMS.cpp:86
A service that can be added to the simulation and that can be used by a WMS when executing a workflow...
Definition: Service.h:26
void runDynamicOptimizations()
Perform dynamic optimizations. Optimizations are executed in order of insertion.
Definition: WMS.cpp:116
void runStaticOptimizations()
Perform static optimizations. Optimizations are executed in order of insertion.
Definition: WMS.cpp:125
A workflow management system (WMS)
Definition: WMS.h:42