CloudService.h
1 
11 #ifndef WRENCH_CLOUDSERVICE_H
12 #define WRENCH_CLOUDSERVICE_H
13 
14 #include <map>
15 #include <simgrid/s4u/VirtualMachine.hpp>
16 
17 #include "wrench/services/compute/ComputeServiceMessage.h"
18 #include "wrench/services/compute/ComputeService.h"
19 #include "wrench/services/compute/cloud/CloudServiceProperty.h"
20 #include "wrench/services/compute/cloud/CloudServiceMessagePayload.h"
21 #include "wrench/simulation/Simulation.h"
22 #include "wrench/simgrid_S4U_util/S4U_VirtualMachine.h"
23 #include "wrench/workflow/job/PilotJob.h"
24 
25 
26 namespace wrench {
27 
28  class Simulation;
29 
30  class ComputeService;
31 
37  class CloudService : public ComputeService {
38 
39  private:
40  std::map<std::string, std::string> default_property_values = {
44  };
45 
46  std::map<std::string, std::string> default_messagepayload_values = {
67  };
68 
69  public:
70  CloudService(const std::string &hostname,
71  std::vector<std::string> &execution_hosts,
72  double scratch_space_size,
73  std::map<std::string, std::string> property_list = {},
74  std::map<std::string, std::string> messagepayload_list = {});
75 
76  /***********************/
78  /***********************/
79 
80  virtual std::string createVM(unsigned long num_cores = ComputeService::ALL_CORES,
81  double ram_memory = ComputeService::ALL_RAM,
82  std::map<std::string, std::string> property_list = {},
83  std::map<std::string, std::string> messagepayload_list = {});
84 
85  virtual bool shutdownVM(const std::string &vm_hostname);
86 
87  virtual bool startVM(const std::string &vm_hostname);
88 
89  virtual bool suspendVM(const std::string &vm_hostname);
90 
91  virtual bool resumeVM(const std::string &vm_hostname);
92 
93  std::vector<std::string> getExecutionHosts();
94 
95  /***********************/
97  /***********************/
98 
99  /***********************/
101  /***********************/
102  void submitStandardJob(StandardJob *job, std::map<std::string, std::string> &service_specific_args) override;
103 
104  void submitPilotJob(PilotJob *job, std::map<std::string, std::string> &service_specific_args) override;
105 
106  void terminateStandardJob(StandardJob *job) override;
107  void terminatePilotJob(PilotJob *job) override;
108 
109  void validateProperties();
110 
111  ~CloudService();
112 
113  /***********************/
115  /***********************/
116 
117  protected:
118  /***********************/
120  /***********************/
121 
122  friend class Simulation;
123 
124  int main() override;
125 
126  std::unique_ptr<SimulationMessage> sendRequest(std::string &answer_mailbox, ComputeServiceMessage *message);
127 
128  virtual bool processNextMessage();
129 
130  virtual void processGetResourceInformation(const std::string &answer_mailbox);
131 
132  virtual void processGetExecutionHosts(const std::string &answer_mailbox);
133 
134  virtual void processCreateVM(const std::string &answer_mailbox,
135  const std::string &pm_hostname,
136  const std::string &vm_name,
137  unsigned long num_cores,
138  double ram_memory,
139  std::map<std::string, std::string> &property_list,
140  std::map<std::string, std::string> &messagepayload_list);
141 
142  virtual void processShutdownVM(const std::string &answer_mailbox, const std::string &vm_hostname);
143 
144  virtual void processStartVM(const std::string &answer_mailbox, const std::string &vm_name);
145 
146  virtual void processSuspendVM(const std::string &answer_mailbox, const std::string &vm_hostname);
147 
148  virtual void processResumeVM(const std::string &answer_mailbox, const std::string &vm_hostname);
149 
150  virtual void processSubmitStandardJob(const std::string &answer_mailbox, StandardJob *job,
151  std::map<std::string, std::string> &service_specific_args);
152 
153  virtual void processSubmitPilotJob(const std::string &answer_mailbox, PilotJob *job,
154  std::map<std::string, std::string> &service_specific_args);
155 
156  void stopAllVMs();
157 
159  static unsigned long VM_ID;
163  std::vector<std::string> execution_hosts;
164 
166  std::map<std::string, double> cs_available_ram;
167 
169  std::map<std::string, std::tuple<std::shared_ptr<S4U_VirtualMachine>, std::shared_ptr<ComputeService>, unsigned long, unsigned long>> vm_list;
170 
172  std::map<std::string, unsigned long> used_cores_per_execution_host;
173 
174  /***********************/
176  /***********************/
177  };
178 }
179 
180 #endif //WRENCH_CLOUDSERVICE_H
static const std::string START_VM_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the service in answer to a VM start request...
Definition: CloudServiceMessagePayload.h:38
virtual void processSubmitPilotJob(const std::string &answer_mailbox, PilotJob *job, std::map< std::string, std::string > &service_specific_args)
Process a submit pilot job request.
Definition: CloudService.cpp:865
Top-level class for messages received/sent by a ComputeService.
Definition: ComputeServiceMessage.h:32
virtual bool startVM(const std::string &vm_hostname)
Start a VM.
Definition: CloudService.cpp:192
void validateProperties()
Validate the service&#39;s properties.
Definition: CloudService.cpp:976
virtual void processSuspendVM(const std::string &answer_mailbox, const std::string &vm_hostname)
: Process a VM suspend request
Definition: CloudService.cpp:702
~CloudService()
Destructor.
Definition: CloudService.cpp:66
static const std::string SUSPEND_VM_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the service in answer to a VM suspend request...
Definition: CloudServiceMessagePayload.h:42
static const std::string STOP_DAEMON_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the daemon to terminate it.
Definition: ServiceMessagePayload.h:31
static const std::string SUBMIT_PILOT_JOB_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent from the daemon to acknowledge a pilot job submission...
Definition: ComputeServiceMessagePayload.h:40
std::map< std::string, std::string > property_list
The service&#39;s property list.
Definition: Service.h:104
virtual void processShutdownVM(const std::string &answer_mailbox, const std::string &vm_hostname)
: Process a VM shutdown request
Definition: CloudService.cpp:602
static const std::string CREATE_VM_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the service to request a VM creation.
Definition: CloudServiceMessagePayload.h:28
static const std::string SUBMIT_STANDARD_JOB_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the daemon to acknowledge a standard job submissio...
Definition: ComputeServiceMessagePayload.h:28
std::map< std::string, unsigned long > used_cores_per_execution_host
A map of the number of used cores (per VM) per execution host.
Definition: CloudService.h:172
virtual void processCreateVM(const std::string &answer_mailbox, const std::string &pm_hostname, const std::string &vm_name, unsigned long num_cores, double ram_memory, std::map< std::string, std::string > &property_list, std::map< std::string, std::string > &messagepayload_list)
Create a BareMetalComputeService VM on a physical machine.
Definition: CloudService.cpp:510
std::vector< std::string > getExecutionHosts()
Get the list of execution hosts available to run VMs.
Definition: CloudService.cpp:78
void terminateStandardJob(StandardJob *job) override
Terminate a standard job to the compute service (virtual)
Definition: CloudService.cpp:340
static constexpr double ALL_RAM
A convenient constant to mean "use all ram of a physical host" whenever a ram capacity is needed when...
Definition: ComputeService.h:59
void submitStandardJob(StandardJob *job, std::map< std::string, std::string > &service_specific_args) override
Submit a standard job to the cloud service.
Definition: CloudService.cpp:278
void stopAllVMs()
Terminate all VMs.
Definition: CloudService.cpp:955
CloudService(const std::string &hostname, std::vector< std::string > &execution_hosts, double scratch_space_size, std::map< std::string, std::string > property_list={}, std::map< std::string, std::string > messagepayload_list={})
Constructor.
Definition: CloudService.cpp:39
virtual void processGetResourceInformation(const std::string &answer_mailbox)
Process a "get resource information message".
Definition: CloudService.cpp:892
static const std::string GET_EXECUTION_HOSTS_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the service to request a get execution hosts...
Definition: CloudServiceMessagePayload.h:24
static const std::string SHUTDOWN_VM_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the service to request a VM shutdown.
Definition: CloudServiceMessagePayload.h:32
std::map< std::string, std::tuple< std::shared_ptr< S4U_VirtualMachine >, std::shared_ptr< ComputeService >, unsigned long, unsigned long > > vm_list
A map of VMs described by the VM actor, the actual compute service, the total number of cores...
Definition: CloudService.h:169
std::map< std::string, double > cs_available_ram
Map of available RAM at hosts.
Definition: CloudService.h:166
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:47
A pilot (i.e., non-standard) workflow job that can be submitted to a ComputeService by a WMS (via a J...
Definition: PilotJob.h:29
A standard (i.e., non-pilot) workflow job that can be submitted to a ComputeService by a WMS (via a J...
Definition: StandardJob.h:38
static constexpr unsigned long ALL_CORES
A convenient constant to mean "use all cores of a physical host" whenever a number of cores is needed...
Definition: ComputeService.h:54
A class that provides basic simulation methods.
Definition: Simulation.h:34
virtual bool processNextMessage()
Wait for and react to any incoming message.
Definition: CloudService.cpp:404
int main() override
Main method of the daemon.
Definition: CloudService.cpp:350
static const std::string RESUME_VM_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the service to request a VM resume.
Definition: CloudServiceMessagePayload.h:44
virtual bool suspendVM(const std::string &vm_hostname)
Suspend a running VM.
Definition: CloudService.cpp:220
static const std::string CREATE_VM_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the service in answer to a VM creation request...
Definition: CloudServiceMessagePayload.h:30
static const std::string SUBMIT_PILOT_JOB_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the daemon to submit a pilot job.
Definition: ComputeServiceMessagePayload.h:38
The compute service base class.
Definition: ComputeService.h:35
std::unique_ptr< SimulationMessage > sendRequest(std::string &answer_mailbox, ComputeServiceMessage *message)
Send a message request.
Definition: CloudService.cpp:375
static const std::string RESUME_VM_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the service in answer to a VM resume request...
Definition: CloudServiceMessagePayload.h:46
void submitPilotJob(PilotJob *job, std::map< std::string, std::string > &service_specific_args) override
Asynchronously submit a pilot job to the cloud service.
Definition: CloudService.cpp:311
virtual void processGetExecutionHosts(const std::string &answer_mailbox)
Process a execution host list request.
Definition: CloudService.cpp:483
A cloud-based compute service that manages a set of physical hosts and controls access to their resou...
Definition: CloudService.h:37
static const std::string SUPPORTS_PILOT_JOBS
Whether the compute service supports pilot jobs (true or false)
Definition: ComputeServiceProperty.h:26
std::map< std::string, std::string > messagepayload_list
The service&#39;s messagepayload list.
Definition: Service.h:107
virtual bool resumeVM(const std::string &vm_hostname)
Resume a suspended VM.
Definition: CloudService.cpp:248
void terminatePilotJob(PilotJob *job) override
non-implemented
Definition: CloudService.cpp:1003
virtual std::string createVM(unsigned long num_cores=ComputeService::ALL_CORES, double ram_memory=ComputeService::ALL_RAM, std::map< std::string, std::string > property_list={}, std::map< std::string, std::string > messagepayload_list={})
Create a BareMetalComputeService VM (balances load on execution hosts)
Definition: CloudService.cpp:112
static const std::string SUSPEND_VM_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the service to request a VM suspend.
Definition: CloudServiceMessagePayload.h:40
static const std::string RESOURCE_DESCRIPTION_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the daemon to ask it for information on its resour...
Definition: ComputeServiceMessagePayload.h:56
virtual void processResumeVM(const std::string &answer_mailbox, const std::string &vm_hostname)
: Process a VM resume request
Definition: CloudService.cpp:740
virtual void processSubmitStandardJob(const std::string &answer_mailbox, StandardJob *job, std::map< std::string, std::string > &service_specific_args)
Process a submit standard job request.
Definition: CloudService.cpp:782
static const std::string SUPPORTS_STANDARD_JOBS
Whether the compute service supports standard jobs (true or false)
Definition: ComputeServiceProperty.h:24
virtual void processStartVM(const std::string &answer_mailbox, const std::string &vm_name)
: Process a VM start request
Definition: CloudService.cpp:643
static const std::string VM_BOOT_OVERHEAD_IN_SECONDS
The overhead, in seconds, to boot a VM.
Definition: CloudServiceProperty.h:24
static const std::string SHUTDOWN_VM_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the service in answer to a VM shutdown request...
Definition: CloudServiceMessagePayload.h:34
static const std::string START_VM_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the service to request a VM start.
Definition: CloudServiceMessagePayload.h:36
static const std::string SUBMIT_STANDARD_JOB_REQUEST_MESSAGE_PAYLOAD
The number of bytes in the control message sent to the daemon to submit a standard job...
Definition: ComputeServiceMessagePayload.h:26
std::vector< std::string > execution_hosts
List of execution host names.
Definition: CloudService.h:163
static const std::string GET_EXECUTION_HOSTS_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the service in answer to a get execution hosts req...
Definition: CloudServiceMessagePayload.h:26
static const std::string DAEMON_STOPPED_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the daemon to confirm it has terminated.
Definition: ServiceMessagePayload.h:33
virtual bool shutdownVM(const std::string &vm_hostname)
Shutdown an active VM.
Definition: CloudService.cpp:164
static const std::string RESOURCE_DESCRIPTION_ANSWER_MESSAGE_PAYLOAD
The number of bytes in the control message sent by the daemon to state information on its resources...
Definition: ComputeServiceMessagePayload.h:58
Definition: TerminalOutput.cpp:15