1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #212: better initialization of Scheduler class

This commit is contained in:
Ruben S. Montero 2010-05-18 18:59:44 +02:00
parent 2b5ffb2c1a
commit 8a15d380f6
5 changed files with 51 additions and 32 deletions

View File

@ -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

View File

@ -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'
])

View File

@ -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

View File

@ -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;
}

View File

@ -19,8 +19,7 @@
#include <fstream>
#include <pwd.h>
#include <stdlib.h>
#include <stdexcept>
#include <limits.h>
#include <string.h>
@ -64,10 +63,8 @@ void Client::set_one_auth(string secret)
}
else
{
NebulaLog::log("XMLRPC",Log::ERROR,
"ONE_AUTH wrong format, must be <username>:<password>");
throw;
throw runtime_error("Wrong format for auth token, must "
"be <username>:<passwd>");
}
}
}