From 82ab8df8d647c6a086ae336b78e4e277c932eec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Tue, 10 Nov 2020 12:22:42 +0100 Subject: [PATCH] F #2586: Shutdown hard override soft shutdown (#401) --- src/dm/DispatchManagerActions.cc | 29 +++++++++++++++-- src/lcm/LifeCycleActions.cc | 53 ++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index f16268152e..a58de29517 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -438,6 +438,15 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra, lcm->trigger_delete(vid, ra); break; + case VirtualMachine::SHUTDOWN: + if (hard) + { + // Override previous (probably freezed) shutdown action + lcm->trigger_shutdown(vid, hard, ra); + break; + } + // else fallthrough to default + default: oss.str(""); oss << "Could not terminate VM " << vid @@ -487,6 +496,12 @@ int DispatchManager::undeploy(int vid, bool hard, const RequestAttributes& ra, lcm->trigger_undeploy(vid, ra); } } + else if ( hard && + vm->get_state() == VirtualMachine::ACTIVE && + vm->get_lcm_state() == VirtualMachine::SHUTDOWN_UNDEPLOY) + { + lcm->trigger_undeploy_hard(vid, ra); + } else { goto error; @@ -525,9 +540,11 @@ int DispatchManager::poweroff(int vid, bool hard, const RequestAttributes& ra, oss << "Powering off VM " << vid; NebulaLog::log("DiM",Log::DEBUG,oss); - if (vm->get_state() == VirtualMachine::ACTIVE && - (vm->get_lcm_state() == VirtualMachine::RUNNING || - vm->get_lcm_state() == VirtualMachine::UNKNOWN)) + auto lcm_state = vm->get_lcm_state(); + + if (vm->get_state() == VirtualMachine::ACTIVE && + (lcm_state == VirtualMachine::RUNNING || + lcm_state == VirtualMachine::UNKNOWN)) { if (hard) { @@ -538,6 +555,12 @@ int DispatchManager::poweroff(int vid, bool hard, const RequestAttributes& ra, lcm->trigger_poweroff(vid, ra); } } + else if (hard && + vm->get_state() == VirtualMachine::ACTIVE && + lcm_state == VirtualMachine::SHUTDOWN_POWEROFF ) + { + lcm->trigger_poweroff_hard(vid, ra); + } else { goto error; diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 5f8158cf3b..981500a6d9 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -434,7 +434,7 @@ void LifeCycleManager::trigger_shutdown(int vid, bool hard, vm->get_template_attribute("MEMORY", memory); vm->get_template_attribute("CPU", cpu); - if ( (vm->get_state() == VirtualMachine::SUSPENDED) || + if ((vm->get_state() == VirtualMachine::SUSPENDED) || (vm->get_state() == VirtualMachine::POWEROFF) || (vm->get_state() == VirtualMachine::STOPPED) || (vm->get_state() == VirtualMachine::UNDEPLOYED)) @@ -448,9 +448,20 @@ void LifeCycleManager::trigger_shutdown(int vid, bool hard, quota_tmpl.add("VMS", 0); } - if (vm->get_state() == VirtualMachine::ACTIVE && - (vm->get_lcm_state() == VirtualMachine::RUNNING || - vm->get_lcm_state() == VirtualMachine::UNKNOWN)) + auto lcm_state = vm->get_lcm_state(); + + if (hard && (vm->get_state() == VirtualMachine::ACTIVE && + lcm_state == VirtualMachine::SHUTDOWN)) + { + // Cancel previous shutdown action + vmm->trigger_driver_cancel(vid); + + lcm_state = VirtualMachine::RUNNING; // Force execute of hard shutdown + } + + if (vm->get_state() == VirtualMachine::ACTIVE && + (lcm_state == VirtualMachine::RUNNING || + lcm_state == VirtualMachine::UNKNOWN)) { //---------------------------------------------------- // SHUTDOWN STATE @@ -545,9 +556,20 @@ void LifeCycleManager::trigger_undeploy(int vid, bool hard, return; } - if (vm->get_state() == VirtualMachine::ACTIVE && - (vm->get_lcm_state() == VirtualMachine::RUNNING || - vm->get_lcm_state() == VirtualMachine::UNKNOWN)) + auto lcm_state = vm->get_lcm_state(); + + if (hard && (vm->get_state() == VirtualMachine::ACTIVE && + lcm_state == VirtualMachine::SHUTDOWN_UNDEPLOY)) + { + // Cancel previous undeploy action + vmm->trigger_driver_cancel(vid); + + lcm_state = VirtualMachine::RUNNING; // Force execute of hard shutdown + } + + if (vm->get_state() == VirtualMachine::ACTIVE && + (lcm_state == VirtualMachine::RUNNING || + lcm_state == VirtualMachine::UNKNOWN)) { //---------------------------------------------------- // SHUTDOWN_UNDEPLOY STATE @@ -647,9 +669,20 @@ void LifeCycleManager::trigger_poweroff(int vid, bool hard, return; } - if (vm->get_state() == VirtualMachine::ACTIVE && - (vm->get_lcm_state() == VirtualMachine::RUNNING || - vm->get_lcm_state() == VirtualMachine::UNKNOWN)) + auto lcm_state = vm->get_lcm_state(); + + if (hard && (vm->get_state() == VirtualMachine::ACTIVE && + lcm_state == VirtualMachine::SHUTDOWN_POWEROFF)) + { + // Cancel previous shutdown action + vmm->trigger_driver_cancel(vid); + + lcm_state = VirtualMachine::RUNNING; // Force execute of hard shutdown + } + + if (vm->get_state() == VirtualMachine::ACTIVE && + (lcm_state == VirtualMachine::RUNNING || + lcm_state == VirtualMachine::UNKNOWN)) { //---------------------------------------------------- // SHUTDOWN_POWEROFF STATE