diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index beec7d8651..a8e0ccf26f 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -560,6 +560,13 @@ protected: */ void set_umask(int umask); + /** + * Sets an error message with timestamp in the template + * @param name of the error attribute + * @param message Message string + */ + void set_template_error_message(const string& name, const string& message); + /** * The object's unique ID */ @@ -643,11 +650,6 @@ private: * Pointer to the SQL table for the PoolObjectSQL */ const char * table; - - /** - * Name for the error messages attribute - */ - static const char * error_attribute_name; }; #endif /*POOL_OBJECT_SQL_H_*/ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index acda5dd6bb..f32253ce5f 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -698,13 +698,28 @@ public: */ int replace_template(const string& tmpl_str, bool keep_restricted, string& error); - void get_user_template_attribute( - const char * name, - string& value) const + /** + * This function gets an attribute from the user template + * @param name of the attribute + * @param value of the attribute + */ + void get_user_template_attribute(const char * name, string& value) const { user_obj_template->get(name,value); } + /** + * Sets an error message with timestamp in the template (ERROR_MONITOR) + * @param message Message string + */ + void set_template_monitor_error(const string& message); + + /** + * Deletes the error message from the template (ERROR_MONITOR) + * @param message Message string + */ + void clear_template_monitor_error(); + // ------------------------------------------------------------------------ // States // ------------------------------------------------------------------------ @@ -761,7 +776,7 @@ public: }; // ------------------------------------------------------------------------ - // Timers & + // Timers & Requirements // ------------------------------------------------------------------------ /** * Gets time from last information polling. @@ -772,6 +787,15 @@ public: return last_poll; }; + /** + * Sets time of last information polling. + * @param poll time in epoch, normally time(0) + */ + void set_last_poll(time_t poll) + { + last_poll = poll; + }; + /** * Get the VM physical requirements for the host. * @param cpu diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index e43f802cc9..d6f5696d74 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -93,12 +93,12 @@ public: int oid; iss >> oid; - + if ( iss.fail() ) { return 0; } - + return static_cast(PoolSQL::get(oid,lock)); }; @@ -205,16 +205,16 @@ public: }; /** - * Dumps the VM accounting information in XML format. A filter can be also + * Dumps the VM accounting information in XML format. A filter can be also * added to the query as well as a time frame. * @param oss the output stream to dump the pool contents * @param where filter for the objects, defaults to all * * @return 0 on success */ - int dump_acct(ostringstream& oss, - const string& where, - int time_start, + int dump_acct(ostringstream& oss, + const string& where, + int time_start, int time_end); /** diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index bdc5c9a41b..23d7188e57 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -134,29 +134,32 @@ int PoolObjectSQL::drop(SqlDB *db) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -const char * PoolObjectSQL::error_attribute_name = "ERROR"; - void PoolObjectSQL::set_template_error_message(const string& message) +{ + set_template_error_message("ERROR", message); +} + +/* -------------------------------------------------------------------------- */ + +void PoolObjectSQL::set_template_error_message(const string& name, + const string& message) { SingleAttribute * attr; ostringstream error_value; error_value << one_util::log_time() << " : " << message; - //Replace previous error message and insert the new one + attr = new SingleAttribute(name, error_value.str()); - attr = new SingleAttribute(error_attribute_name, error_value.str()); - - obj_template->erase(error_attribute_name); + obj_template->erase(name); obj_template->set(attr); } -/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ void PoolObjectSQL::clear_template_error_message() { - remove_template_attribute(error_attribute_name); + remove_template_attribute("ERROR"); } /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 0ffd8dd040..5109fd3e3c 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -3169,7 +3169,7 @@ void VirtualMachine::update_info( set_vm_info(); - clear_template_error_message(); + clear_template_monitor_error(); }; /* -------------------------------------------------------------------------- */ @@ -3214,3 +3214,16 @@ int VirtualMachine::replace_template( return 0; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void VirtualMachine::set_template_monitor_error(const string& message) +{ + set_template_error_message("ERROR_MONITOR", message); +} + +void VirtualMachine::clear_template_monitor_error() +{ + remove_template_attribute("ERROR_MONITOR"); +} diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 5abe46be43..9a24583728 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -1550,6 +1550,10 @@ void VirtualMachineManager::timer_action() delete drv_msg; + vm->set_last_poll(thetime); + + vmpool->update(vm); + vm->unlock(); } } diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index d0adc0e5d3..a1dd2c7a2c 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -153,6 +153,29 @@ static void log_error(VirtualMachine* vm, vm->log("VMM",Log::ERROR,os); } +/* -------------------------------------------------------------------------- */ + +static void log_monitor_error(VirtualMachine* vm, + ostringstream& os, + istringstream& is, + const char * msg) +{ + string info; + + getline(is,info); + + os.str(""); + os << msg; + + if (!info.empty() && info[0] != '-') + { + os << ": " << info; + vm->set_template_monitor_error(os.str()); + } + + vm->log("VMM",Log::ERROR,os); +} + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -532,7 +555,7 @@ void VirtualMachineManagerDriver::protocol( Nebula &ne = Nebula::instance(); LifeCycleManager* lcm = ne.get_lcm(); - log_error(vm, os, is, "Error monitoring VM"); + log_monitor_error(vm, os, is, "Error monitoring VM"); lcm->trigger(LifeCycleManager::MONITOR_DONE, vm->get_oid()); }