1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-31 17:17:40 +03:00

F #1548: Added relative TIME specs for Actions. Format is TIME="+<sec>" action will be executed after sec seconds of being created

This commit is contained in:
Ruben S. Montero 2019-02-14 16:37:49 +01:00
parent 3d748610d4
commit d59f79deb3
6 changed files with 37 additions and 8 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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<int> nics_ids_auto;
map<int, VirtualMachineNicXML *> nics;

View File

@ -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 );

View File

@ -1737,7 +1737,7 @@ int Scheduler::do_scheduled_actions()
{
ostringstream oss;
if (!(*action)->is_due())
if (!(*action)->is_due(vm->get_stime()))
{
continue;
}

View File

@ -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));
}