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 LIFE_CYCLE_MANAGER_H_
# define LIFE_CYCLE_MANAGER_H_
# include "ActionManager.h"
2020-07-02 23:42:10 +03:00
# include "NebulaLog.h"
2008-06-17 20:27:32 +04:00
extern " C " void * lcm_action_loop ( void * arg ) ;
2015-04-24 17:27:08 +03:00
//Forward definitions
class TransferManager ;
class DispatchManager ;
class VirtualMachineManager ;
2015-07-17 19:31:38 +03:00
class ImageManager ;
2020-07-02 23:42:10 +03:00
class ClusterPool ;
class HostPool ;
class ImagePool ;
class SecurityGroupPool ;
class VirtualMachinePool ;
class VirtualMachine ;
2017-02-07 19:26:23 +03:00
struct RequestAttributes ;
2015-04-24 17:27:08 +03:00
2017-02-03 16:19:15 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class LCMAction : public ActionRequest
2008-06-17 20:27:32 +04:00
{
public :
enum Actions
{
2017-02-03 16:19:15 +03:00
NONE ,
2009-07-09 18:34:34 +04:00
SAVE_SUCCESS , /**< Sent by the VMM when a save action succeeds */
SAVE_FAILURE , /**< Sent by the VMM when a save action fails */
2016-05-02 19:34:42 +03:00
DEPLOY_SUCCESS , /**< Sent by the VMM deploy/restore/migrate succeeds*/
DEPLOY_FAILURE , /**< Sent by the VMM deploy/restore/migrate fails */
2009-07-09 18:34:34 +04:00
SHUTDOWN_SUCCESS , /**< Sent by the VMM when a shutdown action succeeds*/
SHUTDOWN_FAILURE , /**< Sent by the VMM when a shutdown action fails */
CANCEL_SUCCESS , /**< Sent by the VMM when a cancel action succeeds */
CANCEL_FAILURE , /**< Sent by the VMM when a cancel action fails */
2016-05-02 19:34:42 +03:00
MONITOR_SUSPEND , /**< Sent by the VMM when a VM is paused in active */
2014-06-22 09:58:22 +04:00
MONITOR_DONE , /**< Sent by the VMM when a Host cannot be monitored*/
2016-05-02 19:34:42 +03:00
MONITOR_POWEROFF , /**< Sent by the VMM when a VM is not found */
MONITOR_POWERON , /**< Sent by the VMM when a VM is found again */
2009-07-09 18:34:34 +04:00
PROLOG_SUCCESS , /**< Sent by the TM when the prolog phase succeeds */
PROLOG_FAILURE , /**< Sent by the TM when the prolog phase fails */
EPILOG_SUCCESS , /**< Sent by the TM when the epilog phase succeeds */
EPILOG_FAILURE , /**< Sent by the TM when the epilog phase fails */
2012-06-13 20:42:42 +04:00
ATTACH_SUCCESS , /**< Sent by the VMM when an attach action succeeds */
ATTACH_FAILURE , /**< Sent by the VMM when an attach action fails */
2012-06-14 19:45:41 +04:00
DETACH_SUCCESS , /**< Sent by the VMM when a detach action succeeds */
DETACH_FAILURE , /**< Sent by the VMM when a detach action fails */
2016-05-02 19:34:42 +03:00
ATTACH_NIC_SUCCESS , /**< Sent by the VMM when attach nic action succeeds*/
ATTACH_NIC_FAILURE , /**< Sent by the VMM when attach nic action fails */
DETACH_NIC_SUCCESS , /**< Sent by the VMM when detach nic action succeeds*/
DETACH_NIC_FAILURE , /**< Sent by the VMM when detach nic action fails */
2013-01-21 15:27:18 +04:00
CLEANUP_SUCCESS , /**< Sent by the VMM when a cleanup action succeeds */
CLEANUP_FAILURE , /**< Sent by the VMM when a cleanup action fails */
2015-06-10 13:53:55 +03:00
SAVEAS_SUCCESS , /**< Sent by the VMM when saveas succeeds */
SAVEAS_FAILURE , /**< Sent by the VMM when saveas fails */
2013-02-19 18:21:33 +04:00
SNAPSHOT_CREATE_SUCCESS , /**< Sent by the VMM on snap. create success */
SNAPSHOT_CREATE_FAILURE , /**< Sent by the VMM on snap. create failure */
2013-02-20 19:04:09 +04:00
SNAPSHOT_REVERT_SUCCESS , /**< Sent by the VMM on snap. revert success */
SNAPSHOT_REVERT_FAILURE , /**< Sent by the VMM on snap. revert failure */
2013-02-21 18:01:48 +04:00
SNAPSHOT_DELETE_SUCCESS , /**< Sent by the VMM on snap. revert success */
SNAPSHOT_DELETE_FAILURE , /**< Sent by the VMM on snap. revert failure */
2016-05-02 19:34:42 +03:00
DISK_SNAPSHOT_SUCCESS , /**< Sent by TM when a snap. succeeds */
DISK_SNAPSHOT_FAILURE , /**< Sent by TM when a snap. fails */
2009-07-09 18:34:34 +04:00
DEPLOY , /**< Sent by the DM to deploy a VM on a host */
SUSPEND , /**< Sent by the DM to suspend an running VM */
RESTORE , /**< Sent by the DM to restore a suspended VM */
STOP , /**< Sent by the DM to stop an running VM */
CANCEL , /**< Sent by the DM to cancel an running VM */
MIGRATE , /**< Sent by the DM to migrate a VM to other host */
LIVE_MIGRATE , /**< Sent by the DM to live-migrate a VM */
2018-12-04 14:00:13 +03:00
POFF_MIGRATE , /**< Sent by the DM to migrate a VM in a poff cycle */
POFF_HARD_MIGRATE , /**< Sent by the DM to migrate a VM in a poff hard cycle */
2009-07-09 18:34:34 +04:00
SHUTDOWN , /**< Sent by the DM to shutdown a running VM */
2013-04-02 19:01:22 +04:00
UNDEPLOY , /**< Sent by the DM to undeploy a running VM */
UNDEPLOY_HARD , /**< Sent by the DM to force undeploy a running VM */
2012-09-04 20:30:53 +04:00
POWEROFF , /**< Sent by the DM to power off a running VM */
2013-03-27 16:48:06 +04:00
POWEROFF_HARD , /**< Sent by the DM to power off hard a running VM */
2009-07-09 18:34:34 +04:00
RESTART , /**< Sent by the DM to restart a deployed VM */
DELETE , /**< Sent by the DM to delete a VM */
2016-05-02 19:34:42 +03:00
DELETE_RECREATE , /**< Sent by the DM to cleanup a VM for resubmission*/
2016-12-11 23:05:07 +03:00
UPDATESG , /**< Sent by RM/VMM to trigger the secgroup update*/
DISK_LOCK_SUCCESS , /**< Sent by IM, image moves from locked to ready */
DISK_LOCK_FAILURE , /**< Sent by IM, image moves from locked to error */
DISK_RESIZE_SUCCESS , /**< Sent by TM/VMM when a disk resize succeeds */
2019-07-26 14:45:26 +03:00
DISK_RESIZE_FAILURE , /**< Sent by TM/VMM when a disk resize fails */
UPDATE_CONF_SUCCESS , /**< Sent by TM/VMM when a update conf succeeds */
UPDATE_CONF_FAILURE /**< Sent by TM/VMM when a update conf fails */
2017-02-03 16:19:15 +03:00
} ;
2017-02-07 19:26:23 +03:00
LCMAction ( Actions a , int v , int u , int g , int r ) :
ActionRequest ( ActionRequest : : USER ) , _action ( a ) , _vm_id ( v ) , _uid ( u ) ,
2019-07-26 14:45:26 +03:00
_gid ( g ) , _req_id ( r ) { }
2017-02-03 16:19:15 +03:00
2017-02-08 14:24:42 +03:00
LCMAction ( const LCMAction & o ) : ActionRequest ( o . _type ) , _action ( o . _action ) ,
2019-07-26 14:45:26 +03:00
_vm_id ( o . _vm_id ) , _uid ( o . _uid ) , _gid ( o . _gid ) , _req_id ( o . _req_id ) { }
2017-02-08 14:24:42 +03:00
2017-02-03 16:19:15 +03:00
Actions action ( ) const
{
return _action ;
}
int vm_id ( ) const
{
return _vm_id ;
}
2017-02-07 19:26:23 +03:00
int uid ( ) const
{
return _uid ;
}
int gid ( ) const
{
return _gid ;
}
int req_id ( ) const
{
return _req_id ;
}
2017-02-08 14:24:42 +03:00
ActionRequest * clone ( ) const
{
return new LCMAction ( * this ) ;
}
2017-02-03 16:19:15 +03:00
private :
Actions _action ;
2017-02-07 19:26:23 +03:00
int _vm_id ;
int _uid ;
int _gid ;
int _req_id ;
2017-02-03 16:19:15 +03:00
} ;
/**
* The Virtual Machine Life - cycle Manager module . This class is responsible for
* managing the life - cycle of a Virtual Machine .
*/
class LifeCycleManager : public ActionListener
{
public :
LifeCycleManager ( ) :
vmpool ( 0 ) , hpool ( 0 ) , ipool ( 0 ) , sgpool ( 0 ) , clpool ( 0 ) , tm ( 0 ) , vmm ( 0 ) ,
dm ( 0 ) , imagem ( 0 )
{
am . addListener ( this ) ;
2008-06-17 20:27:32 +04:00
} ;
2019-07-26 14:45:26 +03:00
~ LifeCycleManager ( ) = default ;
2017-02-03 16:19:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Triggers specific actions to the Life - cycle Manager . This function
* wraps the ActionManager trigger function .
* @ param action the LCM action
2010-12-30 03:11:40 +03:00
* @ param vid VM unique id . This is the argument of the passed to the
2008-06-17 20:27:32 +04:00
* invoked action .
2017-02-07 19:26:23 +03:00
* @ param r RM request attributes to copy to the action request : uid ,
* gid and request_id .
2008-06-17 20:27:32 +04:00
*/
2017-02-07 19:26:23 +03:00
void trigger ( LCMAction : : Actions action , int id , const RequestAttributes & r ) ;
2017-02-03 16:19:15 +03:00
2017-02-07 19:26:23 +03:00
void trigger ( LCMAction : : Actions action , int id ) ;
2017-02-03 16:19:15 +03:00
void finalize ( )
{
am . finalize ( ) ;
}
2008-06-17 20:27:32 +04:00
/**
2010-12-30 03:11:40 +03:00
* This functions starts a new thread for the Life - cycle Manager . This
2008-06-17 20:27:32 +04:00
* thread will wait in an action loop till it receives ACTION_FINALIZE .
* @ return 0 on success .
*/
int start ( ) ;
2015-04-24 17:27:08 +03:00
/**
* Initializes internal pointers to other managers . Must be called when
* all the other managers exist in Nebula : : instance
*/
void init_managers ( ) ;
2008-06-17 20:27:32 +04:00
/**
* Gets the thread identification .
* @ return pthread_t for the manager thread ( that in the action loop ) .
*/
pthread_t get_thread_id ( ) const
{
return lcm_thread ;
} ;
2013-05-17 02:45:38 +04:00
/**
* Recovers a VM by self - triggering the associated lost transition .
* @ param vm to be recovered
* @ param success trigger successful transition if true , fail otherwise
*/
2017-02-07 19:26:23 +03:00
void recover ( VirtualMachine * vm , bool success , const RequestAttributes & ra ) ;
2013-05-17 02:45:38 +04:00
2015-07-01 22:15:40 +03:00
/**
* Retries the last VM operation that lead to a failure . The underlying
* driver actions may be invoked and should be " re-entrant " .
*/
2015-04-21 18:15:10 +03:00
void retry ( VirtualMachine * vm ) ;
2008-06-17 20:27:32 +04:00
private :
/**
* Thread id for the Virtual Machine Manager
*/
pthread_t lcm_thread ;
/**
* Pointer to the Virtual Machine Pool , to access VMs
*/
VirtualMachinePool * vmpool ;
2010-12-30 03:11:40 +03:00
2008-06-22 05:51:49 +04:00
/**
* Pointer to the Host Pool , to access hosts
*/
2010-12-30 03:11:40 +03:00
HostPool * hpool ;
2008-06-17 20:27:32 +04:00
2015-04-24 17:27:08 +03:00
/**
* Pointer to the Image Pool , to access images
*/
ImagePool * ipool ;
2016-03-02 01:31:31 +03:00
/**
* Pointer to the SecurityGroup Pool
*/
SecurityGroupPool * sgpool ;
2016-04-05 13:47:21 +03:00
/**
* Pointer to the Cluster Pool
*/
ClusterPool * clpool ;
2015-04-24 17:27:08 +03:00
/**
* Pointer to TransferManager
*/
TransferManager * tm ;
/**
* Pointer to VirtualMachineManager
*/
VirtualMachineManager * vmm ;
/**
* Pointer to DispatchManager
*/
DispatchManager * dm ;
2008-06-17 20:27:32 +04:00
/**
* Action engine for the Manager
*/
ActionManager am ;
2015-07-17 19:31:38 +03:00
/**
* Pointer to ImageManager
*/
ImageManager * imagem ;
2008-06-17 20:27:32 +04:00
/**
2010-12-30 03:11:40 +03:00
* Function to execute the Manager action loop method within a new pthread
2008-06-17 20:27:32 +04:00
* ( requires C linkage )
*/
friend void * lcm_action_loop ( void * arg ) ;
2017-02-03 16:19:15 +03:00
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
void finalize_action ( const ActionRequest & ar )
{
NebulaLog : : log ( " LCM " , Log : : INFO , " Stopping Life-cycle Manager... " ) ;
} ;
void user_action ( const ActionRequest & ar ) ;
2008-06-17 20:27:32 +04:00
2010-12-30 03:11:40 +03:00
/**
* Cleans up a VM , canceling any pending or ongoing action and closing
* the history registers
2013-03-14 21:03:15 +04:00
*
* @ param vm with the lock acquired
* @ param dispose true if the vm will end in DONE , false to resubmit to PENDING
* @ param image_id If the VM is in the middle of a save as operation , an
* image may need to be set to error state .
2010-12-30 03:11:40 +03:00
*/
2019-07-26 14:45:26 +03:00
void clean_up_vm ( VirtualMachine * vm , bool dispose , int & image_id ,
2017-02-09 18:58:47 +03:00
const LCMAction & la ) ;
2010-12-30 03:11:40 +03:00
2017-02-07 19:26:23 +03:00
// -------------------------------------------------------------------------
// Internal Actions, triggered by OpenNebula components & drivers
// -------------------------------------------------------------------------
2019-02-05 14:26:31 +03:00
void start_prolog_migrate ( VirtualMachine * vm ) ;
void revert_migrate_after_failure ( VirtualMachine * vm ) ;
2018-12-04 14:00:13 +03:00
2008-06-17 20:27:32 +04:00
void save_success_action ( int vid ) ;
void save_failure_action ( int vid ) ;
void deploy_success_action ( int vid ) ;
void deploy_failure_action ( int vid ) ;
2008-06-22 05:51:49 +04:00
void shutdown_success_action ( int vid ) ;
void shutdown_failure_action ( int vid ) ;
2010-12-30 03:11:40 +03:00
2008-06-23 02:38:55 +04:00
void monitor_suspend_action ( int vid ) ;
2008-06-23 22:43:44 +04:00
void monitor_done_action ( int vid ) ;
2014-06-22 09:58:22 +04:00
void monitor_poweroff_action ( int vid ) ;
2014-10-09 16:10:21 +04:00
void monitor_poweron_action ( int vid ) ;
2008-06-17 20:27:32 +04:00
void prolog_success_action ( int vid ) ;
void prolog_failure_action ( int vid ) ;
void epilog_success_action ( int vid ) ;
2010-12-30 03:11:40 +03:00
void epilog_failure_action ( int vid ) ;
2008-06-17 20:27:32 +04:00
2012-06-13 21:15:33 +04:00
void attach_success_action ( int vid ) ;
2015-03-18 14:51:01 +03:00
void attach_failure_action ( int vid ) ;
2012-06-13 21:15:33 +04:00
2012-06-14 19:45:41 +04:00
void detach_success_action ( int vid ) ;
void detach_failure_action ( int vid ) ;
2015-06-10 13:53:55 +03:00
void saveas_success_action ( int vid ) ;
void saveas_failure_action ( int vid ) ;
2013-03-01 22:04:56 +04:00
2012-12-12 21:31:27 +04:00
void attach_nic_success_action ( int vid ) ;
void attach_nic_failure_action ( int vid ) ;
void detach_nic_success_action ( int vid ) ;
void detach_nic_failure_action ( int vid ) ;
2013-01-21 15:27:18 +04:00
void cleanup_callback_action ( int vid ) ;
2013-02-19 18:21:33 +04:00
void snapshot_create_success ( int vid ) ;
void snapshot_create_failure ( int vid ) ;
2013-02-20 19:04:09 +04:00
void snapshot_revert_success ( int vid ) ;
void snapshot_revert_failure ( int vid ) ;
2013-02-21 18:01:48 +04:00
void snapshot_delete_success ( int vid ) ;
void snapshot_delete_failure ( int vid ) ;
2015-05-21 15:52:36 +03:00
void disk_snapshot_success ( int vid ) ;
void disk_snapshot_failure ( int vid ) ;
2016-04-18 18:44:47 +03:00
void disk_lock_success ( int vid ) ;
void disk_lock_failure ( int vid ) ;
2016-12-11 23:05:07 +03:00
void disk_resize_success ( int vid ) ;
void disk_resize_failure ( int vid ) ;
2019-07-26 14:45:26 +03:00
void update_conf_success ( int vid ) ;
void update_conf_failure ( int vid ) ;
2017-02-07 19:26:23 +03:00
// -------------------------------------------------------------------------
// External Actions, triggered by user requests
// -------------------------------------------------------------------------
void deploy_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void suspend_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void restore_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void stop_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void checkpoint_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void migrate_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void live_migrate_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void shutdown_action ( const LCMAction & la , bool hard ) ;
2008-06-17 20:27:32 +04:00
2017-02-07 19:26:23 +03:00
void undeploy_action ( const LCMAction & la , bool hard ) ;
2013-03-27 21:15:53 +04:00
2017-02-07 19:26:23 +03:00
void poweroff_action ( const LCMAction & la ) ;
2012-09-04 20:30:53 +04:00
2017-02-07 19:26:23 +03:00
void poweroff_hard_action ( const LCMAction & la ) ;
2013-03-27 16:48:06 +04:00
2017-02-09 18:58:47 +03:00
void poweroff_action ( int vid , bool hard , const LCMAction & la ) ;
2013-03-27 16:48:06 +04:00
2017-02-07 19:26:23 +03:00
void updatesg_action ( const LCMAction & la ) ;
2009-07-09 18:34:34 +04:00
2017-02-07 19:26:23 +03:00
void restart_action ( const LCMAction & la ) ;
2009-07-09 18:34:34 +04:00
2017-02-07 19:26:23 +03:00
void delete_action ( const LCMAction & la ) ;
2010-12-31 19:48:50 +03:00
2017-02-07 19:26:23 +03:00
void delete_recreate_action ( const LCMAction & la ) ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*LIFE_CYCLE_MANAGER_H_*/