mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-22 22:03:39 +03:00
#15 : Brought back threads for HM
git-svn-id: http://svn.opennebula.org/one/trunk@457 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
7a144a8e1e
commit
a0b869996e
@ -19,17 +19,23 @@
|
||||
#define HOOK_MANAGER_H_
|
||||
|
||||
#include "MadManager.h"
|
||||
#include "ActionManager.h"
|
||||
#include "HookManagerDriver.h"
|
||||
#include "VirtualMachinePool.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class HookManager : public MadManager
|
||||
extern "C" void * hm_action_loop(void *arg);
|
||||
|
||||
class HookManager : public MadManager, public ActionListener
|
||||
{
|
||||
public:
|
||||
|
||||
HookManager(vector<const Attribute*>& _mads, VirtualMachinePool * _vmpool)
|
||||
:MadManager(_mads),vmpool(_vmpool){};
|
||||
:MadManager(_mads),vmpool(_vmpool)
|
||||
{
|
||||
am.addListener(this);
|
||||
};
|
||||
|
||||
~HookManager(){};
|
||||
|
||||
@ -38,11 +44,36 @@ public:
|
||||
*/
|
||||
static const char * hook_driver_name;
|
||||
|
||||
/**
|
||||
* This functions starts the associated listener thread, and creates a
|
||||
* new thread for the Hook Manager. This thread will wait in
|
||||
* an action loop till it receives ACTION_FINALIZE.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int start();
|
||||
|
||||
/**
|
||||
* Gets the HookManager thread identification.
|
||||
* @return pthread_t for the manager thread (that in the action loop).
|
||||
*/
|
||||
pthread_t get_thread_id() const
|
||||
{
|
||||
return hm_thread;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void load_mads(int uid=0);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void finalize()
|
||||
{
|
||||
am.trigger(ACTION_FINALIZE,0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a pointer to a Information Manager MAD. The driver is
|
||||
* searched by its name and owned by oneadmin with uid=0.
|
||||
@ -63,7 +94,32 @@ private:
|
||||
/**
|
||||
* Pointer to the VirtualMachine Pool
|
||||
*/
|
||||
VirtualMachinePool * vmpool;
|
||||
VirtualMachinePool * vmpool;
|
||||
|
||||
/**
|
||||
* Thread id for the HookManager
|
||||
*/
|
||||
pthread_t hm_thread;
|
||||
|
||||
/**
|
||||
* Action engine for the Manager
|
||||
*/
|
||||
ActionManager am;
|
||||
|
||||
/**
|
||||
* Function to execute the Manager action loop method within a new pthread
|
||||
* (requires C linkage)
|
||||
*/
|
||||
friend void * hm_action_loop(void *arg);
|
||||
|
||||
/**
|
||||
* The action function executed when an action is triggered.
|
||||
* @param action the name of the action
|
||||
* @param arg arguments for the action function
|
||||
*/
|
||||
void do_action(
|
||||
const string & action,
|
||||
void * arg);
|
||||
};
|
||||
|
||||
#endif /*HOOK_MANAGER_H*/
|
||||
|
@ -23,6 +23,29 @@ const char * HookManager::hook_driver_name = "hook_exe";
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
extern "C" void * hm_action_loop(void *arg)
|
||||
{
|
||||
HookManager * hm;
|
||||
|
||||
if ( arg == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Hook Manager started.");
|
||||
|
||||
hm = static_cast<HookManager *>(arg);
|
||||
|
||||
hm->am.loop(0,0);
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Hook Manager stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void HookManager::load_mads(int uid)
|
||||
{
|
||||
HookManagerDriver * hm_mad;
|
||||
@ -60,3 +83,48 @@ void HookManager::load_mads(int uid)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HookManager::start()
|
||||
{
|
||||
int rc;
|
||||
pthread_attr_t pattr;
|
||||
|
||||
rc = MadManager::start();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Starting Hook Manager...");
|
||||
|
||||
pthread_attr_init (&pattr);
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
rc = pthread_create(&hm_thread,&pattr,hm_action_loop,(void *) this);
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void HookManager::do_action(const string &action, void * arg)
|
||||
{
|
||||
if (action == ACTION_FINALIZE)
|
||||
{
|
||||
Nebula::log("HKM",Log::INFO,"Stopping Hook Manager...");
|
||||
|
||||
MadManager::stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Unknown action name: " << action;
|
||||
|
||||
Nebula::log("HKM", Log::ERROR, oss);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -345,6 +345,13 @@ void Nebula::start()
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
rc = hm->start();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Hook Manager");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Load mads
|
||||
@ -353,7 +360,7 @@ void Nebula::start()
|
||||
sleep(2);
|
||||
|
||||
vmm->load_mads(0);
|
||||
|
||||
|
||||
im->load_mads(0);
|
||||
tm->load_mads(0);
|
||||
hm->load_mads(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user