1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

feature #1243: Scheduler makes use of the resched flag. Needs to get live/cold migration type from config

This commit is contained in:
Ruben S. Montero 2012-04-28 02:33:18 +02:00
parent 8ff221052d
commit f2105549a7
6 changed files with 91 additions and 30 deletions

View File

@ -47,13 +47,14 @@ public:
return static_cast<VirtualMachineXML *>(PoolXML::get(oid));
};
int dispatch(int vid, int hid) const;
int dispatch(int vid, int hid, bool resched) const;
protected:
int get_suitable_nodes(vector<xmlNodePtr>& content)
{
return get_nodes("/VM_POOL/VM", content);
return get_nodes("/VM_POOL/VM[STATE=1 or (LCM_STATE=3 and RESCHED=1)]",
content);
};
virtual void add_object(xmlNodePtr node);

View File

@ -56,10 +56,19 @@ public:
return gid;
};
int get_hid() const
{
return hid;
};
bool is_resched() const
{
return (resched == 1);
}
/**
* Adds a new share to the map of suitable shares to start this VM
* Adds a new host to the list of suitable hosts to start this VM
* @param hid of the selected host
* @param hsid of the selected host share
*/
void add_host(int hid);
@ -151,6 +160,10 @@ protected:
int uid;
int gid;
int hid;
int resched;
int memory;
float cpu;

View File

@ -27,7 +27,7 @@ int HostPoolXML::set_up()
if ( rc == 0 )
{
oss.str("");
oss << "Discovered Hosts (enabled):";
oss << "Discovered Hosts (enabled):" << endl;
map<int,ObjectXML*>::iterator it;

View File

@ -21,11 +21,13 @@ int VirtualMachinePoolXML::set_up()
{
ostringstream oss;
int rc;
rc = PoolXML::set_up();
if ( rc == 0 )
{
oss.str("");
oss << "Pending virtual machines :";
oss << "Pending and rescheduling VMs:" << endl;
map<int,ObjectXML*>::iterator it;
@ -72,7 +74,7 @@ int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result)
-2, // VM from all users
-1, // start_id (none)
-1, // end_id (none)
1); // in pending state
-1); // not in DONE state
return 0;
}
catch (exception const& e)
@ -90,27 +92,48 @@ int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result)
/* -------------------------------------------------------------------------- */
int VirtualMachinePoolXML::dispatch(int vid, int hid) const
int VirtualMachinePoolXML::dispatch(int vid, int hid, bool resched) const
{
ostringstream oss;
xmlrpc_c::value deploy_result;
oss.str("");
oss << "Dispatching virtual machine " << vid
<< " to HID: " << hid;
if (resched == true)
{
oss << "Rescheduling ";
}
else
{
oss << "Dispatching ";
}
oss << "virtual machine " << vid << " to host " << hid;
NebulaLog::log("VM",Log::INFO,oss);
try
{
client->call( client->get_endpoint(), // serverUrl
"one.vm.deploy", // methodName
"sii", // arguments format
&deploy_result, // resultP
client->get_oneauth().c_str(), // argument 0
vid, // argument 1
hid // argument 2
);
//TODO Get live migration from config file
if (resched == true)
{
client->call(client->get_endpoint(), // serverUrl
"one.vm.migrate", // methodName
"siib", // arguments format
&deploy_result, // resultP
client->get_oneauth().c_str(), // argument 0 (AUTH)
vid, // argument 1 (VM)
hid, // argument 2 (HOST)
true); // argument 3 (LIVE)
}
else
{
client->call(client->get_endpoint(), // serverUrl
"one.vm.deploy", // methodName
"sii", // arguments format
&deploy_result, // resultP
client->get_oneauth().c_str(), // argument 0 (AUTH)
vid, // argument 1 (VM)
hid); // argument 2 (HOST)
}
}
catch (exception const& e)
{

View File

@ -66,7 +66,29 @@ void VirtualMachineXML::init_attributes()
else
{
requirements = "";
}
result = ((*this)["/VM/HISTORY_RECORDS/HISTORY/HID"]);
if (result.size() > 0)
{
hid = atoi(result[0].c_str());
}
else
{
hid = -1;
}
result = ((*this)["/VM/RESCHED"]);
if (result.size() > 0)
{
resched = atoi(result[0].c_str());
}
else
{
resched = 0;
}
}
/* -------------------------------------------------------------------------- */
@ -87,13 +109,16 @@ VirtualMachineXML::~VirtualMachineXML()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineXML::add_host(int hid)
void VirtualMachineXML::add_host(int host_id)
{
VirtualMachineXML::Host * ss;
if (( resched == 1 && host_id != hid ) || ( resched == 0 ))
{
VirtualMachineXML::Host * ss;
ss = new VirtualMachineXML::Host(hid);
ss = new VirtualMachineXML::Host(host_id);
hosts.push_back(ss);
hosts.push_back(ss);
}
}
/* -------------------------------------------------------------------------- */

View File

@ -329,7 +329,6 @@ void Scheduler::match()
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
const map<int, ObjectXML*> hosts = hpool->get_objects();
for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++)
{
vm = static_cast<VirtualMachineXML*>(vm_it->second);
@ -516,15 +515,15 @@ void Scheduler::dispatch()
map<int, int> host_vms;
oss << "Select hosts" << endl;
oss << "\tPRI\tHID" << endl;
oss << "\t-------------------" << endl;
oss << "Selected hosts:" << endl;
for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++)
{
vm = static_cast<VirtualMachineXML*>(vm_it->second);
oss << "Virtual Machine: " << vm->get_oid() << "\n" << *vm << endl;
oss << "\t PRI\tHID VM: " << vm->get_oid() << endl
<< "\t-----------------------" << endl
<< *vm << endl;
}
NebulaLog::log("SCHED",Log::INFO,oss);
@ -541,9 +540,9 @@ void Scheduler::dispatch()
if (rc == 0)
{
rc = vmpool->dispatch(vm_it->first,hid);
rc = vmpool->dispatch(vm_it->first, hid, vm->is_resched());
if (rc == 0)
if (rc == 0 && !vm->is_resched())
{
dispatched_vms++;
}