1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-08-11 21:49:27 +03:00

Feature #1112: Cluster does not inherit from ObjectCollection, instead it now contains 3 collections for hosts, DS and vnets

This commit is contained in:
Carlos Martín
2012-02-27 14:55:43 +01:00
parent 11f0c3d06b
commit 85caad3a1e
5 changed files with 52 additions and 16 deletions

View File

@ -25,7 +25,7 @@ using namespace std;
/**
* The Cluster class.
*/
class Cluster : public PoolObjectSQL, ObjectCollection
class Cluster : public PoolObjectSQL
{
public:
@ -44,6 +44,15 @@ public:
*/
int from_xml(const string &xml_str);
/**
* Checks if all the collections are empty, and therefore this cluster
* can be dropped.
*
* @param error_msg Error message, if any.
* @return 0 if cluster can be dropped, -1 otherwise
*/
int check_drop(string& error_msg);
/**
* Adds this user's ID to the set.
* @param id of the user to be added to the cluster
@ -51,7 +60,7 @@ public:
*/
int add_host(int id)
{
return add_collection_id(id);
return hosts.add_collection_id(id);
}
/**
@ -61,7 +70,7 @@ public:
*/
int del_host(int id)
{
return del_collection_id(id);
return hosts.del_collection_id(id);
}
private:
@ -78,10 +87,20 @@ private:
Cluster(int id, const string& name):
PoolObjectSQL(id,CLUSTER,name,-1,-1,"","",table),
ObjectCollection("HOSTS"){};
hosts("HOSTS"),
images("DATASTORES"),
vnets("VNETS"){};
virtual ~Cluster(){};
// *************************************************************************
// Object Collections (Private)
// *************************************************************************
ObjectCollection hosts;
ObjectCollection images;
ObjectCollection vnets;
// *************************************************************************
// DataBase implementation (Private)
// *************************************************************************

View File

@ -28,7 +28,7 @@ using namespace std;
*/
class ObjectCollection
{
protected:
public:
ObjectCollection(const string& _collection_name)
:collection_name(_collection_name){};

View File

@ -33,6 +33,26 @@ const char * Cluster::db_bootstrap = "CREATE TABLE IF NOT EXISTS cluster_pool ("
"gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, "
"UNIQUE(name))";
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Cluster::check_drop(string& error_msg)
{
ostringstream oss;
if ( hosts.get_collection_size() > 0 )
{
oss << "Cluster " << oid << " is not empty, it contains "
<< hosts.get_collection_size() << " hosts.";
error_msg = oss.str();
return -1;
}
return 0;
}
/* ************************************************************************ */
/* Cluster :: Database Access Functions */
/* ************************************************************************ */
@ -130,13 +150,11 @@ string& Cluster::to_xml(string& xml) const
ostringstream oss;
string collection_xml;
ObjectCollection::to_xml(collection_xml);
oss <<
"<CLUSTER>" <<
"<CLUSTER>" <<
"<ID>" << oid << "</ID>" <<
"<NAME>" << name << "</NAME>" <<
collection_xml <<
hosts.to_xml(collection_xml) <<
"</CLUSTER>";
xml = oss.str();
@ -174,7 +192,7 @@ int Cluster::from_xml(const string& xml)
}
// Set of IDs
rc += ObjectCollection::from_xml_node(content[0]);
rc += hosts.from_xml_node(content[0]);
ObjectXML::free_nodes(content);

View File

@ -53,7 +53,7 @@ ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table)
set_update_lastOID(99);
}
return;
error_bootstrap:
@ -68,7 +68,7 @@ error_bootstrap:
int ClusterPool::allocate(string name, int * oid, string& error_str)
{
Cluster * cluster;
Cluster * cluster;
ostringstream oss;
if ( name.empty() )
@ -132,11 +132,8 @@ int ClusterPool::drop(PoolObjectSQL * objsql, string& error_msg)
return -2;
}
if( cluster->get_collection_size() > 0 )
if ( cluster->check_drop(error_msg) < 0 )
{
ostringstream oss;
oss << "Cluster " << cluster->get_oid() << " is not empty.";
error_msg = oss.str();
NebulaLog::log("CLUSTER", Log::ERROR, error_msg);
return -3;

View File

@ -321,6 +321,8 @@ int HostAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
int cluster_id = ClusterPool::DEFAULT_CLUSTER_ID;
string cluster_name = ClusterPool::DEFAULT_CLUSTER_NAME;
// TODO: Add to auth request CLUSTER MANAGE or ADMIN
HostPool * hpool = static_cast<HostPool *>(pool);
return hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad,