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

feature #201: Minor changes to cluster core component

This commit is contained in:
Ruben S. Montero 2010-07-11 19:45:10 +02:00
parent fd0da733a9
commit fc15b99792
11 changed files with 324 additions and 145 deletions

View File

@ -32,20 +32,21 @@ using namespace std;
*/
class ClusterPool
{
public:
/**
* Cluster name for the default cluster
*/
static const string DEFAULT_CLUSTER_NAME;
private:
// -------------------------------------------------------------------------
// Friends
// -------------------------------------------------------------------------
friend class HostPool;
/* ---------------------------------------------------------------------- */
/* Attributes */
/* ---------------------------------------------------------------------- */
/**
* This map stores the clusters
*/
@ -121,7 +122,7 @@ private:
*
* @return 0 on success
*/
void dump(ostringstream& oss, int id, string name);
void dump_cluster(ostringstream& oss, int id, string name);
/* ---------------------------------------------------------------------- */

View File

@ -20,6 +20,7 @@
#include "PoolSQL.h"
#include "HostShare.h"
#include "HostTemplate.h"
#include "ClusterPool.h"
using namespace std;
@ -90,14 +91,14 @@ public:
if ( state != DISABLED) //Don't change the state is host is disabled
{
if (success == true)
{
state = MONITORED;
}
else
{
state = ERROR;
}
if (success == true)
{
state = MONITORED;
}
else
{
state = ERROR;
}
}
};
@ -107,7 +108,7 @@ public:
*/
void disable()
{
state = DISABLED;
state = DISABLED;
};
/**
@ -116,17 +117,17 @@ public:
*/
void enable()
{
state = INIT;
state = INIT;
};
/**
* Returns host host_name
* @return host_name Host's hostname
*/
const string& get_hostname() const
const string& get_hostname() const
{
return hostname;
};
return hostname;
};
/** Update host counters and update the whole host on the DB
* @param parse_str string with values to be parsed
@ -188,7 +189,11 @@ public:
return last_monitored;
};
int set_cluster(string cluster_name)
/**
* Sets the cluster for this host
* @return time_t last monitored time
*/
int set_cluster(const string& cluster_name)
{
cluster = cluster_name;
return 0;

View File

@ -87,7 +87,7 @@ public:
};
/**
* Get the 10 least monitored hosts
* Get the least monitored hosts
* @param discovered hosts, map to store the retrieved hosts hids and
* hostnames
* @param host_limit max. number of hosts to monitor at a time
@ -147,16 +147,11 @@ public:
*/
int dump(ostringstream& oss, const string& where);
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* Methods for cluster management */
/* ---------------------------------------------------------------------- */
/*
ClusterPool * cluster_pool()
{
return &cluster_pool;
}
//*/
/* ---------------------------------------------------------------------- */
/**
* Returns true if the clid is an id for an existing cluster
@ -164,10 +159,10 @@ public:
*
* @return true if the clid is an id for an existing cluster
*/
bool exists_cluster(int clid)
/* bool exists_cluster(int clid)
{
return cluster_pool.exists(clid);
};
};*/
/**
* Allocates a new cluster in the pool
@ -222,7 +217,7 @@ public:
it = cluster_pool.cluster_names.find(clid);
if(it == cluster_pool.cluster_names.end())
if (it == cluster_pool.cluster_names.end())
{
return -1;
}
@ -230,26 +225,22 @@ public:
return host->set_cluster( it->second );
};
/**
* Removes the host from the given cluster.
* The result is the same as assigning the host to
* the default cluster.
* Removes the host from the given cluster setting the default one.
* @param host The host to assign
*
* @return 0 on success
*/
int remove_cluster(Host* host)
int set_default_cluster(Host* host)
{
// To remove a host from a cluster means
// moving it to the default cluster.
return set_cluster(host, 0);
return host->set_cluster(ClusterPool::DEFAULT_CLUSTER_NAME);
};
private:
ClusterPool cluster_pool;
/**
* ClusterPool, clusters defined and persistance functionality
*/
ClusterPool cluster_pool;
/**
* Factory method to produce Host objects

View File

@ -25,6 +25,8 @@ const char * ClusterPool::db_bootstrap =
"oid INTEGER PRIMARY KEY, cluster_name VARCHAR(128), "
"UNIQUE(cluster_name) )";
const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
/* -------------------------------------------------------------------------- */
int ClusterPool::allocate(int * clid, string name, SqlDB *db)
@ -74,7 +76,7 @@ string ClusterPool::info(int clid)
if(it != cluster_names.end())
{
dump(oss, it->first, it->second);
dump_cluster(oss, it->first, it->second);
}
return oss.str();
@ -116,7 +118,7 @@ int ClusterPool::dump(ostringstream& oss)
for(it=cluster_names.begin();it!=cluster_names.end();it++)
{
dump(oss, it->first, it->second);
dump_cluster(oss, it->first, it->second);
}
oss << "</CLUSTER_POOL>";
@ -124,6 +126,7 @@ int ClusterPool::dump(ostringstream& oss)
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ClusterPool::insert(int oid, string name, SqlDB *db)
@ -157,9 +160,10 @@ int ClusterPool::insert(int oid, string name, SqlDB *db)
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ClusterPool::dump(ostringstream& oss, int id, string name)
void ClusterPool::dump_cluster(ostringstream& oss, int id, string name)
{
oss <<
"<CLUSTER>" <<

View File

@ -40,8 +40,8 @@ Host::Host(
vmm_mad_name(_vmm_mad_name),
tm_mad_name(_tm_mad_name),
last_monitored(0),
host_template(id),
cluster("default")
cluster(ClusterPool::DEFAULT_CLUSTER_NAME),
host_template(id)
{};
@ -123,7 +123,6 @@ int Host::select(SqlDB *db)
}
// Get the template
rc = host_template.select(db);
if ( rc != 0 )
@ -132,7 +131,6 @@ int Host::select(SqlDB *db)
}
// Select the host shares from the DB
rc = host_share.select(db);
if ( rc != 0 )
@ -143,7 +141,6 @@ int Host::select(SqlDB *db)
return 0;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
@ -421,21 +418,20 @@ int Host::update_info(string &parse_str)
ostream& operator<<(ostream& os, Host& host)
{
string host_str;
string host_str;
os << host.to_xml(host_str);
os << host.to_xml(host_str);
return os;
};
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
string& Host::to_xml(string& xml) const
{
string template_xml;
string share_xml;
string share_xml;
ostringstream oss;
oss <<
@ -448,9 +444,9 @@ string& Host::to_xml(string& xml) const
"<TM_MAD>" << tm_mad_name << "</TM_MAD>" <<
"<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
"<CLUSTER>" << cluster << "</CLUSTER>" <<
host_share.to_xml(share_xml) <<
host_share.to_xml(share_xml) <<
host_template.to_xml(template_xml) <<
"</HOST>";
"</HOST>";
xml = oss.str();
@ -463,23 +459,23 @@ string& Host::to_xml(string& xml) const
string& Host::to_str(string& str) const
{
string template_str;
string share_str;
string share_str;
ostringstream os;
os <<
"ID = " << oid << endl <<
"NAME = " << hostname << endl <<
"STATE = " << state << endl <<
"IM MAD = " << im_mad_name << endl <<
"VMM MAD = " << vmm_mad_name << endl <<
"TM MAD = " << tm_mad_name << endl <<
"LAST_MON = " << last_monitored << endl <<
"ID = " << oid << endl <<
"NAME = " << hostname << endl <<
"STATE = " << state << endl <<
"IM MAD = " << im_mad_name << endl <<
"VMM MAD = " << vmm_mad_name << endl <<
"TM MAD = " << tm_mad_name << endl <<
"LAST_MON = " << last_monitored << endl <<
"CLUSTER = " << cluster << endl <<
"ATTRIBUTES" << endl << host_template.to_str(template_str) << endl <<
"HOST SHARES" << endl << host_share.to_str(share_str) <<endl;
str = os.str();
str = os.str();
return str;
return str;
}

View File

@ -18,10 +18,15 @@
/* Host Pool */
/* ************************************************************************** */
#include <stdexcept>
#include "HostPool.h"
#include "ClusterPool.h"
#include "NebulaLog.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int HostPool::init_cb(void *nil, int num, char **values, char **names)
{
if ( num != 2 || values == 0 || values[0] == 0 )
@ -51,15 +56,11 @@ HostPool::HostPool(SqlDB* db):PoolSQL(db,Host::table)
if (cluster_pool.cluster_names.empty())
{
string default_name = "default";
// Insert the "default" cluster
int rc = cluster_pool.insert(0, default_name, db);
int rc = cluster_pool.insert(0, ClusterPool::DEFAULT_CLUSTER_NAME, db);
if(rc != 0)
{
NebulaLog::log("HOST",Log::ERROR,
"Cluster pool is empty but couldn't create default cluster.");
throw runtime_error("Could not create default cluster HostPool");
}
}
}
@ -184,23 +185,28 @@ int HostPool::drop_cluster(int clid)
{
int rc;
map<int, string>::iterator it;
string cluster_name;
it = cluster_pool.cluster_names.find(clid);
if ( it == cluster_pool.cluster_names.end() )
{
return -1;
}
cluster_name = it->second;
// try to drop the cluster from the pool and DB
rc = cluster_pool.drop(clid, db);
// Move the hosts assigned to the deleted cluster to the default one
if( rc == 0 )
{
// Search the hosts assigned to this cluster
Host* host;
vector<int> hids;
vector<int>::iterator hid_it;
string cluster_name = it->second;
string where = "cluster = '" + cluster_name + "'";
string where = "cluster = '" + cluster_name + "'";
search(hids, Host::table, where);
@ -208,7 +214,13 @@ int HostPool::drop_cluster(int clid)
{
host = get(*hid_it, true);
remove_cluster(host);
if ( host == 0 )
{
continue;
}
set_default_cluster(host);
update(host);
host->unlock();

View File

@ -33,7 +33,7 @@ const string xmls[] =
{
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
"<LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>0</HID>"
"<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID>"
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
@ -42,7 +42,7 @@ const string xmls[] =
"<HOST><ID>1</ID><NAME>Second host</NAME><STATE>0</STATE>"
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
"<LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>1</HID>"
"<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID>"
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
@ -53,35 +53,35 @@ const string xmls[] =
// This xml dump result has the LAST_MON_TIMEs modified to 0000000000
const string xml_dump =
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>000000"
"0000</LAST_MON_TIME><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_M"
"ON_TIME><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
"ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOS"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
"T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
"NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHAR"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
"E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
"MS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
"ATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad"
"</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>4</HID>"
"</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>4</HID>"
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
"</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
@ -90,37 +90,43 @@ const string xml_dump =
const string xml_dump_like_a =
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>000000"
"0000</LAST_MON_TIME><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_M"
"ON_TIME><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
"ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOS"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
"T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
"NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHAR"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
"E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
"MS>0</RUNNING_VMS></HOST_SHARE></HOST></HOST_POOL>";
const string replacement = "0000000000";
const string cluster_default =
"<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
const string cluster_xml_dump =
"<CLUSTER_POOL><CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER><CLUSTER><ID>1</ID><NAME>cluster_a</NAME></CLUSTER><CLUSTER><ID>3</ID><NAME>cluster_c</NAME></CLUSTER><CLUSTER><ID>4</ID><NAME>cluster_d</NAME></CLUSTER></CLUSTER_POOL>";
const string host_0_cluster =
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>cluster_a</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
/* ************************************************************************* */
/* ************************************************************************* */
@ -136,6 +142,14 @@ class HostPoolTest : public PoolTest
CPPUNIT_TEST (discover);
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (cluster_init);
CPPUNIT_TEST (cluster_allocate);
CPPUNIT_TEST (cluster_drop);
CPPUNIT_TEST (cluster_id);
CPPUNIT_TEST (cluster_dump);
CPPUNIT_TEST (set_cluster);
CPPUNIT_TEST (remove_cluster);
CPPUNIT_TEST_SUITE_END ();
protected:
@ -168,13 +182,9 @@ protected:
CPPUNIT_ASSERT( name == names[index] );
// Get the xml and replace the LAST_MON_TIME to 0, so we can compare
// it with a prepared string.
// Get the xml
host->to_xml(xml_str);
xml_str.replace( xml_str.find("<LAST_MON_TIME>")+15, 10, "0000000000");
CPPUNIT_ASSERT( xml_str == xmls[index]);
};
@ -215,6 +225,8 @@ public:
CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
};
/* ********************************************************************* */
void duplicates()
{
int rc, oid_0, oid_1;
@ -249,6 +261,7 @@ public:
CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad_2 );
}
/* ********************************************************************* */
void dump()
{
@ -265,18 +278,13 @@ public:
rc = ((HostPool*)pool)->dump(oss, "");
CPPUNIT_ASSERT(rc == 0);
// To be able to compare one string to another, the monitoring times
// have to be changed
string result = oss.str();
result.replace( 142, 10, replacement);
result.replace( 648, 10, replacement);
result.replace(1154, 10, replacement);
result.replace(1666, 10, replacement);
result.replace(2170, 10, replacement);
CPPUNIT_ASSERT( result == xml_dump );
}
/* ********************************************************************* */
void dump_where()
{
string names[] = {"a", "a name", "a_name", "another name", "host"};
@ -292,18 +300,14 @@ public:
rc = ((HostPool*)pool)->dump(oss, "host_name LIKE 'a%'");
CPPUNIT_ASSERT(rc == 0);
// To be able to compare one string to another, the monitoring times
// have to be changed
string result = oss.str();
result.replace( 142, 10, replacement);
result.replace( 648, 10, replacement);
result.replace(1154, 10, replacement);
result.replace(1666, 10, replacement);
string result = oss.str();
CPPUNIT_ASSERT( result == xml_dump_like_a );
}
/* ********************************************************************* */
void discover()
{
int rc, oid, i;
@ -332,7 +336,7 @@ public:
}
// Discover the enabled hosts
rc = hp->discover(&dh);
rc = hp->discover(&dh, 100);
CPPUNIT_ASSERT(rc == 0);
CPPUNIT_ASSERT(dh.size() == 8);
@ -346,8 +350,198 @@ public:
CPPUNIT_ASSERT(host->isEnabled());
}
}
/* ********************************************************************* */
/* ********************************************************************* */
void cluster_init()
{
HostPool * hp = static_cast<HostPool *>(pool);
CPPUNIT_ASSERT( hp->info_cluster(0) == cluster_default );
}
/* ********************************************************************* */
void cluster_allocate()
{
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
rc = hp->allocate_cluster(&clid, "new_cluster");
CPPUNIT_ASSERT( rc == clid );
CPPUNIT_ASSERT( clid == 1 );
CPPUNIT_ASSERT( hp->info_cluster(clid) ==
"<CLUSTER><ID>1</ID><NAME>new_cluster</NAME></CLUSTER>");
// Try to allocate using the same name
rc = hp->allocate_cluster(&clid, "new_cluster");
CPPUNIT_ASSERT( rc == clid );
CPPUNIT_ASSERT( clid == -1 );
}
/* ********************************************************************* */
void cluster_drop()
{
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
// Drop a non-existing cluster
rc = hp->drop_cluster(20);
CPPUNIT_ASSERT( rc == -1 );
// Allocate a cluster and drop it
rc = hp->allocate_cluster(&clid, "new_cluster");
CPPUNIT_ASSERT( clid == 1);
rc = hp->drop_cluster(clid);
CPPUNIT_ASSERT( rc == 0 );
// Try to drop the default cluster, should fail
rc = hp->drop_cluster(0);
CPPUNIT_ASSERT( rc == -1 );
}
/* ********************************************************************* */
void cluster_id()
{
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
ostringstream oss;
// Allocate some clusters
rc = hp->allocate_cluster(&clid, "cluster_a");
CPPUNIT_ASSERT( rc == 1 );
rc = hp->allocate_cluster(&clid, "cluster_b");
CPPUNIT_ASSERT( rc == 2 );
rc = hp->allocate_cluster(&clid, "cluster_c");
CPPUNIT_ASSERT( rc == 3 );
rc = hp->allocate_cluster(&clid, "cluster_d");
CPPUNIT_ASSERT( rc == 4 );
// Drop id 2
rc = hp->drop_cluster(2);
CPPUNIT_ASSERT( rc == 0 );
// Next one should use id 5, because the biggest id is 4
rc = hp->allocate_cluster(&clid, "cluster_e");
CPPUNIT_ASSERT( rc == 5 );
// Drop id 5
rc = hp->drop_cluster(5);
CPPUNIT_ASSERT( rc == 0 );
// Next one should use id 5, because the biggest id is 4 again
rc = hp->allocate_cluster(&clid, "cluster_f");
CPPUNIT_ASSERT( rc == 5 );
}
/* ********************************************************************* */
void cluster_dump()
{
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
ostringstream oss;
// Allocate some clusters
rc = hp->allocate_cluster(&clid, "cluster_a");
CPPUNIT_ASSERT( rc == 1 );
rc = hp->allocate_cluster(&clid, "cluster_b");
CPPUNIT_ASSERT( rc == 2 );
rc = hp->allocate_cluster(&clid, "cluster_c");
CPPUNIT_ASSERT( rc == 3 );
rc = hp->allocate_cluster(&clid, "cluster_d");
CPPUNIT_ASSERT( rc == 4 );
// Drop one of them
rc = hp->drop_cluster(2);
CPPUNIT_ASSERT( rc == 0 );
// dump the pool
rc = hp->dump_cluster(oss);
CPPUNIT_ASSERT( oss.str() == cluster_xml_dump );
}
/* ********************************************************************* */
void set_cluster()
{
HostPool * hp = static_cast<HostPool *>(pool);
Host* host;
int clid, rc, oid;
string xml_str;
// Allocate a host
oid = allocate(0);
host = hp->get(0, false);
rc = hp->allocate_cluster(&clid, "cluster_a");
CPPUNIT_ASSERT( rc == 1 );
rc = hp->set_cluster(host, clid);
CPPUNIT_ASSERT( rc == 0 );
host->to_xml(xml_str);
CPPUNIT_ASSERT( xml_str == host_0_cluster);
// Try to set a non-existing cluster
rc = hp->set_cluster(host, 20);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( xml_str == host_0_cluster);
}
/* ********************************************************************* */
void remove_cluster()
{
HostPool * hp = static_cast<HostPool *>(pool);
Host* host;
int clid, rc, oid;
string xml_str;
// Allocate a host
oid = allocate(0);
host = hp->get(0, false);
rc = hp->allocate_cluster(&clid, "cluster_a");
CPPUNIT_ASSERT( rc == 1 );
// Set host 0 to cluster 1
rc = hp->set_cluster(host, clid);
CPPUNIT_ASSERT( rc == 0 );
// Check
host->to_xml(xml_str);
CPPUNIT_ASSERT( xml_str == host_0_cluster);
// Remove the cluster
rc = hp->set_default_cluster(host);
CPPUNIT_ASSERT( rc == 0 );
// The host should have been moved to the default cluster
host->to_xml(xml_str);
check(0, host);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */

View File

@ -54,13 +54,6 @@ void RequestManager::ClusterAdd::execute(
goto error_authenticate;
}
// Check if cluster exists
if ( !ClusterAdd::hpool->exists_cluster(clid) )
{
goto error_cluster;
}
// Check if host exists
host = ClusterAdd::hpool->get(hid,true);
@ -97,10 +90,6 @@ error_authenticate:
oss << "User not authorized to add hosts to clusters";
goto error_common;
error_cluster:
oss << "Error getting cluster with CLID = " << clid;
goto error_common;
error_host_get:
oss << "The host " << hid << " does not exists";
goto error_common;
@ -108,7 +97,7 @@ error_host_get:
error_cluster_add:
host->unlock();
oss << "Can not add host " << hid << " to cluster " << clid <<
oss << "Can not add host " << hid << " to cluster " << clid <<
", returned error code [" << rc << "]";
goto error_common;

View File

@ -23,7 +23,7 @@
void RequestManager::ClusterDelete::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
{
string session;
// <clid> of the cluster to delete from the HostPool
@ -43,19 +43,12 @@ void RequestManager::ClusterDelete::execute(
// Only oneadmin can delete clusters
rc = ClusterDelete::upool->authenticate(session);
if ( rc != 0 )
{
goto error_authenticate;
}
// Check if cluster exists
if ( !ClusterDelete::hpool->exists_cluster(clid) )
{
goto error_cluster;
}
rc = ClusterDelete::hpool->drop_cluster(clid);
if ( rc != 0 )
@ -78,12 +71,8 @@ error_authenticate:
oss << "User not authorized to delete clusters";
goto error_common;
error_cluster:
oss << "Error getting cluster with CLID = " << clid;
goto error_common;
error_cluster_delete:
oss << "Can not delete cluster with CLID " << clid <<
oss << "Can not delete cluster with CLID " << clid <<
" from the ClusterPool, returned error code [" << rc << "]";
goto error_common;

View File

@ -50,16 +50,14 @@ void RequestManager::ClusterInfo::execute(
goto error_authenticate;
}
// Check if cluster exists
rc = ClusterInfo::hpool->exists_cluster(clid);
info = ClusterInfo::hpool->info_cluster(clid);
if ( rc != 0 )
// Cluster does not exists
if ( info.empty() )
{
goto error_cluster;
}
info = ClusterInfo::hpool->info_cluster(clid);
// All nice, return the cluster info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_string(info));

View File

@ -62,7 +62,7 @@ void RequestManager::ClusterRemove::execute(
}
// Remove host from cluster
rc = ClusterRemove::hpool->remove_cluster(host);
rc = ClusterRemove::hpool->set_default_cluster(host);
if ( rc != 0 )
{