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

F #2347: Fix minor bugs in CLI. Better dispatching for affined groups,

fix issue for anti-affined sets
This commit is contained in:
Ruben S. Montero 2017-01-26 17:06:46 +01:00
parent 90ed2f5c28
commit a845425a1d
5 changed files with 99 additions and 30 deletions

View File

@ -47,7 +47,7 @@ class OneVMGroupHelper < OpenNebulaHelper::OneHelper
end
column :VMS, "Number of VMs in the VM Group", :left, :size=>4 do |d|
roles = d["ROLES"]["ROLE"]
roles = [d["ROLES"]["ROLE"]].flatten
vms = 0
if !roles.nil?
@ -60,7 +60,7 @@ class OneVMGroupHelper < OpenNebulaHelper::OneHelper
end
column :ROLES, "Roles in the VM Group", :left, :size=>36 do |d|
roles = d["ROLES"]["ROLE"]
roles = [d["ROLES"]["ROLE"]].flatten
roles_names = ""
if !roles.nil?

View File

@ -122,12 +122,12 @@ public:
vector<VectorAttribute *> &pci);
/**
* Return the requirements of this VM (as is)
* Return the requirements of this VM (as is) and reset them
* @param cpu in unit
* @param memory in kb
* @param disk in mb (system ds usage)
*/
void get_raw_requirements(float& cpu, int& memory, long long& disk);
void reset_requirements(float& cpu, int& memory, long long& disk);
/**
* @return the usage requirements in image ds.
@ -262,6 +262,23 @@ public:
*/
bool is_only_public_cloud() const;
/**
* Add a VM to the set of affined VMs. This is used for the VM leader
* when scheduling a group.
*
* @param vmid of the affined vm
*
*/
void add_affined(int vmid)
{
affined_vms.insert(vmid);
}
const set<int>& get_affined_vms() const
{
return affined_vms;
}
//--------------------------------------------------------------------------
// Capacity Interface
//--------------------------------------------------------------------------
@ -361,12 +378,16 @@ protected:
void init_storage_usage();
/* ------------------- SCHEDULER INFORMATION --------------------------- */
ResourceMatch match_hosts;
ResourceMatch match_datastores;
bool only_public_cloud;
set<int> affined_vms;
/* ----------------------- VIRTUAL MACHINE ATTRIBUTES ------------------- */
int oid;
@ -397,6 +418,7 @@ protected:
VirtualMachineTemplate * vm_template; /**< The VM template */
VirtualMachineTemplate * user_template; /**< The VM user template */
};
#endif /* VM_XML_H_ */

View File

