2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2022-04-07 20:49:58 +03:00
/* Copyright 2002-2022, 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 TRANSFER_MANAGER_H_
# define TRANSFER_MANAGER_H_
2020-06-29 13:14:00 +03:00
# include "ProtocolMessages.h"
# include "DriverManager.h"
2020-07-24 17:00:59 +03:00
# include "Listener.h"
2008-06-17 20:27:32 +04:00
2020-06-29 13:14:00 +03:00
class HostPool ;
class VirtualMachine ;
2016-12-11 23:05:07 +03:00
class VirtualMachineDisk ;
2020-06-29 13:14:00 +03:00
class VirtualMachinePool ;
2020-07-24 17:00:59 +03:00
class LifeCycleManager ;
2016-12-11 23:05:07 +03:00
2017-02-03 16:19:15 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2020-06-29 13:14:00 +03:00
class TransferManager :
public DriverManager < Driver < transfer_msg_t > > ,
2020-07-24 17:00:59 +03:00
public Listener
2017-02-03 16:19:15 +03:00
{
public :
TransferManager (
VirtualMachinePool * _vmpool ,
HostPool * _hpool ,
2020-06-29 13:14:00 +03:00
const std : : string & _mad_location ) :
DriverManager ( _mad_location ) ,
2020-07-24 17:00:59 +03:00
Listener ( " Transfer Manager " ) ,
2017-02-03 16:19:15 +03:00
vmpool ( _vmpool ) ,
hpool ( _hpool )
{
} ;
2019-07-26 14:45:26 +03:00
~ TransferManager ( ) = default ;
2017-02-03 16:19:15 +03:00
2008-06-17 20:27:32 +04:00
/**
2012-09-10 20:08:00 +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-06-29 13:14:00 +03:00
* Loads Transfer Manager Drivers in configuration file
* @ param _mads configuration of drivers
2008-06-17 20:27:32 +04:00
*/
2020-06-29 13:14:00 +03:00
int load_drivers ( const std : : vector < const VectorAttribute * > & _mads ) ;
2012-09-10 20:08:00 +04:00
2012-06-13 20:19:22 +04:00
/**
* Inserts a transfer command in the xfs stream
*
* @ param vm The VM
* @ param disk Disk to transfer
* @ param disk_index Disk index
* @ param system_tm_mad The Transfer Manager for the system datastore
* @ param opennebula_hostname The front - end hostname
* @ param xfr Stream where the transfer command will be written
2012-06-15 18:28:30 +04:00
* @ param error Error reason , if any
2012-06-13 20:19:22 +04:00
*
* @ return 0 on success
*/
int prolog_transfer_command (
VirtualMachine * vm ,
2016-12-11 23:05:07 +03:00
const VirtualMachineDisk * disk ,
2020-06-29 13:14:00 +03:00
std : : string & system_tm_mad ,
std : : string & opennebula_hostname ,
std : : ostream & xfr ,
std : : ostringstream & error ) ;
2012-06-13 20:19:22 +04:00
2016-01-25 18:20:12 +03:00
/**
* Inserts a context command in the xfs stream
*
* @ param vm The VM
* @ param token_password Owner user ' s token password
* @ param system_tm_mad The Transfer Manager for the system datastore
2016-03-16 21:13:40 +03:00
* @ param disk_id of the context disk
2016-01-25 18:20:12 +03:00
* @ param xfr Stream where the transfer command will be written
*
2016-03-16 21:13:40 +03:00
* @ return - 1 in case of error , 0 if the VM has no context , 1 on success
2016-01-25 18:20:12 +03:00
*/
int prolog_context_command (
VirtualMachine * vm ,
2020-06-29 13:14:00 +03:00
const std : : string & token_password ,
std : : string & system_tm_mad ,
2016-03-16 21:13:40 +03:00
int & disk_id ,
2020-06-29 13:14:00 +03:00
std : : ostream & xfr ) ;
2016-01-25 18:20:12 +03:00
2012-06-14 19:45:41 +04:00
/**
* Inserts a transfer command in the xfs stream
*
* @ param vm The VM
2016-05-02 19:34:42 +03:00
* @ param host where the operation will be performed fe or host
2012-06-14 19:45:41 +04:00
* @ param disk Disk to transfer
* @ param disk_index Disk index
* @ param xfr Stream where the transfer command will be written
*/
2012-06-15 18:28:30 +04:00
void epilog_transfer_command (
2012-06-14 19:45:41 +04:00
VirtualMachine * vm ,
2020-06-29 13:14:00 +03:00
const std : : string & host ,
2016-12-11 23:05:07 +03:00
const VirtualMachineDisk * disk ,
2020-06-29 13:14:00 +03:00
std : : ostream & xfr ) ;
2012-09-08 01:58:45 +04:00
/**
* Inserts a transfer command in the xfs stream , for live migration
*
* @ param vm The VM
* @ param xfr Stream where the transfer command will be written
*/
void migrate_transfer_command (
VirtualMachine * vm ,
2020-06-29 13:14:00 +03:00
std : : ostream & xfr ) ;
2012-06-14 19:45:41 +04:00
2013-01-21 03:15:46 +04:00
/**
2015-07-01 14:37:58 +03:00
* This function generates the epilog_delete sequence for current ,
2013-01-21 03:15:46 +04:00
* front - end and previous hosts .
* @ param vm pointer to VM , locked
* @ param xfr stream to write the commands
* @ param local true to delete the front - end
* @ param previous true to delete the previous host
*
* @ return 0 on success
*/
int epilog_delete_commands ( VirtualMachine * vm ,
2020-06-29 13:14:00 +03:00
std : : ostream & xfr ,
2013-01-21 03:15:46 +04:00
bool local ,
bool previous ) ;
2015-07-01 14:37:58 +03:00
/**
* This function generates the TM command for the given snapshot action
* @ param vm pointer to VM , locked
* @ param snap_action : " SNAP_CREATE, SNAP_DELETE, SNAP_REVERT "
* @ param xfr stream to write the commands
*
* @ return 0 on success
*/
int snapshot_transfer_command ( VirtualMachine * vm ,
const char * snap_action ,
2020-06-29 13:14:00 +03:00
std : : ostream & xfr ) ;
2016-12-11 23:05:07 +03:00
/**
* Inserts a resize command in the xfr stream
* @ param vm
* @ param disk to resize
* @ param xfr stream to include the command .
*/
void resize_command (
VirtualMachine * vm ,
const VirtualMachineDisk * disk ,
2020-06-29 13:14:00 +03:00
std : : ostream & xfr ) ;
2012-06-15 18:28:30 +04:00
private :
2008-06-17 20:27:32 +04:00
/**
2008-11-13 19:21:17 +03:00
* Pointer to the Virtual Machine Pool , to access VMs
2008-06-17 20:27:32 +04:00
*/
2008-11-13 19:21:17 +03:00
VirtualMachinePool * vmpool ;
/**
* Pointer to the Host Pool , to access hosts
*/
HostPool * hpool ;
2012-09-10 20:08:00 +04:00
2012-02-25 04:28:28 +04:00
/**
* Generic name for the TransferManager driver
*/
static const char * transfer_driver_name ;
2008-11-13 19:21:17 +03:00
/**
2012-09-10 20:08:00 +04:00
* Returns a pointer to a Transfer Manager driver . The driver is
2008-11-13 19:21:17 +03:00
* searched by its name .
* @ param name the name of the driver
* @ return the TM driver owned by uid with attribute name equal to value
* or 0 in not found
*/
2020-07-05 23:01:32 +03:00
const Driver < transfer_msg_t > * get ( const std : : string & name ) const
2008-11-13 19:21:17 +03:00
{
2020-06-29 13:14:00 +03:00
return DriverManager : : get_driver ( name ) ;
2008-11-13 19:21:17 +03:00
} ;
2012-09-10 20:08:00 +04:00
2012-02-25 04:28:28 +04:00
/**
2012-09-10 20:08:00 +04:00
* Returns a pointer to a Transfer Manager driver . The driver is
2012-02-25 04:28:28 +04:00
* searched by its name .
* @ return the TM driver for the Transfer Manager
*/
2020-07-05 23:01:32 +03:00
const Driver < transfer_msg_t > * get ( ) const
2012-02-25 04:28:28 +04:00
{
2020-06-29 13:14:00 +03:00
return DriverManager : : get_driver ( transfer_driver_name ) ;
2012-02-25 04:28:28 +04:00
} ;
2020-06-29 13:14:00 +03:00
// -------------------------------------------------------------------------
// Protocol implementation, procesing messages from driver
// -------------------------------------------------------------------------
2020-07-02 23:42:10 +03:00
static void _undefined ( std : : unique_ptr < transfer_msg_t > msg ) ;
2020-07-24 17:00:59 +03:00
2020-07-02 23:42:10 +03:00
void _transfer ( std : : unique_ptr < transfer_msg_t > msg ) ;
2020-07-24 17:00:59 +03:00
2020-07-02 23:42:10 +03:00
static void _log ( std : : unique_ptr < transfer_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
2017-02-03 16:19:15 +03:00
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
2020-06-29 13:14:00 +03:00
static const int drivers_timeout = 10 ;
2020-07-24 17:00:59 +03:00
void finalize_action ( )
2017-02-03 16:19:15 +03:00
{
2020-06-29 13:14:00 +03:00
DriverManager : : stop ( drivers_timeout ) ;
2017-02-03 16:19:15 +03:00
} ;
2020-07-24 17:00:59 +03:00
public :
2008-06-17 20:27:32 +04:00
/**
2012-09-10 20:08:00 +04:00
* This function starts the prolog sequence
2008-06-17 20:27:32 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_prolog ( VirtualMachine * vm ) ;
2008-06-17 20:27:32 +04:00
2008-11-13 19:21:17 +03:00
/**
2012-09-10 20:08:00 +04:00
* This function starts the prolog migration sequence
2008-11-13 19:21:17 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_prolog_migr ( VirtualMachine * vm ) ;
2008-11-13 19:21:17 +03:00
/**
2012-09-10 20:08:00 +04:00
* This function starts the prolog resume sequence
2008-11-13 19:21:17 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_prolog_resume ( VirtualMachine * vm ) ;
2012-09-10 20:08:00 +04:00
2015-03-18 14:51:01 +03:00
/**
* This function starts the prolog attach sequence
*/
2020-07-24 17:00:59 +03:00
void trigger_prolog_attach ( VirtualMachine * vm ) ;
2015-03-18 14:51:01 +03:00
2008-06-17 20:27:32 +04:00
/**
* This function starts the epilog sequence
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog ( bool local , VirtualMachine * vm ) ;
2008-06-17 20:27:32 +04:00
2008-11-13 19:21:17 +03:00
/**
* This function starts the epilog_stop sequence
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_stop ( VirtualMachine * vm ) ;
2012-09-10 20:08:00 +04:00
2009-07-09 18:34:34 +04:00
/**
2013-01-21 03:15:46 +04:00
* This function starts the epilog_delete sequence in the current host
* @ param vid the Virtual Machine ID
2009-07-09 18:34:34 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_delete ( VirtualMachine * vm )
2012-06-27 20:50:19 +04:00
{
2020-07-24 17:00:59 +03:00
trigger_epilog_delete ( false , vm ) ;
2012-06-27 20:50:19 +04:00
}
/**
* This function starts the epilog_delete_stop sequence on the local host
2013-01-21 03:15:46 +04:00
* i . e . the front - end ( the VM is not running )
* @ param vid the Virtual Machine ID
2012-06-27 20:50:19 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_delete_stop ( VirtualMachine * vm )
2012-06-27 20:50:19 +04:00
{
2020-07-24 17:00:59 +03:00
trigger_epilog_delete ( true , vm ) ;
2012-06-27 20:50:19 +04:00
}
/**
2013-01-21 03:15:46 +04:00
* This function starts the epilog_delete sequence on the previous host
* @ param vid the Virtual Machine ID
2012-06-27 20:50:19 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_delete_previous ( VirtualMachine * vm ) ;
2009-07-09 18:34:34 +04:00
2013-01-21 02:05:14 +04:00
/**
2013-01-21 03:15:46 +04:00
* This function starts the epilog_delete sequence on the current and
* previous hosts
* @ param vid the Virtual Machine ID
2013-01-21 02:05:14 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_delete_both ( VirtualMachine * vm ) ;
2013-01-21 03:15:46 +04:00
2009-07-09 18:34:34 +04:00
/**
2013-01-21 03:15:46 +04:00
* This function starts the epilog_delete sequence
2009-07-09 18:34:34 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_delete ( bool local , VirtualMachine * vm ) ;
2009-07-09 18:34:34 +04:00
2015-03-18 14:51:01 +03:00
/**
* This function starts the epilog detach sequence
*/
2020-07-24 17:00:59 +03:00
void trigger_epilog_detach ( VirtualMachine * vm ) ;
2015-03-18 14:51:01 +03:00
2008-06-17 20:27:32 +04:00
/**
* This function starts the epilog sequence
*/
2020-07-24 17:00:59 +03:00
void trigger_checkpoint ( int vid ) ;
2009-07-09 18:34:34 +04:00
/**
* This function cancels the operation being performed by the driver
*/
2020-07-24 17:00:59 +03:00
void trigger_driver_cancel ( int vid ) ;
2013-03-08 01:44:18 +04:00
/**
* This function starts the saveas of the given disk
*/
2020-07-24 17:00:59 +03:00
void trigger_saveas_hot ( int vid ) ;
2015-05-20 18:48:27 +03:00
2015-05-26 12:24:34 +03:00
/**
* This function performs a generic snapshot action
*/
void do_snapshot_action ( int vid , const char * action ) ;
2015-05-20 18:48:27 +03:00
/**
* This function takes an snapshot of a disk
*/
2020-07-24 17:00:59 +03:00
void trigger_snapshot_create ( int vid ) ;
2015-05-20 18:48:27 +03:00
2015-05-26 12:24:34 +03:00
/**
* This function takes an snapshot of a disk
*/
2020-07-24 17:00:59 +03:00
void trigger_snapshot_revert ( int vid ) ;
2015-05-26 12:24:34 +03:00
2015-05-20 18:48:27 +03:00
/**
* This function deletes an snapshot of a disk
*/
2020-07-24 17:00:59 +03:00
void trigger_snapshot_delete ( int vid ) ;
2016-12-11 23:05:07 +03:00
/**
* This function resizes a VM disk
*/
2020-07-24 17:00:59 +03:00
void trigger_resize ( int vid ) ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*TRANSFER_MANAGER_H*/