2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2019-01-16 13:27:59 +03:00
/* Copyright 2002-2019, 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 REQUEST_MANAGER_H_
# define REQUEST_MANAGER_H_
# include "ActionManager.h"
# include "VirtualMachinePool.h"
# include "HostPool.h"
2009-07-09 18:34:34 +04:00
# include "UserPool.h"
2008-11-13 19:21:17 +03:00
# include "VirtualNetworkPool.h"
2010-05-31 20:40:38 +04:00
# include "ImagePool.h"
2011-03-30 21:03:49 +04:00
# include "VMTemplatePool.h"
2011-05-10 20:45:15 +04:00
# include "GroupPool.h"
2008-06-17 20:27:32 +04:00
2011-05-25 14:13:17 +04:00
# include "AuthManager.h"
2008-06-17 20:27:32 +04:00
# include <xmlrpc-c/base.hpp>
# include <xmlrpc-c/registry.hpp>
# include <xmlrpc-c/server_abyss.hpp>
using namespace std ;
extern " C " void * rm_action_loop ( void * arg ) ;
extern " C " void * rm_xml_server_loop ( void * arg ) ;
class RequestManager : public ActionListener
{
public :
2013-07-31 18:40:45 +04:00
RequestManager (
2016-12-28 02:16:49 +03:00
const string & _port ,
2013-07-31 18:40:45 +04:00
int _max_conn ,
int _max_conn_backlog ,
int _keepalive_timeout ,
int _keepalive_max_conn ,
int _timeout ,
2016-12-28 02:16:49 +03:00
const string & _xml_log_file ,
const string & call_log_format ,
const string & _listen_address ,
2015-02-20 17:10:57 +03:00
int message_size ) ;
2008-06-17 20:27:32 +04:00
2014-10-28 20:52:48 +03:00
~ RequestManager ( ) { } ;
2008-06-17 20:27:32 +04:00
/**
2010-08-05 21:28:28 +04:00
* This functions starts the associated listener thread ( XML server ) , and
2008-06-17 20:27:32 +04:00
* creates a new thread for the Request 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 rm_thread ;
} ;
/**
2018-10-09 12:05:08 +03:00
* Stops the main RM thread .
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
} ;
2018-10-09 12:05:08 +03:00
/**
* @ return an AbyssServer to run xmlrpc connections
*/
xmlrpc_c : : serverAbyss * create_abyss ( ) ;
2011-05-24 16:32:39 +04:00
2008-06-17 20:27:32 +04:00
private :
//--------------------------------------------------------------------------
// Friends, thread functions require C-linkage
//--------------------------------------------------------------------------
friend void * rm_xml_server_loop ( void * arg ) ;
friend void * rm_action_loop ( void * arg ) ;
/**
* Thread id for the RequestManager
*/
2018-10-09 12:05:08 +03:00
pthread_t rm_thread ;
2008-06-17 20:27:32 +04:00
/**
* Thread id for the XML Server
*/
2018-10-09 12:05:08 +03:00
pthread_t rm_xml_server_thread ;
2008-06-17 20:27:32 +04:00
/**
* Port number where the connection will be open
*/
2016-12-28 02:16:49 +03:00
string port ;
2010-08-05 21:28:28 +04:00
2008-06-17 20:27:32 +04:00
/*
* FD for the XML server socket
2010-08-05 21:28:28 +04:00
*/
2008-06-17 20:27:32 +04:00
int socket_fd ;
2013-07-31 14:28:13 +04:00
/**
* Max connections
*/
int max_conn ;
/*
* Max backlog connections
*/
int max_conn_backlog ;
/*
* Keepalive timeout
*/
int keepalive_timeout ;
/*
* Keepalive max conn
*/
int keepalive_max_conn ;
/*
* Timeout
*/
int timeout ;
2008-06-17 20:27:32 +04:00
/**
* Filename for the log of the xmlrpc server that listens
*/
string xml_log_file ;
2015-07-07 00:34:47 +03:00
/**
* Specifies the address xmlrpc server will bind to
*/
string listen_address ;
2008-06-17 20:27:32 +04:00
/**
* Action engine for the Manager
*/
2018-10-09 12:05:08 +03:00
ActionManager am ;
2008-06-17 20:27:32 +04:00
/**
* To register XML - RPC methods
*/
xmlrpc_c : : registry RequestManagerRegistry ;
2010-07-15 14:43:27 +04:00
/**
2011-05-24 17:36:40 +04:00
* Register the XML - RPC API Calls
2010-08-05 21:28:28 +04:00
*/
2011-05-24 17:36:40 +04:00
void register_xml_methods ( ) ;
2010-06-01 21:35:42 +04:00
2011-05-24 17:36:40 +04:00
int setup_socket ( ) ;
2010-08-05 21:28:28 +04:00
2017-02-03 16:19:15 +03:00
// ------------------------------------------------------------------------
// ActioListener Interface
// ------------------------------------------------------------------------
virtual void finalize_action ( const ActionRequest & ar )
{
NebulaLog : : log ( " ReM " , Log : : INFO , " Stopping Request Manager... " ) ;
pthread_cancel ( rm_xml_server_thread ) ;
pthread_join ( rm_xml_server_thread , 0 ) ;
NebulaLog : : log ( " ReM " , Log : : INFO , " XML-RPC server stopped. " ) ;
if ( socket_fd ! = - 1 )
{
close ( socket_fd ) ;
}
} ;
} ;
2010-05-31 20:40:38 +04:00
2008-06-17 20:27:32 +04:00
# endif