2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2013-01-24 19:18:30 +04:00
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
2008-06-17 20:27:32 +04:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
# ifndef INFORMATION_MANAGER_H_
# define INFORMATION_MANAGER_H_
# include "MadManager.h"
# include "ActionManager.h"
# include "InformationManagerDriver.h"
# include "HostPool.h"
using namespace std ;
extern " C " void * im_action_loop ( void * arg ) ;
class InformationManager : public MadManager , public ActionListener
{
public :
InformationManager (
HostPool * _hpool ,
time_t _timer_period ,
time_t _monitor_period ,
2011-08-16 20:12:45 +04:00
int _host_limit ,
2010-08-17 02:28:48 +04:00
const string & _remotes_location ,
2008-06-17 20:27:32 +04:00
vector < const Attribute * > & _mads )
: MadManager ( _mads ) ,
hpool ( _hpool ) ,
timer_period ( _timer_period ) ,
2010-08-17 02:28:48 +04:00
monitor_period ( _monitor_period ) ,
2011-08-16 20:12:45 +04:00
host_limit ( _host_limit ) ,
2010-08-17 02:28:48 +04:00
remotes_location ( _remotes_location )
2008-06-17 20:27:32 +04:00
{
am . addListener ( this ) ;
} ;
~ InformationManager ( ) { } ;
2013-10-25 19:52:56 +04:00
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 ) ;
2008-06-17 20:27:32 +04:00
/**
2010-08-17 02:28:48 +04:00
* This functions starts the associated listener thread , and creates a
2008-06-17 20:27:32 +04:00
* new thread for the Information Manager . This thread will wait in
* an action loop till it receives ACTION_FINALIZE .
* @ return 0 on success .
*/
int start ( ) ;
/**
* Gets the thread identification .
* @ return pthread_t for the manager thread ( that in the action loop ) .
*/
pthread_t get_thread_id ( ) const
{
return im_thread ;
} ;
/**
2010-08-17 02:28:48 +04:00
*
2008-06-17 20:27:32 +04:00
*/
2013-10-25 17:16:44 +04:00
int load_mads ( int uid = 0 ) ;
2008-06-17 20:27:32 +04:00
/**
2010-08-17 02:28:48 +04:00
*
2008-06-17 20:27:32 +04:00
*/
void finalize ( )
{
am . trigger ( ACTION_FINALIZE , 0 ) ;
} ;
2013-10-25 19:52:56 +04:00
void stop_monitor ( int hid ) ;
2008-06-17 20:27:32 +04:00
private :
/**
* Thread id for the Information Manager
*/
pthread_t im_thread ;
/**
* Pointer to the Host Pool , to access hosts
*/
HostPool * hpool ;
/**
* Timer period for the Virtual Machine Manager .
*/
time_t timer_period ;
2010-08-17 02:28:48 +04:00
2008-06-17 20:27:32 +04:00
/**
* Host monitoring interval
*/
time_t monitor_period ;
2010-08-17 02:28:48 +04:00
2011-08-16 20:12:45 +04:00
/**
* Host monitoring limit
*/
int host_limit ;
2010-08-17 02:28:48 +04:00
/**
* Path for the remote action programs
*/
string remotes_location ;
2008-06-17 20:27:32 +04:00
/**
* Action engine for the Manager
*/
ActionManager am ;
/**
2010-08-17 02:28:48 +04:00
* Function to execute the Manager action loop method within a new pthread
2008-06-17 20:27:32 +04:00
* ( requires C linkage )
*/
friend void * im_action_loop ( void * arg ) ;
2012-05-18 02:14:18 +04:00
/**
2013-02-14 18:26:30 +04:00
* Time in seconds to expire a monitoring action ( 5 minutes )
2012-05-18 02:14:18 +04:00
*/
static const time_t monitor_expire ;
2008-06-17 20:27:32 +04:00
/**
2010-08-17 02:28:48 +04:00
* Returns a pointer to a Information Manager MAD . The driver is
2008-06-17 20:27:32 +04:00
* searched by its name and owned by gwadmin with uid = 0.
* @ param name of the driver
2010-08-17 02:28:48 +04:00
* @ return the VM driver owned by uid 0 , with attribute " NAME " equal to
2008-06-17 20:27:32 +04:00
* name or 0 in not found
*/
const InformationManagerDriver * get (
const string & name )
{
string _name ( " NAME " ) ;
return static_cast < const InformationManagerDriver * >
( MadManager : : get ( 0 , _name , name ) ) ;
} ;
/**
* 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 ) ;
/**
* This function is executed periodically to monitor Nebula hosts .
*/
void timer_action ( ) ;
} ;
# endif /*VIRTUAL_MACHINE_MANAGER_H*/