5
use POSIX qw(ceil floor);
7
our @ISA = ('Exporter');
8
our @EXPORT_OK = ('cluster_info',
12
use LogUtils ( 'start_logging', 'error', 'warning', 'debug' );
14
##########################################
15
# Saved private variables
16
##########################################
19
our $running = undef; # total running jobs in a queue
21
# the queue passed in the latest call to queue_info, jobs_info or users_info
22
my $currentqueue = undef;
24
# Resets queue-specific global variables if
25
# the queue has changed since the last call
28
if (not defined $currentqueue or $currentqueue ne $qname) {
29
$currentqueue = $qname;
35
##########################################
37
##########################################
39
my $dbh = DBI->connect('DBI:mysql:ATLAS;host=localhost','','',{RaiseError=>1});
45
my $sth = $dbh->prepare('select sum(p_ncpus) from host where expavg_credit>0');
47
my $result = $sth->fetchrow_array();
48
if(defined($result)){return $result;}
53
my $sth = $dbh->prepare('select sum(p_ncpus) from host');
55
my $result = $sth->fetchrow_array();
56
if(defined($result)){return $result;}
59
sub get_jobs_in_que(){
61
my $sth = $dbh->prepare('select count(*) from result where server_state=2');
63
my $result = $sth->fetchrow_array();
64
if(defined($result)){return $result;}
67
sub get_jobs_in_run(){
69
my $sth = $dbh->prepare('select count(*) from result where server_state=4');
71
my $result = $sth->fetchrow_array();
72
if(defined($result)){return $result;}
76
############################################
78
#############################################
80
sub cluster_info ($) {
85
$lrms_cluster{lrms_type} = "boinc";
86
$lrms_cluster{lrms_version} = "1";
88
# only enforcing per-process cputime limit
89
$lrms_cluster{has_total_cputime_limit} = 0;
91
my ($total_cpus) = get_total_cpus();
92
my ($max_cpus) = get_max_cpus();
93
$lrms_cluster{totalcpus} = $total_cpus;
95
$lrms_cluster{cpudistribution} = $lrms_cluster{totalcpus}."cpu:1";
97
my $que_jobs = get_jobs_in_que();
98
my $run_jobs = get_jobs_in_run();
99
$lrms_cluster{usedcpus} = $run_jobs;
101
$lrms_cluster{runningjobs} = $lrms_cluster{usedcpus};
103
$lrms_cluster{queuedcpus} = $max_cpus-$total_cpus;
104
$lrms_cluster{queuedjobs} = $que_jobs;
105
$lrms_cluster{queue} = [ ];
106
return %lrms_cluster;
109
sub queue_info ($$) {
110
my ($config) = shift;
113
init_globals($qname);
115
my ($total_cpus) = get_total_cpus();
116
my ($max_cpus) = get_max_cpus();
117
my $que_jobs = get_jobs_in_que();
118
my $running = get_jobs_in_run();
119
if (defined $running) {
120
# job_info was already called, we know exactly how many grid jobs
122
$lrms_queue{running} = $running;
125
# assuming that the submitted grid jobs are cpu hogs, approximate
126
# the number of running jobs with the number of running processes
128
$lrms_queue{running}= 0;
130
$lrms_queue{totalcpus} = $total_cpus;
132
$lrms_queue{status} = $lrms_queue{totalcpus}-$lrms_queue{running};
134
# reserve negative numbers for error states
135
# Fork is not real LRMS, and cannot be in error state
136
if ($lrms_queue{status}<0) {
137
debug("lrms_queue{status} = $lrms_queue{status}");
138
$lrms_queue{status} = 0;
144
$lrms_queue{maxrunning} = $job_limit;
145
$lrms_queue{maxuserrun} = $job_limit;
146
$lrms_queue{maxqueuable} = $job_limit;
148
$lrms_queue{maxcputime} = "";
150
$lrms_queue{queued} = $que_jobs;
151
$lrms_queue{mincputime} = "";
152
$lrms_queue{defaultcput} = "";
153
$lrms_queue{minwalltime} = "";
154
$lrms_queue{defaultwallt} = "";
155
$lrms_queue{maxwalltime} = $lrms_queue{maxcputime};
161
sub jobs_info ($$@) {
162
my ($config) = shift;
166
init_globals($qname);
170
foreach my $id (@$jids){
171
$lrms_jobs{$id}{nodes} = [ hostname ];
172
$lrms_jobs{$id}{mem} = 2000000000;
173
$lrms_jobs{$id}{walltime} = "";
174
$lrms_jobs{$id}{cputime} = "";
175
$lrms_jobs{$id}{status} = 'R';
176
$lrms_jobs{$id}{comment} = [ "LRMS: Running under boinc" ];
178
$lrms_jobs{$id}{reqwalltime} = "";
179
$lrms_jobs{$id}{reqcputime} = "";
180
$lrms_jobs{$id}{rank} = "0";
181
$lrms_jobs{$id}{cpus} = "1";
188
sub users_info($$@) {
189
my ($config) = shift;
193
init_globals($qname);
200
if ( ! exists $lrms_queue{status} ) {
201
%lrms_queue = queue_info( $config, $qname );
204
foreach my $u ( @{$accts} ) {
205
$lrms_users{$u}{freecpus} = $lrms_queue{maxuserrun} - $lrms_queue{running};
206
$lrms_users{$u}{queuelength} = "$lrms_queue{queued}";