From d59f79deb361665d31b877dc3916706a6b674edb Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 14 Feb 2019 16:37:49 +0100 Subject: [PATCH] F #1548: Added relative TIME specs for Actions. Format is TIME="+" action will be executed after sec seconds of being created --- include/ScheduledAction.h | 3 ++- src/scheduler/include/VirtualMachinePoolXML.h | 4 +-- src/scheduler/include/VirtualMachineXML.h | 9 ++++++- src/scheduler/src/pool/VirtualMachineXML.cc | 2 ++ src/scheduler/src/sched/Scheduler.cc | 2 +- src/vm_template/ScheduledAction.cc | 25 ++++++++++++++++--- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/ScheduledAction.h b/include/ScheduledAction.h index 3fde13b517..96ca4fff7e 100644 --- a/include/ScheduledAction.h +++ b/include/ScheduledAction.h @@ -99,9 +99,10 @@ public: int parse(std::string& error, bool clean); /** + * @param stime time when the time was started for relative time specs * @return true if the action needs to be executed. */ - bool is_due(); + bool is_due(time_t stime); /** * Compute the next action, updating the TIME attribute for this action diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 2272e12cc4..2337c7bcdb 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -165,8 +165,8 @@ protected: { ostringstream oss; - oss << "/VM_POOL/VM/USER_TEMPLATE/SCHED_ACTION[TIME < " << time(0) - << " and not(DONE > 0)]/../.."; + oss << "/VM_POOL/VM/USER_TEMPLATE/SCHED_ACTION[(TIME < " << time(0) + << " and not(DONE > 0)) or ( TIME[starts-with(text(),\"+\")] and not(DONE>0) ) ]/../.."; return get_nodes(oss.str().c_str(), content); } diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 9ac3698816..a7c884d56a 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -160,6 +160,11 @@ public: return dsid; }; + time_t get_stime() const + { + return stime; + } + bool is_resched() const { return (resched == 1); @@ -586,7 +591,7 @@ protected: int state; - long int memory; + long int memory; float cpu; long long system_ds_usage; @@ -600,6 +605,8 @@ protected: string ds_requirements; string ds_rank; + time_t stime; + set nics_ids_auto; map nics; diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index d17c5fccf1..c1a8198aa9 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -169,6 +169,8 @@ void VirtualMachineXML::init_attributes() xpath(action, "/VM/HISTORY_RECORDS/HISTORY/ACTION", -1); + xpath(stime, "/VM/STIME", (time_t) 0); + resume = (action == History::STOP_ACTION || action == History::UNDEPLOY_ACTION || action == History::UNDEPLOY_HARD_ACTION ); diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 1702088057..5cc1930c53 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -1737,7 +1737,7 @@ int Scheduler::do_scheduled_actions() { ostringstream oss; - if (!(*action)->is_due()) + if (!(*action)->is_due(vm->get_stime())) { continue; } diff --git a/src/vm_template/ScheduledAction.cc b/src/vm_template/ScheduledAction.cc index f3bc8b972d..9840fc5b47 100644 --- a/src/vm_template/ScheduledAction.cc +++ b/src/vm_template/ScheduledAction.cc @@ -293,13 +293,32 @@ static int days_in_period(SchedAction::Repeat& r, int month, int year) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -bool SchedAction::is_due() +bool SchedAction::is_due(time_t stime) { - time_t action_time, done_time; + time_t action_time, done_time, origin = 0; + + std::istringstream iss; bool has_done = vector_value("DONE", done_time) == 0; - vector_value("TIME", action_time); + std::string action_time_s = vector_value("TIME"); + + if ( action_time_s[0] == '+' ) + { + origin = stime; + action_time_s.erase(0, 1); + } + + iss.str(action_time_s); + + iss >> action_time; + + if (iss.fail() || !iss.eof()) + { + return false; + } + + action_time += origin; return ((!has_done || done_time < action_time) && action_time < time(0)); }