Skip to content

Commit

Permalink
M #-: External scheduler check response VM in range (#2968)
Browse files Browse the repository at this point in the history
* M #-: External scheduler check response VM in range

* Check VM ID from response is in pending_vms
* Add ddebug output for request and response
* Improve error messages
  • Loading branch information
paczerny authored Mar 6, 2024
1 parent 4225245 commit 868597a
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/scheduler/src/sched/Scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1771,16 +1771,22 @@ void Scheduler::external_scheduler()
pending_json["VMS"] += vm_json;
}

auto request = pending_json.dump();

NebulaLog::ddebug("SCHED", "Sending data to External Scheduler: " + request);

// Call Http Request
string response;

if (ext_scheduler.post_json(pending_json.dump(), response) != 0)
if (ext_scheduler.post_json(request, response) != 0)
{
NebulaLog::error("SCH", "Error connecting to External Scheduler: " + response);
NebulaLog::error("SCHED", "Error connecting to External Scheduler: " + response);

return;
}

NebulaLog::ddebug("SCHED", "External Scheduler response: " + response);

// Parse the result, update VM matched hosts by values from Orchestrator
auto resp = json::parse(response);
auto vms_json = resp["VMS"];
Expand All @@ -1791,7 +1797,19 @@ void Scheduler::external_scheduler()
for (auto vm_json : vms_json)
{
// Note: We use only valid answers for VMs, ignoring others
auto vm = static_cast<VirtualMachineXML*>(pending_vms.at(vm_json["ID"]));
int vm_id = vm_json["ID"];

auto it = pending_vms.find(vm_id);

if ( it == pending_vms.end())
{
NebulaLog::warn("SCHED", "External Scheduler: Received scheduling for VM "
+ to_string(vm_id) + ", which is not in pending state, ignoring");

continue;
}

auto vm = static_cast<VirtualMachineXML*>(it->second);

auto host_json = vm_json["HOST_ID"];
if (!host_json.is_number_integer())
Expand Down Expand Up @@ -1826,7 +1844,7 @@ void Scheduler::external_scheduler()
}
catch(const exception &e)
{
NebulaLog::error("SCHED", e.what());
NebulaLog::error("SCHED", string("Exception procesing External Scheduler response: ") + e.what());
}
}

Expand Down

0 comments on commit 868597a

Please sign in to comment.