2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2024-07-29 15:25:20 +03:00
/* Copyright 2002-2024, 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 HISTORY_H_
# define HISTORY_H_
# include "ObjectSQL.h"
2017-01-30 01:46:59 +03:00
# include "ObjectXML.h"
2019-09-09 14:13:52 +03:00
# include "VMActions.h"
2008-06-17 20:27:32 +04:00
/**
* The History class , it represents an execution record of a Virtual Machine .
*/
2011-03-01 19:47:20 +03:00
class History : public ObjectSQL , public ObjectXML
2008-06-17 20:27:32 +04:00
{
public :
2008-06-22 05:51:49 +04:00
History ( int oid , int _seq = - 1 ) ;
History (
2024-06-03 12:40:24 +03:00
int oid ,
int seq ,
int hid ,
const std : : string & hostname ,
int cid ,
const std : : string & vmm ,
const std : : string & tmm ,
int ds_id ,
const std : : string & vm_info ) ;
~ History ( ) { } ;
2008-06-22 05:51:49 +04:00
2009-07-09 18:34:34 +04:00
/**
* Function to write the History Record in an output stream
*/
2020-07-02 23:42:10 +03:00
friend std : : ostream & operator < < ( std : : ostream & os , const History & history ) ;
2009-07-09 18:34:34 +04:00
/**
* 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
*/
2020-07-02 23:42:10 +03:00
std : : string & to_xml ( std : : string & xml ) const ;
2010-04-11 00:16:47 +04:00
2018-10-09 12:05:08 +03:00
/**
* Function to print the History object into a string in
* XML format with reduce information
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
2020-07-02 23:42:10 +03:00
std : : string & to_xml_short ( std : : string & xml ) const ;
2018-10-09 12:05:08 +03: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
void non_persistent_data ( ) ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
// ----------------------------------------
// History fields
// ----------------------------------------
2020-07-02 23:42:10 +03:00
int oid ;
int seq ;
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
int uid ;
int gid ;
int req_id ;
2017-02-09 18:58:47 +03:00
2020-07-02 23:42:10 +03:00
int hid ;
std : : string hostname ;
int cid ;
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
std : : string vmm_mad_name ;
std : : string tm_mad_name ;
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
int ds_id ;
2012-06-29 18:48:43 +04:00
2020-07-02 23:42:10 +03:00
time_t stime ;
time_t etime ;
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
time_t prolog_stime ;
time_t prolog_etime ;
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
time_t running_stime ;
time_t running_etime ;
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
time_t epilog_stime ;
time_t epilog_etime ;
2008-06-17 20:27:32 +04:00
2019-09-09 14:13:52 +03:00
VMActions : : Action action ;
2013-04-03 18:18:50 +04:00
2020-07-02 23:42:10 +03:00
std : : string vm_info ;
2012-05-04 19:29:36 +04:00
2012-02-26 02:31:44 +04:00
// -------------------------------------------------------------------------
// Non-persistent history fields
// -------------------------------------------------------------------------
// Local paths
2020-07-02 23:42:10 +03:00
std : : string transfer_file ;
std : : string deployment_file ;
std : : string context_file ;
std : : string token_file ;
2009-03-06 15:10:15 +03:00
2012-02-26 02:31:44 +04:00
// Remote paths
2020-07-02 23:42:10 +03:00
std : : string checkpoint_file ;
std : : string rdeployment_file ;
std : : string system_dir ;
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 .
*/
2023-02-07 10:50:30 +03:00
int insert ( SqlDB * db , std : : string & error_str ) override
2011-03-08 19:55:14 +03:00
{
error_str . clear ( ) ;
return insert_replace ( db , false ) ;
}
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 .
*/
2023-02-07 10:50:30 +03:00
int select ( SqlDB * db ) override ;
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 .
*/
2024-06-03 12:40:24 +03:00
int update ( SqlDB * db ) override
{
2011-03-08 19:55:14 +03:00
return insert_replace ( db , true ) ;
2024-06-03 12:40:24 +03:00
}
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
*/
2023-02-07 10:50:30 +03:00
int drop ( SqlDB * db ) override ;
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
2012-05-04 19:29:36 +04:00
/**
* Function to print the History object into a string in
* XML format , to be stored in the DB . It includes the VM template info
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
2020-07-02 23:42:10 +03:00
std : : string & to_db_xml ( std : : string & xml ) const ;
2012-05-04 19:29:36 +04:00
/**
* Function to print the History object into a string in
* XML format . The VM info can be optionally included
* @ param xml the resulting XML string
* @ param database If it is true , the TEMPLATE element will be included
* @ return a reference to the generated string
*/
2020-07-02 23:42:10 +03:00
std : : string & to_xml ( std : : string & xml , bool database ) const ;
2012-05-04 19:29:36 +04:00
2020-07-02 23:42:10 +03:00
std : : string & to_json ( std : : string & json ) const ;
2019-01-30 02:10:18 +03:00
2009-07-09 18:34:34 +04:00
/**
2011-03-01 19:47:20 +03:00
* Rebuilds the object from an xml node
* @ param node The xml node pointer
*
* @ return 0 on success , - 1 otherwise
*/
2011-03-08 19:55:14 +03:00
int from_xml_node ( const xmlNodePtr node )
{
ObjectXML : : update_from_node ( node ) ;
return rebuild_attributes ( ) ;
}
2011-03-01 19:47:20 +03:00
/**
* Rebuilds the object from an xml formatted string
* @ param xml_str The xml - formatted string
*
* @ return 0 on success , - 1 otherwise
*/
2020-07-02 23:42:10 +03:00
int from_xml ( const std : : string & xml_str )
2011-03-08 19:55:14 +03:00
{
ObjectXML : : update_from_str ( xml_str ) ;
return rebuild_attributes ( ) ;
}
2011-03-01 19:47:20 +03:00
/**
* Rebuilds the internal attributes using xpath
2009-07-09 18:34:34 +04:00
*/
2011-03-01 19:47:20 +03:00
int rebuild_attributes ( ) ;
2008-06-17 20:27:32 +04:00
} ;
2010-09-02 22:44:14 +04:00
# endif /*HISTORY_H_*/