diff --git a/include/HostPool.h b/include/HostPool.h index 2c270c7461..8ccb539097 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -160,8 +160,6 @@ public: } }; - int drop(int hid, string& error_msg); - int drop(PoolObjectSQL * objsql, string& error_msg) { Host * host = static_cast(objsql); diff --git a/include/InformationManager.h b/include/InformationManager.h index 59ff6a5d95..985a7739cd 100644 --- a/include/InformationManager.h +++ b/include/InformationManager.h @@ -20,18 +20,21 @@ #include "MadManager.h" #include "ActionManager.h" #include "InformationManagerDriver.h" -#include "HostPool.h" using namespace std; extern "C" void * im_action_loop(void *arg); +class HostPool; +class ClusterPool; + class InformationManager : public MadManager, public ActionListener { public: InformationManager( HostPool * _hpool, + ClusterPool * _clpool, time_t _timer_period, time_t _monitor_period, time_t _monitor_push_period, @@ -40,6 +43,7 @@ public: vector& _mads) :MadManager(_mads), hpool(_hpool), + clpool(_clpool), timer_period(_timer_period), monitor_period(_monitor_period), monitor_push_period(_monitor_push_period), @@ -105,10 +109,15 @@ private: pthread_t im_thread; /** - * Pointer to the Host Pool, to access hosts + * Pointer to the Host Pool */ HostPool * hpool; + /** + * Pointer to the Cluster Pool + */ + ClusterPool * clpool; + /** * Timer period for the Virtual Machine Manager. */ diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index acfc064856..08a4cda7ed 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -233,54 +233,6 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int HostPool::drop(int hid, string& error_msg) -{ - Host * host = get(hid,true); - - if (host == 0) - { - ostringstream oss; - oss << "Could not get host " << hid; - error_msg = oss.str(); - - return -1; - } - - int cluster_id = host->get_cluster_id(); - - int rc = drop(host, error_msg); - - host->unlock(); - - if ( cluster_id != ClusterPool::NONE_CLUSTER_ID && rc == 0 ) - { - Nebula& nd = Nebula::instance(); - - ClusterPool * clpool = nd.get_clpool(); - Cluster * cluster = clpool->get(cluster_id, true); - - if( cluster != 0 ) - { - rc = cluster->del_host(hid, error_msg); - - if ( rc < 0 ) - { - cluster->unlock(); - return rc; - } - - clpool->update(cluster); - - cluster->unlock(); - } - } - - return rc; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - int HostPool::discover_cb(void * _set, int num, char **values, char **names) { set * discovered_hosts; diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 4e2d8b46c5..17e2ae44ad 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -176,6 +176,12 @@ void InformationManager::do_action(const string &action, void * arg) void InformationManager::stop_monitor(int hid) { + string error_msg; + int rc; + + // ------------------------------------------------------------------------- + // Drop host from DB + // ------------------------------------------------------------------------- Host * host = hpool->get(hid,true); if (host == 0) //Already deleted silently return @@ -183,25 +189,56 @@ void InformationManager::stop_monitor(int hid) return; } - const InformationManagerDriver * imd = get(host->get_im_mad()); + int cluster_id = host->get_cluster_id(); + string im_mad = host->get_im_mad(); - if (imd == 0) //No IM Driver to call, delete host. + rc = hpool->drop(host, error_msg); + + host->unlock(); + + if (rc != 0) //Error (a VM has been allocated or DB error) { - string error_str; + ostringstream oss; - hpool->drop(host, error_str); + oss << "Could not delete host " << hid << ": " << error_msg; - if (!error_str.empty()) - { - NebulaLog::log("InM", Log::ERROR, error_str); - } + NebulaLog::log("InM", Log::ERROR, oss); + + return; } - else + + // ------------------------------------------------------------------------- + // Send STOPMONITOR to the IM driver if defined + // ------------------------------------------------------------------------- + const InformationManagerDriver * imd = get(im_mad); + + if (imd != 0) { imd->stop_monitor(hid, host->get_name()); } - host->unlock(); + // ------------------------------------------------------------------------- + // Remove host from cluster + // ------------------------------------------------------------------------- + if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) + { + Cluster * cluster = clpool->get(cluster_id, true); + + if( cluster != 0 ) + { + rc = cluster->del_host(hid, error_msg); + + if ( rc < 0 ) + { + cluster->unlock(); + return; + } + + clpool->update(cluster); + + cluster->unlock(); + } + } } /* -------------------------------------------------------------------------- */ diff --git a/src/im/InformationManagerDriver.cc b/src/im/InformationManagerDriver.cc index ddfb718401..3cd43d7a54 100644 --- a/src/im/InformationManagerDriver.cc +++ b/src/im/InformationManagerDriver.cc @@ -294,7 +294,6 @@ void InformationManagerDriver::protocol(const string& message) const } else if (action == "STOPMONITOR") { - int rc; string error; if (result != "SUCCESS") @@ -307,16 +306,6 @@ void InformationManagerDriver::protocol(const string& message) const oss << "Could not stop monitor on host " << id << " " << info; NebulaLog::log("InM", Log::ERROR, oss.str()); } - - rc = hpool->drop(id, error); - - if (rc != 0) - { - ostringstream oss; - - oss << "Could not delete host " << id << " " << error; - NebulaLog::log("InM",Log::ERROR,oss.str()); - } } return; diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index e95b4d1c32..73ee813381 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -722,6 +722,7 @@ void Nebula::start(bool bootstrap_only) nebula_configuration->get("IM_MAD", im_mads); im = new InformationManager(hpool, + clpool, timer_period, monitor_period, monitor_push_period, diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index f635c007a1..b29f5d7ee9 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -153,6 +153,7 @@ int HostDelete::drop(int oid, PoolObjectSQL * object, string& error_msg) Host* host = static_cast(object); + //Do not trigger delete event on IM if there are VMs running on the host if ( host->get_share_running_vms() > 0 ) { error_msg = "Can not remove a host with running VMs";