1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-26 09:57:23 +03:00

feature #407: Minor modification on Cluster and Host classes

This commit is contained in:
Ruben S. Montero 2011-03-17 21:04:24 +01:00
parent 88aa07edf1
commit 3a833878c0
6 changed files with 37 additions and 35 deletions

View File

@ -82,7 +82,7 @@ private:
// Constructor
// *************************************************************************
Cluster(int id, string _name);
Cluster(int id, const string& name);
virtual ~Cluster();

View File

@ -356,7 +356,6 @@ private:
// -------------------------------------------------------------------------
friend class HostPool;
friend class ClusterPool;
// -------------------------------------------------------------------------
// Host Description
@ -382,7 +381,7 @@ private:
string tm_mad_name;
/**
* If Host State = MONITORED last time it got fully monitored or 1 Jan 1970
* If Host State= MONITORED last time it got fully monitored or 1 Jan 1970
* Host State = MONITORING last time it got a signal to be monitored
*/
time_t last_monitored;
@ -410,12 +409,12 @@ private:
// Constructor
// *************************************************************************
Host(int id=-1,
string _hostname="",
string _im_mad_name="",
string _vmm_mad_name="",
string _tm_mad_name="",
string _cluster="");
Host(int id=-1,
const string& hostname="",
const string& im_mad_name="",
const string& vmm_mad_name="",
const string& tm_mad_name="",
const string& cluster="");
virtual ~Host();

View File

@ -151,12 +151,6 @@ protected:
*/
SqlDB * db;
/**
* Last object ID assigned to an object. It must be initialized by the
* target pool.
*/
int lastOID;
/**
* Dumps the pool in XML format. A filter can be also added to the
* query
@ -170,6 +164,14 @@ protected:
int dump(ostringstream& oss, const string& elem_name,
const char * table, const string& where);
/**
* Returns the value of the last identifier assigned by the pool
*/
int get_lastOID()
{
return lastOID;
};
private:
pthread_mutex_t mutex;
@ -181,6 +183,12 @@ private:
*/
static const unsigned int MAX_POOL_SIZE;
/**
* Last object ID assigned to an object. It must be initialized by the
* target pool.
*/
int lastOID;
/**
* The pool is implemented with a Map of SQL object pointers, using the
* OID as key.

View File

@ -35,13 +35,9 @@ const char * Cluster::db_bootstrap = "CREATE TABLE IF NOT EXISTS cluster_pool ("
/* Cluster :: Constructor/Destructor */
/* ************************************************************************ */
Cluster::Cluster(
int id,
string _name):
PoolObjectSQL(id,_name,-1,table)
{}
Cluster::Cluster(int id, const string& name):PoolObjectSQL(id,name,-1,table){};
Cluster::~Cluster(){}
Cluster::~Cluster(){};
/* ************************************************************************ */
/* Cluster :: Database Access Functions */
@ -155,9 +151,9 @@ string& Cluster::to_xml(string& xml) const
ostringstream oss;
oss <<
"<CLUSTER>" <<
"<ID>" << oid << "</ID>" <<
"<NAME>" << name << "</NAME>" <<
"<CLUSTER>" <<
"<ID>" << oid << "</ID>" <<
"<NAME>" << name << "</NAME>" <<
"</CLUSTER>";
xml = oss.str();
@ -176,8 +172,8 @@ int Cluster::from_xml(const string& xml)
update_from_str(xml);
// Get class base attributes
rc += xpath(oid, "/CLUSTER/ID", -1);
rc += xpath(name, "/CLUSTER/NAME", "not_found");
rc += xpath(oid, "/CLUSTER/ID", -1);
rc += xpath(name,"/CLUSTER/NAME", "not_found");
if (rc != 0)
{

View File

@ -25,11 +25,10 @@ const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ClusterPool::ClusterPool(SqlDB * db):
PoolSQL(db, Cluster::table)
ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table)
{
// lastOID is set in PoolSQL::init_cb
if (lastOID == -1)
if (get_lastOID() == -1)
{
int rc;
Cluster * cluster;
@ -137,4 +136,4 @@ int ClusterPool::drop(Cluster * cluster)
}
return rc;
}
}

View File

@ -29,11 +29,11 @@
Host::Host(
int id,
string _hostname,
string _im_mad_name,
string _vmm_mad_name,
string _tm_mad_name,
string _cluster):
const string& _hostname,
const string& _im_mad_name,
const string& _vmm_mad_name,
const string& _tm_mad_name,
const string& _cluster):
PoolObjectSQL(id,_hostname,-1,table),
state(INIT),
im_mad_name(_im_mad_name),