diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 45cf63530b..3fdeeb1bb7 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -927,6 +927,7 @@ VM_RESTRICTED_ATTR = "MEMORY_COST" VM_RESTRICTED_ATTR = "DISK_COST" VM_RESTRICTED_ATTR = "PCI" VM_RESTRICTED_ATTR = "EMULATOR" +VM_RESTRICTED_ATTR = "USER_PRIORITY" #VM_RESTRICTED_ATTR = "USER_INPUTS/CPU" #VM_RESTRICTED_ATTR = "USER_INPUTS/MEMORY" #VM_RESTRICTED_ATTR = "USER_INPUTS/VCPU" diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 589ba6c42a..5c8b9beefb 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -120,6 +120,11 @@ protected: ds_policies.push_back(policy); } + void add_vm_policy(SchedulerPolicy *policy) + { + vm_policies.push_back(policy); + } + // --------------------------------------------------------------- // Scheduler main methods // --------------------------------------------------------------- @@ -159,6 +164,7 @@ private: vector host_policies; vector ds_policies; + vector vm_policies; // --------------------------------------------------------------- // Configuration attributes diff --git a/src/scheduler/include/SchedulerPolicy.h b/src/scheduler/include/SchedulerPolicy.h index 8361865d22..76e1bc9997 100644 --- a/src/scheduler/include/SchedulerPolicy.h +++ b/src/scheduler/include/SchedulerPolicy.h @@ -55,7 +55,7 @@ public: policy(obj, priority); //2. Scale priorities - sw.max =fabs(*max_element(priority.begin(), priority.end(), abs_cmp)); + sw.max = fabs(*max_element(priority.begin(), priority.end(), abs_cmp)); transform(priority.begin(), priority.end(), priority.begin(), sw); diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 1712994a0b..a8959cbcdb 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -85,12 +85,19 @@ public: }; /** - * - * + * Returns a vector of matched hosts */ - void clear() + const vector get_vm_resources() { - flush(); + return vm_resources.get_resources(); + } + + /** + * Sort the VMs in the pool + */ + void sort_vm_resources() + { + vm_resources.sort_resources(); } protected: @@ -110,6 +117,12 @@ protected: * Do live migrations to resched VMs */ bool live_resched; + +private: + /** + * Stores the list of vms, and it associated user prioty vm_resources. + */ + ResourceMatch vm_resources; }; /* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 2faf5d6100..0e2d9e4b87 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -26,14 +26,22 @@ int VirtualMachinePoolXML::set_up() if ( rc == 0 ) { + map::iterator it; + if (objects.empty()) { return -2; } + vm_resources.clear(); + + for ( it = objects.begin(); it != objects.end(); ++it ) + { + vm_resources.add_resource(it->first); + } + if (NebulaLog::log_level() >= Log::DDDEBUG) { - map::iterator it; oss << "Pending/rescheduling VM and capacity requirements:" << endl; diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 3b92809280..df711ac0ea 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -1077,27 +1077,37 @@ void Scheduler::dispatch() bool dispatched, matched; char * estr; - map::const_iterator vm_it; + vector::const_reverse_iterator i, j, k; - vector::const_reverse_iterator i, j; + vector::iterator sp_it; - const map pending_vms = vmpool->get_objects(); + //-------------------------------------------------------------------------- + // Schedule pending VMs according to the VM policies (e.g. User priority) + //-------------------------------------------------------------------------- + for (sp_it = vm_policies.begin() ; sp_it != vm_policies.end() ; ++sp_it) + { + (*sp_it)->schedule(0); + } - dss << "Dispatching VMs to hosts:\n" << "\tVMID\tHost\tSystem DS\n" - << "\t-------------------------\n"; + vmpool->sort_vm_resources(); + + const vector vm_rs = vmpool->get_vm_resources(); + + //-------------------------------------------------------------------------- + dss << "Dispatching VMs to hosts:\n" + << "\tVMID\tPriority\tHost\tSystem DS\n" + << "\t--------------------------------------------------------------\n"; + //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Dispatch each VM till we reach the dispatch limit //-------------------------------------------------------------------------- - - for (vm_it = pending_vms.begin(); - vm_it != pending_vms.end() && - ( dispatch_limit <= 0 || dispatched_vms < dispatch_limit ); - vm_it++) + for (k = vm_rs.rbegin(); k != vm_rs.rend() && + ( dispatch_limit <= 0 || dispatched_vms < dispatch_limit ); ++k) { dispatched = false; - vm = static_cast(vm_it->second); + vm = vmpool->get((*k)->oid); const vector resources = vm->get_match_hosts(); @@ -1273,12 +1283,15 @@ void Scheduler::dispatch() //------------------------------------------------------------------ // Dispatch and update host and DS capacity, and dispatch counters //------------------------------------------------------------------ - if (vmpool->dispatch(vm_it->first, hid, dsid, vm->is_resched()) != 0) + if (vmpool->dispatch((*k)->oid, hid, dsid, vm->is_resched()) != 0) { continue; } - dss << "\t" << vm_it->first << "\t" << hid << "\t" << dsid << "\n"; + //------------------------------------------------------------------ + dss << "\t" << (*k)->oid << "\t" << (*k)->priority << "\t\t" << hid + << "\t" << dsid << "\n"; + //------------------------------------------------------------------ // DS capacity skip VMs deployed in public cloud hosts if (!host->is_public_cloud()) @@ -1347,10 +1360,10 @@ void Scheduler::dispatch() } } - if (vm_it != pending_vms.end()) + if (k != vm_rs.rend()) { dss << endl << "MAX_DISPATCH limit of " << dispatch_limit << " reached, " - << std::distance(vm_it, pending_vms.end()) + << std::distance(k, vm_rs.rend()) << " VMs were not dispatched"; } diff --git a/src/scheduler/src/sched/mm_sched.cc b/src/scheduler/src/sched/mm_sched.cc index c8cee61163..751113f133 100644 --- a/src/scheduler/src/sched/mm_sched.cc +++ b/src/scheduler/src/sched/mm_sched.cc @@ -17,6 +17,7 @@ #include "Scheduler.h" #include "SchedulerTemplate.h" #include "RankPolicy.h" +#include "UserPriorityPolicy.h" #include #include #include @@ -32,19 +33,14 @@ class RankScheduler : public Scheduler { public: - RankScheduler():Scheduler(),rp_host(0),rp_ds(0){}; + RankScheduler():Scheduler(),rp_host(0),rp_ds(0),rp_vm(0){}; ~RankScheduler() { - if ( rp_host != 0 ) - { - delete rp_host; - } + delete rp_host; + delete rp_ds; - if ( rp_ds != 0 ) - { - delete rp_ds; - } + delete rp_vm; }; void register_policies(const SchedulerTemplate& conf) @@ -56,11 +52,17 @@ public: rp_ds = new RankDatastorePolicy(dspool, conf.get_ds_policy(), 1.0); add_ds_policy(rp_ds); + + rp_vm = new UserPriorityPolicy(vmpool, 1.0); + + add_vm_policy(rp_vm); }; private: RankPolicy * rp_host; RankPolicy * rp_ds; + + UserPriorityPolicy * rp_vm; }; int main(int argc, char **argv)