1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-10 01:17:40 +03:00

feature #307: Now the IM protocol is MONITOR hid hostname update

This commit is contained in:
Ruben S. Montero 2010-08-17 00:28:48 +02:00
parent 5707604e97
commit f05fb71f13
6 changed files with 98 additions and 70 deletions

View File

@ -34,11 +34,13 @@ public:
HostPool * _hpool,
time_t _timer_period,
time_t _monitor_period,
const string& _remotes_location,
vector<const Attribute*>& _mads)
:MadManager(_mads),
hpool(_hpool),
timer_period(_timer_period),
monitor_period(_monitor_period)
monitor_period(_monitor_period),
remotes_location(_remotes_location)
{
am.addListener(this);
};
@ -46,7 +48,7 @@ public:
~InformationManager(){};
/**
* This functions starts the associated listener thread, and creates a
* This functions starts the associated listener thread, and creates a
* new thread for the Information Manager. This thread will wait in
* an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
@ -63,12 +65,12 @@ public:
};
/**
*
*
*/
void load_mads(int uid=0);
/**
*
*
*/
void finalize()
{
@ -90,28 +92,33 @@ private:
* Timer period for the Virtual Machine Manager.
*/
time_t timer_period;
/**
* Host monitoring interval
*/
time_t monitor_period;
/**
* Path for the remote action programs
*/
string remotes_location;
/**
* Action engine for the Manager
*/
ActionManager am;
/**
* Function to execute the Manager action loop method within a new pthread
* Function to execute the Manager action loop method within a new pthread
* (requires C linkage)
*/
friend void * im_action_loop(void *arg);
/**
* Returns a pointer to a Information Manager MAD. The driver is
* Returns a pointer to a Information Manager MAD. The driver is
* searched by its name and owned by gwadmin with uid=0.
* @param name of the driver
* @return the VM driver owned by uid 0, with attribute "NAME" equal to
* @return the VM driver owned by uid 0, with attribute "NAME" equal to
* name or 0 in not found
*/
const InformationManagerDriver * get(

View File

@ -30,7 +30,7 @@ using namespace std;
/**
* InformationManagerDriver provides a base class to implement IM
* Drivers. This class implements the protocol and recover functions
* from the Mad interface. This class may be used to further specialize
* from the Mad interface. This class may be used to further specialize
* the IM driver.
*/
class InformationManagerDriver : public Mad
@ -42,35 +42,28 @@ public:
const map<string,string>& attrs,
bool sudo,
HostPool * pool):
Mad(userid,attrs,sudo),hpool(pool)
{}
;
Mad(userid,attrs,sudo),hpool(pool){};
virtual ~InformationManagerDriver()
{}
;
virtual ~InformationManagerDriver(){};
/**
* Implements the IM driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(string& message);
/**
* TODO: What do we need here? just poll the Hosts to recover..
*/
void recover();
/**
* Sends a monitor request to the MAD: "MONITOR ID HOSTNAME -"
* @param oid the virtual machine id.
* @param host the hostname
* @param conf the filename of the deployment file
* @param update the remotes directory in host
*/
void monitor (
int oid,
const string& host) const;
void monitor(int oid, const string& host, bool update) const;
private:
/**
@ -78,8 +71,7 @@ private:
*/
HostPool * hpool;
friend class InformationManager;
friend class InformationManager;
};
/* -------------------------------------------------------------------------- */

View File

@ -232,11 +232,12 @@ private:
{
nebula_location = "/";
mad_location = "/usr/lib/one/mads/";
etc_location = "/etc/one/";
log_location = "/var/log/one/";
var_location = "/var/lib/one/";
hook_location= "/usr/share/one/hooks/";
mad_location = "/usr/lib/one/mads/";
etc_location = "/etc/one/";
log_location = "/var/log/one/";
var_location = "/var/lib/one/";
hook_location = "/usr/share/one/hooks/";
remotes_location = "/usr/lib/one/remotes/";
}
else
{
@ -247,11 +248,12 @@ private:
nebula_location += "/";
}
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
hook_location= nebula_location + "share/hooks/";
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
hook_location = nebula_location + "share/hooks/";
remotes_location = nebula_location + "lib/remotes/";
}
};
@ -348,6 +350,8 @@ private:
string log_location;
string var_location;
string hook_location;
string remotes_location;
string hostname;
// ---------------------------------------------------------------

