From 930ef686e4f189c492be54360b469de0bd951422 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 24 Apr 2013 01:12:22 +0200 Subject: [PATCH 1/6] bug #1949: Add MONITORING States. Change DISABLED behavior --- include/Host.h | 87 ++++++++++++++++++----------- src/host/Host.cc | 20 +++---- src/im/InformationManager.cc | 103 +++++++++++++++++++++-------------- src/rm/RequestManagerHost.cc | 1 + 4 files changed, 126 insertions(+), 85 deletions(-) diff --git a/include/Host.h b/include/Host.h index e5975d44f6..327222601d 100644 --- a/include/Host.h +++ b/include/Host.h @@ -44,7 +44,9 @@ public: MONITORED = 2, /**< The host has been successfully monitored. */ ERROR = 3, /**< An error ocurrer while monitoring the host. */ DISABLED = 4, /**< The host is disabled won't be monitored. */ - MONITORING_ERROR = 5 /**< Monitoring the host (from error). */ + MONITORING_ERROR = 5, /**< Monitoring the host (from error). */ + MONITORING_INIT = 6, /**< Monitoring the host (from init). */ + MONITORING_DISABLED = 7 /**< Monitoring the host (from disabled). */ }; /** @@ -68,7 +70,7 @@ public: */ bool isEnabled() const { - return state != DISABLED; + return state != DISABLED && state != MONITORING_DISABLED; } /** @@ -77,17 +79,17 @@ public: */ bool isMonitoring() const { - return ((state == MONITORING_ERROR) || (state==MONITORING_MONITORED)); + return ((state == MONITORING_ERROR) || + (state == MONITORING_MONITORED)|| + (state == MONITORING_INIT)|| + (state == MONITORING_DISABLED)); } /** * Disables the current host, it will not be monitored nor used by the * scheduler */ - void disable() - { - state = DISABLED; - }; + void disable(); /** * Enables the current host, it will be monitored and could be used by @@ -98,6 +100,14 @@ public: state = INIT; }; + /** + * Sets the host in error + */ + void set_error() + { + state = ERROR; + } + /** * Update host after a successful monitor. It modifies counters, state * and template attributes @@ -169,27 +179,31 @@ public: return im_mad_name; }; - /** - * Sets host state - * @param HostState state that applies to this host - */ - void set_state(HostState state) - { - this->state = state; - }; - /** * Sets the corresponding monitoring state based on the actual host state */ void set_monitoring_state() { - if ( state == ERROR ) + switch (state) { - state = MONITORING_ERROR; - } - else if ( state == MONITORED ) - { - state = MONITORING_MONITORED; + case ERROR: + state = MONITORING_ERROR; + break; + + case MONITORED: + state = MONITORING_MONITORED; + break; + + case INIT: + state = MONITORING_INIT; + break; + + case DISABLED: + state = MONITORING_DISABLED; + break; + + default: + break; } }; @@ -434,16 +448,27 @@ private: { last_monitored = time(0); - if ( state != DISABLED) //Don't change the state is host is disabled + switch (state) { - if (success == true) - { - state = MONITORED; - } - else - { - state = ERROR; - } + case MONITORING_DISABLED: + state = DISABLED; + break; + + case MONITORING_ERROR: + case MONITORING_INIT: + case MONITORING_MONITORED: + if (success == true) + { + state = MONITORED; + } + else + { + state = ERROR; + } + break; + + default: + break; } }; diff --git a/src/host/Host.cc b/src/host/Host.cc index a18586c3df..a1cae2765e 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -217,6 +217,10 @@ int Host::update_info(string &parse_str, return -1; } + // Touch the host to update its last_monitored timestamp and state + + touch(true); + tmpl = new Template(); tmpl->parse(parse_str, &error_msg); @@ -225,11 +229,7 @@ int Host::update_info(string &parse_str, // Extract share information // // ---------------------------------------------------------------------- // - if (state == Host::DISABLED) - { - reset_share_monitoring(); - } - else + if (isEnabled()) { get_template_attribute("TOTALCPU", fv); host_share.max_cpu = static_cast(fv); @@ -325,17 +325,15 @@ int Host::update_info(string &parse_str, delete tmpl; - // Touch the host to update its last_monitored timestamp and state - - touch(true); - return 0; } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void Host::reset_share_monitoring() +void Host::disable() { + state = DISABLED; + host_share.max_cpu = 0; host_share.max_mem = 0; @@ -353,8 +351,6 @@ void Host::reset_share_monitoring() remove_template_attribute("USEDCPU"); remove_template_attribute("USEDMEMORY"); - - touch(true); } /* -------------------------------------------------------------------------- */ diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index f042729f04..465d8f116f 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -152,11 +152,13 @@ void InformationManager::timer_action() const InformationManagerDriver * imd; - Host * host; - istringstream iss; + Host * host; + istringstream iss; - time_t monitor_length; - time_t target_time; + time_t monitor_length; + time_t target_time; + + bool do_monitor; mark = mark + timer_period; @@ -199,57 +201,74 @@ void InformationManager::timer_action() monitor_length = now - host->get_last_monitored(); - if (host->isMonitoring() && (monitor_length >= monitor_expire)) - { - host->set_state(Host::INIT); + /** + * Monitor hosts that are: + * - enabled and have been being monitored for more than monitor_expire + * - enabled and not being monitored + * - disabled and not being monitored but have running vms + * - disabled with running vms and have been being monitored + * for more than monitor_expire secs. + */ - hpool->update(host); + do_monitor = false; + + if (host->isEnabled()) + { + if (!host->isMonitoring()) + { + do_monitor = true; + } + else if (monitor_length >= monitor_expire ) + { + do_monitor = true; + } + } + else if ( host->get_share_running_vms() > 0 ) + { + if (!host->isMonitoring()) + { + do_monitor = true; + } + else if (monitor_length >= monitor_expire) + { + do_monitor = true; + } } - if ( !(host->isMonitoring()) ) + if (do_monitor) { - if (!host->isEnabled() && host->get_share_running_vms() == 0 ) - { - host->reset_share_monitoring(); + oss.str(""); + oss << "Monitoring host " << host->get_name() << " (" + << host->get_oid() << ")"; - hpool->update(host); - hpool->update_monitoring(host); + NebulaLog::log("InM",Log::INFO,oss); + + imd = get(host->get_im_mad()); + + if (imd == 0) + { + oss.str(""); + oss << "Could not find information driver " << host->get_im_mad(); + NebulaLog::log("InM",Log::ERROR,oss); + + host->set_error(); } else { - oss.str(""); - oss << "Monitoring host " << host->get_name() - << " (" << host->get_oid() << ")"; + bool update_remotes = false; - NebulaLog::log("InM",Log::INFO,oss); - - imd = get(host->get_im_mad()); - - if (imd == 0) + if ((sb.st_mtime != 0) && + (sb.st_mtime > host->get_last_monitored())) { - oss.str(""); - oss << "Could not find information driver " << host->get_im_mad(); - NebulaLog::log("InM",Log::ERROR,oss); - - host->set_state(Host::ERROR); - } - else - { - bool update_remotes = false; - - if ((sb.st_mtime != 0) && - (sb.st_mtime > host->get_last_monitored())) - { - update_remotes = true; - } - - imd->monitor(host->get_oid(),host->get_name(),update_remotes); - - host->set_monitoring_state(); + update_remotes = true; } - hpool->update(host); + imd->monitor(host->get_oid(),host->get_name(),update_remotes); + + host->set_monitoring_state(); } + + hpool->update(host); } host->unlock(); diff --git a/src/rm/RequestManagerHost.cc b/src/rm/RequestManagerHost.cc index 6c4d6576f4..67fc7dacb5 100644 --- a/src/rm/RequestManagerHost.cc +++ b/src/rm/RequestManagerHost.cc @@ -55,6 +55,7 @@ void HostEnable::request_execute(xmlrpc_c::paramList const& paramList, else { host->disable(); + hpool->update_monitoring(host); } hpool->update(host); From 61fc5c575280fc11d3133873961d74e48fd08f47 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 24 Apr 2013 01:14:22 +0200 Subject: [PATCH 2/6] bug #1949: Add OCA state --- src/oca/ruby/opennebula/host.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/oca/ruby/opennebula/host.rb b/src/oca/ruby/opennebula/host.rb index e2456b9b12..70a913da21 100644 --- a/src/oca/ruby/opennebula/host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -42,6 +42,8 @@ module OpenNebula "ERROR" => "err", "DISABLED" => "off", "MONITORING_ERROR" => "retry", + "MONITORING_INIT" => "init", + "MONITORING_DISABLED" => "off" } # Creates a Host description with just its identifier From 0c35a80ac12d535f222b3bad46642724fecc9d5d Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 24 Apr 2013 01:21:58 +0200 Subject: [PATCH 3/6] bug #1949: remove function definition --- include/Host.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/Host.h b/include/Host.h index 327222601d..c774ccb029 100644 --- a/include/Host.h +++ b/include/Host.h @@ -122,11 +122,6 @@ public: set &lost, map &found); - /** - * Sets the host_share monitoring values to 0 - */ - void reset_share_monitoring(); - /** * Update host after a failed monitor. It state * and template attributes From e267375c6aa892fe920074590f6050802d71d039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 24 Apr 2013 15:56:59 +0200 Subject: [PATCH 4/6] Bug #1949: Add new states to oca, sunstone, ozones --- share/doc/xsd/host.xsd | 2 ++ src/oca/java/src/org/opennebula/client/host/Host.java | 4 ++-- src/oca/ruby/opennebula/host.rb | 2 +- src/ozones/Server/public/js/ozones.js | 8 ++++++-- src/sunstone/public/js/opennebula.js | 8 ++++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/share/doc/xsd/host.xsd b/share/doc/xsd/host.xsd index f6565baec4..a504583829 100644 --- a/share/doc/xsd/host.xsd +++ b/share/doc/xsd/host.xsd @@ -13,6 +13,8 @@ ERROR = 3 An error ocurrer while monitoring the host DISABLED = 4 The host is disabled won't be monitored MONITORING_ERROR = 5 Monitoring the host (from error) + MONITORING_INIT = 6 Monitoring the host (from init) + MONITORING_DISABLED = 7 Monitoring the host (from disabled) --> diff --git a/src/oca/java/src/org/opennebula/client/host/Host.java b/src/oca/java/src/org/opennebula/client/host/Host.java index e76f54e5e4..b81dd1ea79 100644 --- a/src/oca/java/src/org/opennebula/client/host/Host.java +++ b/src/oca/java/src/org/opennebula/client/host/Host.java @@ -37,10 +37,10 @@ public class Host extends PoolElement{ private static final String[] HOST_STATES = {"INIT", "MONITORING_MONITORED", "MONITORED", "ERROR", "DISABLED", - "MONITORING_ERROR"}; + "MONITORING_ERROR", "MONITORING_INIT", "MONITORING_DISABLED"}; private static final String[] SHORT_HOST_STATES = - {"init", "update", "on", "err", "off", "retry"}; + {"init", "update", "on", "err", "off", "retry", "init", "off"}; /** * Creates a new Host representation. diff --git a/src/oca/ruby/opennebula/host.rb b/src/oca/ruby/opennebula/host.rb index 70a913da21..58fe274c55 100644 --- a/src/oca/ruby/opennebula/host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -33,7 +33,7 @@ module OpenNebula :monitoring => "host.monitoring" } - HOST_STATES=%w{INIT MONITORING_MONITORED MONITORED ERROR DISABLED MONITORING_ERROR} + HOST_STATES=%w{INIT MONITORING_MONITORED MONITORED ERROR DISABLED MONITORING_ERROR MONITORING_INIT MONITORING_DISABLED} SHORT_HOST_STATES={ "INIT" => "init", diff --git a/src/ozones/Server/public/js/ozones.js b/src/ozones/Server/public/js/ozones.js index ee70bb595c..a2d6de841e 100644 --- a/src/ozones/Server/public/js/ozones.js +++ b/src/ozones/Server/public/js/ozones.js @@ -54,7 +54,9 @@ var oZones = { "MONITORED", "ERROR", "DISABLED", - "MONITORING_ERROR"][value]); + "MONITORING_ERROR", + "MONITORING_INIT", + "MONITORING_DISABLED"][value]); break; case "HOST_SIMPLE": case "host_simple": @@ -63,7 +65,9 @@ var oZones = { "ON", "ERROR", "OFF", - "RETRY"][value]); + "RETRY", + "INIT", + "OFF"][value]); break; case "VM": case "vm": diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index cb928a8cb7..8a0eb448a8 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -62,7 +62,9 @@ var OpenNebula = { "MONITORED", "ERROR", "DISABLED", - "MONITORING_ERROR"][value]); + "MONITORING_ERROR", + "MONITORING_INIT", + "MONITORING_DISABLED"][value]); break; case "HOST_SIMPLE": case "host_simple": @@ -71,7 +73,9 @@ var OpenNebula = { "ON", "ERROR", "OFF", - "RETRY"][value]); + "RETRY", + "INIT", + "OFF"][value]); break; case "VM": case "vm": From 28d8e44ea4a920904fc0fbf3fbb61e1b5f82e072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 25 Apr 2013 15:10:12 +0200 Subject: [PATCH 5/6] Bug #1949: Prevent bug #1800 from reappearing --- include/Host.h | 68 +++++++++++++++++------------------- src/im/InformationManager.cc | 11 +++++- src/rm/RequestManagerHost.cc | 1 - 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/include/Host.h b/include/Host.h index c774ccb029..812d544ad4 100644 --- a/include/Host.h +++ b/include/Host.h @@ -108,6 +108,38 @@ public: state = ERROR; } + /** + * Updates the Host's last_monitored time stamp. + * @param success if the monitored action was successfully performed + */ + void touch(bool success) + { + last_monitored = time(0); + + switch (state) + { + case MONITORING_DISABLED: + state = DISABLED; + break; + + case MONITORING_ERROR: + case MONITORING_INIT: + case MONITORING_MONITORED: + if (success == true) + { + state = MONITORED; + } + else + { + state = ERROR; + } + break; + + default: + break; + } + }; + /** * Update host after a successful monitor. It modifies counters, state * and template attributes @@ -431,42 +463,6 @@ private: virtual ~Host(); - // ************************************************************************* - // Host Management - // ************************************************************************* - - /** - * Updates the Host's last_monitored time stamp. - * @param success if the monitored action was successfully performed - */ - void touch(bool success) - { - last_monitored = time(0); - - switch (state) - { - case MONITORING_DISABLED: - state = DISABLED; - break; - - case MONITORING_ERROR: - case MONITORING_INIT: - case MONITORING_MONITORED: - if (success == true) - { - state = MONITORED; - } - else - { - state = ERROR; - } - break; - - default: - break; - } - }; - // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 465d8f116f..f8efeddd62 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -267,10 +267,19 @@ void InformationManager::timer_action() host->set_monitoring_state(); } + } + else if (!host->isEnabled() && host->get_share_running_vms() == 0 ) + { + // Disabled hosts without VMs are not monitored, but we need to + // update the last_mon_time to rotate the Hosts returned by + // HostPool::discover. We also update the monitoring values with + // 0s - hpool->update(host); + host->touch(true); + hpool->update_monitoring(host); } + hpool->update(host); host->unlock(); } } diff --git a/src/rm/RequestManagerHost.cc b/src/rm/RequestManagerHost.cc index 67fc7dacb5..6c4d6576f4 100644 --- a/src/rm/RequestManagerHost.cc +++ b/src/rm/RequestManagerHost.cc @@ -55,7 +55,6 @@ void HostEnable::request_execute(xmlrpc_c::paramList const& paramList, else { host->disable(); - hpool->update_monitoring(host); } hpool->update(host); From de3df1432dc6c59c31b175ecc4745f61b4b67158 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 25 Apr 2013 16:00:03 +0200 Subject: [PATCH 6/6] bug #1949: Update last_monitor --- include/Host.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/Host.h b/include/Host.h index 812d544ad4..801f32cc3c 100644 --- a/include/Host.h +++ b/include/Host.h @@ -211,6 +211,8 @@ public: */ void set_monitoring_state() { + last_monitored = time(0); //Needed to expire this monitor action + switch (state) { case ERROR: