diff --git a/src/scheduler/include/Resource.h b/src/scheduler/include/Resource.h index 5c4cf52a56..ac1a78c6a5 100644 --- a/src/scheduler/include/Resource.h +++ b/src/scheduler/include/Resource.h @@ -25,23 +25,13 @@ class PoolXML; * This class represents a target resource to schedule a "schedulable" * resource. */ -class Resource +struct Resource { public: Resource(int _oid):oid(_oid), priority(0){}; virtual ~Resource(){}; - static bool cmp (const Resource * a, const Resource * b) - { - return a->priority < b->priority; - }; - - bool operator<(const Resource& b) const - { - return priority < b.priority; - }; - int oid; float priority; }; @@ -76,9 +66,17 @@ public: /** * Sort the matched resources in the vector */ - void sort_resources() + virtual void sort_resources() { - sort(resources.begin(), resources.end(), Resource::cmp); + struct ResourceCompare + { + bool operator() (const Resource * a, const Resource * b) const + { + return a->priority < b->priority; + }; + } cmp; + + std::sort(resources.begin(), resources.end(), cmp); } /** @@ -106,9 +104,36 @@ public: resources.clear(); } -private: +protected: vector resources; }; +/** + * Abstract class that models an object that can be scheduled over a resource + */ +class VirtualMachineResourceMatch: public ResourceMatch +{ +public: + void sort_resources() + { + struct ResourceCompare + { + bool operator() (const Resource * a, const Resource * b) const + { + if ( a->priority == b->priority ) + { + std::ostringstream oss; + + return a->oid > b->oid; + } + + return a->priority < b->priority; + }; + } cmp; + + std::sort(resources.begin(), resources.end(), cmp); + } +}; + #endif /*RESOURCE_H_*/ diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index a8959cbcdb..94b6d99560 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -122,7 +122,7 @@ private: /** * Stores the list of vms, and it associated user prioty vm_resources. */ - ResourceMatch vm_resources; + VirtualMachineResourceMatch vm_resources; }; /* -------------------------------------------------------------------------- */