From e37c4d1665be7059f2a7f21ed3e7bf471d49af27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 13 Feb 2013 18:06:20 +0100 Subject: [PATCH] Feature #1739: Add messages when extra VMs are detected --- include/PoolObjectSQL.h | 12 +++++- src/im/InformationManagerDriver.cc | 64 +++++++++++++++++++++++++++--- src/pool/PoolObjectSQL.cc | 29 ++++++-------- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index d9f77426d8..e6055e3ef7 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -397,12 +397,20 @@ public: } /** - * Sets an error message for the VM in the template - * @param message + * Sets an error message with timestamp in the template + * @param message Message string * @return 0 on success */ void set_template_error_message(const string& message); + /** + * Sets a message with timestamp in the template + * @param att_name Name for the attribute + * @param message Message string + * @return 0 on success + */ + void set_template_message(const string& att_name, const string& message); + /** * Factory method for templates, it should be implemented * by classes that uses templates diff --git a/src/im/InformationManagerDriver.cc b/src/im/InformationManagerDriver.cc index 1868e1b124..b984bc7c1b 100644 --- a/src/im/InformationManagerDriver.cc +++ b/src/im/InformationManagerDriver.cc @@ -138,7 +138,7 @@ void InformationManagerDriver::protocol( goto error_common_info; } - // TODO The hinfo string is parsed again because HostTemplate has + // The hinfo string is parsed again because HostTemplate has // replace_mode set to true, but we expect several VM vector attributes Template* tmpl = new Template(); tmpl->parse(*hinfo, &error_msg); @@ -159,6 +159,9 @@ void InformationManagerDriver::protocol( host->unlock(); + vector external_vms; + map rogue_vms; + for (it=vm_att.begin(); it != vm_att.end(); it++) { vatt = dynamic_cast(*it); @@ -171,7 +174,7 @@ void InformationManagerDriver::protocol( rc = vatt->vector_value("ID", vmid); - if (rc == 0) + if (rc == 0 && vmid != -1) { if (vm_ids.erase(vmid) == 1) { @@ -181,12 +184,12 @@ void InformationManagerDriver::protocol( } else { - // TODO: This VM shoulnd't be running on this host + rogue_vms[vmid] = vatt->vector_value("DEPLOY_ID"); } } - else + else if (rc == 0) { - // TODO: unknown VM found running on this host + external_vms.push_back( vatt->vector_value("DEPLOY_ID") ); } delete *it; @@ -201,6 +204,57 @@ void InformationManagerDriver::protocol( VirtualMachineManagerDriver::process_failed_poll(*it); } } + + if (!rogue_vms.empty()) + { + map::iterator it; + + oss.str(""); + oss << "Manual intervention required, these VMs should" + << " not be running on Host " << id << ":"; + + for(it = rogue_vms.begin(); it != rogue_vms.end(); it++) + { + oss << " VM " << it->first << " (hypervisor name '" << it->second << "')"; + } + + host = hpool->get(id,true); + + if ( host != 0 ) + { + host->set_template_error_message(oss.str()); + + hpool->update(host); + + host->unlock(); + } + + NebulaLog::log("InM",Log::ERROR,oss); + } + + if (!external_vms.empty()) + { + vector::iterator it; + + oss.str(""); + oss << "External VMs found:"; + + for(it = external_vms.begin(); it != external_vms.end(); it++) + { + oss << " " << *it; + } + + host = hpool->get(id,true); + + if ( host != 0 ) + { + host->set_template_message("INFO_MESSAGE", oss.str()); + + hpool->update(host); + + host->unlock(); + } + } } else if (action == "LOG") { diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index b4bc95f356..ea667e73b0 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -137,30 +137,27 @@ int PoolObjectSQL::drop(SqlDB *db) const char * PoolObjectSQL::error_attribute_name = "ERROR"; void PoolObjectSQL::set_template_error_message(const string& message) +{ + set_template_message(error_attribute_name, message); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void PoolObjectSQL::set_template_message( + const string& att_name, + const string& message) { SingleAttribute * attr; ostringstream error_value; - char str[26]; - time_t the_time; - - the_time = time(NULL); - -#ifdef SOLARIS - ctime_r(&(the_time),str,sizeof(char)*26); -#else - ctime_r(&(the_time),str); -#endif - - str[24] = '\0'; // Get rid of final enter character - - error_value << str << " : " << message; + error_value << one_util::log_time() << " : " << message; //Replace previous error message and insert the new one - attr = new SingleAttribute(error_attribute_name, error_value.str()); + attr = new SingleAttribute(att_name, error_value.str()); - obj_template->erase(error_attribute_name); + obj_template->erase(att_name); obj_template->set(attr); }