diff --git a/src/scheduler/include/DatastorePoolXML.h b/src/scheduler/include/DatastorePoolXML.h index d245ed0922..b263fde1a7 100644 --- a/src/scheduler/include/DatastorePoolXML.h +++ b/src/scheduler/include/DatastorePoolXML.h @@ -44,14 +44,41 @@ public: protected: - int get_suitable_nodes(vector& content) - { - return get_nodes("/DATASTORE_POOL/DATASTORE[TYPE=1]", content); - }; + virtual int get_suitable_nodes(vector& content) = 0; void add_object(xmlNodePtr node); int load_info(xmlrpc_c::value &result); }; +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +class SystemDatastorePoolXML : public DatastorePoolXML +{ +public: + SystemDatastorePoolXML(Client* client):DatastorePoolXML(client){}; + +protected: + int get_suitable_nodes(vector& content) + { + return get_nodes("/DATASTORE_POOL/DATASTORE[TYPE=1]", content); + }; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +class ImageDatastorePoolXML : public DatastorePoolXML +{ +public: + ImageDatastorePoolXML(Client* client):DatastorePoolXML(client){}; + +protected: + int get_suitable_nodes(vector& content) + { + return get_nodes("/DATASTORE_POOL/DATASTORE[TYPE=0]", content); + }; +}; + #endif /* DATASTORE_POOL_XML_H_ */ diff --git a/src/scheduler/include/DatastoreXML.h b/src/scheduler/include/DatastoreXML.h index e4dffa31d2..cfa4b3cfc7 100644 --- a/src/scheduler/include/DatastoreXML.h +++ b/src/scheduler/include/DatastoreXML.h @@ -42,9 +42,7 @@ public: */ bool test_capacity(unsigned int vm_disk_mb) const { - return true; - //TODO Perform test. - //return (vm_disk_mb < free_mb); + return (vm_disk_mb < free_mb); }; /** diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index c0da3604d0..48e6f929f2 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -91,6 +91,11 @@ protected: delete dspool; } + if ( img_dspool != 0) + { + delete img_dspool; + } + if ( acls != 0) { delete acls; @@ -112,6 +117,7 @@ protected: VirtualMachinePoolXML * vmpool; VirtualMachineActionsPoolXML* vmapool; DatastorePoolXML * dspool; + DatastorePoolXML * img_dspool; AclXML * acls; diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 94d1051606..1f953798a9 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -257,6 +257,8 @@ protected: */ void init_attributes(); + void init_storage_usage(); + ResourceMatch match_hosts; ResourceMatch match_datastores; @@ -274,6 +276,9 @@ protected: int memory; float cpu; + float system_ds_usage; + + map ds_usage; string rank; string requirements; diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index a76aa0cbcf..ec35f45991 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -49,6 +49,8 @@ int VirtualMachinePoolXML::set_up() oss << "Storage usage:" << endl; + int tmp, disk; + for (it=objects.begin();it!=objects.end();it++) { VirtualMachineXML * vm = static_cast(it->second); @@ -58,6 +60,9 @@ int VirtualMachinePoolXML::set_up() 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++) { oss << "DS " << ds_it->first << " " << ds_it->second << "MB; "; diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index c6af448c63..29d53cfbbf 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -195,6 +195,15 @@ void VirtualMachineXML::init_attributes() { user_template = 0; } + + if (vm_template != 0) + { + init_storage_usage(); + } + else + { + system_ds_usage = 0; + } } /* -------------------------------------------------------------------------- */ @@ -254,7 +263,7 @@ void VirtualMachineXML::get_requirements (int& cpu, int& memory, int& disk) cpu = (int) (this->cpu * 100);//now in 100% memory = this->memory * 1024; //now in Kilobytes - disk = 0; + disk = this->system_ds_usage; // MB } /* -------------------------------------------------------------------------- */ @@ -272,20 +281,20 @@ bool isVolatile(const VectorAttribute * disk) map VirtualMachineXML::get_storage_usage() { - map ds_usage; + return ds_usage; +} - vector disks; - vector::iterator it; +void VirtualMachineXML::init_storage_usage() +{ + vector disks; + vector::iterator it; - float size; - string st; - int ds_id; + float size; + string st; + int ds_id; + bool clone; - bool clone; - - // Usage for the system DS will be stored in the index 0, although - // it may not be DS 0 - ds_usage[0] = 0; + system_ds_usage = 0; vm_template->remove("DISK", disks); @@ -306,7 +315,7 @@ map VirtualMachineXML::get_storage_usage() if (isVolatile(disk)) { - ds_usage[0] += size; + system_ds_usage += size; } else { @@ -342,12 +351,10 @@ map VirtualMachineXML::get_storage_usage() } else if (st == "SYSTEM") { - ds_usage[0] += size; + system_ds_usage += size; } // else st == NONE } } - - return ds_usage; } /* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index c959eb6634..9860626dcd 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -214,7 +214,8 @@ void Scheduler::start() machines_limit, (live_rescheds == 1)); vmapool= new VirtualMachineActionsPoolXML(client, machines_limit); - dspool = new DatastorePoolXML(client); + dspool = new SystemDatastorePoolXML(client); + img_dspool = new ImageDatastorePoolXML(client); acls = new AclXML(client); @@ -317,6 +318,8 @@ int Scheduler::set_up_pools() //Cleans the cache and get the datastores //-------------------------------------------------------------------------- + // TODO: Avoid two ds pool info calls to oned + rc = dspool->set_up(); if ( rc != 0 ) @@ -324,6 +327,13 @@ int Scheduler::set_up_pools() return rc; } + rc = img_dspool->set_up(); + + if ( rc != 0 ) + { + return rc; + } + //-------------------------------------------------------------------------- //Cleans the cache and get the hosts ids //-------------------------------------------------------------------------- @@ -398,12 +408,15 @@ void Scheduler::match_schedule() map::const_iterator vm_it; map::const_iterator h_it; + map::const_iterator ds_it; + map::const_iterator ds_usage_it; vector::iterator it; - const map pending_vms = vmpool->get_objects(); - const map hosts = hpool->get_objects(); - const map datastores = dspool->get_objects(); + 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++) { @@ -422,6 +435,35 @@ void Scheduler::match_schedule() n_auth = 0; n_error = 0; + map ds_usage = vm->get_storage_usage(); + + 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 ); + + if (ds_it == img_datastores.end()) + { + // TODO log error + continue; + } + + ds = static_cast( ds_it->second ); + + if (!ds->test_capacity((unsigned int) ds_usage_it->second)) + { + ostringstream oss; + + oss << "VM " << oid << " cannot be deployed because Datastore " + << ds_usage_it->first << " does not have enough free storage."; + + NebulaLog::log("SCHED",Log::INFO,oss); + + vm->log(oss.str()); + } + + break; + } + // --------------------------------------------------------------------- // Match hosts for this VM that: // 1. Fulfills ACL @@ -663,7 +705,9 @@ void Scheduler::match_schedule() // Check datastore capacity // ----------------------------------------------------------------- - if (ds->test_capacity(vm_disk)) + // TODO, system DS monitorization needs to be implemented +// if (ds->test_capacity(vm_disk)) + if (true) { vm->add_match_datastore(ds->get_oid()); @@ -876,6 +920,8 @@ void Scheduler::dispatch() host->add_capacity(cpu,mem,dsk); + // TODO update img & system DS free space + host_vms[hid]++; dispatched_vms++;