forked from oar-team/oargrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoargriddel
executable file
·99 lines (86 loc) · 3.21 KB
/
oargriddel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
use oargrid_lib;
use oargrid_conflib;
use Data::Dumper;
use Getopt::Long;
use strict;
use warnings;
# Print help messages
sub usage(){
print <<EOU;
Usage oargriddel reservation_number [-h|-v|-V]
-h show this help message and exit
-v turn on verbose mode
-V print oargrid version and exit
EOU
}
$SIG{INT} = 'IGNORE';
# Get the user name
if (!defined($ENV{SUDO_UID})){
die("[OAR_GRISUBD] I can not get user id\n");
}
my $lusr= getpwuid($ENV{SUDO_UID});
# parse arguments
my $sos;
my $verbose;
my $version;
Getopt::Long::Configure ("gnu_getopt");
GetOptions (
"help|h" => \$sos,
"verbose|v" => \$verbose,
"VERSION|V" => \$version
);
if (defined($version)){
print("OARGRID version : ".oargrid_lib::get_version()."\n");
exit(0);
}
if (defined($sos) || !defined($ARGV[0])){
usage();
exit(1);
}
# Initialize database connection
oargrid_conflib::init_conf(oargrid_lib::get_config_file_name());
my $DB_SERVER = oargrid_conflib::get_conf("DB_HOSTNAME");
my $DB_BASE_NAME= oargrid_conflib::get_conf("DB_BASE_NAME");
my $DB_BASE_LOGIN = oargrid_conflib::get_conf("DB_BASE_LOGIN");
my $DB_BASE_PASSWD = oargrid_conflib::get_conf("DB_BASE_PASSWD");
my $dbh = oargrid_lib::connect($DB_SERVER,$DB_BASE_NAME,$DB_BASE_LOGIN,$DB_BASE_PASSWD);
my $commandTimeout = oargrid_lib::get_command_timeout();
my $exit_code = 0;
my %clusters = oargrid_lib::get_cluster_names($dbh);
if ((defined($ARGV[0])) && ($ARGV[0] =~ m/\d+/m)){
my %resaInfo = oargrid_lib::get_reservation_informations($dbh,$ARGV[0]);
if (defined($resaInfo{reservationUser})){
if (($resaInfo{reservationUser} eq $lusr) || ($lusr eq "oargrid")){
foreach my $i (keys(%{$resaInfo{clusterJobs}})){
foreach my $j (values(%{$resaInfo{clusterJobs}->{$i}})){
my $deleteCmd = oargrid_lib::get_oardel_command($clusters{$i}->{hostname},$lusr,$j->{batchId});
print("Launch command : $deleteCmd\n") if (defined($verbose));
print("[OAR_GRIDDEL] I am deleting the job $j->{batchId} on the cluster $i ...");
my %cmdRes = oargrid_lib::launch_command_with_timeout($deleteCmd, $commandTimeout);
if (!defined($cmdRes{status}) || ($cmdRes{status} != 0)){
if ($cmdRes{status} >> 8 == 6) {
oargrid_lib::mark_job_as_terminated($dbh,$i,$j->{batchId});
print (" ALREADY TERMINATED\n");
}
else {
print(" ERROR $cmdRes{status}\n");
oargrid_lib::mail_notify("[OAR_GRIDDEL] I can not delete the job $j->{batchId} on the cluster $i","The command timed out or the exit status code != 0\nThe command executed was :\n$deleteCmd\n");
$exit_code = 3;
}
}else{
oargrid_lib::mark_job_as_terminated($dbh,$i,$j->{batchId});
print(" DONE\n");
}
}
}
}else{
print("[OAR_GRIDDEL] You are not allowed to delete the reservation n° $ARGV[0]; It is owned by the user $resaInfo{reservationUser}\n");
}
}
}else{
usage();
$exit_code = 2;
}
oargrid_lib::disconnect($dbh);
exit($exit_code);