From fadbe3a4d742eaa6097fffa6289dd962491486f9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 4 Mar 2011 23:26:55 +0100 Subject: [PATCH] feature #407: All resources now uses the base classes and index --- include/PoolObjectSQL.h | 3 +-- include/PoolSQL.h | 3 +-- include/User.h | 27 ++----------------- include/UserPool.h | 2 +- include/VirtualMachine.h | 17 ------------ src/pool/test/TestPoolSQL.cc | 4 +-- src/pool/test/TestPoolSQL.h | 4 +-- src/pool/test/pool.cc | 4 +-- src/rm/RequestManagerAllocate.cc | 2 +- src/rm/RequestManagerImageAllocate.cc | 2 +- .../RequestManagerVirtualNetworkAllocate.cc | 2 +- src/um/User.cc | 9 +++---- src/um/UserPool.cc | 2 +- src/um/test/UserPoolTest.cc | 4 +-- src/vm/VirtualMachine.cc | 4 +-- src/vm/VirtualMachinePool.cc | 2 +- 16 files changed, 23 insertions(+), 68 deletions(-) diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 8a5e921161..c7575ea754 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -37,8 +37,7 @@ class PoolObjectSQL : public ObjectSQL, public ObjectXML { public: - //TODO remove Defaults for Constructor Attributes - PoolObjectSQL(int id=-1, const string& _name ="", int _uid=0,const char *_table = 0) + PoolObjectSQL(int id, const string& _name, int _uid,const char *_table) :ObjectSQL(),ObjectXML(),oid(id),name(_name),uid(_uid), valid(true),table(_table) { diff --git a/include/PoolSQL.h b/include/PoolSQL.h index a750d04b80..333d241364 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -47,8 +47,7 @@ public: * counter). If null the OID counter is not updated. * @param with_uid the Pool objects have an owner id (uid) */ - //TODO REmove defaults - PoolSQL(SqlDB * _db, const char * table, bool with_uid=false); + PoolSQL(SqlDB * _db, const char * table, bool with_uid); virtual ~PoolSQL(); diff --git a/include/User.h b/include/User.h index 21c2a95781..5f98877f88 100644 --- a/include/User.h +++ b/include/User.h @@ -43,15 +43,6 @@ public: */ string& to_xml(string& xml) const; - /** - * Get the User unique identifier UID, that matches the OID of the object - * @return UID User identifier - */ - int get_uid() const - { - return oid; - }; - /** * Check if the user is enabled * @return true if the user is enabled @@ -61,15 +52,6 @@ public: return enabled; } - /** - * Returns user username - * @return username User's hostname - */ - const string& get_username() const - { - return username; - }; - /** * Returns user password * @return username User's hostname @@ -98,11 +80,11 @@ public: /** * Sets user username */ - void set_username(string _username) +/* void set_username(string _username) { username = _username; }; - +*/ /** * Sets user password */ @@ -138,11 +120,6 @@ private: // User Attributes // ------------------------------------------------------------------------- - /** - * User's username - */ - string username; - /** * User's password */ diff --git a/include/UserPool.h b/include/UserPool.h index 3c96cdf683..7b0c886c91 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -113,7 +113,7 @@ public: if ( rc == 0) { - known_users.erase(user->get_username()); + known_users.erase(user->get_name()); } return rc; diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 56d4117b2e..277d6c5316 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -183,16 +183,6 @@ public: } }; - - /** - * Returns the name of the VM - * @return the VM name - */ - const string& get_name() const - { - return name; - }; - /** * Returns the deployment ID * @return the VMM driver specific ID @@ -687,7 +677,6 @@ public: return uid; }; - // ------------------------------------------------------------------------ // Timers // ------------------------------------------------------------------------ @@ -753,7 +742,6 @@ public: */ int generate_context(string &files); - // ------------------------------------------------------------------------ // Image repository related functions // ------------------------------------------------------------------------ @@ -802,11 +790,6 @@ private: // Virtual Machine Description // ------------------------------------------------------------------------- - /** - * Name of the VM - */ - string name; - /** * The Virtual Machine template, holds the VM attributes. */ diff --git a/src/pool/test/TestPoolSQL.cc b/src/pool/test/TestPoolSQL.cc index 81e768140c..16823677ed 100644 --- a/src/pool/test/TestPoolSQL.cc +++ b/src/pool/test/TestPoolSQL.cc @@ -32,10 +32,10 @@ const char * TestObjectSQL::table = "test_pool"; -const char * TestObjectSQL::db_names = "(oid,number,text)"; +const char * TestObjectSQL::db_names = "(oid,number,name)"; const char * TestObjectSQL::db_bootstrap = "CREATE TABLE test_pool (" - "oid INTEGER, number INTEGER, text TEXT, PRIMARY KEY(oid))"; + "oid INTEGER, number INTEGER, name TEXT, PRIMARY KEY(oid))"; /* -------------------------------------------------------------------------- */ diff --git a/src/pool/test/TestPoolSQL.h b/src/pool/test/TestPoolSQL.h index 62d4578889..bf82904690 100644 --- a/src/pool/test/TestPoolSQL.h +++ b/src/pool/test/TestPoolSQL.h @@ -30,7 +30,7 @@ class TestObjectSQL : public PoolObjectSQL { public: //OBJECT ATTRIBUTES - TestObjectSQL(int n=-1, string t="default"):number(n),text(t){}; + TestObjectSQL(int n=-1, string t="default"):PoolObjectSQL(-1,"",0,0),number(n),text(t){}; ~TestObjectSQL(){}; @@ -88,7 +88,7 @@ class TestPool : public PoolSQL { public: - TestPool(SqlDB *db):PoolSQL(db,"test_pool"){}; + TestPool(SqlDB *db):PoolSQL(db,"test_pool",false){}; ~TestPool(){}; TestObjectSQL * get( diff --git a/src/pool/test/pool.cc b/src/pool/test/pool.cc index 5455d79d90..46523d8134 100644 --- a/src/pool/test/pool.cc +++ b/src/pool/test/pool.cc @@ -141,7 +141,7 @@ public: vector results; const char * table = "test_pool"; - string where = "text = '" + stB + "'"; + string where = "name = '" + stB + "'"; int ret; ret = pool->search(results, table, where); @@ -205,4 +205,4 @@ public: int main(int argc, char ** argv) { return OneUnitTest::main(argc, argv, PoolTest::suite()); -} \ No newline at end of file +} diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index ea83042503..f51ff1820c 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -134,7 +134,7 @@ void RequestManager::VirtualMachineAllocate::execute( goto error_user_get; } - user_name = user->get_username(); + user_name = user->get_name(); user->unlock(); diff --git a/src/rm/RequestManagerImageAllocate.cc b/src/rm/RequestManagerImageAllocate.cc index ae97859c9f..3146da6850 100644 --- a/src/rm/RequestManagerImageAllocate.cc +++ b/src/rm/RequestManagerImageAllocate.cc @@ -110,7 +110,7 @@ void RequestManager::ImageAllocate::execute( goto error_user_get; } - user_name = user->get_username(); + user_name = user->get_name(); user->unlock(); diff --git a/src/rm/RequestManagerVirtualNetworkAllocate.cc b/src/rm/RequestManagerVirtualNetworkAllocate.cc index 812daf5111..ac73e52705 100644 --- a/src/rm/RequestManagerVirtualNetworkAllocate.cc +++ b/src/rm/RequestManagerVirtualNetworkAllocate.cc @@ -109,7 +109,7 @@ void RequestManager::VirtualNetworkAllocate::execute( goto error_user_get; } - user_name = user->get_username(); + user_name = user->get_name(); user->unlock(); diff --git a/src/um/User.cc b/src/um/User.cc index 3d4c9ba1a8..e3b7618c47 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -35,8 +35,7 @@ User::User( string _username, string _password, bool _enabled): - PoolObjectSQL(id, table), - username (_username), + PoolObjectSQL(id, _username, 0, table), password (_password), enabled (_enabled) {}; @@ -105,7 +104,7 @@ int User::insert_replace(SqlDB *db, bool replace) // Update the User - sql_username = db->escape_str(username.c_str()); + sql_username = db->escape_str(name.c_str()); if ( sql_username == 0 ) { @@ -172,7 +171,7 @@ string& User::to_xml(string& xml) const oss << "" "" << oid <<"" << - "" << username <<"" << + "" << name <<"" << "" << password <<"" << "" << enabled_int <<"" << ""; @@ -194,7 +193,7 @@ int User::from_xml(const string& xml) update_from_str(xml); rc += xpath(oid, "/USER/ID", -1); - rc += xpath(username, "/USER/NAME", "not_found"); + rc += xpath(name, "/USER/NAME", "not_found"); rc += xpath(password, "/USER/PASSWORD", "not_found"); rc += xpath(int_enabled, "/USER/ENABLED", 0); diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 844b754542..a24355104c 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -45,7 +45,7 @@ int UserPool::init_cb(void *nil, int num, char **values, char **names) /* -------------------------------------------------------------------------- */ -UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table) +UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table,false) { ostringstream sql; diff --git a/src/um/test/UserPoolTest.cc b/src/um/test/UserPoolTest.cc index b931ea0b9a..281705207d 100644 --- a/src/um/test/UserPoolTest.cc +++ b/src/um/test/UserPoolTest.cc @@ -100,7 +100,7 @@ protected: { CPPUNIT_ASSERT( obj != 0 ); - string name = ((User*)obj)->get_username(); + string name = ((User*)obj)->get_name(); CPPUNIT_ASSERT( name == usernames[index] ); CPPUNIT_ASSERT( ((User*)obj)->get_password() == passwords[index] ); }; @@ -150,7 +150,7 @@ public: CPPUNIT_ASSERT(user != 0); CPPUNIT_ASSERT( user->get_uid() == 0 ); - CPPUNIT_ASSERT( user->get_username() == "one_user_test" ); + CPPUNIT_ASSERT( user->get_name() == "one_user_test" ); CPPUNIT_ASSERT( user->get_password() == User::sha1_digest("password") ); } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 534d0fe69d..48df263341 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -39,11 +39,9 @@ VirtualMachine::VirtualMachine(int id, string _user_name, VirtualMachineTemplate * _vm_template): - PoolObjectSQL(id,table), - uid(-1), + PoolObjectSQL(id,"",-1,table), user_name(_user_name), last_poll(0), - name(""), state(INIT), lcm_state(LCM_INIT), stime(time(0)), diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 60fdfc2ad7..09995f1a09 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -27,7 +27,7 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, vector hook_mads, const string& hook_location) - : PoolSQL(db,VirtualMachine::table) + : PoolSQL(db,VirtualMachine::table,true) { const VectorAttribute * vattr;