2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2010-02-22 20:00:30 +03:00
/* Copyright 2002-2010, 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 HISTORY_H_
# define HISTORY_H_
# include "ObjectSQL.h"
using namespace std ;
/**
* The History class , it represents an execution record of a Virtual Machine .
*/
class History : public ObjectSQL
{
public :
enum MigrationReason
{
2010-04-11 00:16:47 +04:00
NONE , /** < Normal termination in host */
ERROR , /** < The VM was migrated because of an error */
2008-06-23 02:38:55 +04:00
STOP_RESUME , /** < The VM was migrated because of a stop/resume request*/
2010-04-11 00:16:47 +04:00
USER , /** < The VM was migrated because of an explicit request */
CANCEL /** < The VM was migrated because of an explicit cancel */
2008-06-17 20:27:32 +04:00
} ;
2008-06-22 05:51:49 +04:00
History ( int oid , int _seq = - 1 ) ;
History (
2010-04-11 00:16:47 +04:00
int oid ,
int seq ,
int hid ,
string & hostname ,
string & vm_dir ,
string & vmm ,
string & tm ) ;
2008-06-22 05:51:49 +04:00
~ History ( ) { } ;
2009-07-09 18:34:34 +04:00
/**
* Function to write the History Record in an output stream
*/
friend ostream & operator < < ( ostream & os , const History & history ) ;
/**
* Function to print the History object into a string in
* plain text
* @ param str the resulting string
* @ return a reference to the generated string
*/
string & to_str ( string & str ) const ;
/**
* Function to print the History object into a string in
* XML format
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
string & to_xml ( string & xml ) const ;
2010-04-11 00:16:47 +04:00
2008-06-17 20:27:32 +04:00
private :
friend class VirtualMachine ;
2010-04-11 00:16:47 +04:00
friend class VirtualMachinePool ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
// ----------------------------------------
// DataBase implementation variables
// ----------------------------------------
enum ColNames
{
2008-11-13 19:21:17 +03:00
VID = 0 ,
2008-06-17 20:27:32 +04:00
SEQ = 1 ,
HOSTNAME = 2 ,
VM_DIR = 3 ,
HID = 4 ,
VMMMAD = 5 ,
TMMAD = 6 ,
STIME = 7 ,
ETIME = 8 ,
PROLOG_STIME = 9 ,
PROLOG_ETIME = 10 ,
RUNNING_STIME = 11 ,
RUNNING_ETIME = 12 ,
EPILOG_STIME = 13 ,
EPILOG_ETIME = 14 ,
REASON = 15 ,
LIMIT = 16
} ;
static const char * table ;
static const char * db_names ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
static const char * db_bootstrap ;
void non_persistent_data ( ) ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
static string column_name ( const ColNames column )
{
switch ( column )
{
case HID :
2009-03-06 15:10:15 +03:00
return " hid " ;
2008-06-17 20:27:32 +04:00
case ETIME :
return " etime " ;
case RUNNING_ETIME :
return " retime " ;
default :
return " " ;
}
}
// ----------------------------------------
// History fields
// ----------------------------------------
int oid ;
int seq ;
string hostname ;
2008-11-13 19:21:17 +03:00
string vm_dir ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
int hid ;
string vmm_mad_name ;
string tm_mad_name ;
time_t stime ;
time_t etime ;
time_t prolog_stime ;
time_t prolog_etime ;
time_t running_stime ;
time_t running_etime ;
time_t epilog_stime ;
time_t epilog_etime ;
MigrationReason reason ;
//Non-persistent history fields
string vm_lhome ;
2008-11-13 19:21:17 +03:00
string transfer_file ;
string deployment_file ;
2009-03-06 15:10:15 +03:00
string context_file ;
2008-11-13 19:21:17 +03:00
string vm_rhome ;
2008-06-17 20:27:32 +04:00
string checkpoint_file ;
2008-11-13 19:21:17 +03:00
string rdeployment_file ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Writes the history record in the DB
* @ param db pointer to the database .
* @ return 0 on success .
*/
2010-08-05 21:28:28 +04:00
int insert ( SqlDB * db , string & error_str ) ;
2008-06-17 20:27:32 +04:00
/**
* Reads the history record from the DB
* @ param db pointer to the database .
* @ return 0 on success .
*/
2010-04-11 00:16:47 +04:00
int select ( SqlDB * db ) ;
2010-08-05 21:28:28 +04:00
2008-06-17 20:27:32 +04:00
/**
2010-05-03 21:13:37 +04:00
* Updates the history record
2008-06-17 20:27:32 +04:00
* @ param db pointer to the database .
* @ return 0 on success .
*/
2010-05-03 21:13:37 +04:00
int update ( SqlDB * db ) ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
2010-05-03 21:13:37 +04:00
* Removes the all history records from the DB
2008-06-17 20:27:32 +04:00
* @ param db pointer to the database .
* @ return 0 on success .
2009-03-06 15:10:15 +03:00
*/
2010-05-03 21:13:37 +04:00
int drop ( SqlDB * db ) ;
2010-08-05 21:28:28 +04:00
2010-05-03 21:13:37 +04:00
/**
2010-08-05 21:28:28 +04:00
* Execute an INSERT or REPLACE Sql query .
2010-05-03 21:13:37 +04:00
* @ param db The SQL DB
2010-08-05 21:28:28 +04:00
* @ param replace Execute an INSERT or a REPLACE
2010-05-03 21:13:37 +04:00
* @ return 0 on success
*/
int insert_replace ( SqlDB * db , bool replace ) ;
2008-06-17 20:27:32 +04:00
/**
2010-04-11 00:16:47 +04:00
* Callback function to unmarshall a history object ( History : : select )
2008-06-17 20:27:32 +04:00
* @ param num the number of columns read from the DB
* @ para names the column names
* @ para vaues the column values
* @ return 0 on success
*/
2010-04-11 00:16:47 +04:00
int select_cb ( void * nil , int num , char * * values , char * * names ) ;
2009-07-09 18:34:34 +04:00
/**
* Function to unmarshall a History object into an output stream with XML
* format .
* @ param oss the output stream
* @ param num the number of columns read from the DB
* @ param names the column names
* @ param vaues the column values
* @ return 0 on success
*/
2010-04-11 00:16:47 +04:00
static int dump ( ostringstream & oss , int num , char * * names , char * * values ) ;
2008-06-17 20:27:32 +04:00
} ;
2010-04-11 00:16:47 +04:00
# endif /*HISTORY_H_*/