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

Feature #1112: Move host to cluster addition from Host::allocate to RMAllocate

This commit is contained in:
Carlos Martín 2012-02-29 12:50:26 +01:00
parent bc6f8630bf
commit 6ee5900bf6
2 changed files with 37 additions and 30 deletions

View File

@ -25,7 +25,6 @@
#include "HostHook.h"
#include "NebulaLog.h"
#include "GroupPool.h"
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -158,14 +157,9 @@ int HostPool::allocate (
const string& cluster_name,
string& error_str)
{
Nebula& nd = Nebula::instance();
Host * host;
ostringstream oss;
ClusterPool * clpool;
Cluster * cluster;
if ( hostname.empty() )
{
goto error_name;
@ -213,32 +207,8 @@ int HostPool::allocate (
*oid = PoolSQL::allocate(host, error_str);
if ( *oid < 0 )
{
return *oid;
}
// Add Host to Cluster
clpool = nd.get_clpool();
cluster = clpool->get(cluster_id, true);
if( cluster == 0 )
{
return -1;
}
if ( cluster->add_host(*oid, error_str) < 0 )
{
return -1;
}
clpool->update(cluster);
cluster->unlock();
return *oid;
error_name:
oss << "NAME cannot be empty.";
goto error_common;

View File

@ -325,6 +325,7 @@ void HostAllocate::request_execute(
Nebula& nd = Nebula::instance();
Cluster * cluster = 0;
ClusterPool * clpool = nd.get_clpool();
HostPool * hpool = static_cast<HostPool *>(pool);
@ -365,6 +366,42 @@ void HostAllocate::request_execute(
return;
}
// ------------- Add Host to Cluster --------------------------------------
cluster = clpool->get(cluster_id, true);
if ( cluster == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::CLUSTER), cluster_id), att);
return;
}
rc = cluster->add_host(id, error_str);
if ( rc < 0 )
{
string drop_err;
Host * host = 0;
cluster->unlock();
host = hpool->get(id, true);
if ( host != 0 )
{
hpool->drop(host, drop_err);
host->unlock();
}
failure_response(INTERNAL, allocate_error(error_str), att);
return;
}
clpool->update(cluster);
cluster->unlock();
success_response(id, att);
}