1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-22 17:57:46 +03:00

feature #1613: Add datastore monitor action call to OpenNebula core

This commit is contained in:
Ruben S. Montero 2013-06-27 01:34:31 +02:00
parent d32c736b5c
commit 9da1385ebc
5 changed files with 116 additions and 6 deletions

View File

@ -32,8 +32,14 @@ class ImageManager : public MadManager, public ActionListener
{
public:
ImageManager(ImagePool * _ipool, vector<const Attribute*>& _mads):
MadManager(_mads), ipool(_ipool)
ImageManager(time_t _timer_period,
time_t _monitor_period,
ImagePool * _ipool,
vector<const Attribute*>& _mads):
MadManager(_mads),
timer_period(_timer_period),
monitor_period(_monitor_period),
ipool(_ipool)
{
am.addListener(this);
};
@ -181,10 +187,20 @@ private:
static const char * image_driver_name;
/**
* Thread id for the Transfer Manager
* Thread id for the Image Manager
*/
pthread_t imagem_thread;
/**
* Timer period for the Image Manager.
*/
time_t timer_period;
/**
* Datastore Monitor Interval
*/
time_t monitor_period;
/**
* Pointer to the Image Pool to access VMs
*/
@ -242,6 +258,11 @@ private:
* @return the XML message
*/
string * format_message(const string& img_data, const string& ds_data);
/**
* This function is executed periodically to monitor Datastores.
*/
void timer_action();
};
#endif /*IMAGE_MANAGER_H*/

View File

@ -99,6 +99,13 @@ private:
* @param drv_msg xml data for the mad operation.
*/
void rm(int oid, const string& drv_msg) const;
/**
* Sends a monitor request to the MAD: "MONITOR DS_ID DS_XML"
* @param oid the datastore id.
* @param drv_msg xml data for the mad operation.
*/
void monitor(int oid, const string& drv_msg) const;
};
/* -------------------------------------------------------------------------- */

View File

@ -17,6 +17,7 @@
#include "ImageManager.h"
#include "NebulaLog.h"
#include "ImagePool.h"
#include "Nebula.h"
const char * ImageManager::image_driver_name = "image_exe";
@ -36,7 +37,7 @@ extern "C" void * image_action_loop(void *arg)
im = static_cast<ImageManager *>(arg);
im->am.loop(0,0);
im->am.loop(im->timer_period, 0);
NebulaLog::log("ImM",Log::INFO,"Image Manager stopped.");
@ -113,7 +114,11 @@ int ImageManager::start()
void ImageManager::do_action(const string &action, void * arg)
{
if (action == ACTION_FINALIZE)
if (action == ACTION_TIMER)
{
timer_action();
}
else if (action == ACTION_FINALIZE)
{
NebulaLog::log("ImM",Log::INFO,"Stopping Image Manager...");
MadManager::stop();
@ -126,3 +131,69 @@ void ImageManager::do_action(const string &action, void * arg)
NebulaLog::log("ImM", Log::ERROR, oss);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ImageManager::timer_action()
{
static int mark = 0;
static int tics = 0;
mark += timer_period;
tics += timer_period;
if ( mark >= 600 )
{
NebulaLog::log("ImM",Log::INFO,"--Mark--");
mark = 0;
}
if ( tics < monitor_period )
{
return;
}
tics = 0;
int rc;
vector<int> datastores;
vector<int>::iterator it;
Nebula& nd = Nebula::instance();
DatastorePool * dspool = nd.get_dspool();
rc = dspool->list(datastores);
if ( rc != 0 )
{
return;
}
const ImageManagerDriver* imd = get();
for(it = datastores.begin() ; it != datastores.end(); it++)
{
string ds_data;
string* drv_msg;
Datastore * ds = dspool->get(*it, true);
if ( ds == 0 )
{
continue;
}
drv_msg = format_message("", ds->to_xml(ds_data));
ds->unlock();
imd->monitor(*it, *drv_msg);
delete drv_msg;
}
return;
}

View File

@ -82,6 +82,17 @@ void ImageManagerDriver::rm(int oid, const string& drv_msg) const
write(os);
}
/* -------------------------------------------------------------------------- */
void ImageManagerDriver::monitor(int oid, const string& drv_msg) const
{
ostringstream os;
os << "MONITOR " << oid << " " << drv_msg << endl;
write(os);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -836,7 +836,7 @@ void Nebula::start()
nebula_configuration->get("DATASTORE_MAD", image_mads);
imagem = new ImageManager(ipool,image_mads);
imagem = new ImageManager(timer_period,monitor_period,ipool,image_mads);
}
catch (bad_alloc&)
{