diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index bd72115061..3ead792f4c 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -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; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 909bfcfcc4..cf16784fb3 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -325,6 +325,7 @@ void HostAllocate::request_execute( Nebula& nd = Nebula::instance(); + Cluster * cluster = 0; ClusterPool * clpool = nd.get_clpool(); HostPool * hpool = static_cast(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); }