resched-3.4.0.patch
opennebula-3.4.0/include/DispatchManager.h 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
202 | 202 |
int vid); |
203 | 203 | |
204 | 204 |
/** |
205 |
* Moves a VM to RESCHED state |
|
206 |
* @param vid VirtualMachine identification |
|
207 |
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is |
|
208 |
* in a wrong a state |
|
209 |
*/ |
|
210 |
int resched( |
|
211 |
int vid); |
|
212 | ||
213 |
/** |
|
205 | 214 |
* Moves a VM to PENDING state preserving any resource (i.e. leases) and id |
206 | 215 |
* @param vid VirtualMachine identification |
207 | 216 |
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is |
... | ... | |
267 | 276 | |
268 | 277 |
void failed_action(int vid); |
269 | 278 | |
279 |
void resched_action(int vid); |
|
280 | ||
270 | 281 |
void resubmit_action(int vid); |
271 | 282 |
}; |
272 | 283 |
opennebula-3.4.0/include/VirtualMachine.h 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
55 | 55 |
STOPPED = 4, |
56 | 56 |
SUSPENDED = 5, |
57 | 57 |
DONE = 6, |
58 |
FAILED = 7 |
|
58 |
FAILED = 7, |
|
59 |
RESCHED = 8 |
|
59 | 60 |
}; |
60 | 61 | |
61 | 62 |
/** |
opennebula-3.4.0/src/cli/one_helper/onevm_helper.rb 2012-04-18 13:29:57.211500431 +0000 | ||
---|---|---|
85 | 85 |
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d| |
86 | 86 |
if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY'] |
87 | 87 |
state_str = VirtualMachine::VM_STATE[d['STATE'].to_i] |
88 |
if %w{ACTIVE SUSPENDED}.include? state_str |
|
88 |
if %w{ACTIVE SUSPENDED RESCHED}.include? state_str
|
|
89 | 89 |
d['HISTORY_RECORDS']['HISTORY']['HOSTNAME'] |
90 | 90 |
end |
91 | 91 |
end |
opennebula-3.4.0/src/cli/onevm 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
254 | 254 |
end |
255 | 255 |
end |
256 | 256 | |
257 |
resched_desc = <<-EOT.unindent |
|
258 |
Reschedules the VM. |
|
259 | ||
260 |
States: RUNNING |
|
261 |
EOT |
|
262 | ||
263 |
command :resched, resched_desc, [:range,:vmid_list] do |
|
264 |
helper.perform_actions(args[0],options,"rescheduling") do |vm| |
|
265 |
vm.resched |
|
266 |
end |
|
267 |
end |
|
268 | ||
257 | 269 |
resubmit_desc = <<-EOT.unindent |
258 | 270 |
Resubmits the VM to PENDING state. This is intented for VMs stuck in a |
259 | 271 |
transient state. To re-deploy a fresh copy of the same VM, create a |
opennebula-3.4.0/src/dm/DispatchManagerActions.cc 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
134 | 134 |
oss << "Live-migrating VM " << vid; |
135 | 135 |
NebulaLog::log("DiM",Log::DEBUG,oss); |
136 | 136 | |
137 |
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
|
137 |
if ((vm->get_state() == VirtualMachine::ACTIVE || vm->get_state() == VirtualMachine::RESCHED) &&
|
|
138 | 138 |
vm->get_lcm_state() == VirtualMachine::RUNNING ) |
139 | 139 |
{ |
140 | 140 |
Nebula& nd = Nebula::instance(); |
... | ... | |
628 | 628 |
vm->log("DiM", Log::INFO, "New VM state is DONE."); |
629 | 629 |
break; |
630 | 630 | |
631 |
case VirtualMachine::RESCHED: |
|
631 | 632 |
case VirtualMachine::ACTIVE: |
632 | 633 |
lcm->trigger(LifeCycleManager::DELETE,vid); |
633 | 634 |
break; |
... | ... | |
662 | 663 | |
663 | 664 |
switch (vm->get_state()) |
664 | 665 |
{ |
666 |
case VirtualMachine::RESCHED: |
|
667 |
NebulaLog::log("DiM",Log::ERROR, |
|
668 |
"Cannot resubmit a rescheduled VM. Let it reschedule first"); |
|
669 |
rc = -2; |
|
670 |
break; |
|
671 | ||
665 | 672 |
case VirtualMachine::SUSPENDED: |
666 | 673 |
NebulaLog::log("DiM",Log::ERROR, |
667 | 674 |
"Cannot resubmit a suspended VM. Resume it first"); |
... | ... | |
697 | 704 | |
698 | 705 |
return rc; |
699 | 706 |
} |
707 | ||
708 |
/* -------------------------------------------------------------------------- */ |
|
709 |
/* -------------------------------------------------------------------------- */ |
|
710 | ||
711 |
int DispatchManager::resched( |
|
712 |
int vid) |
|
713 |
{ |
|
714 |
VirtualMachine * vm; |
|
715 |
ostringstream oss; |
|
716 | ||
717 |
vm = vmpool->get(vid,true); |
|
718 | ||
719 |
if ( vm == 0 ) |
|
720 |
{ |
|
721 |
return -1; |
|
722 |
} |
|
723 | ||
724 |
oss << "Rescheduling VM " << vid; |
|
725 |
NebulaLog::log("DiM",Log::DEBUG,oss); |
|
726 | ||
727 |
if (vm->get_state() == VirtualMachine::ACTIVE && |
|
728 |
vm->get_lcm_state() == VirtualMachine::RUNNING ) |
|
729 |
{ |
|
730 |
vm->set_state(VirtualMachine::RESCHED); |
|
731 |
vmpool->update(vm); |
|
732 | ||
733 |
vm->log("DiM", Log::INFO, "New VM state is RESCHED."); |
|
734 |
} |
|
735 |
else |
|
736 |
{ |
|
737 |
goto error; |
|
738 |
} |
|
739 | ||
740 |
vm->unlock(); |
|
741 | ||
742 |
return 0; |
|
743 | ||
744 |
error: |
|
745 |
oss.str(""); |
|
746 |
oss << "Could not reschedule VM " << vid << ", wrong state."; |
|
747 |
NebulaLog::log("DiM",Log::ERROR,oss); |
|
748 | ||
749 |
vm->unlock(); |
|
750 |
return -2; |
|
751 |
} |
opennebula-3.4.0/src/dm/DispatchManagerStates.cc 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
112 | 112 |
lcm_state = vm->get_lcm_state(); |
113 | 113 |
dm_state = vm->get_state(); |
114 | 114 | |
115 |
if ((dm_state == VirtualMachine::ACTIVE) && |
|
115 |
if ((dm_state == VirtualMachine::ACTIVE || dm_state == VirtualMachine::RESCHED) &&
|
|
116 | 116 |
(lcm_state == VirtualMachine::EPILOG || |
117 | 117 |
lcm_state == VirtualMachine::CANCEL || |
118 | 118 |
lcm_state == VirtualMachine::CLEANUP )) |
opennebula-3.4.0/src/lcm/LifeCycleActions.cc 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
241 | 241 |
return; |
242 | 242 |
} |
243 | 243 | |
244 |
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
|
244 |
if ((vm->get_state() == VirtualMachine::ACTIVE || vm->get_state() == VirtualMachine::RESCHED) &&
|
|
245 | 245 |
vm->get_lcm_state() == VirtualMachine::RUNNING) |
246 | 246 |
{ |
247 | 247 |
Nebula& nd = Nebula::instance(); |
... | ... | |
252 | 252 |
// MIGRATE STATE |
253 | 253 |
//---------------------------------------------------- |
254 | 254 | |
255 |
vm->set_state(VirtualMachine::ACTIVE); |
|
256 | ||
255 | 257 |
vm->set_state(VirtualMachine::MIGRATE); |
256 | 258 | |
257 | 259 |
vmpool->update(vm); |
opennebula-3.4.0/src/oca/ruby/OpenNebula/VirtualMachine.rb 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
35 | 35 |
:chmod => "vm.chmod", |
36 | 36 |
} |
37 | 37 | |
38 |
VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED} |
|
38 |
VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED RESCHED}
|
|
39 | 39 | |
40 | 40 |
LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND |
41 | 41 |
SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG |
... | ... | |
49 | 49 |
"STOPPED" => "stop", |
50 | 50 |
"SUSPENDED" => "susp", |
51 | 51 |
"DONE" => "done", |
52 |
"FAILED" => "fail" |
|
52 |
"FAILED" => "fail", |
|
53 |
"RESCHED" => "resc" |
|
53 | 54 |
} |
54 | 55 | |
55 | 56 |
SHORT_LCM_STATES={ |
... | ... | |
189 | 190 |
action('restart') |
190 | 191 |
end |
191 | 192 | |
193 |
# Reschedules a VM |
|
194 |
def resched |
|
195 |
action('resched') |
|
196 |
end |
|
197 | ||
192 | 198 |
# Resubmits a VM to PENDING state |
193 | 199 |
def resubmit |
194 | 200 |
action('resubmit') |
opennebula-3.4.0/src/rm/RequestManagerPoolInfoFilter.cc 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
62 | 62 |
ostringstream state_filter; |
63 | 63 | |
64 | 64 |
if (( state < VirtualMachinePoolInfo::ALL_VM ) || |
65 |
( state > VirtualMachine::FAILED ))
|
|
65 |
( state > VirtualMachine::RESCHED ))
|
|
66 | 66 |
{ |
67 | 67 |
failure_response(XML_RPC_API, |
68 | 68 |
request_error("Incorrect filter_flag, state",""), |
opennebula-3.4.0/src/rm/RequestManagerVirtualMachine.cc 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
225 | 225 |
{ |
226 | 226 |
rc = dm->finalize(id); |
227 | 227 |
} |
228 |
else if (action == "resched") |
|
229 |
{ |
|
230 |
rc = dm->resched(id); |
|
231 |
} |
|
228 | 232 |
else if (action == "resubmit") |
229 | 233 |
{ |
230 | 234 |
rc = dm->resubmit(id); |
... | ... | |
363 | 367 |
return; |
364 | 368 |
} |
365 | 369 | |
366 |
if((vm->get_state() != VirtualMachine::ACTIVE) || |
|
370 |
if((vm->get_state() != VirtualMachine::ACTIVE && vm->get_state() != VirtualMachine::RESCHED) ||
|
|
367 | 371 |
(vm->get_lcm_state() != VirtualMachine::RUNNING) || |
368 | 372 |
(vm->hasPreviousHistory() && vm->get_previous_reason() == History::NONE)) |
369 | 373 |
{ |
opennebula-3.4.0/src/scheduler/include/Scheduler.h 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
116 | 116 | |
117 | 117 |
virtual int schedule(); |
118 | 118 | |
119 |
virtual int set_up_pools(); |
|
119 |
virtual int set_up_pools(int vmstate);
|
|
120 | 120 | |
121 | 121 |
private: |
122 | 122 |
Scheduler(Scheduler const&){}; |
opennebula-3.4.0/src/scheduler/include/VirtualMachinePoolXML.h 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
34 | 34 | |
35 | 35 |
~VirtualMachinePoolXML(){}; |
36 | 36 | |
37 |
int set_up(); |
|
37 |
int set_up(int vmstate);
|
|
38 | 38 | |
39 | 39 |
/** |
40 | 40 |
* Gets an object from the pool |
... | ... | |
59 | 59 |
virtual void add_object(xmlNodePtr node); |
60 | 60 | |
61 | 61 |
virtual int load_info(xmlrpc_c::value &result); |
62 | ||
63 |
int state; |
|
62 | 64 |
}; |
63 | 65 | |
64 | 66 |
#endif /* VM_POOL_XML_H_ */ |
opennebula-3.4.0/src/scheduler/include/VirtualMachineXML.h 2012-04-18 14:09:18.422958733 +0000 | ||
---|---|---|
56 | 56 |
return gid; |
57 | 57 |
}; |
58 | 58 | |
59 |
int get_hid() const |
|
60 |
{ |
|
61 |
return hid; |
|
62 |
}; |
|
63 | ||
59 | 64 |
/** |
60 | 65 |
* Adds a new share to the map of suitable shares to start this VM |
61 | 66 |
* @param hid of the selected host |
... | ... | |
151 | 156 |
int uid; |
152 | 157 |
int gid; |
153 | 158 | |
159 |
int hid; |
|
160 | ||
154 | 161 |
int memory; |
155 | 162 |
float cpu; |
156 | 163 |
opennebula-3.4.0/src/scheduler/SConstruct 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
23 | 23 |
# Include dirs |
24 | 24 |
env.Append(CPPPATH=[ |
25 | 25 |
cwd + '/include/', |
26 |
cwd + '../../include/' |
|
26 | 27 |
]) |
27 | 28 | |
28 | 29 |
# Library dirs |
opennebula-3.4.0/src/scheduler/src/pool/VirtualMachinePoolXML.cc 2012-04-18 13:28:31.671304264 +0000 | ||
---|---|---|
15 | 15 |
/* -------------------------------------------------------------------------- */ |
16 | 16 | |
17 | 17 |
#include "VirtualMachinePoolXML.h" |
18 |
#include "VirtualMachine.h" |
|
18 | 19 |
#include <stdexcept> |
19 | 20 | |
20 |
int VirtualMachinePoolXML::set_up() |
|
21 |
int VirtualMachinePoolXML::set_up(int vmstate)
|
|
21 | 22 |
{ |
22 | 23 |
ostringstream oss; |
23 | 24 |
int rc; |
25 |
state = vmstate; |
|
24 | 26 |
rc = PoolXML::set_up(); |
25 | 27 |
if ( rc == 0 ) |
26 | 28 |
{ |
27 | 29 |
oss.str(""); |
28 |
oss << "Pending virtual machines :"; |
|
30 |
oss << "Pending virtual machines for state=" << state << ":";
|
|
29 | 31 | |
30 | 32 |
map<int,ObjectXML*>::iterator it; |
31 | 33 | |
... | ... | |
72 | 74 |
-2, // VM from all users |
73 | 75 |
-1, // start_id (none) |
74 | 76 |
-1, // end_id (none) |
75 |
1); // in pending state
|
|
77 |
state); // state
|
|
76 | 78 |
return 0; |
77 | 79 |
} |
78 | 80 |
catch (exception const& e) |
... | ... | |
95 | 97 |
ostringstream oss; |
96 | 98 |
xmlrpc_c::value deploy_result; |
97 | 99 | |
100 | ||
98 | 101 |
oss.str(""); |
99 | 102 |
oss << "Dispatching virtual machine " << vid |
100 | 103 |
<< " to HID: " << hid; |
... | ... | |
103 | 106 | |
104 | 107 |
try |
105 | 108 |
{ |
106 |
client->call( client->get_endpoint(), // serverUrl |
|
107 |
"one.vm.deploy", // methodName |
|
108 |
"sii", // arguments format |
|
109 |
&deploy_result, // resultP |
|
110 |
client->get_oneauth().c_str(), // argument 0 |
|
111 |
vid, // argument 1 |
|
112 |
hid // argument 2 |
|
113 |
); |
|
109 |
switch (state) |
|
110 |
{ |
|
111 |
case VirtualMachine::PENDING: |
|
112 |
client->call( client->get_endpoint(), // serverUrl |
|
113 |
"one.vm.deploy", // methodName |
|
114 |
"sii", // arguments format |
|
115 |
&deploy_result, // resultP |
|
116 |
client->get_oneauth().c_str(), // argument 0 |
|
117 |
vid, // argument 1 |
|
118 |
hid); // argument 2 |
|
119 |
break; |
|
120 | ||
121 |
case VirtualMachine::RESCHED: |
|
122 |
client->call( client->get_endpoint(), // serverUrl |
|
123 |
"one.vm.migrate", // methodName |
|
124 |
"siib", // arguments format |
|
125 |
&deploy_result, // resultP |
|
126 |
client->get_oneauth().c_str(), // argument 0 |
|
127 |
vid, // argument 1 |
|
128 |
hid, // argument 2 |
|
129 |
true); // argument 3 |
|
130 |
break; |
|
131 | ||
132 |
default: |
|
133 |
oss.str(""); |
|
134 |
oss << "Error dispatching virtual machine: invalid state"; |
|
135 |
NebulaLog::log("VM",Log::ERROR,oss); |
|
136 |
return -1; |
|
137 |
} |
|
138 | ||
114 | 139 |
} |
115 | 140 |
catch (exception const& e) |
116 | 141 |
{ |
opennebula-3.4.0/src/scheduler/src/pool/VirtualMachineXML.cc 2012-04-18 14:05:00.502202090 +0000 | ||
---|---|---|
26 | 26 |
uid = atoi(((*this)["/VM/UID"])[0].c_str()); |
27 | 27 |
gid = atoi(((*this)["/VM/GID"])[0].c_str()); |
28 | 28 | |
29 |
result = ((*this)["/VM/HISTORY_RECORDS/HISTORY/HID"]); |
|
30 |
if (result.size() > 0) |
|
31 |
{ |
|
32 |
hid = atoi(result[0].c_str()); |
|
33 |
} |
|
34 |
else |
|
35 |
{ |
|
36 |
hid = -1; |
|
37 |
} |
|
38 | ||
29 | 39 |
result = ((*this)["/VM/TEMPLATE/MEMORY"]); |
30 | 40 |
if (result.size() > 0) |
31 | 41 |
{ |
opennebula-3.4.0/src/scheduler/src/sched/Scheduler.cc 2012-04-18 14:11:29.982143676 +0000 | ||
---|---|---|
34 | 34 |
#include "RankPolicy.h" |
35 | 35 |
#include "NebulaLog.h" |
36 | 36 |
#include "PoolObjectAuth.h" |
37 |
#include "VirtualMachine.h" |
|
37 | 38 | |
38 | 39 |
using namespace std; |
39 | 40 | |
... | ... | |
250 | 251 |
/* -------------------------------------------------------------------------- */ |
251 | 252 |
/* -------------------------------------------------------------------------- */ |
252 | 253 | |
253 |
int Scheduler::set_up_pools() |
|
254 |
int Scheduler::set_up_pools(int vmstate)
|
|
254 | 255 |
{ |
255 | 256 |
int rc; |
256 | 257 |
ostringstream oss; |
... | ... | |
272 | 273 |
//Cleans the cache and get the pending VMs |
273 | 274 |
//-------------------------------------------------------------------------- |
274 | 275 | |
275 |
rc = vmpool->set_up(); |
|
276 |
rc = vmpool->set_up(vmstate);
|
|
276 | 277 | |
277 | 278 |
if ( rc != 0 ) |
278 | 279 |
{ |
... | ... | |
329 | 330 |
const map<int, ObjectXML*> pending_vms = vmpool->get_objects(); |
330 | 331 |
const map<int, ObjectXML*> hosts = hpool->get_objects(); |
331 | 332 | |
332 | ||
333 | 333 |
for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++) |
334 | 334 |
{ |
335 | 335 |
vm = static_cast<VirtualMachineXML*>(vm_it->second); |
... | ... | |
415 | 415 |
NebulaLog::log("SCHED",Log::DEBUG,oss); |
416 | 416 |
continue; |
417 | 417 |
} |
418 | ||
419 |
// ----------------------------------------------------------------- |
|
420 |
// Check host placement (rescheduling) |
|
421 |
// ----------------------------------------------------------------- |
|
422 | ||
423 |
if (vm->get_hid() == host->get_hid()) |
|
424 |
{ |
|
425 |
ostringstream oss; |
|
426 | ||
427 |
oss << "Host " << host->get_hid() << |
|
428 |
" filtered out. VM running on host."; |
|
429 | ||
430 |
NebulaLog::log("SCHED",Log::DEBUG,oss); |
|
431 |
continue; |
|
432 |
} |
|
433 | ||
418 | 434 |
// ----------------------------------------------------------------- |
419 | 435 |
// Check host capacity |
420 | 436 |
// ----------------------------------------------------------------- |
... | ... | |
560 | 576 | |
561 | 577 |
if (name == ACTION_TIMER) |
562 | 578 |
{ |
563 |
rc = set_up_pools(); |
|
579 |
rc = set_up_pools(VirtualMachine::PENDING); |
|
580 | ||
581 |
if ( rc != 0 ) |
|
582 |
{ |
|
583 |
return; |
|
584 |
} |
|
585 | ||
586 |
rc = schedule(); |
|
587 | ||
588 |
if ( rc != 0 ) |
|
589 |
{ |
|
590 |
return; |
|
591 |
} |
|
592 | ||
593 |
dispatch(); |
|
594 | ||
595 |
rc = set_up_pools(VirtualMachine::RESCHED); |
|
564 | 596 | |
565 | 597 |
if ( rc != 0 ) |
566 | 598 |
{ |