From 934f4b02712082d9f8274439a621f9802631a94e Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 10 Jan 2013 12:29:46 +0100 Subject: [PATCH 01/11] feature #1685: continue on error if step has defined :no_fail (cherry picked from commit 6294f0b1b23953d7ed999b8ddb70bde4788f4379) --- src/vmm_mad/exec/one_vmm_exec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 8c6f8ccacb..74497c5188 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -185,7 +185,12 @@ class VmmAction @vmm.log(@id, "Failed to execute #{DRIVER_NAMES[step[:driver]]} " \ "operation: #{step[:action]}.") - break + + if step[:no_fail] + result = DriverExecHelper::RESULT[:success] + else + break + end else @vmm.log(@id, "Successfully execute #{DRIVER_NAMES[step[:driver]]} " \ From c46c0686f44bee7ee4f62314226a305515205b93 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 19 Jan 2013 23:49:43 +0100 Subject: [PATCH 02/11] feature #1685: Adds a new cleanup operation to VMM driver. It cancels the VM and removes all associated files, the operations are synchronized --- src/mad/ruby/VirtualMachineDriver.rb | 7 ++++ src/vmm_mad/dummy/one_vmm_dummy.rb | 10 ++++-- src/vmm_mad/exec/one_vmm_exec.rb | 50 +++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index 335b63a03a..4d2936817a 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -42,6 +42,7 @@ class VirtualMachineDriver < OpenNebulaDriver :log => "LOG", :attach_disk => "ATTACHDISK", :detach_disk => "DETACHDISK", + :cleanup => "CLEANUP" } POLL_ATTRIBUTE = { @@ -89,6 +90,7 @@ class VirtualMachineDriver < OpenNebulaDriver register_action(ACTION[:poll].to_sym, method("poll")) register_action(ACTION[:attach_disk].to_sym, method("attach_disk")) register_action(ACTION[:detach_disk].to_sym, method("detach_disk")) + register_action(ACTION[:cleanup].to_sym, method("cleanup")) end # Decodes the encoded XML driver message received from the core @@ -168,6 +170,11 @@ class VirtualMachineDriver < OpenNebulaDriver send_message(ACTION[:detach_disk],RESULT[:failure],id,error) end + def cleanup(id, drv_message) + error = "Action not implemented by driver #{self.class}" + send_message(ACTION[:cleanup],RESULT[:failure],id,error) + end + private # Interface to handle the pending events from the ActionManager Interface def delete_running_action(action_id) diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index 6ada53fcfc..31f660f35d 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -128,6 +128,12 @@ class DummyDriver < VirtualMachineDriver send_message(ACTION[:detach_disk],result,id) end + def cleanup(id, drv_message) + result = retrieve_result("cleanup") + + send_message(ACTION[:cleanup],result,id) + end + def poll(id, drv_message) result = retrieve_result("poll") @@ -159,7 +165,7 @@ class DummyDriver < VirtualMachineDriver "#{POLL_ATTRIBUTE[:nettx]}=#{prev_nettx+(50*rand(3))} " \ "#{POLL_ATTRIBUTE[:netrx]}=#{prev_netrx+(100*rand(4))} " \ "#{POLL_ATTRIBUTE[:usedmemory]}=#{max_memory * (rand(80)+20)/100} " \ - "#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}" + "#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}" send_message(ACTION[:poll],result,id,monitor_info) end @@ -194,4 +200,4 @@ class DummyDriver < VirtualMachineDriver end dd = DummyDriver.new -dd.start_driver \ No newline at end of file +dd.start_driver diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 74497c5188..33499c1ea4 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -542,7 +542,7 @@ class ExecDriver < VirtualMachineDriver # Bug #1355, argument character limitation in ESX # Message not used in vmware anyway if @hypervisor == "vmware" - drv_message = "drv_message" + drv_message = "drv_message" end steps = [ @@ -608,6 +608,54 @@ class ExecDriver < VirtualMachineDriver action.run(steps) end + # + # CLEANUP action, frees resources allocated in a host: VM and disk images + # + def cleanup(id, drv_message) + aname = ACTION[:cleanup] + xml_data = decode(drv_message) + + tm_command = xml_data.elements['TM_COMMAND'].text.strip + mhost = xml_data.elements['MIGR_HOST'].text.strip + + action = VmmAction.new(self, id, :cleanup, drv_message) + + # Cancel the VM at host + steps = [ + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_id, :host], + :no_fail => true + } + ] + + # Cancel the VM at the previous host (in case of migration) + steps << + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_id, :dest_host], + :destination => true, + :no_fail => true + } if !mhost.empty? + + # Cleans VM disk images and directory + tm_command.each_line { |tc| + tc.strip! + + steps << + { + :driver => :tm, + :action => :tm_command, + :parameters => tm_command.split + :no_fail => true + } if !tc.empty? + } + + action.run(steps) + end + private def ensure_xpath(xml_data, id, action, xpath) From 41789046a64440ebfcd4939ee0d6270b6f137738 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 20 Jan 2013 23:05:14 +0100 Subject: [PATCH 03/11] feature #1685: Epilog delete commands are generated in a separated function --- include/TransferManager.h | 7 + src/tm/TransferManager.cc | 298 ++++++++++++++++++-------------------- 2 files changed, 149 insertions(+), 156 deletions(-) diff --git a/include/TransferManager.h b/include/TransferManager.h index 1b2b1265a6..087cef8b33 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -267,6 +267,13 @@ private: */ void epilog_delete_action(bool local, int vid); + /** + * This function starts the epilog_delete sequence + */ + int epilog_delete_commands(VirtualMachine *vm, + ostream& xfr, + bool local, + bool previous); /** * This function starts the epilog_delete sequence on the previous host */ diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 712ded9e8c..ae6d82f517 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -1195,61 +1195,74 @@ error_common: return; } + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void TransferManager::epilog_delete_action(bool local, int vid) +int TransferManager::epilog_delete_commands(VirtualMachine *vm, + ostream& xfr, + bool local, + bool previous) { - ofstream xfr; ostringstream os; - string xfr_name; string vm_tm_mad; string tm_mad; string vm_ds_id; string ds_id; + string host; + string system_dir; + int disk_id; - VirtualMachine * vm; - Nebula& nd = Nebula::instance(); - - const TransferManagerDriver * tm_md; + Nebula& nd = Nebula::instance(); const VectorAttribute * disk; vector attrs; int num; // ------------------------------------------------------------------------ - // Setup & Transfer script + // Setup transfer // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); - - if (vm == 0) - { - return; - } - if (!vm->hasHistory()) { goto error_history; } - vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); - tm_md = get(); - - if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty()) + if (local) { - goto error_drivers; + host = nd.get_nebula_hostname(); + system_dir = vm->get_system_dir(); + + vm_tm_mad = vm->get_tm_mad(); + vm_ds_id = vm->get_ds_id(); + } + else if (previous) + { + if (!vm->hasPreviousHistory()) + { + goto error_history; + } + + host = vm->get_previous_hostname(); + system_dir = vm->get_remote_system_dir(); + + vm_tm_mad = vm->get_previous_tm_mad(); + vm_ds_id = vm->get_previous_ds_id(); + } + else + { + host = vm->get_hostname(); + system_dir = vm->get_remote_system_dir(); + + vm_tm_mad = vm->get_tm_mad(); + vm_ds_id = vm->get_ds_id(); } - xfr_name = vm->get_transfer_file() + ".delete"; - xfr.open(xfr_name.c_str(), ios::out | ios::trunc); - - if (xfr.fail() == true) + if ( vm_tm_mad.empty() || vm_ds_id.empty()) { - goto error_file; + goto error_drivers; } // ------------------------------------------------------------------------- @@ -1284,103 +1297,57 @@ void TransferManager::epilog_delete_action(bool local, int vid) } } - if ( local ) - { - //DELETE tm_mad fe:system_dir/disk.i vmid dsid - xfr << "DELETE " - << tm_mad << " " - << nd.get_nebula_hostname() << ":" - << vm->get_system_dir() << "/disk." << disk_id << " " - << vm->get_oid() << " " - << ds_id << endl; - } - else - { - //DELETE tm_mad host:remote_system_dir/disk.i vmid dsid - xfr << "DELETE " - << tm_mad << " " - << vm->get_hostname() << ":" - << vm->get_remote_system_dir() << "/disk." << disk_id << " " - << vm->get_oid() << " " - << ds_id << endl; - } - } - - if ( local ) - { - //DELETE vm_tm_mad fe:system_dir vmid dsid(=0) + //DELETE tm_mad host:remote_system_dir/disk.i vmid dsid + // *local* DELETE tm_mad fe:system_dir/disk.i vmid dsid + // *prev* DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id xfr << "DELETE " - << vm_tm_mad << " " - << nd.get_nebula_hostname() <<":"<< vm->get_system_dir() << " " + << tm_mad << " " + << host << ":" + << system_dir << "/disk." << disk_id << " " << vm->get_oid() << " " - << vm_ds_id; - } - else - { - //DELETE vm_tm_mad hostname:remote_system_dir vmid dsid(=0) - xfr << "DELETE " - << vm_tm_mad << " " - << vm->get_hostname() <<":"<< vm->get_remote_system_dir() << " " - << vm->get_oid() << " " - << vm_ds_id; + << ds_id << endl; } - xfr.close(); + //DELETE vm_tm_mad hostname:remote_system_dir vmid dsid + // *local* DELETE vm_tm_mad fe:system_dir vmid dsid + // *prev* DELTE vm_tm_mad prev_host:remote_system_dir vmid ds_id + xfr << "DELETE " + << vm_tm_mad << " " + << host <<":"<< system_dir << " " + << vm->get_oid() << " " + << vm_ds_id; - tm_md->transfer(vid,xfr_name); - - vm->unlock(); - return; + return 0; error_history: - os.str(""); - os << "epilog_delete, VM " << vid << " has no history"; + os << "epilog_delete, VM " << vm->get_oid() << " missing history record"; goto error_common; error_drivers: - os.str(""); os << "epilog_delete, error getting drivers."; goto error_common; -error_file: - os.str(""); - os << "epilog_delete, could not open file: " << xfr_name; - os << ". You may need to manually clean " << vm->get_hostname() - << ":" << vm->get_remote_system_dir(); - goto error_common; - error_common: vm->log("TM", Log::ERROR, os); - (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid); - - vm->unlock(); - return; + return -1; } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void TransferManager::epilog_delete_previous_action(int vid) +void TransferManager::epilog_delete_action(bool local, int vid) { - ofstream xfr; ostringstream os; - string xfr_name; - string vm_tm_mad; - string tm_mad; - string vm_ds_id; - string ds_id; - - int disk_id; + ofstream xfr; + string xfr_name; VirtualMachine * vm; Nebula& nd = Nebula::instance(); const TransferManagerDriver * tm_md; - const VectorAttribute * disk; - vector attrs; - int num; + int rc; // ------------------------------------------------------------------------ // Setup & Transfer script @@ -1392,18 +1359,85 @@ void TransferManager::epilog_delete_previous_action(int vid) return; } - if (!vm->hasHistory() || !vm->hasPreviousHistory()) + tm_md = get(); + + if ( tm_md == 0 ) { - goto error_history; + goto error_driver; } - vm_tm_mad = vm->get_previous_tm_mad(); - vm_ds_id = vm->get_previous_ds_id(); - tm_md = get(); + xfr_name = vm->get_transfer_file() + ".delete"; + xfr.open(xfr_name.c_str(), ios::out | ios::trunc); - if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty() ) + if (xfr.fail() == true) { - goto error_drivers; + goto error_file; + } + + rc = epilog_delete_commands(vm, xfr, local, false); + + if ( rc != 0 ) + { + goto error_common; + } + + xfr.close(); + + tm_md->transfer(vid,xfr_name); + + vm->unlock(); + return; + +error_driver: + os << "epilog_delete, error getting TM driver."; + goto error_common; + +error_file: + os << "epilog_delete, could not open file: " << xfr_name; + os << ". You may need to manually clean " << vm->get_hostname() + << ":" << vm->get_remote_system_dir(); + goto error_common; + +error_common: + vm->log("TM", Log::ERROR, os); + (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE, vid); + + vm->unlock(); + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void TransferManager::epilog_delete_previous_action(int vid) +{ + ostringstream os; + + ofstream xfr; + string xfr_name; + + VirtualMachine * vm; + Nebula& nd = Nebula::instance(); + + const TransferManagerDriver * tm_md; + + int rc; + + // ------------------------------------------------------------------------ + // Setup & Transfer script + // ------------------------------------------------------------------------ + vm = vmpool->get(vid,true); + + if (vm == 0) + { + return; + } + + tm_md = get(); + + if (tm_md == 0) + { + goto error_driver; } xfr_name = vm->get_transfer_file() + ".delete_prev"; @@ -1414,81 +1448,33 @@ void TransferManager::epilog_delete_previous_action(int vid) goto error_file; } - // ------------------------------------------------------------------------ - // Delete the remote VM Directory - // ------------------------------------------------------------------------ - num = vm->get_template_attribute("DISK",attrs); + rc = epilog_delete_commands(vm, xfr, false, true); - for (int i=0 ; i < num ; i++) + if ( rc != 0 ) { - disk = dynamic_cast(attrs[i]); - - if ( disk == 0 ) - { - continue; - } - - disk->vector_value_str("DISK_ID", disk_id); - - if ( isVolatile(disk) == true ) - { - tm_mad = vm_tm_mad; - ds_id = vm_ds_id; - } - else - { - tm_mad = disk->vector_value("TM_MAD"); - ds_id = disk->vector_value("DATASTORE_ID"); - - if ( tm_mad.empty() || ds_id.empty() ) - { - continue; - } - } - - //DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id - xfr << "DELETE " - << tm_mad << " " - << vm->get_previous_hostname() << ":" - << vm->get_remote_system_dir() << "/disk." << disk_id << " " - << vm->get_oid() << " " - << ds_id << endl; + goto error_common; } - //DELTE vm_tm_mad prev_host:remote_system_dir vmid ds_id(=0) - xfr << "DELETE " - << vm_tm_mad << " " - << vm->get_previous_hostname() <<":"<< vm->get_remote_system_dir() - << " " << vm->get_oid() << " " - << vm_ds_id << endl; - xfr.close(); - tm_md->transfer(vid,xfr_name); + tm_md->transfer(vid, xfr_name); vm->unlock(); return; -error_history: - os.str(""); - os << "epilog_delete_previous, VM " << vid << " has no history"; - goto error_common; - -error_drivers: - os.str(""); - os << "epilog_delete_previous, error getting drivers."; +error_driver: + os << "epilog_delete_previous, error getting TM driver."; goto error_common; error_file: - os.str(""); os << "epilog_delete_previous, could not open file: " << xfr_name; os << ". You may need to manually clean " << vm->get_previous_hostname() << ":" << vm->get_remote_system_dir(); goto error_common; error_common: - (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid); vm->log("TM", Log::ERROR, os); + (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE, vid); vm->unlock(); return; From 6c50f2b1477edd90a4c16a1e4fff828d48cc0118 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 21 Jan 2013 00:15:46 +0100 Subject: [PATCH 04/11] feature #1685: Clean network in CLEANUP. Adds cleanup_action to VMM. Make use of new action in LCM --- include/TransferManager.h | 41 ++++++--- include/VirtualMachineManager.h | 9 ++ include/VirtualMachineManagerDriver.h | 42 +++++---- src/lcm/LifeCycleActions.cc | 17 +--- src/tm/TransferManager.cc | 88 ++++++++++++++++++- src/vmm/VirtualMachineManager.cc | 118 +++++++++++++++++++++++++- src/vmm_mad/exec/one_vmm_exec.rb | 19 ++++- 7 files changed, 288 insertions(+), 46 deletions(-) diff --git a/include/TransferManager.h b/include/TransferManager.h index 087cef8b33..6a66e4b1cc 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -54,6 +54,7 @@ public: EPILOG_DELETE, EPILOG_DELETE_PREVIOUS, EPILOG_DELETE_STOP, + EPILOG_DELETE_BOTH, CHECKPOINT, DRIVER_CANCEL, FINALIZE @@ -138,6 +139,20 @@ public: VirtualMachine * vm, ostream& xfr); + /** + * This function generates the the epilog_delete sequence for current, + * front-end and previous hosts. + * @param vm pointer to VM, locked + * @param xfr stream to write the commands + * @param local true to delete the front-end + * @param previous true to delete the previous host + * + * @return 0 on success + */ + int epilog_delete_commands(VirtualMachine *vm, + ostream& xfr, + bool local, + bool previous); private: /** * Thread id for the Transfer Manager @@ -247,7 +262,8 @@ private: void epilog_stop_action(int vid); /** - * This function starts the epilog_delete sequence + * This function starts the epilog_delete sequence in the current host + * @param vid the Virtual Machine ID */ void epilog_delete_action(int vid) { @@ -256,6 +272,8 @@ private: /** * This function starts the epilog_delete_stop sequence on the local host + * i.e. the front-end (the VM is not running) + * @param vid the Virtual Machine ID */ void epilog_delete_stop_action(int vid) { @@ -263,21 +281,22 @@ private: } /** - * This function starts the epilog_delete sequence + * This function starts the epilog_delete sequence on the previous host + * @param vid the Virtual Machine ID */ - void epilog_delete_action(bool local, int vid); + void epilog_delete_previous_action(int vid); + + /** + * This function starts the epilog_delete sequence on the current and + * previous hosts + * @param vid the Virtual Machine ID + */ + void epilog_delete_both_action(int vid); /** * This function starts the epilog_delete sequence */ - int epilog_delete_commands(VirtualMachine *vm, - ostream& xfr, - bool local, - bool previous); - /** - * This function starts the epilog_delete sequence on the previous host - */ - void epilog_delete_previous_action(int vid); + void epilog_delete_action(bool local, int vid); /** * This function starts the epilog sequence diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 42d1525a46..fb34fcb0c5 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -49,6 +49,8 @@ public: SHUTDOWN, CANCEL, CANCEL_PREVIOUS, + CLEANUP, + CLEANUP_BOTH, MIGRATE, RESTORE, REBOOT, @@ -257,6 +259,13 @@ private: void cancel_previous_action( int vid); + /** + * Cleanups a host (cancel VM + delete disk images). + * @param vid the id of the VM. + */ + void cleanup_action( + int vid, bool cancel_previous); + /** * Function to migrate (live) a VM (MIGRATE action). * @param vid the id of the VM. diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index 6c7d55f826..11ef3ab386 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -30,7 +30,7 @@ using namespace std; * VirtualMachineManagerDriver provides a base class to implement VM Manager * Drivers. This class implements the protocol and recover functions * from the Mad interface. Classes derived from the VirtualMachineManagerDriver - * must implement the deployment function to generate specific VM + * must implement the deployment function to generate specific VM * deployment information for the unerlying MAD. */ class VirtualMachineManagerDriver : public Mad @@ -53,7 +53,7 @@ public: string& message); /** - * TODO: What do we need here? just poll the active VMs to recover + * TODO: What do we need here? just poll the active VMs to recover * connections? Or an specific recover action from the MAD? */ void recover(); @@ -67,25 +67,25 @@ public: virtual int deployment_description( const VirtualMachine * vm, const string& file_name) const = 0; - -protected: + +protected: /** - * Gets a configuration attr from driver configuration file (single + * Gets a configuration attr from driver configuration file (single * version) * @param name of config attribute * @param value of the attribute */ void get_default( - const char * name, + const char * name, string& value) const { string sn = name; - + driver_conf.get(sn,value); - } + } /** - * Gets a configuration attr from driver configuration file (vector + * Gets a configuration attr from driver configuration file (vector * version) * @param name of config vector attribute for the domain * @param vname of the attribute @@ -95,20 +95,20 @@ protected: const char * name, const char * vname, string& value) const; - -private: - /** + +private: + /** * Configuration file for the driver */ Template driver_conf; - + /** * Pointer to the Virtual Machine Pool, to access VMs */ VirtualMachinePool * vmpool; friend class VirtualMachineManager; - + /** * Sends a deploy request to the MAD: "DEPLOY ID XML_DRV_MSG" * @param oid the virtual machine id. @@ -169,6 +169,18 @@ private: write_drv("CANCEL", oid, drv_msg); } + /** + * Sends a cleanup request to the MAD: "CLEANUP ID XML_DRV_MSG" + * @param oid the virtual machine id. + * @param drv_msg xml data for the mad operation + */ + void cleanup ( + const int oid, + const string& drv_msg) const + { + write_drv("CLEANUP", oid, drv_msg); + } + /** * Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG" * @param oid the virtual machine id. @@ -263,7 +275,7 @@ private: ostringstream os; os << aname << " " << oid << " " << msg << endl; - + write(os); } }; diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 3833945405..f618bcfe94 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -683,9 +683,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) vmpool->update_history(vm); vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid); - vmm->trigger(VirtualMachineManager::CANCEL,vid); - - tm->trigger(TransferManager::EPILOG_DELETE,vid); + vmm->trigger(VirtualMachineManager::CLEANUP,vid); break; case VirtualMachine::MIGRATE: @@ -701,11 +699,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) hpool->del_capacity(vm->get_previous_hid(), vm->get_oid(), cpu, mem, disk); vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid); - - vmm->trigger(VirtualMachineManager::CANCEL,vid); - vmm->trigger(VirtualMachineManager::CANCEL_PREVIOUS,vid); - - tm->trigger(TransferManager::EPILOG_DELETE,vid); + vmm->trigger(VirtualMachineManager::CLEANUP_BOTH,vid); break; case VirtualMachine::SAVE_STOP: @@ -714,9 +708,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) vmpool->update_history(vm); vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid); - vmm->trigger(VirtualMachineManager::CANCEL,vid); - - tm->trigger(TransferManager::EPILOG_DELETE,vid); + vmm->trigger(VirtualMachineManager::CLEANUP,vid); break; case VirtualMachine::SAVE_MIGRATE: @@ -742,8 +734,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) vmpool->update_history(vm); tm->trigger(TransferManager::DRIVER_CANCEL,vid); - tm->trigger(TransferManager::EPILOG_DELETE,vid); - tm->trigger(TransferManager::EPILOG_DELETE_PREVIOUS,vid); + tm->trigger(TransferManager::EPILOG_DELETE_BOTH,vid); break; case VirtualMachine::EPILOG_STOP: diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index ae6d82f517..4839151a56 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -115,6 +115,10 @@ void TransferManager::trigger(Actions action, int _vid) aname = "EPILOG_DELETE_PREVIOUS"; break; + case EPILOG_DELETE_BOTH: + aname = "EPILOG_DELETE_BOTH"; + break; + case CHECKPOINT: aname = "CHECKPOINT"; break; @@ -183,6 +187,10 @@ void TransferManager::do_action(const string &action, void * arg) { epilog_delete_previous_action(vid); } + else if (action == "EPILOG_DELETE_BOTH") + { + epilog_delete_both_action(vid); + } else if (action == "CHECKPOINT") { checkpoint_action(vid); @@ -1394,8 +1402,7 @@ error_driver: error_file: os << "epilog_delete, could not open file: " << xfr_name; - os << ". You may need to manually clean " << vm->get_hostname() - << ":" << vm->get_remote_system_dir(); + os << ". You may need to manually clean the host (current)"; goto error_common; error_common: @@ -1468,8 +1475,81 @@ error_driver: error_file: os << "epilog_delete_previous, could not open file: " << xfr_name; - os << ". You may need to manually clean " << vm->get_previous_hostname() - << ":" << vm->get_remote_system_dir(); + os << ". You may need to manually clean the host (previous)"; + goto error_common; + +error_common: + vm->log("TM", Log::ERROR, os); + (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE, vid); + + vm->unlock(); + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void TransferManager::epilog_delete_both_action(int vid) +{ + ostringstream os; + + ofstream xfr; + string xfr_name; + + VirtualMachine * vm; + Nebula& nd = Nebula::instance(); + + const TransferManagerDriver * tm_md; + + int rc; + + // ------------------------------------------------------------------------ + // Setup & Transfer script + // ------------------------------------------------------------------------ + vm = vmpool->get(vid,true); + + if (vm == 0) + { + return; + } + + tm_md = get(); + + if (tm_md == 0) + { + goto error_driver; + } + + xfr_name = vm->get_transfer_file() + ".delete_both"; + xfr.open(xfr_name.c_str(),ios::out | ios::trunc); + + if (xfr.fail() == true) + { + goto error_file; + } + + rc = epilog_delete_commands(vm, xfr, false, false); //current + rc = epilog_delete_commands(vm, xfr, false, true); //previous + + if ( rc != 0 ) + { + goto error_common; + } + + xfr.close(); + + tm_md->transfer(vid, xfr_name); + + vm->unlock(); + return; + +error_driver: + os << "epilog_delete_both, error getting TM driver."; + goto error_common; + +error_file: + os << "epilog_delete_both, could not open file: " << xfr_name; + os << ". You may need to manually clean hosts (previous & current)"; goto error_common; error_common: diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index e656c91ad8..c543f1bb6b 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -146,6 +146,14 @@ void VirtualMachineManager::trigger(Actions action, int _vid) aname = "CANCEL_PREVIOUS"; break; + case CLEANUP: + aname = "CLEANUP"; + break; + + case CLEANUP_BOTH: + aname = "CLEANUP_BOTH"; + break; + case MIGRATE: aname = "MIGRATE"; break; @@ -234,6 +242,14 @@ void VirtualMachineManager::do_action(const string &action, void * arg) { cancel_previous_action(vid); } + else if (action == "CLEANUP") + { + cleanup_action(vid, false); + } + else if (action == "CLEANUP_BOTH") + { + cleanup_action(vid, true); + } else if (action == "MIGRATE") { migrate_action(vid); @@ -925,6 +941,106 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void VirtualMachineManager::cleanup_action( + int vid, bool cancel_previous) +{ + int rc; + + VirtualMachine * vm; + ostringstream os; + + string vm_tmpl; + string * drv_msg; + + string m_hostname = ""; + string m_net_drv = ""; + + const VirtualMachineManagerDriver * vmd; + + Nebula& nd = Nebula::instance(); + + // 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; + } + + if ( cancel_previous && vm->hasPreviousHistory() ) + { + m_hostname = vm->get_previous_hostname(); + m_net_drv = vm->get_previous_vnm_mad(); + } + + rc = nd.get_tm()->epilog_delete_commands(vm, os, false, false); + + if ( rc != 0 ) + { + goto error_common; + } + + // Invoke driver method + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + m_hostname, + m_net_drv, + vm->get_deploy_id(), + "", + "", + "", + os.str(), + "", + vm->to_xml(vm_tmpl)); + + vmd->cleanup(vid, *drv_msg); + + delete drv_msg; + + vm->unlock(); + + return; + +error_history: + os.str(""); + os << "cleanup_action, VM has no history"; + goto error_common; + +error_driver: + os.str(""); + os << "cleanup_action, error getting driver " << vm->get_vmm_mad(); + +error_common: + if ( vm->get_lcm_state() == VirtualMachine::CLEANUP) + { + Nebula &ne = Nebula::instance(); + LifeCycleManager * lcm = ne.get_lcm(); + + //TODO + //lcm->trigger(LifeCycleManager::CLEANUP_FAILURE, vid); + } + + vm->unlock(); + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachineManager::migrate_action( int vid) { @@ -1366,7 +1482,7 @@ void VirtualMachineManager::attach_action( vm_tm_mad = vm->get_tm_mad(); opennebula_hostname = nd.get_nebula_hostname(); - rc = Nebula::instance().get_tm()->prolog_transfer_command( + rc = nd.get_tm()->prolog_transfer_command( vm, disk, vm_tm_mad, diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 33499c1ea4..39cc5855ee 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -627,18 +627,33 @@ class ExecDriver < VirtualMachineDriver :action => :cancel, :parameters => [:deploy_id, :host], :no_fail => true + }, + { + :driver => :vnm, + :action => :clean, + :no_fail => true } ] # Cancel the VM at the previous host (in case of migration) - steps << + if !mhost.empty? + steps << { :driver => :vmm, :action => :cancel, :parameters => [:deploy_id, :dest_host], :destination => true, :no_fail => true - } if !mhost.empty? + } + + steps << + { + :driver => :vnm, + :action => :clean, + :destination => true, + :no_fail => true + } + end # Cleans VM disk images and directory tm_command.each_line { |tc| From e4544c42b8358104b44f729340f98dcae5616bc9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 21 Jan 2013 12:27:18 +0100 Subject: [PATCH 05/11] feature #1685: CLEANUP_PREVIOUS action to cleanup previous hosts for migrate operations. Integrate CLEANUP actions with LCM. New state CLEANUP_DELETE. --- include/LifeCycleManager.h | 6 +- include/VirtualMachine.h | 5 +- include/VirtualMachineManager.h | 10 +++ src/dm/DispatchManagerActions.cc | 2 +- src/dm/DispatchManagerStates.cc | 10 +-- src/lcm/LifeCycleActions.cc | 82 ++++++++++++++++------ src/lcm/LifeCycleManager.cc | 16 +++++ src/lcm/LifeCycleStates.cc | 40 ++++++++++- src/tm/TransferManagerDriver.cc | 4 +- src/vmm/VirtualMachineManager.cc | 97 ++++++++++++++++++++++++-- src/vmm/VirtualMachineManagerDriver.cc | 26 +++++-- 11 files changed, 252 insertions(+), 46 deletions(-) diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index 5c280618aa..c8499e33c3 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -62,6 +62,8 @@ public: ATTACH_FAILURE, /**< Sent by the VMM when an attach action fails */ DETACH_SUCCESS, /**< Sent by the VMM when a detach action succeeds */ DETACH_FAILURE, /**< Sent by the VMM when a detach action fails */ + CLEANUP_SUCCESS, /**< Sent by the VMM when a cleanup action succeeds */ + CLEANUP_FAILURE, /**< Sent by the VMM when a cleanup action fails */ DEPLOY, /**< Sent by the DM to deploy a VM on a host */ SUSPEND, /**< Sent by the DM to suspend an running VM */ RESTORE, /**< Sent by the DM to restore a suspended VM */ @@ -145,7 +147,7 @@ private: * the history registers * @param vm with the lock aquired */ - void clean_up_vm (VirtualMachine *vm); + void clean_up_vm (VirtualMachine *vm, bool dispose); void save_success_action(int vid); @@ -185,6 +187,8 @@ private: void detach_failure_action(int vid); + void cleanup_callback_action(int vid); + void deploy_action(int vid); void suspend_action(int vid); diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 01c8da097f..7cc16a5bef 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -81,14 +81,15 @@ public: SHUTDOWN = 12, CANCEL = 13, FAILURE = 14, - CLEANUP = 15, + CLEANUP_RESUBMIT = 15, UNKNOWN = 16, HOTPLUG = 17, SHUTDOWN_POWEROFF = 18, BOOT_UNKNOWN = 19, BOOT_POWEROFF = 20, BOOT_SUSPENDED = 21, - BOOT_STOPPED = 22 + BOOT_STOPPED = 22, + CLEANUP_DELETE = 23 }; // ------------------------------------------------------------------------- diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index fb34fcb0c5..4f6c6a58a6 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -51,6 +51,7 @@ public: CANCEL_PREVIOUS, CLEANUP, CLEANUP_BOTH, + CLEANUP_PREVIOUS, MIGRATE, RESTORE, REBOOT, @@ -262,10 +263,19 @@ private: /** * Cleanups a host (cancel VM + delete disk images). * @param vid the id of the VM. + * @param cancel_previous if true the VM will be canceled in the previous + * host (only relevant to delete VM's in MIGRATE state) */ void cleanup_action( int vid, bool cancel_previous); + /** + * Cleanups the previous host (cancel VM + delete disk images). + * @param vid the id of the VM. + */ + void cleanup_previous_action( + int vid); + /** * Function to migrate (live) a VM (MIGRATE action). * @param vid the id of the VM. diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index c5f642d280..87fe90f1e4 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -868,7 +868,7 @@ int DispatchManager::resubmit(int vid) case VirtualMachine::FAILED: //Cleanup VM host files vm->log("DiM", Log::INFO, "New VM state is CLEANUP."); - vm->set_state(VirtualMachine::CLEANUP); + vm->set_state(VirtualMachine::CLEANUP_RESUBMIT); vm->set_state(VirtualMachine::ACTIVE); vmpool->update(vm); diff --git a/src/dm/DispatchManagerStates.cc b/src/dm/DispatchManagerStates.cc index 98053f2565..2ce1c9903c 100644 --- a/src/dm/DispatchManagerStates.cc +++ b/src/dm/DispatchManagerStates.cc @@ -161,7 +161,7 @@ void DispatchManager::done_action(int vid) if ((dm_state == VirtualMachine::ACTIVE) && (lcm_state == VirtualMachine::EPILOG || lcm_state == VirtualMachine::CANCEL || - lcm_state == VirtualMachine::CLEANUP )) + lcm_state == VirtualMachine::CLEANUP_DELETE)) { vm->set_state(VirtualMachine::DONE); @@ -180,11 +180,11 @@ void DispatchManager::done_action(int vid) uid = vm->get_uid(); gid = vm->get_gid(); tmpl = vm->clone_template(); - + vm->unlock(); Quotas::vm_del(uid, gid, tmpl); - + delete tmpl; } else @@ -196,7 +196,7 @@ void DispatchManager::done_action(int vid) vm->unlock(); } - + return; } @@ -247,7 +247,7 @@ void DispatchManager::resubmit_action(int vid) return; } - if (vm->get_lcm_state() == VirtualMachine::CLEANUP) + if (vm->get_lcm_state() == VirtualMachine::CLEANUP_RESUBMIT) { vm->set_state(VirtualMachine::LCM_INIT); diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index f618bcfe94..970bd8fdb3 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -581,17 +581,32 @@ void LifeCycleManager::delete_action(int vid) return; } - if ( vm->get_state() == VirtualMachine::ACTIVE && - (vm->get_lcm_state() != VirtualMachine::LCM_INIT && - vm->get_lcm_state() != VirtualMachine::CLEANUP)) - { - clean_up_vm(vm); - dm->trigger(DispatchManager::DONE,vid); - } - else + if ( vm->get_state() != VirtualMachine::ACTIVE ) { - vm->log("LCM", Log::ERROR, "delete_action, VM in a wrong state."); + vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state."); + vm->unlock(); + + return; + } + + switch(vm->get_lcm_state()) + { + case VirtualMachine::LCM_INIT: + vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state."); + break; + + case VirtualMachine::CLEANUP_RESUBMIT: + vm->set_state(VirtualMachine::CLEANUP_DELETE); + vmpool->update(vm); + + dm->trigger(DispatchManager::DONE, vid); + break; + + default: + clean_up_vm(vm, true); + dm->trigger(DispatchManager::DONE, vid); + break; } vm->unlock(); @@ -606,6 +621,9 @@ void LifeCycleManager::clean_action(int vid) { VirtualMachine * vm; + Nebula& nd = Nebula::instance(); + DispatchManager * dm = nd.get_dm(); + vm = vmpool->get(vid,true); if ( vm == 0 ) @@ -613,16 +631,28 @@ void LifeCycleManager::clean_action(int vid) return; } - - if ( vm->get_state() == VirtualMachine::ACTIVE && - (vm->get_lcm_state() != VirtualMachine::LCM_INIT && - vm->get_lcm_state() != VirtualMachine::CLEANUP)) - { - clean_up_vm(vm); - } - else + if ( vm->get_state() != VirtualMachine::ACTIVE ) { vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state."); + vm->unlock(); + + return; + } + + switch(vm->get_lcm_state()) + { + case VirtualMachine::LCM_INIT: + case VirtualMachine::CLEANUP_DELETE: + vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state."); + break; + + case VirtualMachine::CLEANUP_RESUBMIT: + dm->trigger(DispatchManager::RESUBMIT, vid); + break; + + default: + clean_up_vm(vm, false); + break; } vm->unlock(); @@ -631,7 +661,7 @@ void LifeCycleManager::clean_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void LifeCycleManager::clean_up_vm(VirtualMachine * vm) +void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose) { int cpu, mem, disk; time_t the_time = time(0); @@ -646,7 +676,15 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) vm->log("LCM", Log::INFO, "New VM state is CLEANUP."); - vm->set_state(VirtualMachine::CLEANUP); + if (dispose) + { + vm->set_state(VirtualMachine::CLEANUP_DELETE); + } + else + { + vm->set_state(VirtualMachine::CLEANUP_RESUBMIT); + } + vm->set_resched(false); vmpool->update(vm); @@ -724,9 +762,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) hpool->del_capacity(vm->get_previous_hid(), vm->get_oid(), cpu, mem, disk); vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid); - vmm->trigger(VirtualMachineManager::CANCEL_PREVIOUS,vid); - - tm->trigger(TransferManager::EPILOG_DELETE_PREVIOUS,vid); + vmm->trigger(VirtualMachineManager::CLEANUP_PREVIOUS,vid); break; case VirtualMachine::PROLOG_MIGRATE: @@ -751,7 +787,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) tm->trigger(TransferManager::EPILOG_DELETE,vid); break; - default: //LCM_INIT,CLEANUP + default: //LCM_INIT,CLEANUP_RESUBMIT, CLEANUP_DELETE break; } } diff --git a/src/lcm/LifeCycleManager.cc b/src/lcm/LifeCycleManager.cc index d763b5dac8..a22e565bab 100644 --- a/src/lcm/LifeCycleManager.cc +++ b/src/lcm/LifeCycleManager.cc @@ -145,6 +145,14 @@ void LifeCycleManager::trigger(Actions action, int _vid) aname = "DETACH_FAILURE"; break; + case CLEANUP_SUCCESS: + aname = "CLEANUP_SUCCESS"; + break; + + case CLEANUP_FAILURE: + aname = "CLEANUP_FAILURE"; + break; + case DEPLOY: aname = "DEPLOY"; break; @@ -298,6 +306,14 @@ void LifeCycleManager::do_action(const string &action, void * arg) { detach_failure_action(vid); } + else if (action == "CLEANUP_SUCCESS") + { + cleanup_callback_action(vid); + } + else if (action == "CLEANUP_FAILURE") + { + cleanup_callback_action(vid); + } else if (action == "DEPLOY") { deploy_action(vid); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index f675572258..81735432ae 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -722,7 +722,7 @@ void LifeCycleManager::epilog_success_action(int vid) { action = DispatchManager::DONE; } - else if ( state == VirtualMachine::CLEANUP ) + else if ( state == VirtualMachine::CLEANUP_RESUBMIT ) { dm->trigger(DispatchManager::RESUBMIT, vid); @@ -762,6 +762,42 @@ void LifeCycleManager::epilog_success_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void LifeCycleManager::cleanup_callback_action(int vid) +{ + Nebula& nd = Nebula::instance(); + DispatchManager * dm = nd.get_dm(); + + VirtualMachine * vm; + + VirtualMachine::LcmState state; + + vm = vmpool->get(vid,true); + + if ( vm == 0 ) + { + return; + } + + state = vm->get_lcm_state(); + + if ( state == VirtualMachine::CLEANUP_RESUBMIT ) + { + dm->trigger(DispatchManager::RESUBMIT, vid); + + } + else + { + vm->log("LCM",Log::ERROR,"cleanup_callback_action, VM in a wrong state"); + } + + vm->unlock(); + + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void LifeCycleManager::epilog_failure_action(int vid) { VirtualMachine * vm; @@ -774,7 +810,7 @@ void LifeCycleManager::epilog_failure_action(int vid) return; } - if ( vm->get_lcm_state() == VirtualMachine::CLEANUP ) + if ( vm->get_lcm_state() == VirtualMachine::CLEANUP_RESUBMIT ) { Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); diff --git a/src/tm/TransferManagerDriver.cc b/src/tm/TransferManagerDriver.cc index dbabe4e9da..6d4faff184 100644 --- a/src/tm/TransferManagerDriver.cc +++ b/src/tm/TransferManagerDriver.cc @@ -127,7 +127,7 @@ void TransferManagerDriver::protocol( case VirtualMachine::EPILOG: case VirtualMachine::EPILOG_STOP: - case VirtualMachine::CLEANUP: + case VirtualMachine::CLEANUP_RESUBMIT: lcm_action = LifeCycleManager::EPILOG_SUCCESS; break; @@ -164,7 +164,7 @@ void TransferManagerDriver::protocol( case VirtualMachine::EPILOG: case VirtualMachine::EPILOG_STOP: - case VirtualMachine::CLEANUP: + case VirtualMachine::CLEANUP_RESUBMIT: lcm_action = LifeCycleManager::EPILOG_FAILURE; break; diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index c543f1bb6b..8d9fc2601a 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -154,6 +154,10 @@ void VirtualMachineManager::trigger(Actions action, int _vid) aname = "CLEANUP_BOTH"; break; + case CLEANUP_PREVIOUS: + aname = "CLEANUP_PREVIOUS"; + break; + case MIGRATE: aname = "MIGRATE"; break; @@ -250,6 +254,10 @@ void VirtualMachineManager::do_action(const string &action, void * arg) { cleanup_action(vid, true); } + else if (action == "CLEANUP_PREVIOUS") + { + cleanup_previous_action(vid); + } else if (action == "MIGRATE") { migrate_action(vid); @@ -1025,15 +1033,92 @@ error_driver: os << "cleanup_action, error getting driver " << vm->get_vmm_mad(); error_common: - if ( vm->get_lcm_state() == VirtualMachine::CLEANUP) - { - Nebula &ne = Nebula::instance(); - LifeCycleManager * lcm = ne.get_lcm(); + (nd.get_lcm())->trigger(LifeCycleManager::CLEANUP_FAILURE, vid); - //TODO - //lcm->trigger(LifeCycleManager::CLEANUP_FAILURE, vid); + vm->unlock(); + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void VirtualMachineManager::cleanup_previous_action( + int vid) +{ + int rc; + + VirtualMachine * vm; + ostringstream os; + + string vm_tmpl; + string * drv_msg; + + const VirtualMachineManagerDriver * vmd; + + Nebula& nd = Nebula::instance(); + + // Get the VM from the pool + vm = vmpool->get(vid,true); + + if (vm == 0) + { + return; } + if (!vm->hasHistory() || !vm->hasPreviousHistory()) + { + goto error_history; + } + + // Get the driver for this VM + vmd = get(vm->get_vmm_mad()); + + if ( vmd == 0 ) + { + goto error_driver; + } + + rc = nd.get_tm()->epilog_delete_commands(vm, os, false, true); + + if ( rc != 0 ) + { + goto error_common; + } + + // Invoke driver method + drv_msg = format_message( + vm->get_previous_hostname(), + vm->get_previous_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + "", + os.str(), + "", + vm->to_xml(vm_tmpl)); + + vmd->cleanup(vid, *drv_msg); + + delete drv_msg; + + vm->unlock(); + + return; + +error_history: + os.str(""); + os << "cleanup_previous_action, VM has no history"; + goto error_common; + +error_driver: + os.str(""); + os << "cleanup_previous_action, error getting driver " << vm->get_vmm_mad(); + +error_common: + (nd.get_lcm())->trigger(LifeCycleManager::CLEANUP_FAILURE, vid); + vm->unlock(); return; } diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 89cfd80b2d..e189f6506b 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -106,8 +106,8 @@ void VirtualMachineManagerDriver::get_default( /* Helpers for the protocol function */ /* -------------------------------------------------------------------------- */ -static void log_error(VirtualMachine* vm, - ostringstream& os, +static void log_error(VirtualMachine* vm, + ostringstream& os, istringstream& is, const char * msg) { @@ -186,8 +186,7 @@ void VirtualMachineManagerDriver::protocol( return; } - if ( vm->get_lcm_state() == VirtualMachine::CLEANUP || - vm->get_lcm_state() == VirtualMachine::FAILURE || + if ( vm->get_lcm_state() == VirtualMachine::FAILURE || vm->get_lcm_state() == VirtualMachine::LCM_INIT ) { os.str(""); @@ -373,6 +372,25 @@ void VirtualMachineManagerDriver::protocol( lcm->trigger(LifeCycleManager::DETACH_FAILURE, id); } } + else if ( action == "CLEANUP" ) + { + Nebula &ne = Nebula::instance(); + LifeCycleManager *lcm = ne.get_lcm(); + + if ( result == "SUCCESS" ) + { + vm->log("VMM", Log::ERROR, "Host Successfully cleaned."); + + lcm->trigger(LifeCycleManager::CLEANUP_SUCCESS, id); + } + else + { + log_error(vm, os, is, "Error cleaning Host"); + vmpool->update(vm); + + lcm->trigger(LifeCycleManager::CLEANUP_FAILURE, id); + } + } else if ( action == "POLL" ) { if (result == "SUCCESS") From 35f44b070898ee55b2d3aa2ec69d8bb829da0406 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 21 Jan 2013 14:05:54 +0100 Subject: [PATCH 06/11] feature #1685: Add sleeps to dummy actions. Add NOP response to action list for dummy driver --- src/vmm_mad/dummy/one_vmm_dummy.rb | 42 +++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index 31f660f35d..d92d3d11e2 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -172,6 +172,26 @@ class DummyDriver < VirtualMachineDriver private + # Retrives the result for a given action from the OpenNebula core. Each + # action has a defined set of responses in: + # /tmp/opennebula_dummy_actions/ + # + # Each line of this file represents a response in the form: + # <"sucess|0" | "failure|1" | "-"> [sleep] + # + # - success or 1 returns SUCCESS + # - failure o 0 returns FAILURE + # - "-" returns nothing + # - sleep optional number of seconds to wait before answering + # + # Example: /tmp/opennebula_dummy_actions/deploy + # 0 + # 0 + # 1 120 + # 1 + # - + # 0 + # def retrieve_result(action) begin actions = File.read(DUMMY_ACTIONS_DIR+"/#{action}") @@ -184,18 +204,26 @@ class DummyDriver < VirtualMachineDriver action_id %= actions_array.size if actions_array && actions_array[action_id] - result = actions_array[action_id] - if result == "success" || result == 0 || result == "0" - return RESULT[:success] - else - return RESULT[:failure] - end @actions_counter[action] += 1 + + result = actions_array[action_id].split + + case result[0] + when "success", 1, "1" + sleep result[1].to_io if result[1] + return RESULT[:success] + when "failure", 0, "0" + sleep result[1].to_io if result[1] + return RESULT[:failure] + when "-" + return nil + else + return RESULT[:success] + end else return RESULT[:success] end - end end From 04dec2c332b69fa0863b73df68439a9de6edfee2 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 21 Jan 2013 18:01:27 +0100 Subject: [PATCH 07/11] feature #1685: Fix bug in dummy driver --- src/vmm_mad/dummy/one_vmm_dummy.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index d92d3d11e2..731186150d 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -211,10 +211,10 @@ class DummyDriver < VirtualMachineDriver case result[0] when "success", 1, "1" - sleep result[1].to_io if result[1] + sleep result[1].to_i if result[1] return RESULT[:success] when "failure", 0, "0" - sleep result[1].to_io if result[1] + sleep result[1].to_i if result[1] return RESULT[:failure] when "-" return nil From f39f7e6975a52790fba9314b922557d22c42813f Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Jan 2013 13:11:45 +0100 Subject: [PATCH 08/11] feature #1685: Fix minor bugs in VMM driver and TM --- src/tm/TransferManager.cc | 2 +- src/vmm_mad/exec/one_vmm_exec.rb | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 4839151a56..d23c7fe2ee 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -1323,7 +1323,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, << vm_tm_mad << " " << host <<":"<< system_dir << " " << vm->get_oid() << " " - << vm_ds_id; + << vm_ds_id << endl; return 0; diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 39cc5855ee..fae1a08c4f 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -615,28 +615,32 @@ class ExecDriver < VirtualMachineDriver aname = ACTION[:cleanup] xml_data = decode(drv_message) - tm_command = xml_data.elements['TM_COMMAND'].text.strip - mhost = xml_data.elements['MIGR_HOST'].text.strip + tm_command = xml_data.elements['TM_COMMAND'].text + mhost = xml_data.elements['MIGR_HOST'].text + deploy_id = xml_data.elements['DEPLOY_ID'].text action = VmmAction.new(self, id, :cleanup, drv_message) + steps = Array.new - # Cancel the VM at host - steps = [ + # Cancel the VM at host (only if we have a valid deploy-id) + if deploy_id && !deploy_id.empty? + steps << { :driver => :vmm, :action => :cancel, :parameters => [:deploy_id, :host], :no_fail => true - }, + } + steps << { :driver => :vnm, :action => :clean, :no_fail => true } - ] + end # Cancel the VM at the previous host (in case of migration) - if !mhost.empty? + if mhost && !mhost.empty? steps << { :driver => :vmm, @@ -645,7 +649,6 @@ class ExecDriver < VirtualMachineDriver :destination => true, :no_fail => true } - steps << { :driver => :vnm, @@ -662,11 +665,11 @@ class ExecDriver < VirtualMachineDriver steps << { :driver => :tm, - :action => :tm_command, - :parameters => tm_command.split + :action => :tm_delete, + :parameters => tc.split, :no_fail => true } if !tc.empty? - } + } if tm_command action.run(steps) end From 68b73989fb181409fb71d02b323ac09953493f64 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Jan 2013 13:34:58 +0100 Subject: [PATCH 09/11] feature 1685: Fix wrong delete/resubmit when a VM was in FAILURE --- src/lcm/LifeCycleActions.cc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 970bd8fdb3..9208d03841 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -573,6 +573,7 @@ void LifeCycleManager::delete_action(int vid) Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); + TransferManager * tm = nd.get_tm(); vm = vmpool->get(vid,true); @@ -603,6 +604,14 @@ void LifeCycleManager::delete_action(int vid) dm->trigger(DispatchManager::DONE, vid); break; + case VirtualMachine::FAILURE: + vm->set_state(VirtualMachine::CLEANUP_DELETE); + vmpool->update(vm); + + tm->trigger(TransferManager::EPILOG_DELETE,vid); + dm->trigger(DispatchManager::DONE, vid); + break; + default: clean_up_vm(vm, true); dm->trigger(DispatchManager::DONE, vid); @@ -623,6 +632,7 @@ void LifeCycleManager::clean_action(int vid) Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); + TransferManager * tm = nd.get_tm(); vm = vmpool->get(vid,true); @@ -650,6 +660,13 @@ void LifeCycleManager::clean_action(int vid) dm->trigger(DispatchManager::RESUBMIT, vid); break; + case VirtualMachine::FAILURE: + vm->set_state(VirtualMachine::CLEANUP_RESUBMIT); + vmpool->update(vm); + + tm->trigger(TransferManager::EPILOG_DELETE,vid); + break; + default: clean_up_vm(vm, false); break; @@ -782,12 +799,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose) tm->trigger(TransferManager::EPILOG_DELETE,vid); break; - case VirtualMachine::FAILURE: - vmpool->update_history(vm); - tm->trigger(TransferManager::EPILOG_DELETE,vid); - break; - - default: //LCM_INIT,CLEANUP_RESUBMIT, CLEANUP_DELETE + default: //LCM_INIT,CLEANUP_RESUBMIT, CLEANUP_DELETE, FAILURE break; } } From 5fb5d9cebef5121078c543bd3031d39ec80857b6 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Jan 2013 13:50:09 +0100 Subject: [PATCH 10/11] feature #1685: Better management of delete/resubmit on CLEANUP_DELETE state. Add new state to OCA bindings --- src/lcm/LifeCycleActions.cc | 1 + .../opennebula/client/vm/VirtualMachine.java | 8 ++-- src/oca/ruby/opennebula/virtual_machine.rb | 47 ++++++++++--------- src/ozones/Server/public/js/ozones.js | 5 +- src/sunstone/public/js/opennebula.js | 5 +- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 9208d03841..d3c189aa40 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -598,6 +598,7 @@ void LifeCycleManager::delete_action(int vid) break; case VirtualMachine::CLEANUP_RESUBMIT: + case VirtualMachine::CLEANUP_DELETE: vm->set_state(VirtualMachine::CLEANUP_DELETE); vmpool->update(vm); diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 6b1509c165..a6e5853bb9 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -83,14 +83,15 @@ public class VirtualMachine extends PoolElement{ "SHUTDOWN", "CANCEL", "FAILURE", - "CLEANUP", + "CLEANUP_RESUBMIT", "UNKNOWN", "HOTPLUG", "SHUTDOWN_POWEROFF", "BOOT_UNKNOWN", "BOOT_POWEROFF", "BOOT_SUSPENDED", - "BOOT_STOPPED" }; + "BOOT_STOPPED", + "CLEANUP_DELETE" }; private static final String[] SHORT_LCM_STATES = { @@ -116,7 +117,8 @@ public class VirtualMachine extends PoolElement{ "boot", "boot", "boot", - "boot" }; + "boot", + "clea" }; /** * Creates a new VM representation. diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 4bc05ae717..37937ddada 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -45,8 +45,8 @@ module OpenNebula LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG - SHUTDOWN CANCEL FAILURE CLEANUP UNKNOWN HOTPLUG SHUTDOWN_POWEROFF - BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED} + SHUTDOWN CANCEL FAILURE CLEANUP_RESUBMIT UNKNOWN HOTPLUG SHUTDOWN_POWEROFF + BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED CLEANUP_DELETE} SHORT_VM_STATES={ "INIT" => "init", @@ -61,28 +61,29 @@ module OpenNebula } SHORT_LCM_STATES={ - "PROLOG" => "prol", - "BOOT" => "boot", - "RUNNING" => "runn", - "MIGRATE" => "migr", - "SAVE_STOP" => "save", - "SAVE_SUSPEND" => "save", - "SAVE_MIGRATE" => "save", - "PROLOG_MIGRATE"=> "migr", - "PROLOG_RESUME" => "prol", - "EPILOG_STOP" => "epil", - "EPILOG" => "epil", - "SHUTDOWN" => "shut", - "CANCEL" => "shut", - "FAILURE" => "fail", - "CLEANUP" => "clea", - "UNKNOWN" => "unkn", - "HOTPLUG" => "hotp", + "PROLOG" => "prol", + "BOOT" => "boot", + "RUNNING" => "runn", + "MIGRATE" => "migr", + "SAVE_STOP" => "save", + "SAVE_SUSPEND" => "save", + "SAVE_MIGRATE" => "save", + "PROLOG_MIGRATE" => "migr", + "PROLOG_RESUME" => "prol", + "EPILOG_STOP" => "epil", + "EPILOG" => "epil", + "SHUTDOWN" => "shut", + "CANCEL" => "shut", + "FAILURE" => "fail", + "CLEANUP_RESUBMIT" => "clea", + "UNKNOWN" => "unkn", + "HOTPLUG" => "hotp", "SHUTDOWN_POWEROFF" => "shut", - "BOOT_UNKNOWN" => "boot", - "BOOT_POWEROFF" => "boot", - "BOOT_SUSPENDED" => "boot", - "BOOT_STOPPED" => "boot" + "BOOT_UNKNOWN" => "boot", + "BOOT_POWEROFF" => "boot", + "BOOT_SUSPENDED" => "boot", + "BOOT_STOPPED" => "boot", + "CLEANUP_DELETE" => "clea" } MIGRATE_REASON=%w{NONE ERROR STOP_RESUME USER CANCEL} diff --git a/src/ozones/Server/public/js/ozones.js b/src/ozones/Server/public/js/ozones.js index 3a1d54501a..d564cb91b5 100644 --- a/src/ozones/Server/public/js/ozones.js +++ b/src/ozones/Server/public/js/ozones.js @@ -94,14 +94,15 @@ var oZones = { "SHUTDOWN", "CANCEL", "FAILURE", - "CLEANUP", + "CLEANUP_RESUBMIT", "UNKNOWN", "HOTPLUG", "SHUTDOWN_POWEROFF", "BOOT_UNKNOWN", "BOOT_POWEROFF", "BOOT_SUSPENDED", - "BOOT_STOPPED"][value]); + "BOOT_STOPPED", + "CLEANUP_DELETE"][value]); break; case "IMAGE": case "image": diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 5c1f5d53c4..49a1de90ab 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -102,14 +102,15 @@ var OpenNebula = { "SHUTDOWN", "CANCEL", "FAILURE", - "CLEANUP", + "CLEANUP_RESUBMIT", "UNKNOWN", "HOTPLUG", "SHUTDOWN_POWEROFF", "BOOT_UNKNOWN", "BOOT_POWEROFF", "BOOT_SUSPENDED", - "BOOT_STOPPED"][value]); + "BOOT_STOPPED", + "CLEANUP_DELETE"][value]); break; case "IMAGE": case "image": From ca955eb73c00f183b747cc93d43cac7734bcdb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 23 Jan 2013 15:29:02 +0100 Subject: [PATCH 11/11] Feature #1685: Add new vm states to xsd files --- share/doc/xsd/acct.xsd | 47 +++++++++++++++++++++--------------------- share/doc/xsd/vm.xsd | 47 +++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/share/doc/xsd/acct.xsd b/share/doc/xsd/acct.xsd index 824bbc25a0..d9b435b817 100644 --- a/share/doc/xsd/acct.xsd +++ b/share/doc/xsd/acct.xsd @@ -83,29 +83,30 @@ diff --git a/share/doc/xsd/vm.xsd b/share/doc/xsd/vm.xsd index a6f1b96bbe..38bbf943c7 100644 --- a/share/doc/xsd/vm.xsd +++ b/share/doc/xsd/vm.xsd @@ -45,29 +45,30 @@