Skip to content

Commit

Permalink
minor improvements to cloud service
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfsilva committed Oct 17, 2017
1 parent d6d089c commit 6fbf070
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
8 changes: 3 additions & 5 deletions examples/simple-wms/scheduler/CloudScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ namespace wrench {
try {
std::string pm_host = choosePMHostname();
std::string vm_host = "vm" + std::to_string(VM_ID++) + "_" + pm_host;
std::string vm_hostname = cs->createVM(pm_host, vm_host,
((StandardJob *) (job))->getMinimumRequiredNumCores());

if (not vm_hostname.empty()) {
this->vm_list[pm_host].push_back(vm_hostname);
if (cs->createVM(pm_host, vm_host, ((StandardJob *) (job))->getMinimumRequiredNumCores())) {
this->vm_list[pm_host].push_back(vm_host);
}

} catch (WorkflowExecutionException &e) {
Expand All @@ -98,7 +96,7 @@ namespace wrench {
}

/**
* Select a physical host (PM) with the least number of VMs.
* @brief Select a physical host (PM) with the least number of VMs.
*
* @return a physical hostname
*/
Expand Down
8 changes: 4 additions & 4 deletions include/wrench/services/compute/cloud/CloudService.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ namespace wrench {
/** \cond DEVELOPER */
/***********************/

std::string createVM(const std::string &pm_hostname,
const std::string &vm_hostname,
unsigned long num_cores,
std::map<std::string, std::string> plist = {});
bool createVM(const std::string &pm_hostname,
const std::string &vm_hostname,
unsigned long num_cores,
std::map<std::string, std::string> plist = {});

// Running jobs
void submitStandardJob(StandardJob *job, std::map<std::string, std::string> &service_specific_args) override;
Expand Down
15 changes: 8 additions & 7 deletions src/wrench/services/compute/cloud/CloudService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ namespace wrench {
*
* @throw WorkflowExecutionException
*/
std::string CloudService::createVM(const std::string &pm_hostname,
const std::string &vm_hostname,
unsigned long num_cores,
std::map<std::string, std::string> plist) {
bool CloudService::createVM(const std::string &pm_hostname,
const std::string &vm_hostname,
unsigned long num_cores,
std::map<std::string, std::string> plist) {

if (this->state == Service::DOWN) {
throw WorkflowExecutionException(new ServiceIsDown(this));
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace wrench {
}

if (auto *msg = dynamic_cast<CloudServiceCreateVMAnswerMessage *>(message.get())) {
return msg->vm_hostname;
return msg->success;
} else {
throw std::runtime_error("CloudService::createVM(): Unexpected [" + msg->getName() + "] message");
}
Expand Down Expand Up @@ -340,13 +340,14 @@ namespace wrench {
S4U_Mailbox::dputMessage(
answer_mailbox,
new CloudServiceCreateVMAnswerMessage(
vm_hostname,
true,
this->getPropertyValueAsDouble(CloudServiceProperty::CREATE_VM_ANSWER_MESSAGE_PAYLOAD)));
} else {
S4U_Mailbox::dputMessage(
answer_mailbox,
new CloudServiceCreateVMAnswerMessage(
"", this->getPropertyValueAsDouble(CloudServiceProperty::CREATE_VM_ANSWER_MESSAGE_PAYLOAD)));
false,
this->getPropertyValueAsDouble(CloudServiceProperty::CREATE_VM_ANSWER_MESSAGE_PAYLOAD)));
}
} catch (std::shared_ptr<NetworkError> &cause) {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/wrench/services/compute/cloud/CloudServiceMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace wrench {
* @param vm_hostname: the new VM hostname
* @param payload: the message size in bytes
*/
CloudServiceCreateVMAnswerMessage::CloudServiceCreateVMAnswerMessage(
const std::string &vm_hostname, double payload) :
CloudServiceMessage("CREATE_VM_ANSWER", payload), vm_hostname(vm_hostname) {}
CloudServiceCreateVMAnswerMessage::CloudServiceCreateVMAnswerMessage(bool success, double payload) :
CloudServiceMessage("CREATE_VM_ANSWER", payload), success(success) {}

}
6 changes: 3 additions & 3 deletions src/wrench/services/compute/cloud/CloudServiceMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ namespace wrench {
*/
class CloudServiceCreateVMAnswerMessage : public CloudServiceMessage {
public:
CloudServiceCreateVMAnswerMessage(const std::string &vm_hostname, double payload);
CloudServiceCreateVMAnswerMessage(bool success, double payload);

std::string vm_hostname;
bool success;
};

/***********************/
/** \endcond */
/***********************/
Expand Down

0 comments on commit 6fbf070

Please sign in to comment.