| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
|
| 4 |
use OAR::IO; |
| 5 |
use Sys::Hostname; |
| 6 |
use OAR::Conf qw(init_conf dump_conf get_conf get_conf_with_default_param is_conf); |
| 7 |
use OAR::Modules::Judas |
| 8 |
qw(oar_debug oar_warn oar_info oar_error send_log_by_email set_current_log_category); |
| 9 |
use OAR::PingChecker; |
| 10 |
use OAR::Tools; |
| 11 |
use Data::Dumper; |
| 12 |
use IPC::Open2; |
| 13 |
|
| 14 |
my $OAR_Tools_module_filepath = "%%PERLLIBDIR%%/OAR/Tools.pm"; |
| 15 |
|
| 16 |
# suitable Data::Dumper configuration for serialization |
| 17 |
$Data::Dumper::Purity = 1; |
| 18 |
$Data::Dumper::Terse = 1; |
| 19 |
$Data::Dumper::Indent = 0; |
| 20 |
$Data::Dumper::Deepcopy = 1; |
| 21 |
|
| 22 |
# Log category |
| 23 |
set_current_log_category('main'); |
| 24 |
|
| 25 |
my $Job_id = shift; |
| 26 |
my $Oarexec_reattach_exit_value = shift; |
| 27 |
my $Oarexec_reattach_script_exit_value = shift; |
| 28 |
my $Oarexec_challenge = shift; |
| 29 |
|
| 30 |
my $Module_name = "Bipbip"; |
| 31 |
my $Session_id = $$; |
| 32 |
|
| 33 |
#get server conf |
| 34 |
init_conf($ENV{OARCONFFILE}); |
| 35 |
my $Remote_host = get_conf("SERVER_HOSTNAME"); |
| 36 |
my $Remote_port = get_conf("SERVER_PORT"); |
| 37 |
|
| 38 |
my $Node_file_db_field = get_conf("NODE_FILE_DB_FIELD"); |
| 39 |
$Node_file_db_field = OAR::Tools::get_default_node_file_db_field() |
| 40 |
if (!defined($Node_file_db_field)); |
| 41 |
|
| 42 |
my $Node_file_db_field_distinct_values = get_conf("NODE_FILE_DB_FIELD_DISTINCT_VALUES"); |
| 43 |
$Node_file_db_field_distinct_values = OAR::Tools::get_default_node_file_db_field_distinct_values() |
| 44 |
if (!defined($Node_file_db_field_distinct_values)); |
| 45 |
|
| 46 |
my $Openssh_cmd = get_conf("OPENSSH_CMD"); |
| 47 |
$Openssh_cmd = OAR::Tools::get_default_openssh_cmd() if (!defined($Openssh_cmd)); |
| 48 |
|
| 49 |
my $Almighty_hostname = $Remote_host; |
| 50 |
if (($Almighty_hostname =~ /^\s*localhost.*$/) or ($Almighty_hostname =~ /^\s*127.*$/)) { |
| 51 |
$Almighty_hostname = hostname(); |
| 52 |
} |
| 53 |
|
| 54 |
my $Deploy_hostname = get_conf("DEPLOY_HOSTNAME"); |
| 55 |
if (!defined($Deploy_hostname)) { |
| 56 |
$Deploy_hostname = $Remote_host; |
| 57 |
} |
| 58 |
my $Cosystem_hostname = get_conf("COSYSTEM_HOSTNAME"); |
| 59 |
if (!defined($Cosystem_hostname)) { |
| 60 |
$Cosystem_hostname = $Remote_host; |
| 61 |
} |
| 62 |
my $Debug_mode = get_conf("OAREXEC_DEBUG_MODE"); |
| 63 |
if (!defined($Debug_mode)) { |
| 64 |
$Debug_mode = 0; |
| 65 |
} |
| 66 |
|
| 67 |
my $Detach_oarexec = get_conf("DETACH_JOB_FROM_SERVER"); |
| 68 |
if (!defined($Detach_oarexec)) { |
| 69 |
$Detach_oarexec = 0; |
| 70 |
} |
| 71 |
|
| 72 |
if (is_conf("OAR_RUNTIME_DIRECTORY")) { |
| 73 |
OAR::Tools::set_default_oarexec_directory(get_conf("OAR_RUNTIME_DIRECTORY")); |
| 74 |
} |
| 75 |
|
| 76 |
my $Server_prologue = get_conf("SERVER_PROLOGUE_EXEC_FILE"); |
| 77 |
my $Server_epilogue = get_conf("SERVER_EPILOGUE_EXEC_FILE"); |
| 78 |
|
| 79 |
my $Cpuset_field = get_conf("JOB_RESOURCE_MANAGER_PROPERTY_DB_FIELD"); |
| 80 |
my $Cpuset_file = get_conf("JOB_RESOURCE_MANAGER_FILE"); |
| 81 |
$Cpuset_file = OAR::Tools::get_default_cpuset_file() if (!defined($Cpuset_file)); |
| 82 |
$Cpuset_file = "$ENV{OARDIR}/$Cpuset_file" if ($Cpuset_file !~ /^\//); |
| 83 |
|
| 84 |
if (is_conf("OAR_SSH_CONNECTION_TIMEOUT")) { |
| 85 |
OAR::Tools::set_ssh_timeout(get_conf("OAR_SSH_CONNECTION_TIMEOUT")); |
| 86 |
} |
| 87 |
|
| 88 |
my $Job_user; |
| 89 |
|
| 90 |
my $base; |
| 91 |
|
| 92 |
$base = OAR::IO::connect(); |
| 93 |
my $Cpuset_path = get_conf("CPUSET_PATH"); |
| 94 |
my $Cpuset_name = OAR::IO::get_job_cpuset_name($base, $Job_id) if (defined($Cpuset_field)); |
| 95 |
my $Cpuset_full_path; |
| 96 |
if (defined($Cpuset_path) and defined($Cpuset_field)) { |
| 97 |
$Cpuset_full_path = $Cpuset_path . '/' . $Cpuset_name; |
| 98 |
} |
| 99 |
|
| 100 |
my ($job_challenge, $ssh_private_key, $ssh_public_key) = OAR::IO::get_job_challenge($base, $Job_id); |
| 101 |
my @hosts = OAR::IO::get_job_current_hostnames($base, $Job_id); |
| 102 |
my $job = OAR::IO::get_job($base, $Job_id); |
| 103 |
my @resources; |
| 104 |
my $moldable; |
| 105 |
|
| 106 |
sub call_server_prologue { |
| 107 |
|
| 108 |
# PROLOGUE EXECUTED ON OAR SERVER # |
| 109 |
# Script is executing with job id in arguments |
| 110 |
if (defined($Server_prologue)) { |
| 111 |
my $cmd = "$Server_prologue $Job_id"; |
| 112 |
my $pid; |
| 113 |
my $exit_value; |
| 114 |
my $signal_num; |
| 115 |
my $dumped_core; |
| 116 |
my $timeout = OAR::Tools::get_default_server_prologue_epilogue_timeout(); |
| 117 |
if (is_conf("SERVER_PROLOGUE_EPILOGUE_TIMEOUT")) { |
| 118 |
$timeout = get_conf("SERVER_PROLOGUE_EPILOGUE_TIMEOUT"); |
| 119 |
} |
| 120 |
eval { |
| 121 |
$SIG{PIPE} = 'IGNORE'; |
| 122 |
$SIG{ALRM} = sub { die "alarm\n" }; |
| 123 |
alarm($timeout); |
| 124 |
$pid = fork(); |
| 125 |
if ($pid == 0) { |
| 126 |
undef($base); |
| 127 |
exec($cmd); |
| 128 |
warn("[ERROR] Cannot find $cmd\n"); |
| 129 |
exit(-1); |
| 130 |
} |
| 131 |
my $wait_res = 0; |
| 132 |
|
| 133 |
# Avoid to be disrupted by a signal |
| 134 |
while ($wait_res != $pid) { |
| 135 |
$wait_res = waitpid($pid, 0); |
| 136 |
} |
| 137 |
alarm(0); |
| 138 |
$exit_value = $? >> 8; |
| 139 |
$signal_num = $? & 127; |
| 140 |
$dumped_core = $? & 128; |
| 141 |
}; |
| 142 |
if ($@) { |
| 143 |
if ($@ eq "alarm\n") { |
| 144 |
if (defined($pid)) { |
| 145 |
my ($children, $cmd_name) = OAR::Tools::get_one_process_children($pid); |
| 146 |
kill(9, @{$children}); |
| 147 |
} |
| 148 |
my $log_str = "Server prologue timed out (cmd: $cmd)"; |
| 149 |
my $str = "[bipbip $Job_id] $log_str"; |
| 150 |
oar_error($Module_name, "$log_str\n", $Session_id, $Job_id); |
| 151 |
OAR::IO::add_new_event($base, "SERVER_PROLOGUE_TIMEOUT", $Job_id, "$str"); |
| 152 |
OAR::IO::disconnect($base); |
| 153 |
OAR::Tools::notify_tcp_socket($Remote_host, $Remote_port, "ChState"); |
| 154 |
if (($job->{job_type} eq "INTERACTIVE") and ($job->{reservation} eq "None")) { |
| 155 |
my ($addr, $port) = split(/:/, $job->{info_type}); |
| 156 |
OAR::Tools::notify_tcp_socket($addr, $port, "ERROR: SERVER PROLOGUE timed out"); |
| 157 |
} |
| 158 |
exit(2); |
| 159 |
} |
| 160 |
} elsif ($exit_value != 0) { |
| 161 |
my $log_str = "Server prologue exit code $exit_value (!=0) (cmd: $cmd)"; |
| 162 |
my $str = "[bipbip $Job_id] $log_str"; |
| 163 |
oar_error($Module_name, "$log_str\n", $Session_id, $Job_id); |
| 164 |
OAR::IO::add_new_event($base, "SERVER_PROLOGUE_EXIT_CODE_ERROR", $Job_id, "$str"); |
| 165 |
OAR::IO::disconnect($base); |
| 166 |
OAR::Tools::notify_tcp_socket($Remote_host, $Remote_port, "ChState"); |
| 167 |
if (($job->{job_type} eq "INTERACTIVE") and ($job->{reservation} eq "None")) { |
| 168 |
my ($addr, $port) = split(/:/, $job->{info_type}); |
| 169 |
OAR::Tools::notify_tcp_socket($addr, $port, |
| 170 |
"ERROR: SERVER PROLOGUE returned a bad value"); |
| 171 |
} |
| 172 |
exit(2); |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
#check if we must treate the end of a oarexec |
| 178 |
if ((defined($Oarexec_reattach_exit_value)) and |
| 179 |
(($job->{state} eq "Launching") or |
| 180 |
($job->{state} eq "Running") or |
| 181 |
($job->{state} eq "Suspended") or |
| 182 |
($job->{state} eq "Resuming")) |
| 183 |
) { |
| 184 |
oar_info($Module_name, |
| 185 |
"OAREXEC end: $Oarexec_reattach_exit_value $Oarexec_reattach_script_exit_value\n", |
| 186 |
$Session_id, $Job_id); |
| 187 |
if ($Oarexec_reattach_exit_value =~ m/\d+/m) { |
| 188 |
if ($Oarexec_challenge eq $job_challenge) { |
| 189 |
OAR::IO::check_end_of_job( |
| 190 |
$base, $Job_id, |
| 191 |
$Oarexec_reattach_script_exit_value, $Oarexec_reattach_exit_value, |
| 192 |
\@hosts, $Remote_host, |
| 193 |
$Remote_port, $job->{job_user}, |
| 194 |
$job->{launching_directory}, $Server_epilogue, |
| 195 |
$Session_id); |
| 196 |
OAR::IO::disconnect($base); |
| 197 |
exit(0); |
| 198 |
} else { |
| 199 |
oar_error($Module_name, |
| 200 |
"Bad challenge from oarexec, perhaps a pirate attack??? ($Oarexec_challenge).\n", |
| 201 |
$Session_id, $Job_id); |
| 202 |
OAR::IO::add_new_event($base, "BIPBIP_CHALLENGE", $Job_id, |
| 203 |
"Bad challenge from oarexec, perhaps a pirate attack??? ($Oarexec_challenge)"); |
| 204 |
OAR::IO::disconnect($base); |
| 205 |
exit(2); |
| 206 |
} |
| 207 |
} else { |
| 208 |
oar_error($Module_name, "Bad argument for bipbip: $Oarexec_reattach_exit_value\n", |
| 209 |
$Session_id, $Job_id); |
| 210 |
OAR::IO::disconnect($base); |
| 211 |
exit(2); |
| 212 |
} |
| 213 |
} else { |
| 214 |
@resources = OAR::IO::get_current_assigned_job_resources($base, $job->{assigned_moldable_job}); |
| 215 |
$moldable = OAR::IO::get_current_moldable_job($base, $job->{assigned_moldable_job}); |
| 216 |
$job = OAR::IO::get_job($base, $Job_id) |
| 217 |
; # In case of the job state has changed since the last call :-( |
| 218 |
if ($job->{state} eq "toLaunch") { |
| 219 |
|
| 220 |
# Tell that the launching process is initiated |
| 221 |
OAR::IO::set_job_state($base, $Job_id, "Launching"); |
| 222 |
$job->{state} = "Launching"; |
| 223 |
} else { |
| 224 |
oar_warn($Module_name, "Job already treated or deleted in the meantime\n", |
| 225 |
$Session_id, $Job_id); |
| 226 |
OAR::IO::disconnect($base); |
| 227 |
exit(1); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
# NOOP jobs |
| 232 |
my $types = OAR::IO::get_job_types_hash($base, $Job_id); |
| 233 |
if (defined($types->{noop})) { |
| 234 |
OAR::IO::set_job_state($base, $Job_id, "Running"); |
| 235 |
OAR::IO::disconnect($base); |
| 236 |
oar_info($Module_name, "User: $job->{job_user}; Set NOOP job to Running\n", |
| 237 |
$Session_id, $Job_id); |
| 238 |
call_server_prologue(); |
| 239 |
exit(0); |
| 240 |
} |
| 241 |
|
| 242 |
# HERE we must launch oarexec on the first node |
| 243 |
oar_info($Module_name, "User: $job->{job_user}; Command: $job->{command} ==> hosts: [@hosts]\n", |
| 244 |
$Session_id, $Job_id); |
| 245 |
|
| 246 |
if (($job->{job_type} eq "INTERACTIVE") and ($job->{reservation} eq "None")) { |
| 247 |
my ($addr, $port) = split(/:/, $job->{info_type}); |
| 248 |
OAR::Tools::notify_tcp_socket($addr, $port, "Starting..."); |
| 249 |
} |
| 250 |
|
| 251 |
$Job_user = $job->{job_user}; |
| 252 |
|
| 253 |
if ((!defined($types->{deploy})) and (!(defined($types->{cosystem})) and ($#hosts >= 0))) { |
| 254 |
my $event_type; |
| 255 |
my @bad; |
| 256 |
############### |
| 257 |
# CPUSET PART # |
| 258 |
############### |
| 259 |
my $cpuset_nodes; |
| 260 |
$cpuset_nodes = |
| 261 |
OAR::IO::get_cpuset_values_for_a_moldable_job($base, $Cpuset_field, |
| 262 |
$job->{assigned_moldable_job}) |
| 263 |
if (defined($Cpuset_field)); |
| 264 |
|
| 265 |
$Job_user = $job->{job_user}; |
| 266 |
$ssh_public_key = |
| 267 |
OAR::Tools::format_ssh_pub_key($ssh_public_key, $Cpuset_full_path, $job->{job_user}, |
| 268 |
$Job_user); |
| 269 |
my $cpuset_data_hash = { |
| 270 |
job_id => $Job_id, |
| 271 |
name => $Cpuset_name, |
| 272 |
nodes => $cpuset_nodes, |
| 273 |
cpuset_path => $Cpuset_path, |
| 274 |
compute_thread_siblings => get_conf_with_default_param("COMPUTE_THREAD_SIBLINGS", "no"), |
| 275 |
ssh_keys => { |
| 276 |
public => { |
| 277 |
file_name => OAR::Tools::get_default_oar_ssh_authorized_keys_file(), |
| 278 |
key => $ssh_public_key |
| 279 |
}, |
| 280 |
private => { |
| 281 |
file_name => OAR::Tools::get_private_ssh_key_file_name($Cpuset_name), |
| 282 |
key => $ssh_private_key |
| 283 |
} |
| 284 |
}, |
| 285 |
oar_tmp_directory => OAR::Tools::get_default_oarexec_directory(), |
| 286 |
user => $job->{job_user}, |
| 287 |
job_user => $Job_user, |
| 288 |
types => $types, |
| 289 |
resources => \@resources, |
| 290 |
node_file_db_fields => $Node_file_db_field, |
| 291 |
node_file_db_fields_distinct_values => $Node_file_db_field_distinct_values, |
| 292 |
array_id => $job->{array_id}, |
| 293 |
array_index => $job->{array_index}, |
| 294 |
stdout_file => OAR::Tools::replace_jobid_tag_in_string($job->{stdout_file}, $Job_id), |
| 295 |
stderr_file => OAR::Tools::replace_jobid_tag_in_string($job->{stderr_file}, $Job_id), |
| 296 |
launching_directory => $job->{launching_directory}, |
| 297 |
job_name => $job->{job_name}, |
| 298 |
walltime_seconds => $moldable->{moldable_walltime}, |
| 299 |
walltime => OAR::IO::duration_to_sql($moldable->{moldable_walltime}), |
| 300 |
project => $job->{project}, |
| 301 |
log_level => OAR::Modules::Judas::get_log_level() }; |
| 302 |
if (defined($cpuset_nodes)) { |
| 303 |
my $taktuk_cmd = get_conf("TAKTUK_CMD"); |
| 304 |
my ($tag, @bad_tmp) = OAR::IO::manage_remote_commands( |
| 305 |
[ keys(%{$cpuset_nodes}) ], $cpuset_data_hash, |
| 306 |
$Cpuset_file, "init", |
| 307 |
$Openssh_cmd, $taktuk_cmd, |
| 308 |
$base, $Module_name, |
| 309 |
$Session_id); |
| 310 |
if ($tag == 0) { |
| 311 |
my $log_str = "Bad cpuset file: $Cpuset_file\n"; |
| 312 |
my $str = "[bipbip $Job_id] [CPUSET] $log_str"; |
| 313 |
oar_error($Module_name, $log_str, $Session_id, $Job_id); |
| 314 |
OAR::IO::add_new_event($base, "CPUSET_MANAGER_FILE", $Job_id, $str); |
| 315 |
} else { |
| 316 |
push(@bad, @bad_tmp); |
| 317 |
$event_type = "CPUSET_ERROR"; |
| 318 |
|
| 319 |
# Clean already configured cpuset |
| 320 |
my @tmp_array = keys(%{$cpuset_nodes}); |
| 321 |
if (($#bad >= 0) and ($#tmp_array > $#bad)) { |
| 322 |
|
| 323 |
# Verify if the job is a reservation |
| 324 |
if ($job->{reservation} ne "None") { |
| 325 |
|
| 326 |
# Look at if there is at least one alive node for the reservation |
| 327 |
my @tmp_hosts; |
| 328 |
|
| 329 |
# Keep only alive nodes |
| 330 |
foreach my $n (@hosts) { |
| 331 |
my $i = 0; |
| 332 |
while (($i <= $#bad) and ($n ne $bad[$i])) { |
| 333 |
$i++; |
| 334 |
} |
| 335 |
push(@tmp_hosts, $n) if ($i > $#bad); |
| 336 |
} |
| 337 |
OAR::IO::lock_table( |
| 338 |
$base, |
| 339 |
[ "jobs", "job_state_logs", |
| 340 |
"resources", "assigned_resources", |
| 341 |
"frag_jobs", "challenges", |
| 342 |
"moldable_job_descriptions", "job_types", |
| 343 |
"job_dependencies", "job_resource_groups", |
| 344 |
"job_resource_descriptions", "event_logs", |
| 345 |
"event_log_hostnames" |
| 346 |
]); |
| 347 |
OAR::IO::set_job_message($base, $Job_id, |
| 348 |
"One or several nodes are not responding correctly(CPUSET_ERROR)"); |
| 349 |
OAR::IO::add_new_event_with_host($base, "$event_type", $Job_id, |
| 350 |
"[bipbip] OAR cpuset suspects nodes for the job $Job_id: @bad", \@bad); |
| 351 |
OAR::IO::archive_some_moldable_job_nodes($base, $job->{assigned_moldable_job}, |
| 352 |
\@bad); |
| 353 |
OAR::IO::unlock_table($base); |
| 354 |
OAR::Tools::notify_tcp_socket($Remote_host, $Remote_port, "ChState"); |
| 355 |
@hosts = @tmp_hosts; |
| 356 |
@bad = (); |
| 357 |
} else { |
| 358 |
|
| 359 |
# remove non initialized nodes |
| 360 |
foreach my $b (@bad) { |
| 361 |
delete($cpuset_nodes->{$b}); |
| 362 |
} |
| 363 |
$cpuset_data_hash->{nodes} = $cpuset_nodes; |
| 364 |
my ($tag, @bad_tmp) = OAR::IO::manage_remote_commands( |
| 365 |
[ keys(%{$cpuset_nodes}) ], $cpuset_data_hash, |
| 366 |
$Cpuset_file, "clean", |
| 367 |
$Openssh_cmd, $taktuk_cmd, |
| 368 |
$base, $Module_name, |
| 369 |
$Session_id); |
| 370 |
push(@bad, @bad_tmp); |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
##################### |
| 376 |
# CPUSET PART, END # |
| 377 |
##################### |
| 378 |
#if (($#bad < 0) and (!defined($cpuset_nodes))){ |
| 379 |
if ($#bad < 0) { |
| 380 |
|
| 381 |
# CHECK nodes |
| 382 |
oar_info($Module_name, "Check nodes: @hosts\n", $Session_id, $Job_id); |
| 383 |
$event_type = "PING_CHECKER_NODE_SUSPECTED"; |
| 384 |
@bad = OAR::PingChecker::test_hosts(@hosts); |
| 385 |
} |
| 386 |
if ($#bad >= 0) { |
| 387 |
OAR::IO::lock_table( |
| 388 |
$base, |
| 389 |
[ "jobs", "job_state_logs", |
| 390 |
"resources", "assigned_resources", |
| 391 |
"frag_jobs", "challenges", |
| 392 |
"moldable_job_descriptions", "job_types", |
| 393 |
"job_dependencies", "job_resource_groups", |
| 394 |
"job_resource_descriptions", "event_logs", |
| 395 |
"event_log_hostnames" |
| 396 |
]); |
| 397 |
OAR::IO::set_job_message($base, $Job_id, |
| 398 |
"One or several nodes are not responding correctly"); |
| 399 |
oar_error($Module_name, "Some nodes are inaccessible ($event_type):\n@bad\n", |
| 400 |
$Session_id, $Job_id); |
| 401 |
my $exit_bipbip = 1; |
| 402 |
if (($job->{job_type} eq "INTERACTIVE") and ($job->{reservation} eq "None")) { |
| 403 |
my ($addr, $port) = split(/:/, $job->{info_type}); |
| 404 |
OAR::Tools::notify_tcp_socket($addr, $port, "ERROR: some resources did not respond"); |
| 405 |
} else { |
| 406 |
|
| 407 |
# Verify if the job is a reservation |
| 408 |
if ($job->{reservation} ne "None") { |
| 409 |
|
| 410 |
# Look at if there is at least one alive node for the reservation |
| 411 |
my @tmp_hosts; |
| 412 |
|
| 413 |
# Keep only alive nodes |
| 414 |
foreach my $n (@hosts) { |
| 415 |
my $i = 0; |
| 416 |
while (($i <= $#bad) and ($n ne $bad[$i])) { |
| 417 |
$i++; |
| 418 |
} |
| 419 |
push(@tmp_hosts, $n) if ($i > $#bad); |
| 420 |
} |
| 421 |
if ($#tmp_hosts < 0) { |
| 422 |
OAR::IO::add_new_event($base, "RESERVATION_NO_NODE", $job->{job_id}, |
| 423 |
"There is no alive node for the reservation $job->{job_id}."); |
| 424 |
} else { |
| 425 |
@hosts = @tmp_hosts; |
| 426 |
$exit_bipbip = 0; |
| 427 |
} |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
#OAR::IO::set_job_state($base,$Job_id,"Error"); |
| 432 |
OAR::IO::add_new_event_with_host($base, "$event_type", $Job_id, |
| 433 |
"[bipbip] OAR suspects nodes for the job $Job_id: @bad", \@bad); |
| 434 |
OAR::IO::unlock_table($base); |
| 435 |
OAR::Tools::notify_tcp_socket($Remote_host, $Remote_port, "ChState"); |
| 436 |
if ($exit_bipbip == 1) { |
| 437 |
OAR::IO::disconnect($base); |
| 438 |
exit(2); |
| 439 |
} |
| 440 |
} else { |
| 441 |
oar_info($Module_name, "No (enough) bad node\n", $Session_id, $Job_id); |
| 442 |
} |
| 443 |
|
| 444 |
# end CHECK |
| 445 |
} |
| 446 |
|
| 447 |
call_server_prologue(); |
| 448 |
|
| 449 |
#CALL OAREXEC ON THE FIRST NODE |
| 450 |
my $pro_epi_timeout = OAR::Tools::get_default_prologue_epilogue_timeout(); |
| 451 |
if (is_conf("PROLOGUE_EPILOGUE_TIMEOUT")) { |
| 452 |
$pro_epi_timeout = get_conf("PROLOGUE_EPILOGUE_TIMEOUT"); |
| 453 |
} |
| 454 |
my $prologue_exec_file; |
| 455 |
if (is_conf("PROLOGUE_EXEC_FILE")) { |
| 456 |
$prologue_exec_file = get_conf("PROLOGUE_EXEC_FILE"); |
| 457 |
} |
| 458 |
my $epilogue_exec_file; |
| 459 |
if (is_conf("EPILOGUE_EXEC_FILE")) { |
| 460 |
$epilogue_exec_file = get_conf("EPILOGUE_EXEC_FILE"); |
| 461 |
} |
| 462 |
my $passive_job_hook_exec_file; |
| 463 |
if (is_conf("PASSIVE_JOB_HOOK_EXEC_FILE")) { |
| 464 |
$passive_job_hook_exec_file = get_conf("PASSIVE_JOB_HOOK_EXEC_FILE"); |
| 465 |
} |
| 466 |
my $deploy_cosystem_job_exec_system; |
| 467 |
if (is_conf("DEPLOY_COSYSTEM_JOB_EXEC_SYSTEM")) { |
| 468 |
$deploy_cosystem_job_exec_system = get_conf("DEPLOY_COSYSTEM_JOB_EXEC_SYSTEM"); |
| 469 |
if (($deploy_cosystem_job_exec_system ne "none") and |
| 470 |
($deploy_cosystem_job_exec_system ne "systemd-run")) { |
| 471 |
oar_error( |
| 472 |
$Module_name, |
| 473 |
"Invalid configuration for DEPLOY_COSYSTEM_JOB_EXEC_SYSTEM: '$deploy_cosystem_job_exec_system' is not supported\n", |
| 474 |
$Session_id, |
| 475 |
$Job_id); |
| 476 |
|
| 477 |
# Don't exit, because it causes the job to be stuck in 'Launching' state... |
| 478 |
} |
| 479 |
} |
| 480 |
my @oarexec_files = ($OAR_Tools_module_filepath, "$ENV{OARDIR}/oarexec"); |
| 481 |
|
| 482 |
my $host_to_connect_via_ssh = $hosts[0]; |
| 483 |
|
| 484 |
#deploy, cosystem and no host part |
| 485 |
if ((defined($types->{cosystem})) or ($#hosts < 0)) { |
| 486 |
$host_to_connect_via_ssh = $Cosystem_hostname; |
| 487 |
} elsif (defined($types->{deploy})) { |
| 488 |
$host_to_connect_via_ssh = $Deploy_hostname; |
| 489 |
} |
| 490 |
|
| 491 |
oar_info($Module_name, "execute oarexec on node $host_to_connect_via_ssh\n", $Session_id, $Job_id); |
| 492 |
|
| 493 |
my $oarexec_cpuset_path; |
| 494 |
if ( |
| 495 |
( defined($Cpuset_full_path) and |
| 496 |
(!defined($types->{cosystem})) and |
| 497 |
(!defined($types->{deploy})) and |
| 498 |
($#hosts >= 0)) |
| 499 |
) { |
| 500 |
# So oarexec will retry several times to contact Almighty until it will be |
| 501 |
# killed by the cpuset manager |
| 502 |
$oarexec_cpuset_path = $Cpuset_full_path; |
| 503 |
} |
| 504 |
|
| 505 |
my %data_to_transfer = ( |
| 506 |
job_id => $Job_id, |
| 507 |
array_id => $job->{array_id}, |
| 508 |
array_index => $job->{array_index}, |
| 509 |
stdout_file => OAR::Tools::replace_jobid_tag_in_string($job->{stdout_file}, $Job_id), |
| 510 |
stderr_file => OAR::Tools::replace_jobid_tag_in_string($job->{stderr_file}, $Job_id), |
| 511 |
launching_directory => $job->{launching_directory}, |
| 512 |
job_env => $job->{job_env}, |
| 513 |
resources => \@resources, |
| 514 |
node_file_db_fields => $Node_file_db_field, |
| 515 |
node_file_db_fields_distinct_values => $Node_file_db_field_distinct_values, |
| 516 |
user => $job->{job_user}, |
| 517 |
job_user => $Job_user, |
| 518 |
types => $types, |
| 519 |
name => $job->{job_name}, |
| 520 |
project => $job->{project}, |
| 521 |
reservation => $job->{reservation}, |
| 522 |
walltime_seconds => $moldable->{moldable_walltime}, |
| 523 |
walltime => OAR::IO::duration_to_sql($moldable->{moldable_walltime}), |
| 524 |
command => $job->{command}, |
| 525 |
challenge => $job_challenge, |
| 526 |
almighty_hostname => $Almighty_hostname, |
| 527 |
almighty_port => $Remote_port, |
| 528 |
checkpoint_signal => $job->{checkpoint_signal}, |
| 529 |
debug_mode => $Debug_mode, |
| 530 |
mode => $job->{job_type}, |
| 531 |
pro_epi_timeout => $pro_epi_timeout, |
| 532 |
prologue => $prologue_exec_file, |
| 533 |
epilogue => $epilogue_exec_file, |
| 534 |
passive_job_hook => $passive_job_hook_exec_file, |
| 535 |
deploy_cosystem_job_exec_system => $deploy_cosystem_job_exec_system, |
| 536 |
tmp_directory => OAR::Tools::get_default_oarexec_directory, |
| 537 |
detach_oarexec => $Detach_oarexec, |
| 538 |
cpuset_full_path => $oarexec_cpuset_path); |
| 539 |
|
| 540 |
my $error = 50; |
| 541 |
my $exit_script_value = 'N'; |
| 542 |
my $init_done = 0; |
| 543 |
eval { |
| 544 |
my $pid; |
| 545 |
$SIG{ALRM} = sub { kill(9, $pid); die "alarm\n" }; |
| 546 |
alarm($pro_epi_timeout + |
| 547 |
OAR::Tools::get_bipbip_ssh_hashtable_send_timeout() + OAR::Tools::get_ssh_timeout()); |
| 548 |
my $ssh_option = ""; |
| 549 |
if ( |
| 550 |
( defined($Cpuset_full_path) and |
| 551 |
(!defined($types->{cosystem})) and |
| 552 |
(!defined($types->{deploy})) and |
| 553 |
($#hosts >= 0)) |
| 554 |
) { |
| 555 |
# for oarsh_shell connection |
| 556 |
$ENV{OAR_CPUSET} = $Cpuset_full_path; |
| 557 |
$ssh_option = "-oSendEnv=OAR_CPUSET"; |
| 558 |
} else { |
| 559 |
$ENV{OAR_CPUSET} = ""; |
| 560 |
} |
| 561 |
$pid = open2(\*READ, \*WRITE, |
| 562 |
"$Openssh_cmd $ssh_option -x -T $host_to_connect_via_ssh perl - $Job_id OAREXEC"); |
| 563 |
foreach my $f (@oarexec_files) { |
| 564 |
open(FILE, $f) or die("Cannot open $f\n"); |
| 565 |
while (<FILE>) { |
| 566 |
print(WRITE); |
| 567 |
} |
| 568 |
close(FILE); |
| 569 |
} |
| 570 |
|
| 571 |
# End of oarexec script transfer |
| 572 |
print(WRITE "\n__END__\n"); |
| 573 |
|
| 574 |
# Send data structure for oarexec |
| 575 |
print(WRITE Dumper(\%data_to_transfer) . "\n"); |
| 576 |
|
| 577 |
close(WRITE); |
| 578 |
|
| 579 |
while (<READ>) { |
| 580 |
oar_info($Module_name, "$_", $Session_id, $Job_id); |
| 581 |
if (($init_done == 0) and ($_ eq OAR::Tools::get_bipbip_oarexec_rendez_vous())) { |
| 582 |
$init_done = 1; |
| 583 |
if ($Detach_oarexec == 0) { |
| 584 |
alarm(0); |
| 585 |
} |
| 586 |
OAR::IO::set_job_state($base, $Job_id, "Running"); |
| 587 |
|
| 588 |
# Notify interactive oarsub |
| 589 |
if (($job->{job_type} eq "INTERACTIVE") and ($job->{reservation} eq "None")) { |
| 590 |
oar_info($Module_name, "Interactive request ;Answer to the client Qsub -I\n", |
| 591 |
$Session_id, $Job_id); |
| 592 |
my ($addr, $port) = split(/:/, $job->{info_type}); |
| 593 |
if (defined(OAR::Tools::notify_tcp_socket($addr, $port, "GOOD JOB"))) { |
| 594 |
oar_error( |
| 595 |
$Module_name, |
| 596 |
"Frag job $Job_id because oarsub cannot be notified by the server on host: $addr:$port. Check your network and firewall configuration\n", |
| 597 |
$Session_id, |
| 598 |
$Job_id); |
| 599 |
OAR::IO::lock_table($base, [ "frag_jobs", "event_logs", "jobs" ]); |
| 600 |
OAR::IO::frag_job($base, $Job_id); |
| 601 |
OAR::IO::unlock_table($base); |
| 602 |
OAR::Tools::notify_tcp_socket($Remote_host, $Remote_port, "Qdel"); |
| 603 |
} |
| 604 |
} |
| 605 |
OAR::IO::disconnect($base) if ($Detach_oarexec == 0); |
| 606 |
} |
| 607 |
|
| 608 |
# Get user script exit code |
| 609 |
if ($_ =~ /^OAREXEC_SCRIPT_EXIT_VALUE\s(\d+|N)$/) { |
| 610 |
$exit_script_value = $1; |
| 611 |
} |
| 612 |
} |
| 613 |
close(READ); |
| 614 |
|
| 615 |
waitpid($pid, 0); |
| 616 |
$error = $? >> 8; |
| 617 |
alarm(0); |
| 618 |
}; |
| 619 |
if (($Detach_oarexec == 1) and ($error == 0)) { |
| 620 |
oar_info($Module_name, "Exit from bipbip normally\n", $Session_id, $Job_id); |
| 621 |
} else { |
| 622 |
if ($init_done == 0) { |
| 623 |
if (($job->{job_type} eq "INTERACTIVE") and ($job->{reservation} eq "None")) { |
| 624 |
my ($addr, $port) = split(/:/, $job->{info_type}); |
| 625 |
OAR::Tools::notify_tcp_socket($addr, $port, |
| 626 |
"ERROR: an error occured on the first job node"); |
| 627 |
} |
| 628 |
} |
| 629 |
$base = OAR::IO::connect() if ($Detach_oarexec == 0); |
| 630 |
OAR::IO::check_end_of_job( |
| 631 |
$base, $Job_id, $exit_script_value, |
| 632 |
$error, \@hosts, $Remote_host, |
| 633 |
$Remote_port, $job->{job_user}, $job->{launching_directory}, |
| 634 |
$Server_epilogue, $Session_id); |
| 635 |
} |
| 636 |
|
| 637 |
OAR::IO::disconnect($base); |
| 638 |
|
| 639 |
exit(0); |
| 640 |
|