@ -203,8 +203,6 @@ void VMGroupXML::set_antiaffinity_requirements(VirtualMachinePoolXML * vmpool,
}
}
}
NebulaLog::log("VMGRP", Log::DEBUG, oss);
}
/* -------------------------------------------------------------------------- */
@ -267,18 +265,21 @@ void VMGroupXML::set_host_requirements(VirtualMachinePoolXML * vmpool,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static void schecule_affined_set(std::set<int> vms,
static void schecule_affined_set(const std::set<int>& vms,
VirtualMachinePoolXML * vmpool, VirtualMachineRolePoolXML * vm_roles_pool,
std::ostringstream& oss)
{
std::set<int>::iterator it;
std::set<int> hosts;
if ( vms.size() == 0 )
if ( vms.size() <= 1 )
{
return;
}
/* ---------------------------------------------------------------------- */
/* Get hosts where the affined set is running */
/* ---------------------------------------------------------------------- */
for ( it = vms.begin() ; it != vms.end() ; ++it )
{
VirtualMachineXML * vm = vm_roles_pool->get(*it);
@ -298,6 +299,12 @@ static void schecule_affined_set(std::set<int> vms,
if ( hosts.size() == 0 )
{
/* ------------------------------------------------------------------ */
/* No VMs of the set are running: */
/* 1. Select a set leader */
/* 2. Allocate VMs in the same host as the leader */
/* 3. Aggregate requirements in the leader for scheduling */
/* ------------------------------------------------------------------ */
VirtualMachineXML * vm;
for ( it = vms.begin(); it != vms.end() ; ++it )
@ -335,10 +342,11 @@ static void schecule_affined_set(std::set<int> vms,
continue;
}
tmp->get_raw_requirements(cpu, memory, disk);
tmp->reset_requirements(cpu, memory, disk);
vm->add_requirements(cpu, memory, disk);
vm->add_requirements(tmp->get_requirements());
vm->add_affined(*it);
tmp->add_requirements(areqs_s);
@ -351,6 +359,10 @@ static void schecule_affined_set(std::set<int> vms,
}
else
{
/* ------------------------------------------------------------------ */
/* VMs in the group already running */
/* 1. Assign VMs to one of the hosts used by the affined set */
/* ------------------------------------------------------------------ */
std::ostringstream oss_reqs;
std::string reqs;
@ -461,14 +473,13 @@ static ostream& operator<<(ostream& os, VMGroupRule::rule_set rules)
{
const VMGroupRule::role_bitset rroles = (*rit).get_roles();
os << setfill(' ') << setw(14) << ' ' << left << setw(14)
<< (*rit).get_policy() << " ";
os << left << setw(14) << (*rit).get_policy() << " ";
for (int i = 0 ; i <VMGroupRoles::MAX_ROLES ; ++i)
{
if ( rroles[i] == 1 )
{
os << right << setw(3) << i << " ";
os << right << setw(2) << i << " ";
}
}
@ -485,26 +496,21 @@ ostream& operator<<(ostream& os, VMGroupXML& vmg)
{
VMGroupRoles::role_iterator it;
os << left << setw(4) << vmg.oid << " "
<< left << setw(8) << vmg.name<< " "
<< left << setw(12)<< "ROLES" << " " << setw(12) << "POLICY" << " "
<< left << "VMS\n"
<< setfill(' ') << setw(14) << " " << setfill('-') << setw(50) << '-'
<< setfill(' ') << "\n";
os << left << setw(7)<< "ROLE ID" << " " << left << setw(8) << "NAME" << " "
<< setw(12) << "POLICY" << " " << left << "VMS\n"
<< setfill('-') << setw(80) << '-' << setfill(' ') << "\n";
for ( it = vmg.roles.begin() ; it != vmg.roles.end() ; ++it )
{
os << setfill(' ') << setw(14) << " "
<< left << setw(3) << (*it)->id() << " "
os << left << setw(7) << (*it)->id() << " "
<< left << setw(8) << (*it)->name() << " "
<< left << setw(12)<< (*it)->policy_s() << " "
<< left << (*it)->vms_s() << "\n";
}
os << "\n";
os << setfill(' ') << setw(14) << ' ' << left << "RULES" << "\n"
<< setfill(' ') << setw(14) << ' ' << setfill('-') << setw(50) << '-'
<< setfill(' ') << "\n";
os << left << "RULES" << "\n"
<< setfill('-') << setw(80) << '-' << setfill(' ') << "\n";
os << vmg.affined;

View File

@ -214,11 +214,15 @@ void VirtualMachineXML::add_requirements(float c, int m, long long d)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineXML::get_raw_requirements (float& c, int& m, long long& d)
void VirtualMachineXML::reset_requirements(float& c, int& m, long long& d)
{
c = cpu;
m = memory;
d = system_ds_usage;
cpu = 0;
memory = 0;
system_ds_usage = 0;
}
/* -------------------------------------------------------------------------- */

View File

@ -1141,12 +1141,18 @@ void Scheduler::dispatch()
cid = host->get_cid();
//------------------------------------------------------------------
// Check host still match requirements for ANTI_AFFINITY rules
// Check host still match requirements with CURRENT_VMS
//------------------------------------------------------------------
if ( host->eval_bool(vm->get_requirements(), matched, &estr) != 0 )
matched = true;
if ( one_util::regex_match("CURRENT_VMS",
vm->get_requirements().c_str()) == 0 )
{
free(estr);
continue;
if (host->eval_bool(vm->get_requirements(), matched, &estr)!=0)
{
free(estr);
continue;
}
}
if (matched == false)
@ -1154,7 +1160,7 @@ void Scheduler::dispatch()
std::ostringstream mss;
mss << "Host " << hid << " no longer meets requirements for VM "
<< vm->get_oid() << "\n";
<< vm->get_oid();
NebulaLog::log("SCHED", Log::DEBUG, mss);
continue;
@ -1297,6 +1303,32 @@ void Scheduler::dispatch()
}
}
//------------------------------------------------------------------
// VM leaders needs to add the select host to the affined VMs
//------------------------------------------------------------------
const set<int>& affined_vms = vm->get_affined_vms();
if ( affined_vms.size() > 0 )
{
set<int>::const_iterator it;
for ( it = affined_vms.begin(); it != affined_vms.end(); ++it )
{
VirtualMachineXML * avm = vmpool->get(*it);
if ( avm == 0 )
{
continue;
}
avm->add_match_host(hid);
avm->add_match_datastore(dsid);
}
}
//------------------------------------------------------------------
// Update usage and statistics counters
//------------------------------------------------------------------
host->add_capacity(vm->get_oid(), cpu, mem, pci);
dispatched_vms++;
@ -1430,11 +1462,16 @@ void Scheduler::do_vm_groups()
ostringstream oss;
oss << "VM Group Scheduling information\n";
for (it = vmgrps.begin(); it != vmgrps.end() ; ++it)
{
VMGroupXML * grp = static_cast<VMGroupXML*>(it->second);
oss << "\nSCHEDULING RESULTS FOR VM GROUP: " << grp->get_name() <<"\n";
oss << setfill('*') << setw(80) << '*' << setfill(' ') << "\n"
<< "SCHEDULING RESULTS FOR VM GROUP " << grp->get_oid() << ", "
<< grp->get_name() <<"\n"
<< setfill('*') << setw(80) << '*' << setfill(' ') << "\n";
oss << *grp << "\n";