mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
feature #1678: Send STOPMONITOR action when host is deleted.
This commit is contained in:
parent
f7aa3c503d
commit
55c1399fd2
@ -160,6 +160,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int drop(int hid, string& error_msg);
|
||||
|
||||
int drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
{
|
||||
Host * host = static_cast<Host *>(objsql);
|
||||
|
@ -49,6 +49,21 @@ public:
|
||||
|
||||
~InformationManager(){};
|
||||
|
||||
enum Actions
|
||||
{
|
||||
STOPMONITOR /** Sent by the RM when a host is deleted **/
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggers specific actions to the Information Manager.
|
||||
* @param action the IM action
|
||||
* @param hid Host unique id. This is the argument of the passed to the
|
||||
* invoked action.
|
||||
*/
|
||||
void trigger(
|
||||
Actions action,
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* This functions starts the associated listener thread, and creates a
|
||||
* new thread for the Information Manager. This thread will wait in
|
||||
@ -79,6 +94,8 @@ public:
|
||||
am.trigger(ACTION_FINALIZE,0);
|
||||
};
|
||||
|
||||
void stop_monitor(int hid);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Thread id for the Information Manager
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
*/
|
||||
void recover();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends a monitor request to the MAD: "MONITOR ID HOSTNAME -"
|
||||
* @param oid the virtual machine id.
|
||||
* @param host the hostname
|
||||
@ -67,6 +67,13 @@ public:
|
||||
void monitor(int oid, const string& host, const string& ds_location,
|
||||
bool update) const;
|
||||
|
||||
/**
|
||||
* Sends a stop monitor request to the MAD: "MONITOR ID HOSTNAME -"
|
||||
* @param oid the virtual machine id.
|
||||
* @param host the hostname
|
||||
*/
|
||||
void stop_monitor(int oid, const string& host) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Pointer to the Virtual Machine Pool, to access VMs
|
||||
|
@ -50,7 +50,7 @@ protected:
|
||||
|
||||
bool delete_authorization(int oid,
|
||||
RequestAttributes& att);
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
@ -98,7 +98,7 @@ public:
|
||||
VirtualNetworkDelete():
|
||||
RequestManagerDelete("VirtualNetworkDelete",
|
||||
"Deletes a virtual network")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = PoolObjectSQL::NET;
|
||||
@ -127,7 +127,7 @@ class ImageDelete: public RequestManagerDelete
|
||||
public:
|
||||
ImageDelete():
|
||||
RequestManagerDelete("ImageDelete", "Deletes an image")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = PoolObjectSQL::IMAGE;
|
||||
@ -149,7 +149,7 @@ class HostDelete : public RequestManagerDelete
|
||||
public:
|
||||
HostDelete():
|
||||
RequestManagerDelete("HostDelete", "Deletes a host")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = PoolObjectSQL::HOST;
|
||||
@ -169,6 +169,10 @@ public:
|
||||
{
|
||||
return cluster->del_host(id, error_msg);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -179,7 +183,7 @@ class GroupDelete: public RequestManagerDelete
|
||||
public:
|
||||
GroupDelete():
|
||||
RequestManagerDelete("GroupDelete", "Deletes a group")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
|
||||
@ -202,7 +206,7 @@ class UserDelete: public RequestManagerDelete
|
||||
public:
|
||||
UserDelete():
|
||||
RequestManagerDelete("UserDelete", "Deletes a user")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
gpool = nd.get_gpool();
|
||||
|
@ -21,10 +21,12 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include "Nebula.h"
|
||||
#include "HostPool.h"
|
||||
#include "HostHook.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "GroupPool.h"
|
||||
#include "ClusterPool.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -79,7 +81,7 @@ HostPool::HostPool(SqlDB* db,
|
||||
|
||||
oss << "Empty ON or COMMAND attribute in HOST_HOOK. Hook "
|
||||
<< "not registered!";
|
||||
NebulaLog::log("VM",Log::WARNING,oss);
|
||||
NebulaLog::log("ONE",Log::WARNING,oss);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -228,6 +230,58 @@ error_common:
|
||||
return *oid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::drop(int hid, string& error_msg)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
Host * host;
|
||||
ClusterPool * clpool;
|
||||
|
||||
host = get(hid,true);
|
||||
|
||||
if (host == 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Could not get host " << hid;
|
||||
error_msg = oss.str();
|
||||
return -1;
|
||||
}
|
||||
|
||||
clpool = nd.get_clpool();
|
||||
|
||||
int cluster_id = host->get_cluster_id();
|
||||
|
||||
int rc = drop(host, error_msg);
|
||||
|
||||
host->unlock();
|
||||
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID && rc == 0 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -119,6 +119,29 @@ int InformationManager::start()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void InformationManager::trigger(Actions action, int _hid)
|
||||
{
|
||||
int * hid;
|
||||
string aname;
|
||||
|
||||
hid = new int(_hid);
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case STOPMONITOR:
|
||||
aname = "STOPMONITOR";
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
am.trigger(aname,hid);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void InformationManager::do_action(const string &action, void * arg)
|
||||
{
|
||||
if (action == ACTION_TIMER)
|
||||
@ -131,6 +154,13 @@ void InformationManager::do_action(const string &action, void * arg)
|
||||
|
||||
MadManager::stop();
|
||||
}
|
||||
else if (action == "STOPMONITOR")
|
||||
{
|
||||
int hid = *(static_cast<int *>(arg));
|
||||
delete static_cast<int *>(arg);
|
||||
|
||||
stop_monitor(hid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
@ -143,6 +173,44 @@ void InformationManager::do_action(const string &action, void * arg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void InformationManager::stop_monitor(int hid)
|
||||
{
|
||||
Host * host;
|
||||
|
||||
const InformationManagerDriver * imd;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
host = hpool->get(hid,true);
|
||||
|
||||
if (host == 0)
|
||||
{
|
||||
oss.str("");
|
||||
oss << "Could get host " << hid;
|
||||
NebulaLog::log("InM",Log::ERROR,oss);
|
||||
return;
|
||||
}
|
||||
|
||||
imd = get(host->get_im_mad());
|
||||
|
||||
if (imd == 0)
|
||||
{
|
||||
oss.str("");
|
||||
oss << "Could not find information driver " << host->get_im_mad();
|
||||
NebulaLog::log("InM",Log::ERROR,oss);
|
||||
|
||||
host->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
imd->stop_monitor(hid, host->get_name());
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void InformationManager::timer_action()
|
||||
{
|
||||
static int mark = 0;
|
||||
|
@ -51,6 +51,15 @@ void InformationManagerDriver::monitor(int oid,
|
||||
write(os);
|
||||
}
|
||||
|
||||
void InformationManagerDriver::stop_monitor(int oid, const string& host) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "STOPMONITOR " << oid << " " << host << " " << endl;
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -281,7 +290,34 @@ void InformationManagerDriver::protocol(const string& message) const
|
||||
getline(is,info);
|
||||
NebulaLog::log("InM",log_type(result[0]),info.c_str());
|
||||
}
|
||||
else if (action == "STOPMONITOR")
|
||||
{
|
||||
if (result != "SUCCESS")
|
||||
{
|
||||
host = hpool->get(id,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host;
|
||||
}
|
||||
|
||||
host->set_error();
|
||||
hpool->update(host);
|
||||
host->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
string error_message;
|
||||
int rc = hpool->drop(id, error_message);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Could not delete host " << id << " " << error_message;
|
||||
NebulaLog::log("InM",Log::ERROR,oss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
error_host:
|
||||
|
@ -80,12 +80,12 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
object = pool->get(oid,true);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object), oid),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int rc = drop(oid, object, error_msg);
|
||||
|
||||
@ -144,6 +144,28 @@ int RequestManagerDelete::drop(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int HostDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
|
||||
InformationManager * im = nd.get_im();
|
||||
HostPool * hpool = nd.get_hpool();
|
||||
|
||||
Host * host = static_cast<Host *>(object);
|
||||
|
||||
host->disable();
|
||||
hpool->update(host);
|
||||
host->unlock();
|
||||
|
||||
im->trigger(InformationManager::STOPMONITOR,oid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
@ -167,7 +189,7 @@ int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
if ( ds == 0 )
|
||||
{
|
||||
error_msg = "Datastore no longer exists cannot remove image";
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user