feature #1712: Restructured scheduler main functions

This commit is contained in:
Ruben S. Montero committed 2013-08-13 01:12:42 +02:00
1 parent a38afa7abc
commit bf84e3ea4f
5 files changed
+71 -118

No files matched your search

-12
View File
@@ -83,18 +83,6 @@ public:
sort(resources.begin(), resources.end(), Resource::cmp);
}
/**
* Selects a resource among the matched and prioritized resources, in a
* scheduling step.
* @param oid of the selected resource.
* @param pool storing the resources.
* @param current number of schedules for each resource in this step.
* @param max number of schedules per resource in this step.
*
* @return 0 if success -1 otherwise
*/
virtual int get_resource(int& oid, PoolXML *pool, map<int,int>& current, int max) = 0;
/**
* Return a reference to the resources of the object
* @return vector of resources.
+1 -3
View File
@@ -133,12 +133,10 @@ protected:
* the capacity of the host is checked. If there is enough room to host the
* VM a share vector is added to the VM.
*/
virtual void match();
virtual void match_schedule_hosts();
virtual void dispatch();
virtual int schedule();
/**
* Retrieves the pools
*
@@ -106,12 +106,6 @@ public:
}
};
/**
* Selects a resource among the matched and prioritized resources, in a
* scheduling step. Overwrite Schedulable method.
*/
int get_resource(int& oid, PoolXML *pool, map<int,int>& current, int max);
//--------------------------------------------------------------------------
// Action Interface
//--------------------------------------------------------------------------
@@ -145,7 +145,6 @@ ostream& operator<<(ostream& os, VirtualMachineXML& vm)
}
vector<Resource *>::reverse_iterator i;
vector<int>::iterator j;
os << "\t PRI\tHID VM: " << vm.oid << endl
<< "\t-----------------------" << endl;
@@ -163,59 +162,6 @@ ostream& operator<<(ostream& os, VirtualMachineXML& vm)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachineXML::get_resource(int& oid,
PoolXML * pool,
map<int,int>& current,
int max)
{
vector<Resource *>::reverse_iterator i;
vector<int>::iterator j;
HostXML * host;
HostPoolXML * hpool = dynamic_cast<HostPoolXML *>(pool);
int cpu;
int mem;
int dsk;
pair<map<int,int>::iterator, bool> rc;
get_requirements(cpu,mem,dsk);
for (i = resources.rbegin() ; i != resources.rend() ; i++)
{
host = hpool->get( (*i)->oid );
if ( host == 0 )
{
continue;
}
if ( host->test_capacity(cpu,mem,dsk) == true )
{
rc = current.insert(make_pair((*i)->oid,0));
if ( rc.first->second < max )
{
host->add_capacity(cpu,mem,dsk);
oid = (*i)->oid;
rc.first->second++;
return 0;
}
}
}
oid = -1;
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineXML::get_requirements (int& cpu, int& memory, int& disk)
{
if (this->memory == 0 || this->cpu == 0)
+70 -43
View File
@@ -365,19 +365,13 @@ int Scheduler::set_up_pools()
return rc;
}
//--------------------------------------------------------------------------
//Get the matching hosts for each VM
//--------------------------------------------------------------------------
match();
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Scheduler::match()
void Scheduler::match_schedule_hosts()
{
VirtualMachineXML * vm;
@@ -404,6 +398,8 @@ void Scheduler::match()
map<int, ObjectXML*>::const_iterator vm_it;
map<int, ObjectXML*>::const_iterator h_it;
vector<SchedulerPolicy *>::iterator it;
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
const map<int, ObjectXML*> hosts = hpool->get_objects();
@@ -561,57 +557,52 @@ void Scheduler::match()
}
vmpool->update(vm);
continue;
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
// ---------------------------------------------------------------------
// Schedule matched hosts
// ---------------------------------------------------------------------
int Scheduler::schedule()
{
vector<SchedulerPolicy *>::iterator it;
map<int, ObjectXML*>::const_iterator vm_it;
VirtualMachineXML * vm;
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
for (vm_it = pending_vms.begin(); vm_it != pending_vms.end(); vm_it++)
{
vm = dynamic_cast<VirtualMachineXML*>(vm_it->second);
for ( it =host_policies.begin() ; it != host_policies.end() ; it++)
for (it=host_policies.begin() ; it != host_policies.end() ; it++)
{
(*it)->schedule(vm);
}
vm->sort_resources();
}
return 0;
};
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Scheduler::dispatch()
{
HostXML * host;
VirtualMachineXML * vm;
ostringstream oss;
int cpu, mem, dsk;
int hid;
int rc;
int irc;
unsigned int dispatched_vms = 0;
map<int, int> host_vms;
map<int, unsigned int> host_vms;
pair<map<int,unsigned int>::iterator, bool> rc;
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
map<int, ObjectXML*>::const_iterator vm_it;
//--------------------------------------------------------------------------
// Print the VMs to schedule and the selected hosts for each one
//--------------------------------------------------------------------------
oss << "Selected hosts:" << endl;
for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++)
for (map<int, ObjectXML*>::const_iterator vm_it=pending_vms.begin();
vm_it != pending_vms.end(); vm_it++)
{
vm = static_cast<VirtualMachineXML*>(vm_it->second);
@@ -620,20 +611,61 @@ void Scheduler::dispatch()
NebulaLog::log("SCHED",Log::INFO,oss);
for (vm_it=pending_vms.begin();
//--------------------------------------------------------------------------
// Dispatch each VM till we reach the dispatch limit
//--------------------------------------------------------------------------
for (map<int, ObjectXML*>::const_iterator vm_it=pending_vms.begin();
vm_it != pending_vms.end() &&
( dispatch_limit <= 0 || dispatched_vms < dispatch_limit );
vm_it++)
{
vm = static_cast<VirtualMachineXML*>(vm_it->second);
rc = vm->get_resource(hid, hpool, host_vms, host_dispatch_limit);
//----------------------------------------------------------------------
// Get the highest ranked host:
// 1. with enough left capacity
// 2. without exceeded dispatch limit
//----------------------------------------------------------------------
const vector<Resource *> resources = vm->get_resources();
if (rc == 0)
vm->get_requirements(cpu,mem,dsk);
hid = -1;
for (vector<Resource *>::const_reverse_iterator i = resources.rbegin() ;
i != resources.rend() ; i++)
{
rc = vmpool->dispatch(vm_it->first, hid, vm->is_resched());
host = hpool->get((*i)->oid);
if (rc == 0 && !vm->is_resched())
if ( host == 0 )
{
continue;
}
if (host->test_capacity(cpu,mem,dsk) == true)
{
rc = host_vms.insert(make_pair((*i)->oid,0));
//Select the host: update capacity and dispatch counter
if (rc.first->second < host_dispatch_limit)
{
host->add_capacity(cpu,mem,dsk);
hid = (*i)->oid;
rc.first->second++;
break;
}
}
}
if (hid != -1)
{
irc = vmpool->dispatch(vm_it->first, hid, vm->is_resched());
if (irc == 0 && !vm->is_resched())
{
dispatched_vms++;
}
@@ -759,12 +791,7 @@ void Scheduler::do_action(const string &name, void *args)
return;
}
rc = schedule();
if ( rc != 0 )
{
return;
}
match_schedule_hosts();
dispatch();
}