1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-26 10:03:37 +03:00

Feature #2665: More DB write checks for federation slaves

This commit is contained in:
Carlos Martín 2014-01-29 13:04:07 +01:00
parent 7254f1b81a
commit c36bc33fd4
8 changed files with 116 additions and 14 deletions

View File

@ -40,7 +40,7 @@ public:
AclManager(SqlDB * _db, int zone_id, bool _refresh_cache, time_t timer_period);
AclManager(int _zone_id)
:zone_id(_zone_id), db(0),lastOID(0), refresh_cache(false)
:zone_id(_zone_id), db(0),lastOID(0), is_federation_slave(false)
{
pthread_mutex_init(&mutex, 0);
};
@ -412,7 +412,7 @@ private:
/**
* Flag to refresh the cache periodically
*/
bool refresh_cache;
bool is_federation_slave;
/**
* Timer period for the cache refresh loop.

View File

@ -62,6 +62,15 @@ public:
bool enabled,
string& error_str);
/**
* Drops the object's data in the data base. The object mutex SHOULD be
* locked.
* @param objsql a pointer to the object
* @param error_msg Error reason, if any
* @return 0 on success, -1 DB error
*/
int drop(PoolObjectSQL * objsql, string& error_msg);
/**
* Function to get a User from the pool, if the object is not in memory
* it is loaded from the DB

View File

@ -91,10 +91,7 @@ public:
* @param zone pointer to Zone
* @return 0 on success
*/
int update(Zone * zone)
{
return zone->update(db);
};
int update(Zone * zone);
/**
* Drops the Zone from the data base. The object mutex SHOULD be

View File

@ -51,9 +51,9 @@ int AclManager::init_cb(void *nil, int num, char **values, char **names)
AclManager::AclManager(
SqlDB * _db,
int _zone_id,
bool _refresh_cache,
bool _is_federation_slave,
time_t _timer_period)
:zone_id(_zone_id), db(_db), lastOID(-1), refresh_cache(_refresh_cache),
:zone_id(_zone_id), db(_db), lastOID(-1), is_federation_slave(_is_federation_slave),
timer_period(_timer_period)
{
ostringstream oss;
@ -143,7 +143,7 @@ int AclManager::start()
rc = select();
if (refresh_cache)
if (is_federation_slave)
{
pthread_attr_t pattr;
@ -165,7 +165,7 @@ int AclManager::start()
void AclManager::finalize()
{
if (refresh_cache)
if (is_federation_slave)
{
am.trigger(ACTION_FINALIZE,0);
}
@ -513,6 +513,15 @@ bool AclManager::match_rules(
int AclManager::add_rule(long long user, long long resource, long long rights,
long long zone, string& error_str)
{
if (is_federation_slave)
{
NebulaLog::log("ONE",Log::ERROR,
"AclManager::add_rule called, but this "
"OpenNebula is a federation slave");
return -1;
}
lock();
if (lastOID == INT_MAX)
@ -609,6 +618,15 @@ int AclManager::del_rule(int oid, string& error_str)
int rc;
bool found = false;
if (is_federation_slave)
{
NebulaLog::log("ONE",Log::ERROR,
"AclManager::del_rule called, but this "
"OpenNebula is a federation slave");
return -1;
}
lock();
// Check the rule exists

View File

@ -93,6 +93,15 @@ int GroupPool::allocate(string name, int * oid, string& error_str)
ostringstream oss;
if (Nebula::instance().is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"GroupPool::allocate called, but this "
"OpenNebula is a federation slave");
return -1;
}
// Check name
if ( !PoolObjectSQL::name_is_valid(name, error_str) )
{
@ -159,6 +168,15 @@ int GroupPool::drop(PoolObjectSQL * objsql, string& error_msg)
int rc;
if (Nebula::instance().is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"GroupPool::drop called, but this "
"OpenNebula is a federation slave");
return -1;
}
// Return error if the group is a default one.
if( group->get_oid() < 100 )
{

View File

@ -914,11 +914,9 @@ void Nebula::start(bool bootstrap_only)
}
// ---- ACL Manager ----
bool refresh_acl_cache = is_federation_slave();
try
{
aclm = new AclManager(db, zone_id, refresh_acl_cache, timer_period);
aclm = new AclManager(db, zone_id, is_federation_slave(), timer_period);
}
catch (bad_alloc&)
{
@ -1079,7 +1077,7 @@ void Nebula::start(bool bootstrap_only)
pthread_join(hm->get_thread_id(),0);
pthread_join(imagem->get_thread_id(),0);
if(refresh_acl_cache)
if(is_federation_slave())
{
pthread_join(aclm->get_thread_id(),0);
}

View File

@ -261,6 +261,15 @@ int UserPool::allocate (
ostringstream oss;
if (nd.is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"UserPool::allocate called, but this "
"OpenNebula is a federation slave");
return -1;
}
// Check username and password
if ( !User::pass_is_valid(password, error_str) )
{
@ -347,6 +356,23 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int UserPool::drop(PoolObjectSQL * objsql, string& error_msg)
{
if (Nebula::instance().is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"UserPool::drop called, but this "
"OpenNebula is a federation slave");
return -1;
}
return PoolSQL::drop(objsql, error_msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int UserPool::update(User * user)
{
if (Nebula::instance().is_federation_slave())

View File

@ -16,6 +16,7 @@
#include "ZonePool.h"
#include "NebulaLog.h"
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
@ -83,6 +84,15 @@ int ZonePool::allocate(
ostringstream oss;
if (Nebula::instance().is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"ZonePool::allocate called, but this "
"OpenNebula is a federation slave");
return -1;
}
zone = new Zone(-1, zone_template);
// -------------------------------------------------------------------------
@ -121,8 +131,34 @@ error_name:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ZonePool::update(Zone * zone)
{
if (Nebula::instance().is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"ZonePool::update called, but this "
"OpenNebula is a federation slave");
return -1;
}
return zone->update(db);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ZonePool::drop(PoolObjectSQL * objsql, string& error_msg)
{
if (Nebula::instance().is_federation_slave())
{
NebulaLog::log("ONE",Log::ERROR,
"ZonePool::drop called, but this "
"OpenNebula is a federation slave");
return -1;
}
Zone * zone = static_cast<Zone*>(objsql);
// Return error if the zone is a default one.