1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #5027:Preserve instantiation priority (FIFO) for VMs with same

priority
This commit is contained in:
Ruben S. Montero 2017-07-07 13:32:57 +02:00
parent f3b5f20a4d
commit aba17b284f
2 changed files with 40 additions and 15 deletions

View File

@ -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<Resource *> 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_*/

View File

@ -122,7 +122,7 @@ private:
/**
* Stores the list of vms, and it associated user prioty vm_resources.
*/
ResourceMatch vm_resources;
VirtualMachineResourceMatch vm_resources;
};
/* -------------------------------------------------------------------------- */