diff --git a/include/Host.h b/include/Host.h index e5975d44f6..801f32cc3c 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,46 @@ public: state = INIT; }; + /** + * Sets the host in error + */ + void set_error() + { + 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 @@ -112,11 +154,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 @@ -169,27 +206,33 @@ 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 ) + last_monitored = time(0); //Needed to expire this monitor action + + 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; } }; @@ -422,31 +465,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); - - if ( state != DISABLED) //Don't change the state is host is disabled - { - if (success == true) - { - state = MONITORED; - } - else - { - state = ERROR; - } - } - }; - // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* 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/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..f8efeddd62 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,59 +201,85 @@ 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(); } } + 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 + host->touch(true); + hpool->update_monitoring(host); + } + + hpool->update(host); host->unlock(); } } 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 e2456b9b12..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", @@ -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 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 46d77e78a6..c991dc550c 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":