From 8a15d380f6a11cc450c24883632c4f8f20e631dc Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 18 May 2010 18:59:44 +0200 Subject: [PATCH] feature #212: better initialization of Scheduler class --- src/scheduler/include/Scheduler.h | 14 +++++++--- src/scheduler/src/sched/SConstruct | 4 +-- src/scheduler/src/sched/Scheduler.cc | 18 +++++++++++-- src/scheduler/src/sched/mm_sched.cc | 38 ++++++++++++++-------------- src/scheduler/src/xml/Client.cc | 9 +++---- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 0508adacb8..bd972185ff 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -44,15 +44,16 @@ public: protected: - Scheduler(string& url, time_t _timer, + Scheduler(string& _url, time_t _timer, int _machines_limit, int _dispatch_limit): hpool(0), vmpool(0), timer(_timer), + url(_url), machines_limit(_machines_limit), dispatch_limit(_dispatch_limit), threshold(0.9), - client("",url) + client(0) { am.addListener(this); }; @@ -68,6 +69,11 @@ protected: { delete vmpool; } + + if ( client != 0) + { + delete client; + } }; // --------------------------------------------------------------- @@ -123,6 +129,8 @@ private: time_t timer; + string url; + /** * Limit of pending virtual machines to process from the pool. */ @@ -141,7 +149,7 @@ private: /** * XML_RPC client */ - Client client; + Client * client; // --------------------------------------------------------------- // Timer to periodically schedule and dispatch VMs diff --git a/src/scheduler/src/sched/SConstruct b/src/scheduler/src/sched/SConstruct index 0dde14b6bf..0a4350277e 100644 --- a/src/scheduler/src/sched/SConstruct +++ b/src/scheduler/src/sched/SConstruct @@ -28,11 +28,11 @@ env.StaticLibrary(lib_name, source_files) # Build daemon env.Append(LIBS=[ - 'scheduler_xml', + 'nebula_common', 'scheduler_sched', 'scheduler_pool', 'nebula_log', - 'nebula_common', + 'scheduler_xml', 'crypto' ]) diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 5de1435576..383161d76e 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -99,14 +99,28 @@ void Scheduler::start() throw; } + // ----------------------------------------------------------- + // XML-RPC Client + // ----------------------------------------------------------- + + try + { + client = new Client("",url); + } + catch(runtime_error &) + { + throw; + } + + xmlInitParser(); // ----------------------------------------------------------- // Pools // ----------------------------------------------------------- - hpool = new HostPoolXML(&client); - vmpool = new VirtualMachinePoolXML(&client, machines_limit); + hpool = new HostPoolXML(client); + vmpool = new VirtualMachinePoolXML(client, machines_limit); // ----------------------------------------------------------- // Load scheduler policies diff --git a/src/scheduler/src/sched/mm_sched.cc b/src/scheduler/src/sched/mm_sched.cc index 79fa58699d..619bbeb1c1 100644 --- a/src/scheduler/src/sched/mm_sched.cc +++ b/src/scheduler/src/sched/mm_sched.cc @@ -31,12 +31,12 @@ class RankScheduler : public Scheduler { public: - RankScheduler(string url, + RankScheduler(string url, + time_t timer, unsigned int machines_limit, - unsigned int dispatch_limit, - time_t timer=1 + unsigned int dispatch_limit ):Scheduler(url,timer,machines_limit, dispatch_limit),rp(0){}; - + ~RankScheduler() { if ( rp != 0 ) @@ -44,17 +44,17 @@ public: delete rp; } }; - + void register_policies() { rp = new RankPolicy(vmpool,hpool,1.0); - - add_host_policy(rp); + + add_host_policy(rp); }; - + private: RankPolicy * rp; - + }; int main(int argc, char **argv) @@ -65,9 +65,9 @@ int main(int argc, char **argv) unsigned int machines_limit = 400; unsigned int dispatch_limit = 300; char opt; - + ostringstream oss; - + while((opt = getopt(argc,argv,"p:t:m:d:")) != -1) { switch(opt) @@ -91,25 +91,25 @@ int main(int argc, char **argv) break; } }; - + /* ---------------------------------------------------------------------- */ - + oss << "http://localhost:" << port << "/RPC2"; - + ss = new RankScheduler(oss.str(),timer, machines_limit, dispatch_limit); - + try { - ss->start(); + ss->start(); } catch (exception &e) { cout << e.what() << endl; - + return -1; } - + delete ss; - + return 0; } diff --git a/src/scheduler/src/xml/Client.cc b/src/scheduler/src/xml/Client.cc index d893023ffd..a2480ce813 100644 --- a/src/scheduler/src/xml/Client.cc +++ b/src/scheduler/src/xml/Client.cc @@ -19,8 +19,7 @@ #include #include #include - - +#include #include #include @@ -64,10 +63,8 @@ void Client::set_one_auth(string secret) } else { - NebulaLog::log("XMLRPC",Log::ERROR, - "ONE_AUTH wrong format, must be :"); - - throw; + throw runtime_error("Wrong format for auth token, must " + "be :"); } } }