1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-13 12:58:17 +03:00

Feature #4369: Force Hosts to be always part of one cluster

This way cluster none (-1) disappears outside of the core
This commit is contained in:
Carlos Martín 2016-03-16 13:31:10 +01:00
parent b715c4f773
commit 400e18964c
6 changed files with 119 additions and 152 deletions

View File

@ -183,7 +183,7 @@ public:
{
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
int cluster_id = ClusterPool::DEFAULT_CLUSTER_ID;
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att);

View File

@ -220,24 +220,21 @@ void InformationManager::stop_monitor(int hid)
// -------------------------------------------------------------------------
// Remove host from cluster
// -------------------------------------------------------------------------
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
Cluster * cluster = clpool->get(cluster_id, true);
if( cluster != 0 )
{
Cluster * cluster = clpool->get(cluster_id, true);
rc = cluster->del_host(hid, error_msg);
if( cluster != 0 )
if ( rc < 0 )
{
rc = cluster->del_host(hid, error_msg);
if ( rc < 0 )
{
cluster->unlock();
return;
}
clpool->update(cluster);
cluster->unlock();
return;
}
clpool->update(cluster);
cluster->unlock();
}
}

View File

@ -204,19 +204,12 @@ void RequestManagerClusterHost::add_generic(
int old_cluster_id;
string old_cluster_name;
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms,
cluster_name, true);
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms,
cluster_name, true);
if ( rc == -1 )
{
return;
}
}
else
if ( rc == -1 )
{
cluster_name = ClusterPool::NONE_CLUSTER_NAME;
return;
}
rc = get_info(hpool, host_id, PoolObjectSQL::HOST, att, obj_perms, obj_name, true);
@ -230,11 +223,7 @@ void RequestManagerClusterHost::add_generic(
{
AuthRequest ar(att.uid, att.group_ids);
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
}
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN HOST
if (UserPool::authorize(ar) == -1)
@ -274,85 +263,79 @@ void RequestManagerClusterHost::add_generic(
host->unlock();
// ------------- Add object to new cluster ---------------------
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
cluster = clpool->get(cluster_id, true);
if ( cluster == 0 )
{
cluster = clpool->get(cluster_id, true);
att.resp_obj = PoolObjectSQL::CLUSTER;
att.resp_id = cluster_id;
failure_response(NO_EXISTS, att);
if ( cluster == 0 )
// Rollback
host = hpool->get(host_id, true);
if ( host != 0 )
{
att.resp_obj = PoolObjectSQL::CLUSTER;
att.resp_id = cluster_id;
failure_response(NO_EXISTS, att);
host->set_cluster(old_cluster_id, old_cluster_name);
// Rollback
host = hpool->get(host_id, true);
hpool->update(host);
if ( host != 0 )
{
host->set_cluster(old_cluster_id, old_cluster_name);
hpool->update(host);
host->unlock();
}
return;
host->unlock();
}
if ( cluster->add_host(host_id, att.resp_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL, att);
// Rollback
host = hpool->get(host_id, true);
if ( host != 0 )
{
host->set_cluster(old_cluster_id, old_cluster_name);
hpool->update(host);
host->unlock();
}
return;
}
clpool->update(cluster);
cluster->unlock();
return;
}
if ( cluster->add_host(host_id, att.resp_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL, att);
// Rollback
host = hpool->get(host_id, true);
if ( host != 0 )
{
host->set_cluster(old_cluster_id, old_cluster_name);
hpool->update(host);
host->unlock();
}
return;
}
clpool->update(cluster);
cluster->unlock();
// ------------- Remove host from old cluster ---------------------
if ( old_cluster_id != ClusterPool::NONE_CLUSTER_ID )
cluster = clpool->get(old_cluster_id, true);
if ( cluster == 0 )
{
cluster = clpool->get(old_cluster_id, true);
if ( cluster == 0 )
{
// This point should be unreachable.
// The old cluster is not empty (at least has the host_id),
// so it cannot be deleted
success_response(cluster_id, att);
return;
}
if ( cluster->del_host(host_id, att.resp_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL, att);
return;
}
clpool->update(cluster);
cluster->unlock();
// This point should be unreachable.
// The old cluster is not empty (at least has the host_id),
// so it cannot be deleted
success_response(cluster_id, att);
return;
}
if ( cluster->del_host(host_id, att.resp_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL, att);
return;
}
clpool->update(cluster);
cluster->unlock();
success_response(cluster_id, att);
return;

View File

@ -123,24 +123,21 @@ int RequestManagerDelete::drop(
{
for(set<int>::iterator it=cluster_ids.begin(); it!=cluster_ids.end(); it++)
{
if ( *it != ClusterPool::NONE_CLUSTER_ID )
Cluster * cluster = clpool->get(*it, true);
if( cluster != 0 )
{
Cluster * cluster = clpool->get(*it, true);
rc = del_from_cluster(cluster, oid, error_msg);
if( cluster != 0 )
if ( rc < 0 )
{
rc = del_from_cluster(cluster, oid, error_msg);
if ( rc < 0 )
{
cluster->unlock();
return rc;
}
clpool->update(cluster);
cluster->unlock();
return rc;
}
clpool->update(cluster);
cluster->unlock();
}
}
}

View File

@ -224,44 +224,37 @@ int RequestManagerVirtualMachine::get_default_ds_information(
ds_id = -1;
if (cluster_id == ClusterPool::NONE_CLUSTER_ID)
cluster = clpool->get(cluster_id, true);
if (cluster == 0)
{
ds_id = DatastorePool::SYSTEM_DS_ID;
att.resp_obj = PoolObjectSQL::CLUSTER;
att.resp_id = cluster_id;
failure_response(NO_EXISTS, att);
return -1;
}
else
set<int> ds_ids = cluster->get_datastores();
cluster->unlock();
ds_id = Cluster::get_default_system_ds(ds_ids);
if (ds_id == -1)
{
cluster = clpool->get(cluster_id, true);
ostringstream oss;
if (cluster == 0)
{
att.resp_obj = PoolObjectSQL::CLUSTER;
att.resp_id = cluster_id;
failure_response(NO_EXISTS, att);
oss << object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id
<< "] does not have any " << object_name(PoolObjectSQL::DATASTORE)
<< " of type " << Datastore::type_to_str(Datastore::SYSTEM_DS)
<< ".";
return -1;
}
att.resp_msg = oss.str();
set<int> ds_ids = cluster->get_datastores();
failure_response(ACTION, att);
cluster->unlock();
ds_id = Cluster::get_default_system_ds(ds_ids);
if (ds_id == -1)
{
ostringstream oss;
oss << object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id
<< "] does not have any " << object_name(PoolObjectSQL::DATASTORE)
<< " of type " << Datastore::type_to_str(Datastore::SYSTEM_DS)
<< ".";
att.resp_msg = oss.str();
failure_response(ACTION, att);
return -1;
}
return -1;
}
set<int> ds_cluster_ids;

View File

@ -112,23 +112,20 @@ void HostPoolXML::merge_clusters(ClusterPoolXML * clpool)
cluster_id = host->get_cid();
if(cluster_id != -1) //ClusterPool::NONE_CLUSTER_ID
cluster = clpool->get(cluster_id);
if(cluster != 0)
{
cluster = clpool->get(cluster_id);
nodes.clear();
if(cluster != 0)
cluster->get_nodes("/CLUSTER/TEMPLATE", nodes);
if (!nodes.empty())
{
nodes.clear();
cluster->get_nodes("/CLUSTER/TEMPLATE", nodes);
if (!nodes.empty())
{
host->add_node("/HOST", nodes[0], "CLUSTER_TEMPLATE");
}
cluster->free_nodes(nodes);
host->add_node("/HOST", nodes[0], "CLUSTER_TEMPLATE");
}
cluster->free_nodes(nodes);
}
}
}