From 5413d42eb6aa90670d8fec4945eba61015c42878 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 25 Oct 2013 17:09:00 +0200 Subject: [PATCH 1/2] feature #2392: Add CID to VM history Modify CLI accordingly --- include/History.h | 4 +++- include/RequestManagerVirtualMachine.h | 1 + include/VirtualMachine.h | 1 + src/cli/one_helper/onevm_helper.rb | 3 +++ src/rm/RequestManagerVirtualMachine.cc | 5 ++++- src/vm/History.cc | 9 +++++++-- src/vm/VirtualMachine.cc | 4 ++++ 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/History.h b/include/History.h index 52e9369e38..40f4860587 100644 --- a/include/History.h +++ b/include/History.h @@ -232,6 +232,7 @@ public: int seq, int hid, const string& hostname, + int cid, const string& vmm, const string& vnm, const string& tmm, @@ -275,8 +276,9 @@ private: int oid; int seq; - string hostname; int hid; + string hostname; + int cid; string vmm_mad_name; string vnm_mad_name; diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index cf845f2468..694244351d 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -96,6 +96,7 @@ protected: int add_history(VirtualMachine * vm, int hid, + int cid, const string& hostname, const string& vmm_mad, const string& vnm_mad, diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 0b9f50e714..f89ac1b891 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -408,6 +408,7 @@ public: */ void add_history( int hid, + int cid, const string& hostname, const string& vmm_mad, const string& vnm_mad, diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 8e78da76f5..4b9cce9352 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -248,6 +248,9 @@ class OneVMHelper < OpenNebulaHelper::OneHelper puts str % ["HOST", vm['/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']] if %w{ACTIVE SUSPENDED POWEROFF}.include? vm.state_str + puts str % ["CLUSTER ID", + vm['/VM/HISTORY_RECORDS/HISTORY[last()]/CID'] ] if + %w{ACTIVE SUSPENDED POWEROFF}.include? vm.state_str puts str % ["START TIME", OpenNebulaHelper.time_to_str(vm['/VM/STIME'])] puts str % ["END TIME", diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index f53bf7171b..6711c388ed 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -440,6 +440,7 @@ VirtualMachine * RequestManagerVirtualMachine::get_vm(int id, int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, int hid, + int cid, const string& hostname, const string& vmm_mad, const string& vnm_mad, @@ -453,7 +454,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, VirtualMachinePool * vmpool = static_cast(pool); - vm->add_history(hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id); + vm->add_history(hid, cid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id); rc = vmpool->update_history(vm); @@ -766,6 +767,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, if (add_history(vm, hid, + cluster_id, hostname, vmm_mad, vnm_mad, @@ -961,6 +963,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList if (add_history(vm, hid, + cluster_id, hostname, vmm_mad, vnm_mad, diff --git a/src/vm/History.cc b/src/vm/History.cc index 0a53ffd56f..6121a735e0 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -40,8 +40,9 @@ History::History( ObjectXML(), oid(_oid), seq(_seq), - hostname(""), hid(-1), + hostname(""), + cid(-1), vmm_mad_name(""), vnm_mad_name(""), tm_mad_name(""), @@ -66,6 +67,7 @@ History::History( int _seq, int _hid, const string& _hostname, + int _cid, const string& _vmm, const string& _vnm, const string& _tmm, @@ -74,8 +76,9 @@ History::History( const string& _vm_info): oid(_oid), seq(_seq), - hostname(_hostname), hid(_hid), + hostname(_hostname), + cid(_cid), vmm_mad_name(_vmm), vnm_mad_name(_vnm), tm_mad_name(_tmm), @@ -301,6 +304,7 @@ string& History::to_xml(string& xml, bool database) const "" << seq << "" << "" << hostname << ""<< "" << hid << "" << + "" << cid << "" << "" << stime << "" << "" << etime << "" << "" << vmm_mad_name << ""<< @@ -341,6 +345,7 @@ int History::rebuild_attributes() rc += xpath(seq , "/HISTORY/SEQ", -1); rc += xpath(hostname , "/HISTORY/HOSTNAME", "not_found"); rc += xpath(hid , "/HISTORY/HID", -1); + rc += xpath(cid , "/HISTORY/CID", -1); rc += xpath(stime , "/HISTORY/STIME", 0); rc += xpath(etime , "/HISTORY/ETIME", 0); rc += xpath(vmm_mad_name , "/HISTORY/VMMMAD", "not_found"); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 85b8bf1bb0..9599c959e1 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1367,6 +1367,7 @@ error_common: void VirtualMachine::add_history( int hid, + int cid, const string& hostname, const string& vmm_mad, const string& vnm_mad, @@ -1395,6 +1396,7 @@ void VirtualMachine::add_history( seq, hid, hostname, + cid, vmm_mad, vnm_mad, tm_mad, @@ -1424,6 +1426,7 @@ void VirtualMachine::cp_history() history->seq + 1, history->hid, history->hostname, + history->cid, history->vmm_mad_name, history->vnm_mad_name, history->tm_mad_name, @@ -1456,6 +1459,7 @@ void VirtualMachine::cp_previous_history() history->seq + 1, previous_history->hid, previous_history->hostname, + previous_history->cid, previous_history->vmm_mad_name, previous_history->vnm_mad_name, previous_history->tm_mad_name, From 1f96ef313d7a651c91d87caa54701f675a750d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 25 Oct 2013 18:02:54 +0200 Subject: [PATCH 2/2] Feature #2392: Add CID to history elems in migrator --- src/onedb/4.2.0_to_4.3.80.rb | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/onedb/4.2.0_to_4.3.80.rb b/src/onedb/4.2.0_to_4.3.80.rb index 4c893b9b03..5d4436cc50 100644 --- a/src/onedb/4.2.0_to_4.3.80.rb +++ b/src/onedb/4.2.0_to_4.3.80.rb @@ -123,6 +123,57 @@ module Migrator @db.run "DROP TABLE old_datastore_pool;" + ######################################################################## + # Feature #2392 + ######################################################################## + + @db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;" + @db.run "CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);" + + @db.fetch("SELECT * FROM old_vm_pool") do |row| + doc = REXML::Document.new(row[:body]) + + doc.root.each_element("HISTORY_RECORDS/HISTORY") do |e| + update_history(e) + end + + @db[:vm_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :last_poll => row[:last_poll], + :state => row[:state], + :lcm_state => row[:lcm_state], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_vm_pool;" + + @db.run "ALTER TABLE history RENAME TO old_history;" + @db.run "CREATE TABLE history (vid INTEGER, seq INTEGER, body MEDIUMTEXT, stime INTEGER, etime INTEGER,PRIMARY KEY(vid,seq));" + + @db.fetch("SELECT * FROM old_history") do |row| + doc = REXML::Document.new(row[:body]) + + doc.root.each_element("/HISTORY") do |e| + update_history(e) + end + + @db[:history].insert( + :vid => row[:vid], + :seq => row[:seq], + :body => doc.root.to_s, + :stime => row[:stime], + :etime => row[:etime]) + end + + @db.run "DROP TABLE old_history;" + + return true end @@ -202,4 +253,23 @@ module Migrator end end + def update_history(history_elem) + hid = nil + + history_elem.each_element("HID") do |e| + hid = e.text + end + + new_elem = history_elem.add_element("CID") + new_elem.text = "-1" # Cluster None + + if hid.nil? + return + end + + @db.fetch("SELECT cid FROM host_pool WHERE oid = #{hid}") do |row| + new_elem.text = row[:cid].to_s + end + end + end