diff --git a/include/Log.h b/include/Log.h index bed96a4c09..bd799fe351 100644 --- a/include/Log.h +++ b/include/Log.h @@ -51,6 +51,11 @@ public: virtual ~Log(){}; + MessageType get_log_level() + { + return log_level; + } + // ------------------------------------------------------------------------- // Logger interface // ------------------------------------------------------------------------- diff --git a/include/NebulaLog.h b/include/NebulaLog.h index 95e3141715..8e28924fe9 100644 --- a/include/NebulaLog.h +++ b/include/NebulaLog.h @@ -118,6 +118,11 @@ public: logger->log(module,type,message.c_str()); }; + static Log::MessageType log_level() + { + return logger->get_log_level(); + } + private: NebulaLog(){}; ~NebulaLog(){}; diff --git a/src/scheduler/include/HostXML.h b/src/scheduler/include/HostXML.h index 297aee46a2..cba3512d35 100644 --- a/src/scheduler/include/HostXML.h +++ b/src/scheduler/include/HostXML.h @@ -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) */ diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 48e6f929f2..441f84f7a8 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -116,8 +116,8 @@ protected: VirtualMachinePoolXML * vmpool; VirtualMachineActionsPoolXML* vmapool; - DatastorePoolXML * dspool; - DatastorePoolXML * img_dspool; + SystemDatastorePoolXML * dspool; + ImageDatastorePoolXML * img_dspool; AclXML * acls; diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 16e074e0c4..eb5c9d8a2a 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -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 &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 &img_datastores); + void add_image_datastore_capacity(ImageDatastorePoolXML * img_dspool); //-------------------------------------------------------------------------- // Action Interface diff --git a/src/scheduler/src/pool/HostXML.cc b/src/scheduler/src/pool/HostXML.cc index 43269065cb..c057b6bd3b 100644 --- a/src/scheduler/src/pool/HostXML.cc +++ b/src/scheduler/src/pool/HostXML.cc @@ -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(hypervisor_mem * static_cast(max_mem)); - vector ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"]; - vector ds_free_mb = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/FREE_MB"]; + vector ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"]; + vector 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; diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 5232e2ce8d..631f1fe585 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -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::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(it->second); - - map ds_usage = vm->get_storage_usage(); - map::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::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(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 ds_usage = vm->get_storage_usage(); + + for (map::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; diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 4b508aa578..809ecf9367 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -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 &img_datastores) +bool VirtualMachineXML::test_image_datastore_capacity( + ImageDatastorePoolXML * img_dspool) { - map::const_iterator ds_it; - map::const_iterator ds_usage_it; - - ostringstream oss; + map::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( 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 /* -------------------------------------------------------------------------- */ void VirtualMachineXML::add_image_datastore_capacity( - const map &img_datastores) + ImageDatastorePoolXML * img_dspool) { - map::const_iterator ds_it; - map::const_iterator ds_usage_it; + map::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( ds_it->second ); - ds->add_capacity(ds_usage_it->second); } } diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index dce50185c9..210db8655f 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -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 pending_vms = vmpool->get_objects(); const map hosts = hpool->get_objects(); const map datastores = dspool->get_objects(); - const map 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::const_reverse_iterator i, j; - const map pending_vms = vmpool->get_objects(); - const map img_datastores = img_dspool->get_objects(); + const map 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);