Skip to content

Commit

Permalink
(#187) Added a CloudComputeService::getVMComputeService method
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Jul 16, 2020
1 parent 6beaa98 commit fc37470
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
10 changes: 6 additions & 4 deletions include/wrench/services/compute/cloud/CloudComputeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ namespace wrench {

public:
CloudComputeService(const std::string &hostname,
std::vector<std::string> &execution_hosts,
std::string scratch_space_mount_point,
std::map<std::string, std::string> property_list = {},
std::map<std::string, double> messagepayload_list = {});
std::vector<std::string> &execution_hosts,
std::string scratch_space_mount_point,
std::map<std::string, std::string> property_list = {},
std::map<std::string, double> messagepayload_list = {});

/***********************/
/** \cond DEVELOPER */
Expand All @@ -95,6 +95,8 @@ namespace wrench {

virtual std::shared_ptr<BareMetalComputeService> startVM(const std::string &vm_name);

virtual std::shared_ptr<BareMetalComputeService> getVMComputeService(const std::string &vm_name);

virtual void suspendVM(const std::string &vm_name);

virtual void resumeVM(const std::string &vm_name);
Expand Down
19 changes: 19 additions & 0 deletions src/wrench/services/compute/cloud/CloudComputeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ namespace wrench {
}
}

/**
* @brief Get the compute service running on a VM, if any
*
* @param vm_name: the name of the VM
*
* @return A BareMetalComputeService that runs on the VM, or nullptr if none
*
* @throw WorkflowExecutionException
* @throw std::invalid_argument
*/
std::shared_ptr<BareMetalComputeService> CloudComputeService::getVMComputeService(const std::string &vm_name) {

if (this->vm_list.find(vm_name) == this->vm_list.end()) {
throw std::invalid_argument("CloudComputeService::startVM(): Unknown VM name '" + vm_name + "'");
}
return this->vm_list.at(vm_name).second;
}


/**
* @brief Suspend a running VM
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,20 @@ class CloudStandardJobTestWMS : public wrench::WMS {

}

// Check that we cannot get the CS back
if (cs->getVMComputeService(vm_name) != nullptr) {
throw std::runtime_error("A non-started VM should have a nullptr compute service");
}

// Start the VM
auto vm_cs = cs->startVM(vm_name);

// Check that we can get the CS back
auto vm_cs_should_be_same = cs->getVMComputeService(vm_name);
if (vm_cs != vm_cs_should_be_same) {
throw std::runtime_error("It should be possible to get the computer service of a started VM");
}

// Check the state
if (not cs->isVMRunning(vm_name)) {
throw std::runtime_error("A just started VM should be running");
Expand Down

0 comments on commit fc37470

Please sign in to comment.