2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2020-04-30 16:00:02 +03:00
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
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_
2020-03-04 18:05:57 +03:00
# include "DriverManager.h"
2008-06-17 20:27:32 +04:00
# include "ActionManager.h"
2020-06-29 13:14:00 +03:00
# include "ProtocolMessages.h"
2020-05-15 17:15:52 +03:00
# include "RaftManager.h"
2008-06-17 20:27:32 +04:00
2013-11-05 22:20:28 +04:00
class HostPool ;
2016-04-12 01:33:09 +03:00
class Host ;
2020-03-04 18:05:57 +03:00
class VirtualMachinePool ;
2013-11-05 22:20:28 +04:00
2020-03-04 18:05:57 +03:00
class InformationManager :
2020-06-29 13:14:00 +03:00
public DriverManager < Driver < im_msg_t > > ,
2020-03-04 18:05:57 +03:00
public ActionListener
2008-06-17 20:27:32 +04:00
{
public :
InformationManager (
2020-03-04 18:05:57 +03:00
HostPool * _hpool ,
VirtualMachinePool * _vmpool ,
2020-07-02 23:42:10 +03:00
const std : : string & mad_location )
2020-03-04 18:05:57 +03:00
: DriverManager ( mad_location )
, hpool ( _hpool )
, vmpool ( _vmpool )
2008-06-17 20:27:32 +04:00
{
am . addListener ( this ) ;
2020-03-04 18:05:57 +03:00
}
2008-06-17 20:27:32 +04:00
2020-03-04 18:05:57 +03:00
~ InformationManager ( ) = default ;
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 ( ) ;
/**
2020-03-04 18:05:57 +03:00
* Join the action loop thread
2008-06-17 20:27:32 +04:00
*/
2020-03-04 18:05:57 +03:00
void join_thread ( )
2008-06-17 20:27:32 +04:00
{
2020-03-04 18:05:57 +03:00
return im_thread . join ( ) ;
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 ( )
{
2017-02-03 16:19:15 +03:00
am . finalize ( ) ;
2008-06-17 20:27:32 +04:00
} ;
2016-04-12 01:33:09 +03:00
/**
* 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
*/
2020-07-02 23:42:10 +03:00
void stop_monitor ( int hid ,
const std : : string & name ,
const std : : string & im_mad ) ;
2016-04-12 01:33:09 +03:00
/**
* 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 19:52:56 +04:00
2008-06-17 20:27:32 +04:00
/**
2020-03-04 18:05:57 +03:00
* Send host info to monitor
2008-06-17 20:27:32 +04:00
*/
2020-03-04 18:05:57 +03:00
void update_host ( Host * host ) ;
2008-06-17 20:27:32 +04:00
/**
2020-03-04 18:05:57 +03:00
* Send host delete message to monitor
2008-06-17 20:27:32 +04:00
*/
2020-03-04 18:05:57 +03:00
void delete_host ( int hid ) ;
2008-06-17 20:27:32 +04:00
2020-05-15 17:15:52 +03:00
/**
* Set raft status , send info to monitor daemon
*/
void raft_status ( RaftManager : : State raft ) ;
2020-03-04 18:05:57 +03:00
protected :
2013-11-05 22:20:28 +04:00
/**
2020-03-04 18:05:57 +03:00
* Received undefined message - > print error
2013-11-05 22:20:28 +04:00
*/
2020-07-02 23:42:10 +03:00
static void _undefined ( std : : unique_ptr < im_msg_t > msg ) ;
2013-11-05 22:20:28 +04:00
2008-06-17 20:27:32 +04:00
/**
2020-03-04 18:05:57 +03:00
* Message HOST_STATE update from monitor
2008-06-17 20:27:32 +04:00
*/
2020-07-02 23:42:10 +03:00
void _host_state ( std : : unique_ptr < im_msg_t > msg ) ;
2010-08-17 02:28:48 +04:00
2008-06-17 20:27:32 +04:00
/**
2020-04-23 21:07:16 +03:00
* Message HOST_SYSTEM update from monitor
2008-06-17 20:27:32 +04:00
*/
2020-07-02 23:42:10 +03:00
void _host_system ( std : : unique_ptr < im_msg_t > msg ) ;
2010-08-17 02:28:48 +04:00
2011-08-16 20:12:45 +04:00
/**
2020-03-04 18:05:57 +03:00
* Message VM_STATE from monitor
2011-08-16 20:12:45 +04:00
*/
2020-07-02 23:42:10 +03:00
void _vm_state ( std : : unique_ptr < im_msg_t > msg ) ;
2010-08-17 02:28:48 +04:00
2020-03-04 18:05:57 +03:00
private :
2008-06-17 20:27:32 +04:00
/**
2020-03-04 18:05:57 +03:00
* Thread for the Information Manager
2008-06-17 20:27:32 +04:00
*/
2020-03-04 18:05:57 +03:00
std : : thread im_thread ;
2008-06-17 20:27:32 +04:00
2013-11-18 21:17:16 +04:00
/**
2020-03-04 18:05:57 +03:00
* Pointer to the Host Pool
2013-11-18 21:17:16 +04:00
*/
2020-03-04 18:05:57 +03:00
HostPool * hpool ;
2013-11-18 21:17:16 +04:00
2012-05-18 02:14:18 +04:00
/**
2020-03-04 18:05:57 +03:00
* Pointer to the Host Pool
2012-05-18 02:14:18 +04:00
*/
2020-03-04 18:05:57 +03:00
VirtualMachinePool * vmpool ;
2012-05-18 02:14:18 +04:00
2008-06-17 20:27:32 +04:00
/**
2020-04-16 19:15:07 +03:00
* Action engine for the Manager
2008-06-17 20:27:32 +04:00
*/
2020-04-16 19:15:07 +03:00
ActionManager am ;
2008-06-17 20:27:32 +04:00
/**
2020-04-16 19:15:07 +03:00
* Default timeout to wait for Information Driver ( monitord )
2008-06-17 20:27:32 +04:00
*/
2020-04-16 19:15:07 +03:00
static const int drivers_timeout = 10 ;
2008-06-17 20:27:32 +04:00
2017-02-03 16:19:15 +03:00
// ------------------------------------------------------------------------
// ActioListener Interface
// ------------------------------------------------------------------------
2020-03-04 18:05:57 +03:00
void finalize_action ( const ActionRequest & ar ) override
2017-02-03 16:19:15 +03:00
{
NebulaLog : : log ( " InM " , Log : : INFO , " Stopping Information Manager... " ) ;
2020-04-16 19:15:07 +03:00
stop ( drivers_timeout ) ;
2017-02-03 16:19:15 +03:00
} ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*VIRTUAL_MACHINE_MANAGER_H*/