1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-27 13:57:23 +03:00

F 1548: Updated scheduler logic to SchedAction class

This commit is contained in:
Ruben S. Montero 2018-05-07 18:31:32 +02:00
parent 546921fc13
commit 35ed08fc82
5 changed files with 74 additions and 85 deletions

View File

@ -96,6 +96,11 @@ public:
*/
int parse(std::string& error);
/**
* @return true if the action needs to be executed.
*/
bool is_due();
/**
* Compute the next action, updating the TIME attribute for this action
* @return -1 if action ended 0 otherwise
@ -123,7 +128,7 @@ public:
tmpl->get("SCHED_ACTION", vas);
init_attribute_map("", vas);
init_attribute_map("TIME", vas);
};
virtual ~SchedActions(){};
@ -148,6 +153,11 @@ public:
return 0;
}
bool empty()
{
return a_set.empty();
}
/* ---------------------------------------------------------------------- */
/* Iterators */
/* ---------------------------------------------------------------------- */

View File

@ -25,6 +25,7 @@
#include "Resource.h"
#include "VirtualMachineTemplate.h"
#include "ScheduledAction.h"
class ImageDatastorePoolXML;
@ -325,20 +326,11 @@ public:
*
* @param attributes to hold the VM actions
*/
void get_actions(vector<Attribute *>& attributes) const
SchedActions * get_actions()
{
attributes.clear();
user_template->remove("SCHED_ACTION", attributes);
return new SchedActions(user_template);
}
/**
* Generate new action
*
* @param attributes to hold the VM actions
*/
int next_action(VectorAttribute& vatt);
/**
* Sets an attribute in the VM Template, it must be allocated in the heap
*

View File

@ -503,13 +503,3 @@ bool VirtualMachineXML::is_only_public_cloud() const
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachineXML::next_action(VectorAttribute& vatt)
{
SchedAction action(&vatt, -1);
return action.next_action();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -34,6 +34,7 @@
#include "NebulaLog.h"
#include "PoolObjectAuth.h"
#include "NebulaUtil.h"
#include "ScheduledAction.h"
using namespace std;
@ -1094,7 +1095,7 @@ void Scheduler::dispatch()
const vector<Resource *> vm_rs = vmpool->get_vm_resources();
//--------------------------------------------------------------------------
dss << "Dispatching VMs to hosts:\n"
dss << "Dispatching VMs to hosts:\n"
<< "\tVMID\tPriority\tHost\tSystem DS\n"
<< "\t--------------------------------------------------------------\n";
//--------------------------------------------------------------------------
@ -1380,92 +1381,74 @@ int Scheduler::do_scheduled_actions()
const map<int, ObjectXML*> vms = vmapool->get_objects();
map<int, ObjectXML*>::const_iterator vm_it;
vector<Attribute *> attributes;
vector<Attribute *>::iterator it;
VectorAttribute* vatt;
int action_time;
int done_time;
int rep_time;
int has_rep;
int has_time;
int has_done;
string action_st, error_msg;
time_t the_time = time(0);
string time_str = one_util::log_time(the_time);
string time_str = one_util::log_time(time(0));
for (vm_it=vms.begin(); vm_it != vms.end(); vm_it++)
{
vm = static_cast<VirtualMachineXML*>(vm_it->second);
SchedActions::schedaction_iterator action;
vm->get_actions(attributes);
vm = static_cast<VirtualMachineXML *>(vm_it->second);
// TODO: Sort actions by TIME
for (it=attributes.begin(); it != attributes.end(); it++)
SchedActions * sas = vm->get_actions();
for ( action = sas->begin(); action != sas->end(); ++action)
{
vatt = dynamic_cast<VectorAttribute*>(*it);
ostringstream oss;
if (vatt == 0)
if (!(*action)->is_due())
{
delete *it;
continue;
}
has_time = vatt->vector_value("TIME", action_time);
has_done = vatt->vector_value("DONE", done_time);
has_rep = vatt->vector_value("REP", rep_time);
action_st = vatt->vector_value("ACTION");
action_st = (*action)->vector_value("ACTION");
if (has_time == 0 && (has_done == -1 || (has_done == 0 && done_time < action_time)) && action_time < the_time)
int rc = VirtualMachineXML::parse_action_name(action_st);
oss << "Executing action '" << action_st << "' for VM "
<< vm->get_oid() << " : ";
if ( rc != 0 )
{
ostringstream oss;
int rc = VirtualMachineXML::parse_action_name(action_st);
oss << "Executing action '" << action_st << "' for VM "
<< vm->get_oid() << " : ";
if ( rc != 0 )
{
error_msg = "This action is not supported.";
}
else
{
rc = vmapool->action(vm->get_oid(), action_st, error_msg);
}
error_msg = "This action is not supported.";
}
else
{
rc = vmapool->action(vm->get_oid(), action_st, error_msg);
if (rc == 0)
{
vatt->remove("MESSAGE");
vatt->replace("DONE", static_cast<int>(the_time));
if ( has_rep == 0 )
{
vm->next_action(*vatt);
}
(*action)->remove("MESSAGE");
(*action)->replace("DONE", time(0));
(*action)->next_action();
oss << "Success.";
}
else
{
ostringstream oss_aux;
oss_aux << time_str << " : " << error_msg;
vatt->replace("MESSAGE", oss_aux.str());
oss << "Failure. " << error_msg;
}
NebulaLog::log("VM", Log::INFO, oss);
}
vm->set_attribute(vatt);
if ( rc != 0 )
{
ostringstream oss_aux;
oss_aux << time_str << " : " << error_msg;
(*action)->replace("MESSAGE", oss_aux.str());
oss << "Failure. " << error_msg;
}
NebulaLog::log("VM", Log::INFO, oss);
}
vmpool->update(vm);
if ( sas->empty() != 0 ) //Do not update VMs without SCHED_ACTION
{
vmpool->update(vm);
}
delete sas;
}
return 0;

View File

@ -281,6 +281,20 @@ static int days_in_period(SchedAction::Repeat& r, int month, int year)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool SchedAction::is_due()
{
time_t action_time, done_time;
bool has_done = vector_value("DONE", done_time) == 0;
vector_value("TIME", action_time);
return ((!has_done || done_time < action_time) && action_time < time(0));
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int SchedAction::next_action()
{
Repeat r;