2009-04-03 23:34:33 +00:00
/* -------------------------------------------------------------------------- */
2023-01-09 12:23:19 +01:00
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
2009-04-03 23:34:33 +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 HOOK_MANAGER_H_
# define HOOK_MANAGER_H_
2020-06-29 12:14:00 +02:00
# include "ProtocolMessages.h"
# include "DriverManager.h"
2020-07-24 16:00:59 +02:00
# include "Listener.h"
2009-04-03 23:34:33 +00:00
2019-09-09 14:43:51 +02:00
# include <vector>
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2020-06-29 12:14:00 +02:00
class HookManager :
public DriverManager < Driver < hook_msg_t > > ,
2024-06-03 11:40:24 +02:00
public Listener
2009-04-03 23:34:33 +00:00
{
public :
2020-07-24 16:00:59 +02:00
HookManager ( const std : : string & mad_location )
: DriverManager ( mad_location )
, Listener ( " Hook Manager " )
2009-04-05 20:34:33 +00:00
{
2020-06-29 12:14:00 +02:00
}
2009-04-03 23:34:33 +00:00
2019-09-09 14:43:51 +02:00
virtual ~ HookManager ( ) = default ;
2009-04-03 23:34:33 +00:00
2009-04-05 20:34:33 +00:00
/**
2010-07-08 18:49:37 +02:00
* This functions starts the associated listener thread , and creates a
2009-04-05 20:34:33 +00:00
* 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 ( ) ;
2009-04-03 23:34:33 +00:00
/**
2019-09-09 14:43:51 +02:00
* Loads Hook Manager Mads defined in configuration file
2020-06-29 12:14:00 +02:00
* @ param _mads configuration of drivers
2009-04-03 23:34:33 +00:00
*/
2020-06-29 12:14:00 +02:00
int load_drivers ( const std : : vector < const VectorAttribute * > & _mads ) ;
2009-04-03 23:34:33 +00:00
/**
2010-07-08 18:49:37 +02:00
* Returns a pointer to a Information Manager MAD . The driver is
2009-04-03 23:34:33 +00:00
* searched by its name and owned by oneadmin with uid = 0.
* @ param name of the driver
2010-07-08 18:49:37 +02:00
* @ return the Hook driver owned by uid 0 , with attribute " NAME " equal to
2009-04-03 23:34:33 +00:00
* name or 0 in not found
*/
2020-07-05 22:01:32 +02:00
const Driver < hook_msg_t > * get ( ) const
2009-04-03 23:34:33 +00:00
{
2020-06-29 12:14:00 +02:00
return DriverManager : : get_driver ( hook_driver_name ) ;
}
2010-07-08 18:49:37 +02:00
2020-07-05 22:01:32 +02:00
static std : : string format_message ( const std : : string & args ,
const std : : string & remote_host ,
int hook_id ) ;
2019-09-09 14:43:51 +02:00
2009-04-03 23:34:33 +00:00
/**
2019-09-09 14:43:51 +02:00
* Generic name for the Hook driver
2009-04-03 23:34:33 +00:00
*/
2020-06-29 12:14:00 +02:00
static const char * hook_driver_name ;
2010-07-08 18:49:37 +02:00
2009-04-05 20:34:33 +00:00
/**
2019-09-09 14:43:51 +02:00
* Send event message to the driver
* @ param message to pass to the driver
2009-04-05 20:34:33 +00:00
*/
2020-07-24 16:00:59 +02:00
void trigger_send_event ( const std : : string & message ) ;
2019-09-09 14:43:51 +02:00
/**
* Send retry message to the driver
* @ param message to pass to the driver
*/
2020-07-24 16:00:59 +02:00
void trigger_retry ( const std : : string & message ) ;
2009-04-05 20:34:33 +00:00
2020-07-24 16:00:59 +02:00
private :
2020-06-29 12:14:00 +02:00
// -------------------------------------------------------------------------
// Protocol implementation, procesing messages from driver
// -------------------------------------------------------------------------
/**
*
*/
2020-07-02 22:42:10 +02:00
static void _undefined ( std : : unique_ptr < hook_msg_t > msg ) ;
2020-06-29 12:14:00 +02:00
/**
*
*/
2020-07-02 22:42:10 +02:00
void _execute ( std : : unique_ptr < hook_msg_t > msg ) ;
2020-06-29 12:14:00 +02:00
/**
*
*/
2020-07-02 22:42:10 +02:00
void _retry ( std : : unique_ptr < hook_msg_t > msg ) ;
2020-06-29 12:14:00 +02:00
/**
*
*/
2020-07-02 22:42:10 +02:00
static void _log ( std : : unique_ptr < hook_msg_t > msg ) ;
2020-06-29 12:14:00 +02:00
2017-02-03 14:19:15 +01:00
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
2020-06-29 12:14:00 +02:00
static const int drivers_timeout = 10 ;
2020-07-24 16:00:59 +02:00
void finalize_action ( ) override
2017-02-03 14:19:15 +01:00
{
2020-06-29 12:14:00 +02:00
DriverManager : : stop ( drivers_timeout ) ;
2017-02-03 14:19:15 +01:00
} ;
2009-04-03 23:34:33 +00:00
} ;
# endif /*HOOK_MANAGER_H*/