mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
bug #1949: Add MONITORING States. Change DISABLED behavior
This commit is contained in:
parent
d365639ab6
commit
930ef686e4
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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<int>(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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -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();
|
||||
|
@ -55,6 +55,7 @@ void HostEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
else
|
||||
{
|
||||
host->disable();
|
||||
hpool->update_monitoring(host);
|
||||
}
|
||||
|
||||
hpool->update(host);
|
||||
|
Loading…
Reference in New Issue
Block a user