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

Feature #662: Better one.*.delete method implementation. GroupPool::drop checks for errors, and returns error messages.

This commit is contained in:
Carlos Martín 2011-06-07 16:32:18 +02:00
parent 057d2e11cd
commit 1c1d981cfe
8 changed files with 55 additions and 52 deletions

View File

@ -111,10 +111,26 @@ public:
/** /**
* Drops the Group from the data base. The object mutex SHOULD be * Drops the Group from the data base. The object mutex SHOULD be
* locked. * locked.
* @param group a pointer to the object * @param objsql a pointer to a Group object
* @return 0 on success. * @return 0 on success.
*/ */
int drop(Group * group); int drop(PoolObjectSQL * objsql)
{
string err;
return drop(objsql, err);
};
/**
* Drops the Group from the data base. The object mutex SHOULD be
* locked.
* @param objsql a pointer to a Group object
* @param error_msg Error reason, if any
* @return 0 on success,
* -1 DB error,
* -2 object is a system group (ID < 100)
* -3 Group's User IDs set is not empty
*/
int drop(PoolObjectSQL * objsql, string& error_msg);
/** /**
* Bootstraps the database table(s) associated to the Group pool * Bootstraps the database table(s) associated to the Group pool

View File

@ -166,16 +166,6 @@ public:
return PoolSQL::search(oids, Host::table, where); return PoolSQL::search(oids, Host::table, where);
}; };
/**
* Drops the object's data in the data base. The object mutex SHOULD be
* locked.
* @param objsql a pointer to the object
* @return 0 on success.
*/
int drop(Host * host)
{
return host->drop(db);
};
private: private:
/** /**

View File

@ -95,15 +95,6 @@ public:
return image->update(db); return image->update(db);
}; };
/** Drops an image from the DB, the image mutex MUST BE locked
* @param image pointer to Image
* @return 0 on success
*/
int drop(Image * image)
{
return PoolSQL::drop(image);
};
/** /**
* Bootstraps the database table(s) associated to the Image pool * Bootstraps the database table(s) associated to the Image pool
*/ */

View File

@ -42,6 +42,13 @@ protected:
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
void request_execute(xmlrpc_c::paramList const& _paramList); void request_execute(xmlrpc_c::paramList const& _paramList);
/* -------------------------------------------------------------------- */
virtual int drop(PoolObjectSQL * object, string& error_msg)
{
return pool->drop(object);
};
}; };
@ -131,6 +138,13 @@ public:
}; };
~GroupDelete(){}; ~GroupDelete(){};
/* -------------------------------------------------------------------- */
int drop(PoolObjectSQL * object, string& error_msg)
{
return static_cast<GroupPool*>(pool)->drop(object, error_msg);
};
}; };
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */

View File

@ -89,14 +89,6 @@ public:
return user->update(db); return user->update(db);
}; };
/** Drops a user from the DB, the user mutex MUST BE locked
* @param user pointer to User
*/
int drop(User * user)
{
return PoolSQL::drop(user);
};
/** /**
* Bootstraps the database table(s) associated to the User pool * Bootstraps the database table(s) associated to the User pool
*/ */

View File

@ -87,17 +87,6 @@ public:
return vm_template->update(db); return vm_template->update(db);
}; };
/**
* Drops the object's data in the data base. The object mutex SHOULD be
* locked.
* @param objsql a pointer to the object
* @return 0 on success.
*/
int drop(VMTemplate * vm_template)
{
return PoolSQL::drop(vm_template);
};
/** /**
* Dumps the pool in XML format. A filter can be also added to the * Dumps the pool in XML format. A filter can be also added to the
* query * query

View File

@ -124,26 +124,36 @@ error_common:
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// TODO: add error string int GroupPool::drop(PoolObjectSQL * objsql, string& error_msg)
int GroupPool::drop(Group * group)
{ {
Group * group = static_cast<Group*>(objsql);
int rc;
// Return error if the group is a default one. // Return error if the group is a default one.
if( group->get_oid() < 100 ) if( group->get_oid() < 100 )
{ {
NebulaLog::log("GROUP",Log::ERROR, error_msg = "System Groups (ID < 100) cannot be deleted.";
"System Groups (ID < 100) cannot be deleted."); NebulaLog::log("GROUP", Log::ERROR, error_msg);
return -1; return -2;
} }
if( group->get_collection_size() > 0 ) if( group->get_collection_size() > 0 )
{ {
ostringstream oss; ostringstream oss;
oss << "Group " << group->get_oid() << " is not empty."; oss << "Group " << group->get_oid() << " is not empty.";
NebulaLog::log("GROUP",Log::ERROR, oss.str()); error_msg = oss.str();
NebulaLog::log("GROUP", Log::ERROR, error_msg);
return -1; return -3;
} }
return group->drop(db); rc = group->drop(db);
if( rc != 0 )
{
rc = -1;
}
return rc;
} }

View File

@ -26,6 +26,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
int oid = xmlrpc_c::value_int(paramList.getInt(1)); int oid = xmlrpc_c::value_int(paramList.getInt(1));
PoolObjectSQL * object; PoolObjectSQL * object;
set<int> group_set; set<int> group_set;
string error_msg;
if ( basic_authorization(oid) == false ) if ( basic_authorization(oid) == false )
{ {
@ -46,13 +47,13 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
group_set = user->get_groups(); group_set = user->get_groups();
} }
int rc = pool->drop(object); int rc = drop(object, error_msg);
object->unlock(); object->unlock();
if ( rc != 0 ) if ( rc != 0 )
{ {
failure_response(INTERNAL,request_error("Internal Error","")); failure_response(INTERNAL,request_error(error_msg, ""));
return; return;
} }