View File

@ -17,6 +17,9 @@
#include "InformationManager.h"
#include "NebulaLog.h"
#include <sys/types.h>
#include <sys/stat.h>
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -145,7 +148,7 @@ void InformationManager::timer_action()
istringstream iss;
// -------------- Max. number of hosts to monitor. ---------------------
int host_limit = 10;
int host_limit = 15;
mark = mark + timer_period;
@ -164,6 +167,16 @@ void InformationManager::timer_action()
thetime = time(0);
struct stat sb;
if (stat(remotes_location.c_str(), &sb) == -1)
{
sb.st_mtime = 0;
NebulaLog::log("InM",Log::ERROR,"Could not stat remotes directory, "
"will not update remotes.");
}
for(it=discovered_hosts.begin();it!=discovered_hosts.end();it++)
{
host = hpool->get(it->first,true);
@ -204,7 +217,15 @@ void InformationManager::timer_action()
}
else
{
imd->monitor(it->first,host->get_hostname());
bool update_remotes = false;
if ((sb.st_mtime != 0) &&
(sb.st_mtime > host->get_last_monitored()))
{
update_remotes = true;
}
imd->monitor(it->first,host->get_hostname(),update_remotes);
host->set_state(Host::MONITORING);
}

View File

@ -23,13 +23,13 @@
/* Driver ASCII Protocol Implementation */
/* ************************************************************************** */
void InformationManagerDriver::monitor (
const int oid,
const string& host) const
void InformationManagerDriver::monitor(int oid,
const string& host,
bool update) const
{
ostringstream os;
os << "MONITOR " << oid << " " << host << endl;
os << "MONITOR " << oid << " " << host << " " << update << endl;
write(os);
};
@ -39,8 +39,8 @@ void InformationManagerDriver::monitor (
void InformationManagerDriver::protocol(
string& message)
{
istringstream is(message);
{
istringstream is(message);
//stores the action name
string action;
//stores the action result
@ -51,7 +51,7 @@ void InformationManagerDriver::protocol(
ostringstream ess;
string hinfo;
Host * host;
// Parse the driver message
if ( is.good() )
@ -84,61 +84,61 @@ void InformationManagerDriver::protocol(
// -----------------------
// Protocol implementation
// -----------------------
if ( action == "MONITOR" )
{
host = hpool->get(id,true);
if ( host == 0 )
{
goto error_host;
}
if (result == "SUCCESS")
{
size_t pos;
{
size_t pos;
int rc;
ostringstream oss;
getline (is,hinfo);
for (pos=hinfo.find(',');pos!=string::npos;pos=hinfo.find(','))
{
hinfo.replace(pos,1,"\n");
}
hinfo += "\n";
oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo;
NebulaLog::log("InM",Log::DEBUG,oss);
rc = host->update_info(hinfo);
if (rc != 0)
{
goto error_parse_info;
}
}
}
else
{
goto error_driver_info;
goto error_driver_info;
}
host->touch(true);
hpool->update(host);
host->unlock();
host->unlock();
}
else if (action == "LOG")
{
string info;
getline(is,info);
NebulaLog::log("InM",Log::INFO,info.c_str());
}
return;
error_driver_info:
@ -146,27 +146,27 @@ error_driver_info:
NebulaLog::log("InM", Log::ERROR, ess);
goto error_common_info;
error_parse_info:
ess << "Error parsing host information: " << hinfo;
NebulaLog::log("InM",Log::ERROR,ess);
error_common_info:
host->touch(false);
hpool->update(host);
host->unlock();
return;
error_host:
ess << "Could not get host " << id;
NebulaLog::log("InM",Log::ERROR,ess);
return;
error_parse:
ess << "Error while parsing driver message: " << message;

View File

@ -345,7 +345,11 @@ void Nebula::start()
nebula_configuration->get("IM_MAD", im_mads);
im = new InformationManager(hpool,timer_period,monitor_period,im_mads);
im = new InformationManager(hpool,
timer_period,
monitor_period,
remotes_location,
im_mads);
}
catch (bad_alloc&)
{