line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
#Base class for sacctmgr entities which can be "list"ed |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Slurm::Sacctmgr::EntityBaseListable; |
6
|
753
|
|
|
753
|
|
4143
|
use strict; |
|
753
|
|
|
|
|
813
|
|
|
753
|
|
|
|
|
16684
|
|
7
|
753
|
|
|
753
|
|
2230
|
use warnings; |
|
753
|
|
|
|
|
721
|
|
|
753
|
|
|
|
|
14437
|
|
8
|
753
|
|
|
753
|
|
2499
|
use base qw(Slurm::Sacctmgr::EntityBase); |
|
753
|
|
|
|
|
622
|
|
|
753
|
|
|
|
|
269297
|
|
9
|
753
|
|
|
753
|
|
2912
|
use Carp qw(carp croak); |
|
753
|
|
|
|
|
659
|
|
|
753
|
|
|
|
|
487181
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#This is intended for regression tests only |
12
|
|
|
|
|
|
|
my $_last_raw_output; |
13
|
|
|
|
|
|
|
sub _eblist_last_raw_output($) |
14
|
586
|
|
|
586
|
|
6022
|
{ return $_last_raw_output; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
sub _clear_eblist_last_raw_output($) |
17
|
0
|
|
|
0
|
|
0
|
{ $_last_raw_output = []; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#2016-03-09: dropping this. |
22
|
|
|
|
|
|
|
#Accessors/mutators for non-string types should convert strings as needed |
23
|
|
|
|
|
|
|
# #------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
# # Data conversion routines |
25
|
|
|
|
|
|
|
# #------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# sub _data_converter_csv($) |
28
|
|
|
|
|
|
|
# #Takes a csv and returns a list ref |
29
|
|
|
|
|
|
|
# { my $csv = shift; |
30
|
|
|
|
|
|
|
# return unless $csv; |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
# my @data = split /\s*,\s*/, $csv; |
33
|
|
|
|
|
|
|
# return [ @data ]; |
34
|
|
|
|
|
|
|
# } |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# my %DATA_TYPES = |
37
|
|
|
|
|
|
|
# ( csv => \&_data_converter_csv, |
38
|
|
|
|
|
|
|
# ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
41
|
|
|
|
|
|
|
# List command |
42
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _sacctmgr_list_cmd($$) |
45
|
10013
|
|
|
10013
|
|
13267
|
{ my $class = shift; |
46
|
10013
|
|
|
|
|
11493
|
my $sacctmgr = shift; |
47
|
10013
|
100
|
|
|
|
22542
|
$class = ref($class) if ref($class); |
48
|
10013
|
|
|
|
|
19621
|
my $me = $class . '::_sacctmgr_list_cmd'; |
49
|
|
|
|
|
|
|
|
50
|
10013
|
50
|
33
|
|
|
50288
|
die "$me: Missing sacctmgr param at " unless $sacctmgr && ref($sacctmgr); |
51
|
|
|
|
|
|
|
|
52
|
10013
|
|
|
|
|
34023
|
my $base = $class->_sacctmgr_entity_name; |
53
|
10013
|
|
|
|
|
27347
|
my $fields = $class->_sacctmgr_fields_in_order($sacctmgr); |
54
|
10013
|
|
|
|
|
28726
|
my $fmtstr = join ",", @$fields; |
55
|
10013
|
|
|
|
|
42432
|
return [ 'list', $base, "format=$fmtstr" ]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub new_from_sacctmgr_list_record($$$) |
59
|
|
|
|
|
|
|
#Generates a new instance from a list ref as obtained from one of the |
60
|
|
|
|
|
|
|
#sacctmgr list commands |
61
|
11285
|
|
|
11285
|
1
|
16651
|
{ my $class = shift; |
62
|
11285
|
|
|
|
|
13597
|
my $record = shift; |
63
|
11285
|
|
|
|
|
11881
|
my $sacctmgr = shift; #Needed for slurm_version specific stuff |
64
|
11285
|
|
|
|
|
17460
|
my $me = __PACKAGE__ . '::new_from_sacctmgr_list_record'; |
65
|
|
|
|
|
|
|
|
66
|
11285
|
50
|
33
|
|
|
66364
|
croak "$me: Missing req parameter sacctmgr at " unless $sacctmgr && ref($sacctmgr); |
67
|
|
|
|
|
|
|
|
68
|
11285
|
|
|
|
|
68842
|
my $fields = $class->_sacctmgr_fields_in_order($sacctmgr); |
69
|
|
|
|
|
|
|
#2016-03-09: dropping special_fields; instead have accessors customized to handle either |
70
|
|
|
|
|
|
|
#the real type or a string as input. On output convert to string based on ref type |
71
|
|
|
|
|
|
|
# my $special = $class->_special_fields; |
72
|
11285
|
|
|
|
|
31770
|
my @record = @$record; |
73
|
|
|
|
|
|
|
|
74
|
11285
|
|
|
|
|
18263
|
my @newargs = (); |
75
|
|
|
|
|
|
|
|
76
|
11285
|
|
|
|
|
23199
|
foreach my $fld (@$fields) |
77
|
94565
|
|
|
|
|
73920
|
{ my $val = shift @record; |
78
|
94565
|
|
|
|
|
97335
|
$fld = lc $fld; |
79
|
|
|
|
|
|
|
|
80
|
94565
|
100
|
100
|
|
|
239038
|
$val = undef if defined $val && $val eq ''; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# my $type = $special->{$fld}; |
83
|
|
|
|
|
|
|
# if ( $type ) |
84
|
|
|
|
|
|
|
# { my $dcf = $DATA_TYPES{$type}; |
85
|
|
|
|
|
|
|
# unless ( $dcf ) |
86
|
|
|
|
|
|
|
# { die "Class $class: invalid data type $type for field $fld"; |
87
|
|
|
|
|
|
|
# } |
88
|
|
|
|
|
|
|
# $val = &$dcf($val); |
89
|
|
|
|
|
|
|
# } |
90
|
94565
|
|
|
|
|
114969
|
push @newargs, $fld, $val; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
11285
|
|
|
|
|
67896
|
my $obj = $class->new(@newargs); |
94
|
11285
|
|
|
|
|
32189
|
return $obj; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub sacctmgr_list($$@) |
98
|
|
|
|
|
|
|
#Does sacctmgr list to get a list all of the entities of this type |
99
|
|
|
|
|
|
|
#matching specified criteria |
100
|
10013
|
|
|
10013
|
1
|
2936068
|
{ my $class = shift; |
101
|
10013
|
|
|
|
|
11294
|
my $sacctmgr = shift; |
102
|
10013
|
|
|
|
|
18762
|
my %where = @_; |
103
|
|
|
|
|
|
|
|
104
|
10013
|
|
|
|
|
14391
|
my $me = 'sacctmgr_list'; |
105
|
10013
|
50
|
33
|
|
|
54685
|
croak "No/invalid Slurm::Sacctmgr object passed to $me at " |
106
|
|
|
|
|
|
|
unless $sacctmgr && ref($sacctmgr); |
107
|
|
|
|
|
|
|
|
108
|
10013
|
|
|
|
|
33279
|
my $cmd = $class->_sacctmgr_list_cmd($sacctmgr); |
109
|
10013
|
|
|
|
|
23221
|
my @cmd = @$cmd; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#Throw a sort in to make ordering deterministic for regression tests |
112
|
10013
|
|
|
|
|
37225
|
foreach my $key (sort (keys %where) ) |
113
|
13251
|
|
|
|
|
18162
|
{ my $val = $where{$key}; |
114
|
13251
|
50
|
|
|
|
22810
|
$val = '' unless defined $val; |
115
|
|
|
|
|
|
|
#push @cmd, "$key='$val'"; |
116
|
|
|
|
|
|
|
#Do NOT put extra quotes around $val; they are NOT needed |
117
|
|
|
|
|
|
|
#(we do not go through shell interpolation) |
118
|
13251
|
|
|
|
|
29064
|
push @cmd, "$key=$val"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
10013
|
|
|
|
|
34466
|
my $list = $sacctmgr->run_generic_sacctmgr_list_command(@cmd); |
122
|
9467
|
50
|
33
|
|
|
64178
|
unless ( $list && ref($list) ) |
123
|
0
|
|
|
|
|
0
|
{ croak "Error running list cmd for $class: $list at "; |
124
|
|
|
|
|
|
|
} |
125
|
9467
|
|
|
|
|
78591
|
$_last_raw_output = $sacctmgr->_sacctmgr_last_raw_output; |
126
|
|
|
|
|
|
|
|
127
|
9467
|
|
|
|
|
36112
|
my @objects = (); |
128
|
9467
|
|
|
|
|
21239
|
foreach my $rec (@$list) |
129
|
11285
|
|
|
|
|
76236
|
{ my $obj = $class->new_from_sacctmgr_list_record($rec, $sacctmgr); |
130
|
11285
|
|
|
|
|
19760
|
push @objects, $obj; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
9467
|
|
|
|
|
85087
|
return [@objects]; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub sacctmgr_list_me($$) |
137
|
|
|
|
|
|
|
#Takes an instance of an entity, and does a sacctmgr list to find the |
138
|
|
|
|
|
|
|
#current value in SlurmDB for this entity instance |
139
|
|
|
|
|
|
|
#Returns undef if no matches (I don't exist) |
140
|
|
|
|
|
|
|
#Returns a new instance with that info |
141
|
|
|
|
|
|
|
#On error, returns a non-ref error string |
142
|
6808
|
|
|
6808
|
1
|
330120
|
{ my $obj = shift; |
143
|
6808
|
|
|
|
|
8383
|
my $sacctmgr = shift; |
144
|
|
|
|
|
|
|
|
145
|
6808
|
|
|
|
|
11710
|
my $me = 'sacctmgr_list_me'; |
146
|
6808
|
50
|
33
|
|
|
33189
|
croak "No/invalid Slurm::Sacctmgr object passed to $me at " |
147
|
|
|
|
|
|
|
unless $sacctmgr && ref($sacctmgr); |
148
|
|
|
|
|
|
|
|
149
|
6808
|
|
|
|
|
21981
|
my $where = $obj->_my_sacctmgr_where_clause; |
150
|
6808
|
|
|
|
|
25031
|
my $list = $obj->sacctmgr_list($sacctmgr, %$where); |
151
|
6552
|
50
|
33
|
|
|
49843
|
return $list unless $list && ref($list) eq 'ARRAY'; |
152
|
6552
|
100
|
|
|
|
20724
|
return unless scalar(@$list); #No matches, I don't exist |
153
|
|
|
|
|
|
|
|
154
|
6014
|
50
|
|
|
|
18652
|
if ( scalar(@$list) > 1 ) |
155
|
0
|
|
|
|
|
0
|
{ my @tmp = map { "$_='" . $where->{$_} . "'" } (keys %$where); |
|
0
|
|
|
|
|
0
|
|
156
|
0
|
|
|
|
|
0
|
my $tmp = join ", ", @tmp; |
157
|
0
|
|
|
|
|
0
|
my $class = ref($obj); |
158
|
0
|
|
|
|
|
0
|
return "Multiple objects of type $class found with [$tmp]"; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
6014
|
|
|
|
|
10065
|
my $obj2 = $list->[0]; |
162
|
6014
|
|
|
|
|
47229
|
return $obj2; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub new_from_sacctmgr_by_name($$$) |
166
|
|
|
|
|
|
|
#Get a new object for this entity class by looking up the appropriate |
167
|
|
|
|
|
|
|
#entity from sacctmgr by the entity's name. |
168
|
|
|
|
|
|
|
# |
169
|
|
|
|
|
|
|
#Returns undef if no object with that name exists. |
170
|
|
|
|
|
|
|
#Returns non-ref true value if encountered error (error message) |
171
|
|
|
|
|
|
|
#Returns the object ref if succeeded. |
172
|
0
|
|
|
0
|
1
|
|
{ my $class = shift; |
173
|
0
|
|
|
|
|
|
my $sacctmgr = shift; |
174
|
0
|
|
|
|
|
|
my $name = shift; |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
my $me = 'new_from_sacctmgr_by_name'; |
177
|
0
|
0
|
0
|
|
|
|
croak "No/invalid Slurm::Sacctmgr object passed to $me at " |
178
|
|
|
|
|
|
|
unless $sacctmgr && ref($sacctmgr); |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my %where = ( name => $name ); |
181
|
0
|
|
|
|
|
|
my $list = $class->sacctmgr_list($sacctmgr, %where); |
182
|
|
|
|
|
|
|
|
183
|
0
|
0
|
0
|
|
|
|
return $list unless $list && ref($list) eq 'ARRAY'; #Error |
184
|
0
|
0
|
|
|
|
|
return unless scalar(@$list); #No matches, I don't exist |
185
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
if ( scalar(@$list) > 1 ) |
187
|
0
|
|
|
|
|
|
{ croak "$me: Error, multiple entities of type $class named '$name' found, aborting at "; |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
|
my $obj = $list->[0]; |
190
|
0
|
|
|
|
|
|
return $obj; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
194
|
|
|
|
|
|
|
__END__ |