2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2012-01-12 15:29:18 +04:00
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
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 DISPATCH_MANAGER_H_
# define DISPATCH_MANAGER_H_
# include "ActionManager.h"
# include "HostPool.h"
# include "VirtualMachinePool.h"
using namespace std ;
extern " C " void * dm_action_loop ( void * arg ) ;
class DispatchManager : public ActionListener
{
public :
DispatchManager (
VirtualMachinePool * _vmpool ,
HostPool * _hpool ) :
hpool ( _hpool ) ,
vmpool ( _vmpool )
{
am . addListener ( this ) ;
} ;
~ DispatchManager ( )
{ }
;
enum Actions
{
2010-12-31 19:48:50 +03:00
SUSPEND_SUCCESS , /**< Send by LCM when a VM is suspended*/
STOP_SUCCESS , /**< Send by LCM when a VM is stopped*/
DONE , /**< Send by LCM when a VM is shut down*/
FAILED , /**< Send by LCM when one of the execution steps fails*/
RESUBMIT , /**< Send by LCM when a VM is ready for resubmission*/
2008-06-17 20:27:32 +04:00
FINALIZE
} ;
/**
* Triggers specific actions to the Dispatch Manager . This function
* wraps the ActionManager trigger function .
* @ param action the DM action
2010-07-14 20:11:29 +04: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 .
*/
void trigger (
Actions action ,
int _vid ) ;
/**
2010-07-14 20:11:29 +04:00
* This functions creates a new thread for the Dispatch 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 ( ) ;
2010-07-14 20:11:29 +04:00
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 dm_thread ;
} ;
//--------------------------------------------------------------------------
// DM Actions, the RM and the Scheduler will invoke this methods
//--------------------------------------------------------------------------
/**
* Deploys a VM . A new history record MUST be added before calling this
* function . Also the VM MUST have its mutex locked . If the function fails
* the calling funtion is responsible for recovering from the error .
* @ param vm pointer to a VirtualMachine with its mutex locked .
2010-07-14 20:11:29 +04:00
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
int deploy (
VirtualMachine * vm ) ;
/**
2010-07-14 20:11:29 +04:00
* Migrates a VM . The following actions must be performed before calling
* this function :
2008-06-17 20:27:32 +04:00
* - Lock the VM mutex .
* - Update the History statistics of the current host .
2010-07-14 20:11:29 +04:00
* - Add a new History record with the new host .
* If the function fails the calling funtion is responsible for recovering
2008-06-17 20:27:32 +04:00
* from the error .
* @ param vm pointer to a VirtualMachine with its mutex locked .
2010-07-14 20:11:29 +04:00
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
int migrate (
VirtualMachine * vm ) ;
/**
2010-07-14 20:11:29 +04:00
* Migrates a VM . The following actions must be performed before calling
* this function :
2008-06-17 20:27:32 +04:00
* - Lock the VM mutex .
* - Update the History statistics of the current host .
2010-07-14 20:11:29 +04:00
* - Add a new History record with the new host .
* If the function fails the calling funtion is responsible for recovering
2008-06-17 20:27:32 +04:00
* from the error .
* @ param vm pointer to a VirtualMachine with its mutex locked .
2010-07-14 20:11:29 +04:00
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
int live_migrate (
VirtualMachine * vm ) ;
2010-07-14 20:11:29 +04:00
2008-06-17 20:27:32 +04:00
/**
* Shuts down a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int shutdown (
int vid ) ;
/**
* Holds a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int hold (
int vid ) ;
/**
* Releases a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int release (
int vid ) ;
/**
* Stops a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int stop (
int vid ) ;
2008-09-08 14:57:52 +04:00
/**
* Cancels a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-09-08 14:57:52 +04:00
int cancel (
int vid ) ;
2008-06-17 20:27:32 +04:00
/**
* Suspends a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int suspend (
int vid ) ;
/**
* Resumes a VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int resume (
int vid ) ;
2010-07-14 20:11:29 +04:00
2009-07-09 18:34:34 +04:00
/**
* Restart a previusly deployed VM .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2009-07-09 18:34:34 +04:00
int restart (
int vid ) ;
2008-06-17 20:27:32 +04:00
/**
* Ends a VM life cycle inside ONE .
* @ param vid VirtualMachine identification
2010-07-14 20:11:29 +04:00
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
2008-06-17 20:27:32 +04:00
int finalize (
int vid ) ;
2010-12-31 19:48:50 +03:00
/**
* Moves a VM to PENDING state preserving any resource ( i . e . leases ) and id
* @ param vid VirtualMachine identification
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
int resubmit (
int vid ) ;
2011-12-26 02:46:19 +04:00
/**
* Reboots a VM preserving any resource and RUNNING state
* @ param vid VirtualMachine identification
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
int reboot (
int vid ) ;
2012-04-26 21:06:49 +04:00
/**
* Set the re - scheduling flag for the VM ( must be in RUNNING state )
* @ param vid VirtualMachine identification
* @ param do_resched set or unset the flag
* @ return 0 on success , - 1 if the VM does not exits or - 2 if the VM is
* in a wrong a state
*/
int resched (
int vid ,
bool do_resched ) ;
2008-06-17 20:27:32 +04:00
private :
/**
* Thread id for the Dispatch Manager
*/
pthread_t dm_thread ;
/**
* Pointer to the Host Pool , to access hosts
*/
HostPool * hpool ;
/**
2008-11-13 19:21:17 +03:00
* Pointer to the Virtual Machine Pool , to access hosts
2008-06-17 20:27:32 +04:00
*/
VirtualMachinePool * vmpool ;
/**
* Action engine for the Manager
*/
ActionManager am ;
/**
2010-07-14 20:11:29 +04: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 * dm_action_loop ( void * arg ) ;
/**
* The action function executed when an action is triggered .
* @ param action the name of the action
* @ param arg arguments for the action function
*/
void do_action (
const string & action ,
void * arg ) ;
//--------------------------------------------------------------------------
// DM Actions associated with a VM state transition
//--------------------------------------------------------------------------
2010-07-14 20:11:29 +04:00
2008-06-17 20:27:32 +04:00
void suspend_success_action ( int vid ) ;
void stop_success_action ( int vid ) ;
void done_action ( int vid ) ;
2010-07-14 20:11:29 +04:00
void failed_action ( int vid ) ;
2010-12-31 19:48:50 +03:00
void resubmit_action ( int vid ) ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*DISPATCH_MANAGER_H*/