mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
feature #1678: Remove host right before sending the STOPMONITOR action to driver
This commit is contained in:
parent
4815b93f22
commit
9837e7c93a
@ -160,8 +160,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int drop(int hid, string& error_msg);
|
||||
|
||||
int drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
{
|
||||
Host * host = static_cast<Host *>(objsql);
|
||||
|
@ -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<const Attribute*>& _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.
|
||||
*/
|
||||
|
@ -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<int> * discovered_hosts;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -153,6 +153,7 @@ int HostDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
|
||||
Host* host = static_cast<Host *>(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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user