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 TRANSFER_MANAGER_H_
# define TRANSFER_MANAGER_H_
# include "MadManager.h"
# include "ActionManager.h"
# include "VirtualMachinePool.h"
# include "LifeCycleManager.h"
2008-11-13 19:21:17 +03:00
# include "TransferManagerDriver.h"
2008-06-17 20:27:32 +04:00
using namespace std ;
extern " C " void * tm_action_loop ( void * arg ) ;
class TransferManager : public MadManager , public ActionListener
{
public :
TransferManager (
2008-11-13 19:21:17 +03:00
VirtualMachinePool * _vmpool ,
HostPool * _hpool ,
2008-06-17 20:27:32 +04:00
vector < const Attribute * > & _mads ) :
MadManager ( _mads ) ,
2008-11-13 19:21:17 +03:00
vmpool ( _vmpool ) ,
hpool ( _hpool )
2008-06-17 20:27:32 +04:00
{
am . addListener ( this ) ;
} ;
~ TransferManager ( ) { } ;
enum Actions
{
PROLOG ,
2008-11-13 19:21:17 +03:00
PROLOG_MIGR ,
PROLOG_RESUME ,
2008-06-17 20:27:32 +04:00
EPILOG ,
2008-11-13 19:21:17 +03:00
EPILOG_STOP ,
2009-07-09 18:34:34 +04:00
EPILOG_DELETE ,
EPILOG_DELETE_PREVIOUS ,
2008-06-17 20:27:32 +04:00
CHECKPOINT ,
2009-07-09 18:34:34 +04:00
DRIVER_CANCEL ,
2008-06-17 20:27:32 +04:00
FINALIZE
} ;
/**
* Triggers specific actions to the Information Manager . This function
* wraps the ActionManager trigger function .
* @ param action the IM action
* @ param vid VM unique id . This is the argument of the passed to the
* invoked action .
*/
2010-11-10 15:58:48 +03:00
virtual void trigger (
2008-06-17 20:27:32 +04:00
Actions action ,
int vid ) ;
/**
* This functions starts the associated listener thread , and creates a
* 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 ( ) ;
/**
* Loads Virtual Machine Manager Mads defined in configuration file
* @ param uid of the user executing the driver . When uid is 0 the nebula
* identity will be used . Otherwise the Mad will be loaded through the
* sudo application .
*/
2008-11-13 19:21:17 +03:00
void load_mads ( int uid ) ;
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 tm_thread ;
} ;
private :
/**
* Thread id for the Transfer Manager
*/
pthread_t tm_thread ;
/**
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 ;
2008-06-17 20:27:32 +04:00
/**
* Action engine for the Manager
*/
2008-11-13 19:21:17 +03:00
ActionManager am ;
/**
* Returns a pointer to a Transfer Manager driver .
* @ param name of an attribute of the driver ( e . g . its type )
* @ param value of the attribute
* @ return the TM driver owned by uid with attribute name equal to value
* or 0 in not found
*/
const TransferManagerDriver * get (
const string & name ,
const string & value )
{
return static_cast < const TransferManagerDriver * >
2009-07-13 17:47:42 +04:00
( MadManager : : get ( 0 , name , value ) ) ;
2008-11-13 19:21:17 +03:00
} ;
2008-06-17 20:27:32 +04:00
2008-11-13 19:21:17 +03:00
/**
* Returns a pointer to a Transfer Manager driver . The driver is
* 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
*/
const TransferManagerDriver * get (
const string & name )
{
string _name ( " NAME " ) ;
return static_cast < const TransferManagerDriver * >
2009-07-13 17:47:42 +04:00
( MadManager : : get ( 0 , _name , name ) ) ;
2008-11-13 19:21:17 +03:00
} ;
2008-06-17 20:27:32 +04:00
/**
* Function to execute the Manager action loop method within a new pthread
* ( requires C linkage )
*/
friend void * tm_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 ) ;
/**
* This function starts the prolog sequence
*/
void prolog_action ( int vid ) ;
2008-11-13 19:21:17 +03:00
/**
* This function starts the prolog migration sequence
*/
void prolog_migr_action ( int vid ) ;
/**
* This function starts the prolog resume sequence
*/
void prolog_resume_action ( int vid ) ;
2008-06-17 20:27:32 +04:00
/**
* This function starts the epilog sequence
*/
void epilog_action ( int vid ) ;
2008-11-13 19:21:17 +03:00
/**
* This function starts the epilog_stop sequence
*/
void epilog_stop_action ( int vid ) ;
2009-07-09 18:34:34 +04:00
/**
* This function starts the epilog_delete sequence
*/
void epilog_delete_action ( int vid ) ;
/**
* This function starts the epilog_delete sequence on the previous host
*/
void epilog_delete_previous_action ( int vid ) ;
2008-06-17 20:27:32 +04:00
/**
* This function starts the epilog sequence
*/
void checkpoint_action ( int vid ) ;
2009-07-09 18:34:34 +04:00
/**
* This function cancels the operation being performed by the driver
*/
void driver_cancel_action ( int vid ) ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*TRANSFER_MANAGER_H*/