mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #360: Scheduler reads default policies and make use of them
This commit is contained in:
parent
eff71e6e7f
commit
f788de12cf
@ -29,12 +29,16 @@ public:
|
||||
RankPolicy(
|
||||
VirtualMachinePoolXML * vmpool,
|
||||
HostPoolXML * hpool,
|
||||
float w=1.0):SchedulerHostPolicy(vmpool,hpool,w){};
|
||||
const string& dr,
|
||||
float w = 1.0)
|
||||
:SchedulerHostPolicy(vmpool,hpool,w), default_rank(dr){};
|
||||
|
||||
~RankPolicy(){};
|
||||
|
||||
private:
|
||||
|
||||
string default_rank;
|
||||
|
||||
void policy(
|
||||
VirtualMachineXML * vm)
|
||||
{
|
||||
@ -53,10 +57,10 @@ private:
|
||||
|
||||
srank = vm->get_rank();
|
||||
|
||||
if (srank == "")
|
||||
if (srank.empty())
|
||||
{
|
||||
NebulaLog::log("RANK",Log::WARNING,"No rank defined for VM");
|
||||
}
|
||||
srank = default_rank;
|
||||
}
|
||||
|
||||
for (i=0;i<hids.size();i++)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ using namespace std;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
extern "C" void * scheduler_action_loop(void *arg);
|
||||
|
||||
class SchedulerTemplate;
|
||||
/**
|
||||
* The Scheduler class. It represents the scheduler ...
|
||||
*/
|
||||
@ -41,7 +41,7 @@ public:
|
||||
|
||||
void start();
|
||||
|
||||
virtual void register_policies() = 0;
|
||||
virtual void register_policies(const SchedulerTemplate& conf) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
|
||||
~SchedulerTemplate(){};
|
||||
|
||||
string get_policy() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Name for the configuration file, oned.conf
|
||||
|
@ -65,7 +65,12 @@ extern "C" void * scheduler_action_loop(void *arg)
|
||||
void Scheduler::start()
|
||||
{
|
||||
int rc;
|
||||
ifstream file;
|
||||
|
||||
ifstream file;
|
||||
ostringstream oss;
|
||||
|
||||
string etc_path;
|
||||
int oned_port;
|
||||
|
||||
pthread_attr_t pattr;
|
||||
|
||||
@ -75,11 +80,7 @@ void Scheduler::start()
|
||||
|
||||
try
|
||||
{
|
||||
string log_file;
|
||||
string etc_path;
|
||||
int oned_port;
|
||||
|
||||
ostringstream oss;
|
||||
string log_file;
|
||||
const char * nl = getenv("ONE_LOCATION");
|
||||
|
||||
if (nl == 0) //OpenNebula installed under root directory
|
||||
@ -104,46 +105,48 @@ void Scheduler::start()
|
||||
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 &)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Configuration File
|
||||
// -----------------------------------------------------------
|
||||
|
||||
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);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// XML-RPC Client
|
||||
// -----------------------------------------------------------
|
||||
@ -173,7 +176,7 @@ void Scheduler::start()
|
||||
// Load scheduler policies
|
||||
// -----------------------------------------------------------
|
||||
|
||||
register_policies();
|
||||
register_policies(conf);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Close stds, we no longer need them
|
||||
|
@ -72,11 +72,55 @@ void SchedulerTemplate::set_conf_default()
|
||||
attribute = new SingleAttribute("MAX_HOST",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
//DEFAULT_SCHED [0: Packing, 1: Striping, 2: Load-aware, or 3:Custom]
|
||||
//DEFAULT_SCHED
|
||||
map<string,string> vvalue;
|
||||
vvalue.insert(make_pair("POLICY","packing"));
|
||||
vvalue.insert(make_pair("POLICY","1"));
|
||||
|
||||
vattribute = new VectorAttribute("DEFAULT_SCHED",vvalue);
|
||||
conf_default.insert(make_pair(attribute->name(),vattribute));
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string SchedulerTemplate::get_policy() const
|
||||
{
|
||||
int policy;
|
||||
string rank;
|
||||
|
||||
istringstream iss;
|
||||
|
||||
vector<const Attribute *> vsched;
|
||||
const VectorAttribute * sched;
|
||||
|
||||
get("DEFAULT_SCHED", vsched);
|
||||
|
||||
sched = static_cast<const VectorAttribute *> (vsched[0]);
|
||||
|
||||
iss.str(sched->vector_value("POLICY"));
|
||||
iss >> policy;
|
||||
|
||||
switch (policy)
|
||||
{
|
||||
case 0: //Packing
|
||||
rank = "RUNNING_VMS";
|
||||
break;
|
||||
|
||||
case 1: //Striping
|
||||
rank = "- RUNNING_VMS";
|
||||
break;
|
||||
|
||||
case 2: //Load-aware
|
||||
rank = "FREE_CPU";
|
||||
break;
|
||||
|
||||
case 3: //Custom
|
||||
rank = sched->vector_value("RANK");
|
||||
break;
|
||||
|
||||
default:
|
||||
rank = "";
|
||||
}
|
||||
|
||||
return rank;
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "Scheduler.h"
|
||||
#include "SchedulerTemplate.h"
|
||||
#include "RankPolicy.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@ -41,9 +42,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void register_policies()
|
||||
void register_policies(const SchedulerTemplate& conf)
|
||||
{
|
||||
rp = new RankPolicy(vmpool,hpool,1.0);
|
||||
rp = new RankPolicy(vmpool, hpool, conf.get_policy(), 1.0);
|
||||
|
||||
add_host_policy(rp);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user