line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
#Part of Slurm::Sacctmgr: Perl wrapper for Slurm's sacctmgr cmd |
4
|
|
|
|
|
|
|
#Represents an Account |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Slurm::Sacctmgr::Account; |
7
|
137
|
|
|
137
|
|
66558
|
use strict; |
|
137
|
|
|
|
|
158
|
|
|
137
|
|
|
|
|
3127
|
|
8
|
137
|
|
|
137
|
|
410
|
use warnings; |
|
137
|
|
|
|
|
152
|
|
|
137
|
|
|
|
|
2853
|
|
9
|
137
|
|
|
137
|
|
430
|
use base qw(Slurm::Sacctmgr::EntityBaseRW); |
|
137
|
|
|
|
|
137
|
|
|
137
|
|
|
|
|
46384
|
|
10
|
137
|
|
|
137
|
|
737
|
use Carp qw(carp croak); |
|
137
|
|
|
|
|
137
|
|
|
137
|
|
|
|
|
6141
|
|
11
|
137
|
|
|
137
|
|
52800
|
use POSIX qw(floor); |
|
137
|
|
|
|
|
640866
|
|
|
137
|
|
|
|
|
446
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
# Globals |
15
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
# Accessors |
19
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @simple_accessors = qw( |
22
|
|
|
|
|
|
|
account |
23
|
|
|
|
|
|
|
description |
24
|
|
|
|
|
|
|
organization |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @arrayref_accessors = qw( |
28
|
|
|
|
|
|
|
coordinators |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my @rw_accessors = (@simple_accessors, @arrayref_accessors ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#The following fields can be set in sacctmgr add or update commands |
34
|
|
|
|
|
|
|
#All but coordinators |
35
|
|
|
|
|
|
|
my @modifiable_fields = @simple_accessors; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(@simple_accessors); |
38
|
|
|
|
|
|
|
__PACKAGE__->mk_arrayref_accessors(@arrayref_accessors); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
42
|
|
|
|
|
|
|
# Overloaded methods |
43
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _rw_fields($) |
46
|
7042
|
|
|
7042
|
|
9458
|
{ my $class = shift; |
47
|
7042
|
|
|
|
|
26566
|
return [ @rw_accessors ]; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _sacctmgr_name_field($) |
51
|
4820
|
|
|
4820
|
|
5422
|
{ my $class = shift; |
52
|
4820
|
|
|
|
|
13721
|
return 'account'; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _sacctmgr_fields($$) |
56
|
1102
|
|
|
1102
|
|
1624
|
{ my $class = shift; |
57
|
1102
|
|
|
|
|
1915
|
my $sacctmgr = shift; |
58
|
1102
|
|
|
|
|
2838
|
return [ @rw_accessors ]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _sacctmgr_fields_addable($$) |
62
|
350
|
|
|
350
|
|
463
|
{ my $class = shift; |
63
|
350
|
|
|
|
|
514
|
my $sacctmgr = shift; |
64
|
350
|
|
|
|
|
1358
|
return [ @modifiable_fields ]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _sacctmgr_fields_updatable($$) |
68
|
968
|
|
|
968
|
|
1530
|
{ my $class = shift; |
69
|
968
|
|
|
|
|
1047
|
my $sacctmgr = shift; |
70
|
968
|
|
|
|
|
3859
|
return [ @modifiable_fields ]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _sacctmgr_fields_in_order($$) |
75
|
4738
|
|
|
4738
|
|
6046
|
{ my $class = shift; |
76
|
4738
|
|
|
|
|
4100
|
my $sacctmgr = shift; |
77
|
4738
|
|
|
|
|
19571
|
return [ @rw_accessors ]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _sacctmgr_list_cmd($$) |
81
|
2384
|
|
|
2384
|
|
2419
|
{ my $class = shift; |
82
|
2384
|
|
|
|
|
2757
|
my $sacctmgr = shift; |
83
|
2384
|
|
|
|
|
5815
|
my $me = $class . '::_sacctmgr_list_cmd'; |
84
|
|
|
|
|
|
|
|
85
|
2384
|
50
|
33
|
|
|
12724
|
die "$me: Missing sacctmgr param at " unless $sacctmgr && ref($sacctmgr); |
86
|
|
|
|
|
|
|
|
87
|
2384
|
|
|
|
|
7460
|
my $tmp = $class->SUPER::_sacctmgr_list_cmd($sacctmgr); |
88
|
2384
|
50
|
33
|
|
|
13756
|
return $tmp unless $tmp && ref($tmp) eq 'ARRAY'; |
89
|
2384
|
|
|
|
|
4806
|
push @$tmp, 'withcoord'; |
90
|
2384
|
|
|
|
|
4636
|
return $tmp; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
94
|
|
|
|
|
|
|
# Constructors, etc |
95
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#All inherited |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
100
|
|
|
|
|
|
|
# Special class methods |
101
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub zero_usage_on_account_cluster($$$$;$) |
104
|
|
|
|
|
|
|
#Given account name and cluster name, zero the usage |
105
|
54
|
|
|
54
|
1
|
57465
|
{ my $class = shift; |
106
|
54
|
|
|
|
|
94
|
my $sacctmgr = shift; |
107
|
54
|
|
|
|
|
46
|
my $account = shift; |
108
|
54
|
|
|
|
|
47
|
my $cluster = shift; |
109
|
54
|
|
|
|
|
53
|
my $quiet = shift; |
110
|
|
|
|
|
|
|
|
111
|
54
|
|
|
|
|
48
|
my $me = 'zero_usage_on_account_cluster'; |
112
|
54
|
50
|
33
|
|
|
325
|
croak "No/invalid Slurm::Sacctmgr object passed to $me at " |
113
|
|
|
|
|
|
|
unless $sacctmgr && ref($sacctmgr); |
114
|
54
|
50
|
|
|
|
172
|
croak "No account name passed to $me at " unless $account; |
115
|
54
|
50
|
|
|
|
107
|
croak "No cluster name passed to $me at " unless $cluster; |
116
|
|
|
|
|
|
|
|
117
|
54
|
|
|
|
|
530
|
my $where = { name => $account, cluster=>$cluster }; |
118
|
54
|
|
|
|
|
116
|
my $set = { rawusage => 0 }; |
119
|
|
|
|
|
|
|
|
120
|
54
|
|
|
|
|
316
|
$class->sacctmgr_modify($sacctmgr, $where, $set, $quiet); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub set_cpumin_limit_on_account_cluster($$$$$) |
124
|
|
|
|
|
|
|
#DEPRECATED. Use set_grptresmin_on_account_cluster instead |
125
|
0
|
|
|
0
|
1
|
0
|
{ my $class = shift; |
126
|
0
|
|
|
|
|
0
|
my @args = @_; |
127
|
0
|
|
|
|
|
0
|
return $class->set_grptresmin_on_account_cluster(@args); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub set_grptresmin_on_account_cluster($$$$$;$) |
131
|
|
|
|
|
|
|
#Given account name and cluster name, and cpumin, set GrpCpuMins to $cpumin |
132
|
|
|
|
|
|
|
#for that account/cluster. Use -1 to unset??? |
133
|
84
|
|
|
84
|
1
|
120028
|
{ my $class = shift; |
134
|
84
|
|
|
|
|
103
|
my $sacctmgr = shift; |
135
|
84
|
|
|
|
|
165
|
my $account = shift; |
136
|
84
|
|
|
|
|
100
|
my $cluster = shift; |
137
|
84
|
|
|
|
|
107
|
my $tresmin = shift; |
138
|
84
|
|
|
|
|
120
|
my $quiet = shift; |
139
|
84
|
|
|
|
|
97
|
my $me = __PACKAGE__ . '::set_grptresmin_on_account_cluster'; |
140
|
|
|
|
|
|
|
|
141
|
84
|
50
|
33
|
|
|
591
|
croak "$me: No/invalid Slurm::Sacctmgr object given at " |
142
|
|
|
|
|
|
|
unless $sacctmgr && ref($sacctmgr); |
143
|
84
|
50
|
|
|
|
191
|
croak "$me: No account name given at " unless $account; |
144
|
84
|
50
|
|
|
|
146
|
croak "$me: No cluster name given at " unless $cluster; |
145
|
84
|
50
|
|
|
|
192
|
croak "$me: No tresmin given at " unless defined $tresmin; |
146
|
|
|
|
|
|
|
|
147
|
84
|
100
|
66
|
|
|
411
|
unless ( $tresmin && ref($tresmin) ) |
148
|
44
|
50
|
|
|
|
87
|
{ croak "$me: undef $tresmin given at " unless defined $tresmin; |
149
|
|
|
|
|
|
|
#See if looks like TRES string or number |
150
|
44
|
100
|
|
|
|
194
|
if ( $tresmin =~ /=/ ) |
151
|
|
|
|
|
|
|
{ #Looks like a tresmin string |
152
|
20
|
|
|
|
|
289
|
$tresmin = $class->_string2hashref($tresmin, $me); |
153
|
|
|
|
|
|
|
} else |
154
|
|
|
|
|
|
|
{ #Assume we were given cpumin for GrpCPUMins |
155
|
|
|
|
|
|
|
#We need to round cpumin to the nearest minute |
156
|
24
|
|
|
|
|
254
|
my $cpumin = floor($tresmin + 0.5); |
157
|
24
|
|
|
|
|
114
|
$tresmin = { cpu => $cpumin }; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
84
|
50
|
|
|
|
371
|
unless ( %$tresmin ) |
162
|
|
|
|
|
|
|
{ #Empty hash given, nothing to do, but warn |
163
|
0
|
|
|
|
|
0
|
carp "$me: Ignoring empty GrpTRESmin hash at "; |
164
|
0
|
|
|
|
|
0
|
return; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
84
|
|
|
|
|
262
|
my $where = { name => $account, cluster=>$cluster }; |
168
|
84
|
|
|
|
|
103
|
my $set; |
169
|
84
|
100
|
|
|
|
352
|
if ( $sacctmgr->sacctmgr_cmd_supports( 'trackable_resources' ) ) |
170
|
|
|
|
|
|
|
{ #Our sacctmgr command supports trackable resources, use them |
171
|
18
|
|
|
|
|
56
|
$set = { grptresmins => $tresmin }; |
172
|
|
|
|
|
|
|
} else |
173
|
|
|
|
|
|
|
{ #We do NOT support TRES |
174
|
66
|
|
|
|
|
232
|
my $tmp = { %$tresmin }; #Make a copy |
175
|
66
|
|
|
|
|
129
|
my $cpumin = delete $tmp->{cpu}; |
176
|
66
|
100
|
|
|
|
151
|
if ( %$tmp ) |
177
|
15
|
|
|
|
|
54
|
{ my @tmp = keys %$tmp; |
178
|
15
|
|
|
|
|
46
|
$tmp = join ", ", @tmp; |
179
|
15
|
50
|
|
|
|
46
|
carp "$me: TRES names [ $tmp ] provided to non-TRES capable sacctmgr, will be ignored, at " |
180
|
|
|
|
|
|
|
unless $quiet; |
181
|
|
|
|
|
|
|
} |
182
|
66
|
|
|
|
|
177
|
$set = { grpcpumins => $cpumin }; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
84
|
|
|
|
|
289
|
$class->sacctmgr_modify($sacctmgr, $where, $set, $quiet); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |
190
|
|
|
|
|
|
|
__END__ |