mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-18 10:53:13 +09:00
feature #1678: Test functions for VM capacity uses Pool. Conditional print VM requirements for DEBUG log level
This commit is contained in:
1 parent
55c1399fd2
commit
beb266a3bb
9 files changed
+82
-98
No files matched your search
@@ -127,11 +127,9 @@ private:
|
||||
int cluster_id;
|
||||
|
||||
// Host share values
|
||||
// long long disk_usage; /**< Disk allocated to VMs (in MB). */
|
||||
long long mem_usage; /**< Memory allocated to VMs (in KB) */
|
||||
long long cpu_usage; /**< CPU allocated to VMs (in percentage) */
|
||||
|
||||
// long long max_disk; /**< Total disk capacity (in MB) */
|
||||
long long max_mem; /**< Total memory capacity (in KB) */
|
||||
long long max_cpu; /**< Total cpu capacity (in percentage) */
|
||||
|
||||
|
||||
@@ -116,8 +116,8 @@ protected:
|
||||
|
||||
VirtualMachinePoolXML * vmpool;
|
||||
VirtualMachineActionsPoolXML* vmapool;
|
||||
DatastorePoolXML * dspool;
|
||||
DatastorePoolXML * img_dspool;
|
||||
SystemDatastorePoolXML * dspool;
|
||||
ImageDatastorePoolXML * img_dspool;
|
||||
|
||||
AclXML * acls;
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "VirtualMachineTemplate.h"
|
||||
|
||||
class ImageDatastorePoolXML;
|
||||
|
||||
using namespace std;
|
||||
|
||||
class VirtualMachineXML : public ObjectXML
|
||||
@@ -195,13 +197,13 @@ public:
|
||||
* @param img_datastores Image Datastores
|
||||
* @return true if the Image Datastores can host the VM
|
||||
*/
|
||||
bool test_image_datastore_capacity(const map<int, ObjectXML*> &img_datastores);
|
||||
bool test_image_datastore_capacity(ImageDatastorePoolXML * img_dspool);
|
||||
|
||||
/**
|
||||
* Adds the VM disk requirements to each Image Datastore counter
|
||||
* @param img_datastores Image Datastores
|
||||
*/
|
||||
void add_image_datastore_capacity(const map<int, ObjectXML*> &img_datastores);
|
||||
void add_image_datastore_capacity(ImageDatastorePoolXML * img_dspool);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Action Interface
|
||||
|
||||
@@ -40,30 +40,28 @@ void HostXML::init_attributes()
|
||||
oid = atoi(((*this)["/HOST/ID"] )[0].c_str() );
|
||||
cluster_id = atoi(((*this)["/HOST/CLUSTER_ID"] )[0].c_str() );
|
||||
|
||||
// disk_usage = atoll(((*this)["/HOST/HOST_SHARE/DISK_USAGE"])[0].c_str());
|
||||
mem_usage = atoll(((*this)["/HOST/HOST_SHARE/MEM_USAGE"])[0].c_str());
|
||||
cpu_usage = atoll(((*this)["/HOST/HOST_SHARE/CPU_USAGE"])[0].c_str());
|
||||
|
||||
// max_disk = atoll(((*this)["/HOST/HOST_SHARE/MAX_DISK"])[0].c_str());
|
||||
max_mem = atoll(((*this)["/HOST/HOST_SHARE/MAX_MEM"])[0].c_str());
|
||||
max_cpu = atoll(((*this)["/HOST/HOST_SHARE/MAX_CPU"])[0].c_str());
|
||||
|
||||
free_disk = atoll(((*this)["/HOST/HOST_SHARE/FREE_DISK"])[0].c_str());
|
||||
free_disk = atoll(((*this)["/HOST/HOST_SHARE/FREE_DISK"])[0].c_str());
|
||||
|
||||
running_vms = atoll(((*this)["/HOST/HOST_SHARE/RUNNING_VMS"])[0].c_str());
|
||||
|
||||
//Reserve memory for the hypervisor
|
||||
max_mem = static_cast<int>(hypervisor_mem * static_cast<float>(max_mem));
|
||||
|
||||
vector<string> ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"];
|
||||
vector<string> ds_free_mb = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/FREE_MB"];
|
||||
vector<string> ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"];
|
||||
vector<string> ds_free_mb = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/FREE_MB"];
|
||||
|
||||
int id;
|
||||
long long disk;
|
||||
|
||||
for (size_t i = 0; i < ds_ids.size() && i < ds_free_mb.size(); i++)
|
||||
{
|
||||
id = atoi(ds_ids[i].c_str());
|
||||
id = atoi(ds_ids[i].c_str());
|
||||
disk = atoll(ds_free_mb[i].c_str());
|
||||
|
||||
ds_free_disk[id] = disk;
|
||||
|
||||
@@ -19,10 +19,8 @@
|
||||
|
||||
int VirtualMachinePoolXML::set_up()
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
rc = PoolXML::set_up();
|
||||
int rc = PoolXML::set_up();
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
@@ -31,48 +29,38 @@ int VirtualMachinePoolXML::set_up()
|
||||
return -2;
|
||||
}
|
||||
|
||||
oss.str("");
|
||||
oss << "Pending and rescheduling VMs:" << endl;
|
||||
|
||||
map<int,ObjectXML*>::iterator it;
|
||||
|
||||
for (it=objects.begin();it!=objects.end();it++)
|
||||
if (NebulaLog::log_level() == Log::DEBUG)
|
||||
{
|
||||
oss << " " << it->first;
|
||||
}
|
||||
ostringstream oss;
|
||||
oss << "Pending/rescheduling VM and capacity requirements:";
|
||||
|
||||
NebulaLog::log("VM",Log::DEBUG,oss);
|
||||
|
||||
// TODO: remove debug log
|
||||
|
||||
oss.str("");
|
||||
|
||||
oss << "Storage usage:" << endl;
|
||||
|
||||
int tmp;
|
||||
long long disk;
|
||||
|
||||
for (it=objects.begin();it!=objects.end();it++)
|
||||
{
|
||||
VirtualMachineXML * vm = static_cast<VirtualMachineXML *>(it->second);
|
||||
|
||||
map<int,long long> ds_usage = vm->get_storage_usage();
|
||||
map<int,long long>::const_iterator ds_it;
|
||||
|
||||
oss << "VM " << vm->get_oid() << ": ";
|
||||
|
||||
vm->get_requirements(tmp, tmp, disk);
|
||||
oss << "System " << disk << "MB; ";
|
||||
|
||||
for (ds_it = ds_usage.begin(); ds_it != ds_usage.end(); ds_it++)
|
||||
for (map<int,ObjectXML*>::iterator it=objects.begin();it!=objects.end();it++)
|
||||
{
|
||||
oss << "DS " << ds_it->first << " " << ds_it->second << "MB; ";
|
||||
int cpu, mem;
|
||||
long long disk;
|
||||
|
||||
VirtualMachineXML * vm = static_cast<VirtualMachineXML *>(it->second);
|
||||
|
||||
vm->get_requirements(cpu, mem, disk);
|
||||
|
||||
oss << endl
|
||||
<< "\tVM: " << it->first << endl
|
||||
<< "\t CPU: " << cpu << endl
|
||||
<< "\t Memory: " << mem << endl
|
||||
<< "\t System DS: " << disk << endl;
|
||||
|
||||
map<int,long long> ds_usage = vm->get_storage_usage();
|
||||
|
||||
for (map<int,long long>::const_iterator ds_it = ds_usage.begin();
|
||||
ds_it != ds_usage.end(); ds_it++)
|
||||
{
|
||||
oss << "\t Image DS " << ds_it->first << ": " << ds_it->second
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
oss << endl;
|
||||
NebulaLog::log("VM",Log::DEBUG,oss);
|
||||
}
|
||||
|
||||
NebulaLog::log("VM",Log::DEBUG,oss);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "VirtualMachineXML.h"
|
||||
#include "DatastoreXML.h"
|
||||
#include "DatastorePoolXML.h"
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
void VirtualMachineXML::init_attributes()
|
||||
@@ -310,7 +311,6 @@ void VirtualMachineXML::init_storage_usage()
|
||||
|
||||
if (disk->vector_value("SIZE", size) != 0)
|
||||
{
|
||||
// TODO: report error?
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -322,7 +322,6 @@ void VirtualMachineXML::init_storage_usage()
|
||||
{
|
||||
if (disk->vector_value("DATASTORE_ID", ds_id) != 0)
|
||||
{
|
||||
// TODO: report error?
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -345,7 +344,8 @@ void VirtualMachineXML::init_storage_usage()
|
||||
st = disk->vector_value("LN_TARGET");
|
||||
}
|
||||
|
||||
// TODO: define constants or enum in Datastore.h ?
|
||||
one_util::toupper(st);
|
||||
|
||||
if (st == "SELF")
|
||||
{
|
||||
ds_usage[ds_id] += size;
|
||||
@@ -408,49 +408,43 @@ int VirtualMachineXML::parse_action_name(string& action_st)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool VirtualMachineXML::test_image_datastore_capacity(const map<int, ObjectXML*> &img_datastores)
|
||||
bool VirtualMachineXML::test_image_datastore_capacity(
|
||||
ImageDatastorePoolXML * img_dspool)
|
||||
{
|
||||
map<int, ObjectXML*>::const_iterator ds_it;
|
||||
map<int,long long>::const_iterator ds_usage_it;
|
||||
|
||||
ostringstream oss;
|
||||
map<int,long long>::const_iterator ds_usage_it;
|
||||
DatastoreXML* ds;
|
||||
|
||||
for (ds_usage_it = ds_usage.begin(); ds_usage_it != ds_usage.end(); ds_usage_it++)
|
||||
{
|
||||
ds_it = img_datastores.find( ds_usage_it->first );
|
||||
ds = img_dspool->get(ds_usage_it->first);
|
||||
|
||||
if (ds_it == img_datastores.end())
|
||||
if (ds == 0) //Should never reach here
|
||||
{
|
||||
oss << "VM " << oid
|
||||
<< ": Image Datastore " << ds_usage_it->first
|
||||
<< " is unknown for the Scheduler.";
|
||||
ostringstream oss;
|
||||
|
||||
break;
|
||||
oss << "Image Datastore " << ds_usage_it->first << " not found.";
|
||||
|
||||
NebulaLog::log("SCHED",Log::INFO,oss);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ds = static_cast<DatastoreXML *>( ds_it->second );
|
||||
|
||||
if (!ds->test_capacity(ds_usage_it->second))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "VM " << oid
|
||||
<< ": Image Datastore " << ds_usage_it->first
|
||||
<< " does not have enough free storage.";
|
||||
|
||||
break;
|
||||
NebulaLog::log("SCHED",Log::INFO,oss);
|
||||
|
||||
log(oss.str());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ds_usage_it != ds_usage.end())
|
||||
{
|
||||
NebulaLog::log("SCHED",Log::INFO,oss);
|
||||
|
||||
// TODO: log into VM template?
|
||||
// log(oss.str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -458,25 +452,21 @@ bool VirtualMachineXML::test_image_datastore_capacity(const map<int, ObjectXML*>
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineXML::add_image_datastore_capacity(
|
||||
const map<int, ObjectXML*> &img_datastores)
|
||||
ImageDatastorePoolXML * img_dspool)
|
||||
{
|
||||
map<int, ObjectXML*>::const_iterator ds_it;
|
||||
map<int,long long>::const_iterator ds_usage_it;
|
||||
map<int,long long>::const_iterator ds_usage_it;
|
||||
|
||||
DatastoreXML *ds;
|
||||
|
||||
for (ds_usage_it = ds_usage.begin(); ds_usage_it != ds_usage.end(); ds_usage_it++)
|
||||
{
|
||||
ds_it = img_datastores.find( ds_usage_it->first );
|
||||
ds = img_dspool->get(ds_usage_it->first);
|
||||
|
||||
if (ds_it == img_datastores.end())
|
||||
if (ds == 0) //Should never reach here
|
||||
{
|
||||
// TODO log error?
|
||||
continue;
|
||||
}
|
||||
|
||||
ds = static_cast<DatastoreXML *>( ds_it->second );
|
||||
|
||||
ds->add_capacity(ds_usage_it->second);
|
||||
}
|
||||
}
|
||||
@@ -210,14 +210,14 @@ void Scheduler::start()
|
||||
|
||||
hpool = new HostPoolXML(client, hypervisor_mem);
|
||||
clpool = new ClusterPoolXML(client);
|
||||
vmpool = new VirtualMachinePoolXML(client,
|
||||
machines_limit,
|
||||
(live_rescheds == 1));
|
||||
vmapool= new VirtualMachineActionsPoolXML(client, machines_limit);
|
||||
dspool = new SystemDatastorePoolXML(client);
|
||||
vmpool = new VirtualMachinePoolXML(client,machines_limit,(live_rescheds==1));
|
||||
|
||||
vmapool = new VirtualMachineActionsPoolXML(client, machines_limit);
|
||||
|
||||
dspool = new SystemDatastorePoolXML(client);
|
||||
img_dspool = new ImageDatastorePoolXML(client);
|
||||
|
||||
acls = new AclXML(client);
|
||||
acls = new AclXML(client);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Load scheduler policies
|
||||
@@ -414,7 +414,6 @@ void Scheduler::match_schedule()
|
||||
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
|
||||
const map<int, ObjectXML*> hosts = hpool->get_objects();
|
||||
const map<int, ObjectXML*> datastores = dspool->get_objects();
|
||||
const map<int, ObjectXML*> img_datastores = img_dspool->get_objects();
|
||||
|
||||
for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++)
|
||||
{
|
||||
@@ -438,7 +437,7 @@ void Scheduler::match_schedule()
|
||||
//--------------------------------------------------------------
|
||||
if (!vm->is_resched())
|
||||
{
|
||||
if (vm->test_image_datastore_capacity(img_datastores) == false)
|
||||
if (vm->test_image_datastore_capacity(img_dspool) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -778,8 +777,7 @@ void Scheduler::dispatch()
|
||||
|
||||
vector<Resource *>::const_reverse_iterator i, j;
|
||||
|
||||
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
|
||||
const map<int, ObjectXML*> img_datastores = img_dspool->get_objects();
|
||||
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Print the VMs to schedule and the selected hosts for each one
|
||||
@@ -816,7 +814,7 @@ void Scheduler::dispatch()
|
||||
|
||||
if (!resources.empty() && !vm->is_resched())
|
||||
{
|
||||
if (vm->test_image_datastore_capacity(img_datastores) == false)
|
||||
if (vm->test_image_datastore_capacity(img_dspool) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -955,7 +953,7 @@ void Scheduler::dispatch()
|
||||
host->add_ds_capacity(ds->get_oid(), dsk);
|
||||
}
|
||||
|
||||
vm->add_image_datastore_capacity(img_datastores);
|
||||
vm->add_image_datastore_capacity(img_dspool);
|
||||
}
|
||||
|
||||
host->add_capacity(cpu,mem);
|
||||
|
||||
Reference in new issue
Block a user