From 740f821a59362ec143be35d61c70e86d8e0bb119 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 8 May 2012 22:33:59 +0200 Subject: [PATCH] feature #1055: Added Reset action to OpenNebula core --- include/DispatchManager.h | 9 ++ include/LifeCycleManager.h | 3 - include/VirtualMachineManager.h | 8 ++ include/VirtualMachineManagerDriver.h | 71 +++++++++++-- src/dm/DispatchManagerActions.cc | 59 ++++++++++- src/lcm/LifeCycleActions.cc | 35 ------- src/lcm/LifeCycleManager.cc | 8 -- src/rm/RequestManagerVirtualMachine.cc | 6 +- src/vmm/VirtualMachineManager.cc | 77 ++++++++++++++ src/vmm/VirtualMachineManagerDriver.cc | 139 +++---------------------- 10 files changed, 229 insertions(+), 186 deletions(-) diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 2ad6b03649..1f9aa56ecb 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -219,6 +219,15 @@ public: int reboot( int vid); + /** + * Resets a VM preserving any resource and RUNNING state + * @param vid VirtualMachine identification + * @return 0 on success, -1 if the VM does not exits or -2 if the VM is + * in a wrong a state + */ + int reset( + int vid); + /** * Set the re-scheduling flag for the VM (must be in RUNNING state) * @param vid VirtualMachine identification diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index 79b4af104c..bad3e951af 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -67,7 +67,6 @@ public: LIVE_MIGRATE, /**< Sent by the DM to live-migrate a VM */ SHUTDOWN, /**< Sent by the DM to shutdown a running VM */ RESTART, /**< Sent by the DM to restart a deployed VM */ - REBOOT, /**< Sent by the DM to reboot a running VM */ DELETE, /**< Sent by the DM to delete a VM */ CLEAN, /**< Sent by the DM to cleanup a VM for resubmission*/ FINALIZE @@ -195,8 +194,6 @@ private: void restart_action(int vid); - void reboot_action(int vid); - void delete_action(int vid); void clean_action(int vid); diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 9073f8dfa3..5691425563 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -52,6 +52,7 @@ public: MIGRATE, RESTORE, REBOOT, + RESET, POLL, TIMER, DRIVER_CANCEL, @@ -269,6 +270,13 @@ private: */ void reboot_action( int vid); + + /** + * Resets a running VM. + * @param vid the id of the VM. + */ + void reset_action( + int vid); /** * Polls a VM. diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index 5c2e197d5d..f7dce5d7ef 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -116,7 +116,10 @@ private: */ void deploy ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("DEPLOY", oid, drv_msg); + } /** * Sends a shutdown request to the MAD: "SHUTDOWN ID XML_DRV_MSG" @@ -125,7 +128,22 @@ private: */ void shutdown ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("SHUTDOWN", oid, drv_msg); + } + + /** + * Sends a reset request to the MAD: "RESET ID XML_DRV_MSG" + * @param oid the virtual machine id. + * @param drv_msg xml data for the mad operation + */ + void reset ( + const int oid, + const string& drv_msg) const + { + write_drv("RESET", oid, drv_msg); + } /** * Sends a reboot request to the MAD: "REBOOT ID XML_DRV_MSG" @@ -134,7 +152,10 @@ private: */ void reboot ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("REBOOT", oid, drv_msg); + } /** * Sends a cancel request to the MAD: "CANCEL ID XML_DRV_MSG" @@ -143,7 +164,10 @@ private: */ void cancel ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("CANCEL", oid, drv_msg); + } /** * Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG" @@ -152,7 +176,10 @@ private: */ void checkpoint ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("CHECKPOINT", oid, drv_msg); + } /** * Sends a save request to the MAD: "SAVE ID XML_DRV_MSG" @@ -161,7 +188,11 @@ private: */ void save ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("SAVE", oid, drv_msg); + } + /** * Sends a save request to the MAD: "RESTORE ID XML_DRV_MSG" @@ -170,7 +201,11 @@ private: */ void restore ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("RESTORE", oid, drv_msg); + } + /** * Sends a migrate request to the MAD: "MIGRATE ID XML_DRV_MSG" @@ -179,7 +214,10 @@ private: */ void migrate ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("MIGRATE", oid, drv_msg); + } /** * Sends a poll request to the MAD: "POLL ID XML_DRV_MSG" @@ -188,7 +226,22 @@ private: */ void poll ( const int oid, - const string& drv_msg) const; + const string& drv_msg) const + { + write_drv("POLL", oid, drv_msg); + + } + +private: + + void write_drv(const char * aname, const int oid, const string& msg) const + { + ostringstream os; + + os << aname << " " << oid << " " << msg << endl; + + write(os); + } }; /* -------------------------------------------------------------------------- */ diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index dc3e702bad..a245389409 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -557,10 +557,14 @@ int DispatchManager::reboot(int vid) if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING ) { - Nebula& nd = Nebula::instance(); - LifeCycleManager * lcm = nd.get_lcm(); + Nebula& nd = Nebula::instance(); + VirtualMachineManager * vmm = nd.get_vmm(); - lcm->trigger(LifeCycleManager::REBOOT,vid); + vmm->trigger(VirtualMachineManager::REBOOT,vid); + + vm->set_resched(false); //Rebooting cancels re-scheduling actions + + vmpool->update(vm); } else { @@ -584,6 +588,55 @@ error: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int DispatchManager::reset(int vid) +{ + VirtualMachine * vm; + ostringstream oss; + + vm = vmpool->get(vid,true); + + if ( vm == 0 ) + { + return -1; + } + + oss << "Resetting VM " << vid; + NebulaLog::log("DiM",Log::DEBUG,oss); + + if (vm->get_state() == VirtualMachine::ACTIVE && + vm->get_lcm_state() == VirtualMachine::RUNNING ) + { + Nebula& nd = Nebula::instance(); + VirtualMachineManager * vmm = nd.get_vmm(); + + vmm->trigger(VirtualMachineManager::RESET,vid); + + vm->set_resched(false); //Resetting cancels re-scheduling actions + + vmpool->update(vm); + } + else + { + goto error; + } + + vm->unlock(); + + return 0; + +error: + oss.str(""); + oss << "Could not reset VM " << vid << ", wrong state."; + NebulaLog::log("DiM",Log::ERROR,oss); + + vm->unlock(); + + return -2; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int DispatchManager::resched(int vid, bool do_resched) { VirtualMachine * vm; diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 234e686a58..c8ae47d557 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -439,41 +439,6 @@ void LifeCycleManager::cancel_action(int vid) return; } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void LifeCycleManager::reboot_action(int vid) -{ - VirtualMachine * vm; - - vm = vmpool->get(vid,true); - - if ( vm == 0 ) - { - return; - } - - if (vm->get_state() == VirtualMachine::ACTIVE && - vm->get_lcm_state() == VirtualMachine::RUNNING) - { - Nebula& nd = Nebula::instance(); - VirtualMachineManager * vmm = nd.get_vmm(); - - vmm->trigger(VirtualMachineManager::REBOOT,vid); - - vm->set_resched(false); //Rebooting cancel re-scheduling actions - - vmpool->update(vm); - } - else - { - vm->log("LCM", Log::ERROR, "reboot_action, VM in a wrong state."); - } - - vm->unlock(); - - return; -} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/lcm/LifeCycleManager.cc b/src/lcm/LifeCycleManager.cc index ead8c7067f..b3a72dda42 100644 --- a/src/lcm/LifeCycleManager.cc +++ b/src/lcm/LifeCycleManager.cc @@ -165,10 +165,6 @@ void LifeCycleManager::trigger(Actions action, int _vid) aname = "RESTART"; break; - case REBOOT: - aname = "REBOOT"; - break; - case DELETE: aname = "DELETE"; break; @@ -302,10 +298,6 @@ void LifeCycleManager::do_action(const string &action, void * arg) { restart_action(vid); } - else if (action == "REBOOT") - { - reboot_action(vid); - } else if (action == "DELETE") { delete_action(vid); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index b252330b84..fbfdcc102d 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -180,7 +180,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, string action = xmlrpc_c::value_string(paramList.getString(1)); int id = xmlrpc_c::value_int(paramList.getInt(2)); - int rc; + int rc = -4; Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); @@ -249,6 +249,10 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, { rc = dm->resched(id, false); } + else if (action == "reset") + { + rc = dm->reset(id); + } switch (rc) { diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 54e53c952a..7f666d31a0 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -130,6 +130,10 @@ void VirtualMachineManager::trigger(Actions action, int _vid) aname = "REBOOT"; break; + case RESET: + aname = "RESET"; + break; + case SHUTDOWN: aname = "SHUTDOWN"; break; @@ -206,6 +210,10 @@ void VirtualMachineManager::do_action(const string &action, void * arg) { reboot_action(vid); } + else if (action == "RESET") + { + reset_action(vid); + } else if (action == "SHUTDOWN") { shutdown_action(vid); @@ -650,6 +658,75 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void VirtualMachineManager::reset_action( + int vid) +{ + VirtualMachine * vm; + const VirtualMachineManagerDriver * vmd; + + string vm_tmpl; + string * drv_msg; + ostringstream os; + + // Get the VM from the pool + vm = vmpool->get(vid,true); + + if (vm == 0) + { + return; + } + + if (!vm->hasHistory()) + { + goto error_history; + } + + // Get the driver for this VM + vmd = get(vm->get_vmm_mad()); + + if ( vmd == 0 ) + { + goto error_driver; + } + + // Invoke driver method + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->reset(vid, *drv_msg); + + delete drv_msg; + + vm->unlock(); + + return; + +error_history: + os.str(""); + os << "reset_action, VM has no history"; + goto error_common; + +error_driver: + os.str(""); + os << "reset_action, error getting driver " << vm->get_vmm_mad(); + +error_common: + vm->log("VMM", Log::ERROR, os); + vm->unlock(); + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachineManager::cancel_action( int vid) { diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index eb285860f7..8ee591a9c3 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -98,133 +98,6 @@ void VirtualMachineManagerDriver::get_default( } } -/* ************************************************************************** */ -/* Driver ASCII Protocol Implementation */ -/* ************************************************************************** */ - -void VirtualMachineManagerDriver::deploy ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os << "DEPLOY " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::shutdown ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os << "SHUTDOWN " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::cancel ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os << "CANCEL " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::checkpoint ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os<< "CHECKPOINT " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::save ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os<< "SAVE " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::restore ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os << "RESTORE " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::migrate ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os<< "MIGRATE " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::poll ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os << "POLL " << oid << " " << drv_msg << endl; - - write(os); -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachineManagerDriver::reboot ( - const int oid, - const string& drv_msg) const -{ - ostringstream os; - - os << "REBOOT " << oid << " " << drv_msg << endl; - - write(os); -}; - /* ************************************************************************** */ /* MAD Interface */ /* ************************************************************************** */ @@ -450,6 +323,18 @@ void VirtualMachineManagerDriver::protocol( vmpool->update(vm); } } + else if ( action == "RESET" ) + { + if (result == "SUCCESS") + { + vm->log("VMM",Log::ERROR,"VM Successfully reseted."); + } + else + { + log_error(vm,os,is,"Error resetting VM, assume it's still running"); + vmpool->update(vm); + } + } else if ( action == "POLL" ) { if (result == "SUCCESS")