2008-06-17 16:27:32 +00:00
/* -------------------------------------------------------------------------- */
2019-01-16 11:27:59 +01:00
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
2008-06-17 16:27:32 +00: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"
2013-11-18 18:17:16 +01:00
# include "MonitorThread.h"
2017-02-03 14:19:15 +01:00
# include "NebulaLog.h"
2008-06-17 16:27:32 +00:00
using namespace std ;
extern " C " void * im_action_loop ( void * arg ) ;
2013-11-05 19:20:28 +01:00
class HostPool ;
class ClusterPool ;
2016-04-12 00:33:09 +02:00
class Host ;
2013-11-05 19:20:28 +01:00
2008-06-17 16:27:32 +00:00
class InformationManager : public MadManager , public ActionListener
{
public :
InformationManager (
HostPool * _hpool ,
2013-11-05 19:20:28 +01:00
ClusterPool * _clpool ,
2008-06-17 16:27:32 +00:00
time_t _timer_period ,
time_t _monitor_period ,
2011-08-16 18:12:45 +02:00
int _host_limit ,
2013-11-18 18:17:16 +01:00
int _monitor_threads ,
2010-08-17 00:28:48 +02:00
const string & _remotes_location ,
2016-02-04 13:10:42 +01:00
vector < const VectorAttribute * > & _mads )
2008-06-17 16:27:32 +00:00
: MadManager ( _mads ) ,
hpool ( _hpool ) ,
2013-11-05 19:20:28 +01:00
clpool ( _clpool ) ,
2008-06-17 16:27:32 +00:00
timer_period ( _timer_period ) ,
2010-08-17 00:28:48 +02:00
monitor_period ( _monitor_period ) ,
2011-08-16 18:12:45 +02:00
host_limit ( _host_limit ) ,
2013-11-18 18:17:16 +01:00
remotes_location ( _remotes_location ) ,
mtpool ( _monitor_threads )
2008-06-17 16:27:32 +00:00
{
am . addListener ( this ) ;
} ;
~ InformationManager ( ) { } ;
/**
2010-08-17 00:28:48 +02:00
* This functions starts the associated listener thread , and creates a
2008-06-17 16:27:32 +00: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 00:28:48 +02:00
*
2008-06-17 16:27:32 +00:00
*/
void finalize ( )
{
2017-02-03 14:19:15 +01:00
am . finalize ( ) ;
2008-06-17 16:27:32 +00:00
} ;
2016-04-12 00:33:09 +02:00
/**
* Load the information drivers
* @ return 0 on success
*/
int load_mads ( int uid = 0 ) ;
/**
* Sends a STOPMONITR command to the associated driver and host
* @ param hid the host id
* @ param name of the host
* @ param im_mad the driver name
*/
void stop_monitor ( int hid , const string & name , const string & im_mad )
{
const InformationManagerDriver * imd = get ( im_mad ) ;
if ( imd ! = 0 )
{
imd - > stop_monitor ( hid , name ) ;
}
}
/**
* Starts the monitor process on the host
* @ param host to monitor
* @ param update_remotes to copy the monitor probes to the host
* @ return 0 on success
*/
int start_monitor ( Host * host , bool update_remotes ) ;
2013-10-25 17:52:56 +02:00
2008-06-17 16:27:32 +00:00
private :
/**
* Thread id for the Information Manager
*/
pthread_t im_thread ;
/**
2013-11-05 19:20:28 +01:00
* Pointer to the Host Pool
2008-06-17 16:27:32 +00:00
*/
HostPool * hpool ;
2013-11-05 19:20:28 +01:00
/**
* Pointer to the Cluster Pool
*/
ClusterPool * clpool ;
2008-06-17 16:27:32 +00:00
/**
* Timer period for the Virtual Machine Manager .
*/
time_t timer_period ;
2010-08-17 00:28:48 +02:00
2008-06-17 16:27:32 +00:00
/**
* Host monitoring interval
*/
time_t monitor_period ;
2010-08-17 00:28:48 +02:00
2011-08-16 18:12:45 +02:00
/**
* Host monitoring limit
*/
int host_limit ;
2010-08-17 00:28:48 +02:00
/**
* Path for the remote action programs
*/
string remotes_location ;
2008-06-17 16:27:32 +00:00
/**
* Action engine for the Manager
*/
ActionManager am ;
2013-11-18 18:17:16 +01:00
/**
* Pool of threads to process each monitor message
*/
MonitorThreadPool mtpool ;
2012-05-18 00:14:18 +02:00
/**
2013-02-14 15:26:30 +01:00
* Time in seconds to expire a monitoring action ( 5 minutes )
2012-05-18 00:14:18 +02:00
*/
static const time_t monitor_expire ;
2008-06-17 16:27:32 +00:00
/**
2010-08-17 00:28:48 +02:00
* Returns a pointer to a Information Manager MAD . The driver is
2008-06-17 16:27:32 +00:00
* searched by its name and owned by gwadmin with uid = 0.
* @ param name of the driver
2010-08-17 00:28:48 +02:00
* @ return the VM driver owned by uid 0 , with attribute " NAME " equal to
2008-06-17 16:27:32 +00: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 ) ) ;
} ;
/**
2017-02-03 14:19:15 +01:00
* Function to execute the Manager action loop method within a new pthread
* ( requires C linkage )
2008-06-17 16:27:32 +00:00
*/
2017-02-03 14:19:15 +01:00
friend void * im_action_loop ( void * arg ) ;
2008-06-17 16:27:32 +00:00
2017-02-03 14:19:15 +01:00
// ------------------------------------------------------------------------
// ActioListener Interface
// ------------------------------------------------------------------------
2008-06-17 16:27:32 +00:00
/**
* This function is executed periodically to monitor Nebula hosts .
*/
2017-02-03 14:19:15 +01:00
void timer_action ( const ActionRequest & ar ) ;
void finalize_action ( const ActionRequest & ar )
{
NebulaLog : : log ( " InM " , Log : : INFO , " Stopping Information Manager... " ) ;
MadManager : : stop ( ) ;
} ;
2008-06-17 16:27:32 +00:00
} ;
# endif /*VIRTUAL_MACHINE_MANAGER_H*/