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

feature #360: Scheduler now uses configuration file parameters. Removed sched options from one start script and scheduler daemon

This commit is contained in:
Ruben S. Montero 2011-12-15 01:19:23 +01:00
parent cc0b108fcd
commit 3f38152881
8 changed files with 78 additions and 97 deletions

View File

@ -59,6 +59,15 @@ public:
Template::get(_name,values);
};
void get(const char *name, unsigned int& values) const
{
int ival;
NebulaTemplate::get(name, ival);
values = static_cast<unsigned int>(ival);
};
void get(const char * name, time_t& values) const
{

View File

@ -43,18 +43,10 @@ fi
KILL_9_SECONDS=5
#------------------------------------------------------------------------------
# Function that checks for running daemons and gets PORT from conf
# Function that checks for running daemons
#------------------------------------------------------------------------------
setup()
{
PORT=$(sed -n '/^[ \t]*PORT/s/^.*PORT\s*=\s*\([0-9]\+\)\s*.*$/\1/p' \
$ONE_CONF)
if [ $? -ne 0 ]; then
echo "Can not find PORT in $ONE_CONF."
exit 1
fi
if [ -f $LOCK_FILE ]; then
if [ -f $ONE_PID ]; then
ONEPID=`cat $ONE_PID`
@ -150,17 +142,7 @@ start()
fi
# Start the scheduler
# The following command line arguments are supported by mm_shed:
# [-p port] to connect to oned - default: 2633
# [-t timer] seconds between two scheduling actions - default: 30
# [-m machines limit] max number of VMs managed in each scheduling action
# - default: 300
# [-d dispatch limit] max number of VMs dispatched in each scheduling action
# - default: 30
# [-h host dispatch] max number of VMs dispatched to a given host in each
# scheduling action - default: 1
$ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1&
$ONE_SCHEDULER&
LASTRC=$?
LASTPID=$!

View File

@ -45,16 +45,15 @@ public:
protected:
Scheduler(string& _url, time_t _timer,
int _machines_limit, int _dispatch_limit, int _host_dispatch_limit):
Scheduler():
hpool(0),
vmpool(0),
acls(0),
timer(_timer),
url(_url),
machines_limit(_machines_limit),
dispatch_limit(_dispatch_limit),
host_dispatch_limit(_host_dispatch_limit),
timer(0),
url(""),
machines_limit(0),
dispatch_limit(0),
host_dispatch_limit(0),
threshold(0.9),
client(0)
{

View File

@ -24,7 +24,7 @@ class SchedulerTemplate : public NebulaTemplate
{
public:
SchedulerTemplate(const string& etc_location, const string& _var_location):
SchedulerTemplate(const string& etc_location):
NebulaTemplate(etc_location, conf_name)
{};

View File

@ -35,6 +35,8 @@ sched_env.Prepend(LIBS=[
'nebula_acl',
'nebula_xml',
'nebula_common',
'nebula_core',
'nebula_template',
'crypto',
])

View File

@ -30,6 +30,7 @@
#include <cmath>
#include "Scheduler.h"
#include "SchedulerTemplate.h"
#include "RankPolicy.h"
#include "NebulaLog.h"
@ -69,30 +70,74 @@ void Scheduler::start()
pthread_attr_t pattr;
// -----------------------------------------------------------
// Log system
// Log system & Configuration File
// -----------------------------------------------------------
try
{
ostringstream oss;
string log_file;
string etc_path;
int oned_port;
ostringstream oss;
const char * nl = getenv("ONE_LOCATION");
if (nl == 0) //OpenNebula installed under root directory
{
oss << "/var/log/one/";
log_file = "/var/log/one/sched.log";
etc_path = "/etc/one/";
}
else
{
oss << nl << "/var/";
}
oss << nl << "/var/sched.log";
oss << "sched.log";
log_file = oss.str();
oss.str("");
oss << nl << "/etc/";
etc_path = oss.str();
}
NebulaLog::init_log_system(NebulaLog::FILE,
Log::DEBUG,
oss.str().c_str());
log_file.c_str());
NebulaLog::log("SCHED", Log::INFO, "Init Scheduler Log system");
// ---------------- Load Configuration parameters ----------------------
SchedulerTemplate conf(etc_path);
if ( conf.load_configuration() != 0 )
{
throw runtime_error("Error reading configuration file.");
}
conf.get("ONED_PORT", oned_port);
oss.str("");
oss << "http://localhost:" << oned_port << "/RPC2";
url = oss.str();
conf.get("SCHED_INTERVAL", timer);
conf.get("MAX_VM", machines_limit);
conf.get("MAX_DISPATCH", dispatch_limit);
conf.get("MAX_HOST", host_dispatch_limit);
oss.str("");
oss << "Starting Scheduler Daemon" << endl;
oss << "----------------------------------------\n";
oss << " Scheduler Configuration File \n";
oss << "----------------------------------------\n";
oss << conf;
oss << "----------------------------------------";
NebulaLog::log("SCHED", Log::INFO, oss);
}
catch(runtime_error &)
{

View File

@ -14,17 +14,17 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "NebulaTemplate.h"
#include "SchedulerTemplate.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const char * OpenNebulaTemplate::conf_name="sched.conf";
const char * SchedulerTemplate::conf_name="sched.conf";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void OpenNebulaTemplate::set_conf_default()
void SchedulerTemplate::set_conf_default()
{
SingleAttribute * attribute;
VectorAttribute * vattribute;

View File

@ -31,16 +31,7 @@ class RankScheduler : public Scheduler
{
public:
RankScheduler(string url,
time_t timer,
unsigned int machines_limit,
unsigned int dispatch_limit,
unsigned int host_dispatch_limit
):Scheduler(url,
timer,
machines_limit,
dispatch_limit,
host_dispatch_limit),rp(0){};
RankScheduler():Scheduler(),rp(0){};
~RankScheduler()
{
@ -64,56 +55,11 @@ private:
int main(int argc, char **argv)
{
RankScheduler * ss;
int port = 2633;
time_t timer= 30;
unsigned int machines_limit = 300;
unsigned int dispatch_limit = 30;
unsigned int host_dispatch_limit = 1;
char opt;
ostringstream oss;
while((opt = getopt(argc,argv,"p:t:m:d:h:")) != -1)
{
switch(opt)
{
case 'p':
port = atoi(optarg);
break;
case 't':
timer = atoi(optarg);
break;
case 'm':
machines_limit = atoi(optarg);
break;
case 'd':
dispatch_limit = atoi(optarg);
break;
case 'h':
host_dispatch_limit = atoi(optarg);
break;
default:
cerr << "usage: " << argv[0] << " [-p port] [-t timer] ";
cerr << "[-m machines limit] [-d dispatch limit] [-h host_dispatch_limit]\n";
exit(-1);
break;
}
};
/* ---------------------------------------------------------------------- */
oss << "http://localhost:" << port << "/RPC2";
ss = new RankScheduler(oss.str(),
timer,
machines_limit,
dispatch_limit,
host_dispatch_limit);
RankScheduler ss;
try
{
ss->start();
ss.start();
}
catch (exception &e)
{
@ -122,7 +68,5 @@ int main(int argc, char **argv)
return -1;
}
delete ss;
return 0;
}