1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-26 09:57:23 +03:00

F #3380: Delete log after deleting hook (#3743)

This commit is contained in:
Christian González 2019-09-20 09:38:16 +02:00 committed by Ruben S. Montero
parent c185bebb57
commit a664466ee9
4 changed files with 52 additions and 2 deletions

View File

@ -204,7 +204,7 @@ private:
* @param db pointer to the db * @param db pointer to the db
* @return 0 on success * @return 0 on success
*/ */
int update(SqlDB *db) int update(SqlDB *db) override
{ {
string error_str; string error_str;
return insert_replace(db, true, error_str); return insert_replace(db, true, error_str);
@ -215,7 +215,7 @@ private:
* @param db pointer to the db * @param db pointer to the db
* @return 0 on success * @return 0 on success
*/ */
int insert(SqlDB *db, string& error_str); int insert(SqlDB *db, string& error_str) override;
/** /**
* Execute an INSERT or REPLACE Sql query. * Execute an INSERT or REPLACE Sql query.
@ -225,6 +225,13 @@ private:
* @return 0 one success * @return 0 one success
*/ */
int insert_replace(SqlDB *db, bool replace, string& error_str); int insert_replace(SqlDB *db, bool replace, string& error_str);
/**
* Drops object from the database
* @param db pointer to the db
* @return 0 on success
*/
int drop(SqlDB *db) override;
}; };
#endif /*HOOK_H_*/ #endif /*HOOK_H_*/

View File

@ -93,6 +93,14 @@ public:
*/ */
static int bootstrap(SqlDB *_db); static int bootstrap(SqlDB *_db);
/**
* Drops object from the database
* @param db pointer to the db
* @return 0 on success
*/
int drop(SqlDB *db, const int hook_id);
private: private:
// ---------------------------------------- // ----------------------------------------

View File

@ -19,6 +19,7 @@
#include "HookImplementation.h" #include "HookImplementation.h"
#include "HookStateHost.h" #include "HookStateHost.h"
#include "HookStateVM.h" #include "HookStateVM.h"
#include "HookLog.h"
#include <string> #include <string>
@ -405,3 +406,25 @@ int Hook::set_hook(HookType hook_type, string& error)
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Hook::drop(SqlDB *db)
{
ostringstream oss;
int rc;
oss << "DELETE FROM " << table << " WHERE oid=" << oid;
rc = db->exec_wr(oss);
if (rc != 0)
{
return rc;
}
Nebula& nd = Nebula::instance();
HookLog* hl = nd.get_hl();
return hl->drop(db, oid);
}

View File

@ -138,6 +138,18 @@ int HookLog::dump_log(std::string &xml_log)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int HookLog::drop(SqlDB *db, const int hook_id)
{
ostringstream oss;
oss << "DELETE FROM " << table << " WHERE hkid =" << hook_id;
return db->exec_wr(oss);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int HookLog::add(int hkid, int hkrc, std::string &xml_result) int HookLog::add(int hkid, int hkrc, std::string &xml_result)
{ {
std::ostringstream oss; std::ostringstream oss;