From c9ccd944d05e9fae694e979ec2da52cb678df5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 29 Jul 2015 18:23:16 +0200 Subject: [PATCH] Bug #3832: Scheduler detects VMs to be resumed instead of first deployments --- src/scheduler/include/VirtualMachineXML.h | 6 ++++ .../src/pool/VirtualMachinePoolXML.cc | 14 +++++++- src/scheduler/src/pool/VirtualMachineXML.cc | 9 +++++ src/scheduler/src/sched/Scheduler.cc | 35 +++++++++++++------ 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 7a827da1ae..4539608df3 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -91,6 +91,11 @@ public: return (resched == 1); } + bool is_resume() const + { + return resume; + } + const string& get_rank() { return rank; @@ -335,6 +340,7 @@ protected: int dsid; int resched; + bool resume; int memory; float cpu; diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 72b5415ced..16c9a23e3e 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -35,7 +35,8 @@ int VirtualMachinePoolXML::set_up() { oss << "Pending/rescheduling VM and capacity requirements:" << endl; - oss << right << setw(8) << "VM" << " " + oss << right << setw(8) << "ACTION" << " " + << right << setw(8) << "VM" << " " << right << setw(4) << "CPU" << " " << right << setw(11) << "Memory" << " " << right << setw(11) << "System DS" << " " @@ -46,12 +47,23 @@ int VirtualMachinePoolXML::set_up() { int cpu, mem; long long disk; + string action = "DEPLOY"; VirtualMachineXML * vm = static_cast(it->second); vm->get_requirements(cpu, mem, disk); + if (vm->is_resched()) + { + action = "RESCHED"; + } + else if (vm->is_resume()) + { + action = "RESUME"; + } + oss << endl + << right << setw(8) << action << " " << right << setw(8) << it->first << " " << right << setw(4) << cpu << " " << right << setw(11) << mem << " " diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 0effa419de..d365de27b0 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -20,12 +20,15 @@ #include "DatastoreXML.h" #include "DatastorePoolXML.h" #include "NebulaUtil.h" +#include "History.h" void VirtualMachineXML::init_attributes() { vector result; vector nodes; + int action; + string automatic_requirements; oid = atoi(((*this)["/VM/ID"] )[0].c_str()); @@ -172,6 +175,12 @@ void VirtualMachineXML::init_attributes() resched = 0; } + this->xpath(action, "/VM/HISTORY_RECORDS/HISTORY/ACTION", -1); + + resume = (action == History::STOP_ACTION || + action == History::UNDEPLOY_ACTION || + action == History::UNDEPLOY_HARD_ACTION ); + if (get_nodes("/VM/TEMPLATE", nodes) > 0) { vm_template = new VirtualMachineTemplate; diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 4c4bb634ce..e059b86d3a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -654,9 +654,11 @@ static bool match_system_ds(AclXML * acls, VirtualMachineXML* vm, long long vdis // ------------------------------------------------------------------------- // Check datastore capacity for shared systems DS (non-shared will be - // checked in a per host basis during dispatch) + // checked in a per host basis during dispatch). Resume actions do not + // add to shared system DS usage, and are skipped also // ------------------------------------------------------------------------- - if (ds->is_shared() && ds->is_monitored() && !ds->test_capacity(vdisk, error)) + if (ds->is_shared() && ds->is_monitored() && !vm->is_resume() && + !ds->test_capacity(vdisk, error)) { return false; } @@ -757,9 +759,9 @@ void Scheduler::match_schedule() n_error = 0; //---------------------------------------------------------------------- - // Test Image Datastore capacity, but not for migrations + // Test Image Datastore capacity, but not for migrations or resume //---------------------------------------------------------------------- - if (!vm->is_resched()) + if (!vm->is_resched() && !vm->is_resume()) { if (vm->test_image_datastore_capacity(img_dspool, m_error) == false) { @@ -1054,10 +1056,10 @@ void Scheduler::dispatch() const vector resources = vm->get_match_hosts(); - //-------------------------------------------------------------- - // Test Image Datastore capacity, but not for migrations - //-------------------------------------------------------------- - if (!resources.empty() && !vm->is_resched()) + //---------------------------------------------------------------------- + // Test Image Datastore capacity, but not for migrations or resume + //---------------------------------------------------------------------- + if (!resources.empty() && !vm->is_resched() && !vm->is_resume()) { if (vm->test_image_datastore_capacity(img_dspool) == false) { @@ -1157,7 +1159,16 @@ void Scheduler::dispatch() { if (ds->is_shared() && ds->is_monitored()) { - test_cap_result = ds->test_capacity(dsk); + // A resume action tests DS capacity only + // for non-shared system DS + if (vm->is_resume()) + { + test_cap_result = true; + } + else + { + test_cap_result = ds->test_capacity(dsk); + } } else { @@ -1199,7 +1210,11 @@ void Scheduler::dispatch() { if (ds->is_shared() && ds->is_monitored()) { - ds->add_capacity(dsk); + // Resumed VMs do not add to shared system DS capacity + if (!vm->is_resume()) + { + ds->add_capacity(dsk); + } } else {