Debian Codegraph @

sources/core/modules/scheduler/oar_sched_gantt_with_timesharing

raw
1 #!/usr/bin/perl
2 #-d:DProf
3
4 use strict;
5 use DBI();
6 use OAR::IO;
7 use Data::Dumper;
8 use OAR::Modules::Judas qw(oar_debug oar_warn oar_info oar_error set_current_log_category);
9 use OAR::Conf qw(init_conf dump_conf get_conf is_conf get_conf_with_default_param);
10 use OAR::Schedulers::GanttHoleStorage;
11 use Storable qw(dclone);
12 use Time::HiRes qw(gettimeofday);
13
14 # Log category
15 set_current_log_category('scheduler');
16 my $scheduler_name = "SchedFifoTS";
17 my $Session_id = $$;
18
19 init_conf($ENV{OARCONFFILE});
20 my $initial_time = time();
21 my $timeout = 10;
22 my $Minimum_timeout_per_job = 0;
23 if (is_conf("SCHEDULER_TIMEOUT")) {
24 $timeout = get_conf("SCHEDULER_TIMEOUT");
25 }
26
27 my $max_waiting_jobs_to_schedule = 1000;
28
29 # $security_time_overhead is the security time (second) used to be sure there
30 # are no problem with overlaping jobs
31 my $security_time_overhead = 60;
32 if (is_conf("SCHEDULER_JOB_SECURITY_TIME")) {
33 $security_time_overhead = get_conf("SCHEDULER_JOB_SECURITY_TIME");
34 }
35
36 # Constant duration time of a besteffort job
37 my $besteffort_duration = 5 * 60;
38 $besteffort_duration = $security_time_overhead if ($besteffort_duration < $security_time_overhead);
39 my $besteffort_kill_duration =
40 get_conf_with_default_param("SCHEDULER_BESTEFFORT_KILL_DURATION_BEFORE_RESERVATION", 0);
41 $besteffort_duration = $besteffort_kill_duration
42 if ($besteffort_duration < $besteffort_kill_duration);
43
44 my $minimum_hole_time = 0;
45 if (is_conf("SCHEDULER_GANTT_HOLE_MINIMUM_TIME")) {
46 $minimum_hole_time = get_conf("SCHEDULER_GANTT_HOLE_MINIMUM_TIME");
47 }
48
49 my $Order_part = get_conf("SCHEDULER_RESOURCE_ORDER");
50
51 my @Sched_available_suspended_resource_type;
52 my $sched_available_suspended_resource_type_tmp =
53 get_conf("SCHEDULER_AVAILABLE_SUSPENDED_RESOURCE_TYPE");
54 if (!defined($sched_available_suspended_resource_type_tmp)) {
55 push(@Sched_available_suspended_resource_type, "default");
56 } else {
57 @Sched_available_suspended_resource_type =
58 split(" ", $sched_available_suspended_resource_type_tmp);
59 }
60
61 # Look at resources that we must add for each job
62 my $Resources_to_always_add_type = get_conf("SCHEDULER_RESOURCES_ALWAYS_ASSIGNED_TYPE");
63 my @Resources_to_always_add = ();
64
65 my $Max_nb_processes = get_conf_with_default_param("SCHEDULER_NB_PROCESSES", 1);
66
67 my $current_time;
68
69 my $queue;
70 if (defined($ARGV[0]) && defined($ARGV[1]) && $ARGV[1] =~ m/\d+/m) {
71 $queue = $ARGV[0];
72 $current_time = $ARGV[1];
73 } else {
74 oar_error($scheduler_name, "No queue specified on command line\n", $Session_id);
75 exit(1);
76 }
77
78 # Init
79 my $base = OAR::IO::connect();
80 my $base_ro = OAR::IO::connect_ro();
81
82 oar_info($scheduler_name, "Starting scheduler for queue $queue at time $current_time\n",
83 $Session_id);
84
85 # First check states of resources that we must add for every job
86 if (defined($Resources_to_always_add_type)) {
87 my $tmp_result_state_resources =
88 OAR::IO::get_specific_resource_states($base, $Resources_to_always_add_type);
89 if ($#{ $tmp_result_state_resources->{"Suspected"} } >= 0) {
90 oar_warn(
91 $scheduler_name,
92 "Some of the resources matching the SCHEDULER_RESOURCES_ALWAYS_ASSIGNED_TYPE configuration directive are Suspected. No job can be scheduled. Exiting\n",
93 $Session_id);
94 exit(1);
95 } else {
96 if (defined($tmp_result_state_resources->{"Alive"})) {
97 @Resources_to_always_add = @{ $tmp_result_state_resources->{"Alive"} };
98 oar_info(
99 $scheduler_name,
100 "The following Alive resources matching the SCHEDULER_RESOURCES_ALWAYS_ASSIGNED_TYPE configuration directive will be added to every job: @Resources_to_always_add\n",
101 $Session_id);
102 }
103 }
104 }
105
106 my $timesharing_gantts;
107
108 # Create the Gantt Diagrams
109 #Init the gantt chart with all resources
110 my $All_resource_list_vec = '';
111 my $max_resources = 1;
112 foreach my $r (OAR::IO::list_resources($base)) {
113 vec($All_resource_list_vec, $r->{resource_id}, 1) = 1;
114 $max_resources = $r->{resource_id} if ($r->{resource_id} > $max_resources);
115 }
116
117 my %Container_gantt_hash;
118 $Container_gantt_hash{0} =
119 OAR::Schedulers::GanttHoleStorage::new($max_resources, $minimum_hole_time);
120 OAR::Schedulers::GanttHoleStorage::add_new_resources($Container_gantt_hash{0},
121 $All_resource_list_vec);
122
123 sub parse_timesharing($$$) {
124 my $str = shift;
125 my $job_user = shift;
126 my $job_name = shift;
127
128 my $user = "*";
129 my $name = "*";
130 foreach my $s (split(',', $str)) {
131 if ($s =~ m/^\s*([\w\*]+)\s*$/m) {
132 if ($1 eq "user") {
133 $user = $job_user;
134 } elsif (($1 eq "name") and ($job_name ne "")) {
135 $name = $job_name;
136 }
137 }
138 }
139
140 return ($user, $name);
141 }
142
143 oar_info($scheduler_name, "Begin phase 1 (already scheduled jobs)\n", $Session_id);
144
145 # Take care of currently scheduled jobs (gantt in the database)
146 my ($order, %already_scheduled_jobs) = OAR::IO::get_gantt_scheduled_jobs($base);
147 my @already_scheduled_jobs_list = @{$order};
148 while (@already_scheduled_jobs_list) {
149 my $i = shift(@already_scheduled_jobs_list);
150 my $types = OAR::IO::get_job_types_hash($base, $i);
151
152 # Do not take care of besteffort jobs
153 if ((!defined($types->{besteffort})) or ($queue eq "besteffort")) {
154 my @resource_list = @{ $already_scheduled_jobs{$i}->[3] };
155 my $resource_list_vec = $already_scheduled_jobs{$i}->[10];
156 my $job_duration = $already_scheduled_jobs{$i}->[1];
157 if ($already_scheduled_jobs{$i}->[4] eq "Suspended") {
158
159 # Remove resources of the type specified in SCHEDULER_AVAILABLE_SUSPENDED_RESOURCE_TYPE
160 ($resource_list_vec, @resource_list) = OAR::IO::get_job_current_resources(
161 $base,
162 $already_scheduled_jobs{$i}->[7],
163 \@Sched_available_suspended_resource_type);
164 next if ($#resource_list < 0);
165 }
166 if ($already_scheduled_jobs{$i}->[8] eq "YES") {
167
168 # This job was suspended so we must recalculate the walltime
169 $job_duration += OAR::IO::get_job_suspended_sum_duration($base, $i, $current_time);
170 }
171
172 my $gantt_to_use = $Container_gantt_hash{0};
173 if (defined($types->{container})) {
174 oar_info($scheduler_name, "container job: create a new gantt for container $i\n",
175 $Session_id, "$i");
176 $Container_gantt_hash{$i} = OAR::Schedulers::GanttHoleStorage::new_with_1_hole(
177 $max_resources, $minimum_hole_time,
178 $already_scheduled_jobs{$i}->[0],
179 $job_duration + $security_time_overhead,
180 $resource_list_vec, $All_resource_list_vec);
181 $gantt_to_use = $Container_gantt_hash{$i};
182 }
183
184 #Handle a job within a container
185 my $container_num = 0;
186 if (defined($types->{inner}) and ($types->{inner} =~ /^(\d+)$/)) {
187 if (defined($Container_gantt_hash{$1})) {
188 $gantt_to_use = $Container_gantt_hash{$1};
189 $container_num = $1;
190 oar_info($scheduler_name, "inner job: using container $container_num\n",
191 $Session_id, "$i");
192 } else {
193 if (grep(/^$1$/, @already_scheduled_jobs_list)) {
194
195 # The container job is later in the list, postpone inner job
196 oar_info($scheduler_name,
197 "inner job: container $1 is not known yet, postponing job.\n",
198 $Session_id, "$i");
199 push @already_scheduled_jobs_list, $i;
200 next;
201 } else {
202 oar_info(
203 $scheduler_name,
204 "inner job: container $1 does not exist but job is already scheduled or running, use container 0.\n",
205 $Session_id,
206 "$i");
207 }
208 }
209 }
210 my $user;
211 my $name;
212 if (defined($types->{timesharing})) {
213 ($user, $name) = parse_timesharing(
214 $types->{timesharing},
215 $already_scheduled_jobs{$i}->[5],
216 $already_scheduled_jobs{$i}->[6]);
217 if (!defined($timesharing_gantts->{$container_num}->{$user}->{$name})) {
218 $timesharing_gantts->{$container_num}->{$user}->{$name} = dclone($gantt_to_use);
219 oar_info($scheduler_name,
220 "timesharing job: cloned a new gantt for ($container_num, $user, $name)\n",
221 $Session_id, "$i");
222 }
223 }
224
225 #Fill all other gantts
226 foreach my $g (keys(%Container_gantt_hash)) {
227 if ($i != $g) {
228 oar_info($scheduler_name, "add job occupation in gantt of container $g\n",
229 $Session_id, "$i");
230 OAR::Schedulers::GanttHoleStorage::set_occupation(
231 $Container_gantt_hash{$g},
232 $already_scheduled_jobs{$i}->[0],
233 $job_duration + $security_time_overhead,
234 $resource_list_vec);
235 }
236 }
237 foreach my $c (keys(%{$timesharing_gantts})) {
238 foreach my $u (keys(%{ $timesharing_gantts->{$c} })) {
239 foreach my $n (keys(%{ $timesharing_gantts->{$c}->{$u} })) {
240 if ((!defined($user)) or (!defined($name)) or (($u ne $user) or ($n ne $name)))
241 {
242 oar_info($scheduler_name,
243 "add job occupation in gantt of timesharing ($c, $u, $n)\n",
244 $Session_id, "$i");
245 OAR::Schedulers::GanttHoleStorage::set_occupation(
246 $timesharing_gantts->{$c}->{$u}->{$n},
247 $already_scheduled_jobs{$i}->[0],
248 $job_duration + $security_time_overhead,
249 $resource_list_vec);
250 } else {
251 oar_info(
252 $scheduler_name,
253 "skip timesharing job occupation in gantt of timesharing ($c, $u, $n)\n",
254 $Session_id,
255 "$i");
256 }
257 }
258 }
259 }
260 }
261 }
262
263 oar_info($scheduler_name, "End phase 1 (already scheduled jobs)\n", $Session_id);
264
265 # End of the initialisation
266 # Begining of the real scheduling
267
268 # Get list of Alive resources
269 my ($Alive_resource_id_vec, undef) = OAR::IO::get_resource_ids_in_state($base, "Alive");
270 my ($Absent_resource_id_vec, undef) = OAR::IO::get_resource_ids_in_state($base, "Absent");
271 my ($Suspected_resource_id_vec, undef) = OAR::IO::get_resource_ids_in_state($base, "Suspected");
272 my ($Dead_resource_id_vec, @Dead_resource_ids) = OAR::IO::get_resource_ids_in_state($base, "Dead");
273
274 # ENERGY SAVING: add fake occupations/holes from energy saving configuration
275 # CM part and Hulot part (wake up nodes in energy saving mode)
276 if (is_conf("SCHEDULER_NODE_MANAGER_WAKE_UP_CMD") or
277 (get_conf("ENERGY_SAVING_INTERNAL") eq "yes" and
278 is_conf("ENERGY_SAVING_NODE_MANAGER_WAKE_UP_CMD"))
279 ) {
280 oar_info($scheduler_name, "Begin EnergySaving phase\n", $Session_id);
281
282 # Check the resources that can be waked_up or shut down
283 my $upto_availability = OAR::IO::get_energy_saving_resources_availability($base, $current_time);
284 foreach my $t (keys(%{$upto_availability})) {
285 my $vec = '';
286 foreach my $r (@{ $upto_availability->{$t} }) {
287 vec($Alive_resource_id_vec, $r, 1) = 1;
288 vec($vec, $r, 1) = 1;
289 }
290
291 #Fill all the gantts
292 foreach my $g (keys(%Container_gantt_hash)) {
293 oar_info(
294 $scheduler_name,
295 "Add EnergySaving occupation in gantt for container $g with available_upto = $t\n",
296 $Session_id);
297 OAR::Schedulers::GanttHoleStorage::set_occupation($Container_gantt_hash{$g},
298 $t, OAR::Schedulers::GanttHoleStorage::get_infinity_value(), $vec);
299 }
300
301 foreach my $c (keys(%{$timesharing_gantts})) {
302 foreach my $u (keys(%{ $timesharing_gantts->{$c} })) {
303 foreach my $n (keys(%{ $timesharing_gantts->{$c}->{$u} })) {
304 oar_info(
305 $scheduler_name,
306 "Add EnergySaving occupation in gantt for timesharing ($c, $u, $n) with available_upto = $t\n",
307 $Session_id);
308 OAR::Schedulers::GanttHoleStorage::set_occupation(
309 $timesharing_gantts->{$c}->{$u}->{$n},
310 $t, OAR::Schedulers::GanttHoleStorage::get_infinity_value(), $vec);
311 }
312 }
313 }
314 }
315 oar_info($scheduler_name, "End EnergySaving phase\n", $Session_id);
316 }
317
318 # CM part
319
320 oar_info($scheduler_name, "Begin phase 2 (waiting jobs)\n", $Session_id);
321 my @jobs = OAR::IO::get_jobs_to_schedule($base, $queue, $max_waiting_jobs_to_schedule);
322 while (@jobs and ((time() - $initial_time) < $timeout)) {
323 my $j = shift(@jobs);
324 oar_info($scheduler_name, "start scheduling\n", $Session_id, "$j->{job_id}");
325
326 my $gantt_to_use = $Container_gantt_hash{0};
327 my $container_num = 0;
328 my $types = OAR::IO::get_job_types_hash($base, $j->{job_id});
329
330 my $scheduler_init_date = $current_time;
331
332 if (defined($types->{postpone})) {
333 my $postpone_time_sec = OAR::IO::sql_to_local($types->{postpone});
334 if ($scheduler_init_date < $postpone_time_sec) {
335 $scheduler_init_date = $postpone_time_sec;
336 oar_info($scheduler_name, "job is postponed to $types->{postpone}\n",
337 $Session_id, "$j->{job_id}");
338 }
339 }
340
341 if (defined($types->{expire})) {
342 my $expire_time_sec = OAR::IO::sql_to_local($types->{expire});
343 if ($scheduler_init_date > $expire_time_sec) {
344 my $message = "job will never run (expire=$types->{expire}), setting it to error";
345 oar_info($scheduler_name, "$message\n", $Session_id, "$j->{job_id}");
346 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
347 OAR::IO::set_job_state($base, $j->{job_id}, "toError");
348 next;
349 }
350 }
351
352 my $deadline_time_sec;
353 if (defined($types->{deadline})) {
354 $deadline_time_sec = OAR::IO::sql_to_local($types->{deadline});
355 if ($scheduler_init_date > $deadline_time_sec) {
356 my $message = "job will never run (deadline=$types->{deadline}), setting it to error";
357 oar_info($scheduler_name, "$message\n", $Session_id, "$j->{job_id}");
358 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
359 OAR::IO::set_job_state($base, $j->{job_id}, "toError");
360 next;
361 }
362 }
363
364 # Search for dependencies
365 my $skip_job = 0;
366 foreach my $d (OAR::IO::get_current_job_dependencies($base, $j->{job_id})) {
367 my $dep_job = OAR::IO::get_job($base, $d);
368 if (($dep_job->{state} ne "Terminated") and ($dep_job->{state} ne "Error")) {
369 my @date_tmp = OAR::IO::get_gantt_job_start_time($base, $d);
370 if (defined($date_tmp[0])) {
371 my $mold_dep = OAR::IO::get_current_moldable_job($base, $date_tmp[1]);
372 my $sched_tmp = $date_tmp[0] + $mold_dep->{moldable_walltime};
373 if ($scheduler_init_date < $sched_tmp) {
374 $scheduler_init_date = $sched_tmp + (2 * $security_time_overhead);
375 }
376 } else {
377 my $message = "cannot determine scheduling time due to dependency with the job $d";
378 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
379 oar_info($scheduler_name, "$message\n", $Session_id, "$j->{job_id}");
380 $skip_job = 1;
381 last;
382 }
383 }
384 }
385 next if ($skip_job == 1);
386
387 if (defined($types->{inner}) and ($types->{inner} =~ /^(\d+)$/)) {
388 if ($1 == $j->{job_id}) {
389 my $message = "inner job: job cannot be its own container, setting it to error";
390 oar_warn($scheduler_name, "$message\n", $Session_id, "$j->{job_id}");
391 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
392 OAR::IO::set_job_state($base, $j->{job_id}, "toError");
393 next;
394 }
395 if (defined($Container_gantt_hash{$1})) {
396 $gantt_to_use = $Container_gantt_hash{$1};
397 $container_num = $1;
398 oar_info($scheduler_name, "inner job: using container $container_num\n",
399 $Session_id, "$j->{job_id}");
400 } else {
401
402 #is the container yet to schedule, by this scheduler or another ?
403 if (grep(/^$1$/, map { $_->{job_id} } @jobs)) {
404
405 # The container job is later in the list, postpone inner job
406 oar_info($scheduler_name,
407 "inner job: container $1 is not known yet, postponing job.\n",
408 $Session_id, "$j->{job_id}");
409 push @jobs, $j;
410 } elsif (grep (/^$1$/, OAR::IO::get_all_waiting_jobids($base))) {
411 my $message =
412 "inner job: container $1 is yet to scheduled, inner job not scheduled";
413 oar_info($scheduler_name, "$message\n", $Session_id, "$j->{job_id}");
414 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
415
416 #OAR::IO::set_job_scheduler_info($base,$j->{job_id},"Container $1 does not exist");
417 } else {
418 my $message =
419 "inner job: container $1 does not exist, inner job will never run, setting it to error";
420 oar_warn($scheduler_name, "$message\n", $Session_id, "$j->{job_id}");
421 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
422 OAR::IO::set_job_state($base, $j->{job_id}, "toError");
423 }
424 next;
425 }
426 }
427 if (defined($types->{timesharing})) {
428 my ($user, $name) =
429 parse_timesharing($types->{timesharing}, $j->{job_user}, $j->{job_name});
430 if (!defined($timesharing_gantts->{$container_num}->{$user}->{$name})) {
431 $timesharing_gantts->{$container_num}->{$user}->{$name} = dclone($gantt_to_use);
432 oar_info($scheduler_name,
433 "timesharing job: cloned a new gantt for ($container_num, $user, $name)\n",
434 $Session_id, "$j->{job_id}");
435 }
436 $gantt_to_use = $timesharing_gantts->{$container_num}->{$user}->{$name};
437 oar_info($scheduler_name, "timesharing job: use gantt for ($container_num, $user, $name)\n",
438 $Session_id, "$j->{job_id}");
439 }
440 my $available_resources_vector = $Alive_resource_id_vec;
441
442 # Allow for scheduling jobs on absent or suspected resources is job has type state=permissive
443 if (defined($types->{state}) and $types->{state} eq "permissive") {
444 $available_resources_vector |= $Absent_resource_id_vec | $Suspected_resource_id_vec;
445 }
446 my $job_properties = "\'1\'";
447 if ((defined($j->{properties})) and ($j->{properties} ne "")) {
448 $job_properties = $j->{properties};
449 }
450
451 # Choose the moldable job to schedule
452 my @moldable_results;
453 my $job_descriptions = OAR::IO::get_resources_data_structure_current_job($base, $j->{job_id});
454 foreach my $moldable (@{$job_descriptions}) {
455
456 #my $moldable = $job_descriptions->[0];
457 my $duration;
458 if (defined($types->{besteffort})) {
459 $duration = $besteffort_duration;
460 } else {
461 $duration = $moldable->[1] + $security_time_overhead;
462 }
463
464 my @tree_list;
465 foreach my $m (@{ $moldable->[0] }) {
466 my $tmp_properties = "\'1\'";
467 if ((defined($m->{property})) and ($m->{property} ne "")) {
468 $tmp_properties = $m->{property};
469 }
470 my $tmp_tree =
471 OAR::IO::get_possible_wanted_resources($base_ro, $available_resources_vector, undef,
472 \@Dead_resource_ids, "$job_properties AND $tmp_properties",
473 $m->{resources}, $Order_part);
474 $tmp_tree =
475 OAR::Schedulers::ResourceTree::delete_tree_nodes_with_not_enough_resources($tmp_tree);
476 push(@tree_list, $tmp_tree);
477
478 #my @leafs = OAR::Schedulers::ResourceTree::get_tree_leafs($tmp_tree);
479 #foreach my $l (@leafs){
480 # vec($resource_id_used_list_vector, OAR::Schedulers::ResourceTree::get_current_resource_value($l), 1) = 1;
481 #}
482 }
483 my $gantt_timeout = ($timeout - (time() - $initial_time)) / 4;
484 $gantt_timeout = $Minimum_timeout_per_job if ($gantt_timeout <= ($timeout / 8));
485 oar_info($scheduler_name, "find_first_hole with a timeout of $gantt_timeout\n",
486 $Session_id, "$j->{job_id}");
487 my @hole;
488 if ($Max_nb_processes <= 1) {
489 @hole = OAR::Schedulers::GanttHoleStorage::find_first_hole($gantt_to_use,
490 $scheduler_init_date, $duration, \@tree_list, $gantt_timeout);
491 } else {
492 oar_info($scheduler_name, "using Gantt PARALLEL algorithm\n",
493 $Session_id, "$j->{job_id}");
494 @hole = OAR::Schedulers::GanttHoleStorage::find_first_hole_parallel($gantt_to_use,
495 $scheduler_init_date, $duration, \@tree_list, $gantt_timeout, $Max_nb_processes);
496 }
497
498 # print("[GANTT] 10 ".gettimeofday."\n");
499 my @res_trees;
500 my @resources;
501 foreach my $t (@{ $hole[1] }) {
502
503 # print("[GANTT] 11 ".gettimeofday."\n");
504 #my $minimal_tree = OAR::Schedulers::ResourceTree::delete_unnecessary_subtrees($t);
505 # print("[GANTT] 12 ".gettimeofday."\n");
506 push(@res_trees, $t);
507 foreach my $r (OAR::Schedulers::ResourceTree::get_tree_leafs($t)) {
508 push(@resources, OAR::Schedulers::ResourceTree::get_current_resource_value($r));
509 }
510
511 # print("[GANTT] 13 ".gettimeofday."\n");
512 }
513 push(
514 @moldable_results,
515 { resources => \@resources,
516 start_date => $hole[0],
517 duration => $duration,
518 moldable_id => $moldable->[2] });
519 }
520
521 # Choose moldable job which will finish the first
522 my $index_to_choose = -1;
523 my $best_stop_time;
524
525 # print("[GANTT] 14 ".gettimeofday."\n");
526 for (my $i = 0; $i <= $#moldable_results; $i++) {
527
528 #my @tmp_array = @{$moldable_results[$i]->{resources}};
529 if ($#{ $moldable_results[$i]->{resources} } >= 0) {
530 my $tmp_stop_date =
531 $moldable_results[$i]->{start_date} + $moldable_results[$i]->{duration};
532 if ((!defined($best_stop_time)) or ($best_stop_time > $tmp_stop_date)) {
533 $best_stop_time = $tmp_stop_date;
534 $index_to_choose = $i;
535 }
536 }
537 }
538 if ($index_to_choose >= 0) {
539 if (defined($deadline_time_sec) and $best_stop_time > $deadline_time_sec) {
540 oar_info(
541 $scheduler_name,
542 "not scheduling job because its deadline is not met: $best_stop_time > $deadline_time_sec\n",
543 $Session_id,
544 "$j->{job_id}");
545 next;
546 }
547
548 # We can schedule the job
549 # print("[GANTT] 15 ".gettimeofday."\n");
550 my $vec = '';
551 foreach my $r (@{ $moldable_results[$index_to_choose]->{resources} }) {
552 vec($vec, $r, 1) = 1;
553 }
554
555 #Fill all other gantts
556 foreach my $g (keys(%Container_gantt_hash)) {
557 if ($j->{job_id} != $g) {
558 oar_info($scheduler_name, "add job occupation in gantt of container $g\n",
559 $Session_id, "$j->{job_id}");
560 OAR::Schedulers::GanttHoleStorage::set_occupation(
561 $Container_gantt_hash{$g},
562 $moldable_results[$index_to_choose]->{start_date},
563 $moldable_results[$index_to_choose]->{duration}, $vec);
564 }
565 }
566 if (defined($types->{container})) {
567 $Container_gantt_hash{ $j->{job_id} } =
568 OAR::Schedulers::GanttHoleStorage::new_with_1_hole(
569 $max_resources,
570 $minimum_hole_time,
571 $moldable_results[$index_to_choose]->{start_date},
572 $moldable_results[$index_to_choose]->{duration},
573 $vec,
574 $All_resource_list_vec);
575 }
576
577 foreach my $c (keys(%{$timesharing_gantts})) {
578 foreach my $u (keys(%{ $timesharing_gantts->{$c} })) {
579
580 # print("[GANTT] 17 ".gettimeofday."\n");
581 foreach my $n (keys(%{ $timesharing_gantts->{$c}->{$u} })) {
582 if (($gantt_to_use != $timesharing_gantts->{$c}->{$u}->{$n})) {
583 oar_info($scheduler_name,
584 "add job occupation in gantt of timesharing ($c, $u, $n)\n",
585 $Session_id, "$j->{job_id}");
586 OAR::Schedulers::GanttHoleStorage::set_occupation(
587 $timesharing_gantts->{$c}->{$u}->{$n},
588 $moldable_results[$index_to_choose]->{start_date},
589 $moldable_results[$index_to_choose]->{duration},
590 $vec);
591 } else {
592 oar_info(
593 $scheduler_name,
594 "skip timesharing job occupation in gantt of timesharing ($c, $u, $n)\n",
595 $Session_id,
596 "$j->{job_id}");
597 }
598 }
599 }
600 }
601
602 #update database
603 push(@{ $moldable_results[$index_to_choose]->{resources} }, @Resources_to_always_add);
604 OAR::IO::add_gantt_scheduled_jobs(
605 $base,
606 $moldable_results[$index_to_choose]->{moldable_id},
607 $moldable_results[$index_to_choose]->{start_date},
608 $moldable_results[$index_to_choose]->{resources});
609 OAR::IO::set_job_message($base, $j->{job_id}, "FIFO scheduling OK");
610 OAR::IO::set_job_scheduler_info($base, $j->{job_id}, "FIFO scheduling OK");
611 } else {
612 oar_info($scheduler_name, "job couldn't be scheduled yet: cannot find enough resources\n",
613 $Session_id, "$j->{job_id}");
614 my $message = "cannot find enough resources for job $j->{job_id} yet";
615 OAR::IO::set_job_message($base, $j->{job_id}, ucfirst($message));
616 }
617 oar_info($scheduler_name, "end scheduling\n", $Session_id, "$j->{job_id}");
618 }
619 oar_info($scheduler_name, "End phase 2 (waiting jobs)\n", $Session_id);
620
621 OAR::IO::disconnect($base);
622 OAR::IO::disconnect($base_ro);
623
624 if (@jobs) {
625 oar_info(
626 $scheduler_name,
627 "Warning: some jobs were not scheduled because the scheduler's timeout was reached ($timeout s)\n",
628 $Session_id);
629 }
630
631 oar_info($scheduler_name, "End of scheduler for queue $queue\n", $Session_id);
632