Subversion Repositories DevTools

Rev

Rev 255 | Rev 267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
255 dpurdie 1
########################################################################
2
# Copyright ( C ) 2008 ERG Limited, All rights reserved
3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : Display Daemon Status information
10
#
11
# Usage         : See POD at end of file
12
#
13
#......................................................................#
14
 
15
require 5.6.1;
16
use strict;
17
use warnings;
18
use JatsError;
19
use JatsSystem;
20
use Getopt::Long;
21
use Pod::Usage;
22
use JatsRmApi;
23
use Term::ANSIColor qw(:constants);
24
use DBI;
25
 
26
my $VERSION = "1.0.0";                      # Update this
27
my $opt_verbose = 1;
28
my $opt_help = 0;
29
my $opt_manual;
30
my $opt_repeat;
31
my $opt_short;
32
my $opt_color;
33
my @opt_rtag;
34
my %opt_rtag;
35
my $opt_filter;
36
my $RM_DB;
37
my %pname;
38
my %rc;
39
my %rl;
40
my %rname;
261 dpurdie 41
my %official;
255 dpurdie 42
my $indefinite = 0;
43
my %StateData = ( 4 => 'Idle' , 2 => 'Paused', 5 => 'Waiting', 3 => 'Building', 1 => 'Broken');
44
my $ff_string = "\f";
45
 
46
#-------------------------------------------------------------------------------
47
# Function        : Main Entry
48
#
49
# Description     :
50
#
51
# Inputs          :
52
#
53
# Returns         :
54
#
55
my $result = GetOptions (
56
                "help+"         => \$opt_help,          # flag, multiple use allowed
57
                "manual"        => \$opt_manual,        # flag
58
                "verbose+"      => \$opt_verbose,       # flag
59
                "repeat=i"      => \$opt_repeat,        # Integer
60
                "short"         => \$opt_short,         # Flag
61
                "color"         => \$opt_color,         # Flag
62
                "rtag=s"        => \@opt_rtag,          # Array
63
                "filter"        => \$opt_filter,        # Flag
64
                );
65
 
66
#
67
#   Process help and manual options
68
#
69
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
70
pod2usage(-verbose => 1)  if ($opt_help == 2 );
71
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
72
 
73
ErrorConfig( 'name'    =>'DSTATUS' );
74
 
75
#
76
#   Native windows doesn't handle color
77
#   Dispable color by default
78
#
79
unless ( $opt_color )
80
{
81
    $ENV{ANSI_COLORS_DISABLED} = 1;
82
    $ff_string = "\n\n\n";
83
}
84
 
85
#
86
#   Convert array of RTAGS into a hash for simpler usage
87
#
88
 
89
$opt_rtag{$_} = 1 foreach ( split( /[,\s]+/, "@opt_rtag"));
90
 
91
#
92
#   Attempt to prevent users from repeating every second
93
#   If the user specified < 10, then set it to 10
94
#   Exports ( with internal knowledge) can set shorter times
95
#
96
$opt_repeat = 10 if ( $opt_repeat && $opt_repeat < 10 );
97
$opt_repeat -= 1000 if ( $opt_repeat && $opt_repeat > 1001 );
98
 
99
#
100
#   Repeat for ever
101
#
102
while (1)
103
{
104
    getGlobal();
105
    GetConfigData();
106
    GetRunData();
107
    DisplayInfo();
108
 
109
    last unless ( $opt_repeat );
110
    sleep ($opt_repeat );
111
}
112
 
113
disconnectRM(\$RM_DB);
114
exit;
115
 
116
#-------------------------------------------------------------------------------
117
# Function        : DisplayInfo
118
#
119
# Description     : Display collected information
120
#
121
# Inputs          : 
122
#
123
# Returns         : 
124
#
125
sub DisplayInfo
126
{
127
 
128
#DebugDumpData ("Data", \%rc);
129
 
130
    #
131
    #   Display a header
132
    #   Include a form feed if possible
133
    #
134
    if ( $opt_repeat )
135
    {
136
        print $ff_string, BOLD, "Build Daemon Status [" . localtime() . "]" , RESET, "\n";
137
    }
138
    if ( $opt_short && $indefinite )
139
    {
140
        print RED "*** Indefinite Pause", RESET, "\n";
141
    }
142
 
143
    #
144
    #  Sort by Project Name and Release Name
145
    #
146
    foreach my $pname ( sort keys %pname )
147
    {
148
        foreach my $rname ( sort keys %{$pname{$pname}} )
149
        {
150
            my $rtag_id = $pname{$pname}{$rname};
151
 
261 dpurdie 152
            print BOLD GREEN "[$rtag_id] $rname{$rtag_id} ($official{$rtag_id})", RESET, "\n";
255 dpurdie 153
            my @orderm;
154
            my @orders;
155
            my $building = 0;
156
 
157
            foreach my $rcon_id ( keys %{$rc{$rtag_id}}  )
158
            {
159
 
160
                #
161
                #   Determine if any of the machines are building a package
162
                #
163
                $building = 1 if ( $rl{$rcon_id}{cpid} );
164
 
165
                #
166
                #   Sort into Master and Slaves
167
                #   Done so that we can print the master at the top of the list
168
                #
169
                if ($rc{$rtag_id}{$rcon_id}{hostmode} =~ m{M} )
170
                {
171
                    push @orderm, $rcon_id;
172
                }
173
                else
174
                {
175
                    push @orders, $rcon_id;
176
                }
177
            }
178
 
179
            if ( $building || !$opt_short  )
180
            {
181
                foreach my $rcon_id ( @orderm, sort(@orders) )
182
                {
183
                    if ( $opt_filter )
184
                    {
185
                         printf "    %1.1s: %-20s %s\n",
186
                            $rc{$rtag_id}{$rcon_id}{hostmode},
187
                            $rc{$rtag_id}{$rcon_id}{hostname},
188
                            $rc{$rtag_id}{$rcon_id}{filter};
189
                    }
190
                    else
191
                    {
192
                             printf "    %1.1s: %-20s %s%10s%s(%1.1s) %-20s\n",
193
                #                $rtag_id, $rcon_id,
194
                                $rc{$rtag_id}{$rcon_id}{hostmode},
195
                                $rc{$rtag_id}{$rcon_id}{hostname},
196
                                $indefinite ? RED : RESET,
197
                                $indefinite ? ('AllStop') : (getState($rl{$rcon_id}{crl})),
198
                                RESET,
199
                                defined ($rl{$rcon_id}{pause} ) ? $rl{$rcon_id}{pause} : '-',
200
                                $rl{$rcon_id}{cpid} || '-'
201
                            ;
202
                    }
203
                }
204
                print "\n";
205
            }
206
        }
207
    }
208
}
209
 
210
#-------------------------------------------------------------------------------
211
# Function        : getGlobal
212
#
213
# Description     : Get global information
214
#
215
# Inputs          : 
216
#
217
# Returns         : 
218
#
219
 
220
sub getGlobal
221
{
222
    my (@row);
223
    $indefinite = 0;
224
 
225
    # if we are not or cannot connect then return 0 as we have not found anything
226
    connectRM( \$RM_DB) unless $RM_DB;
227
 
228
    # First get details from pv_id
229
 
230
    my $m_sqlstr = "SELECT SCHEDULED_PAUSE, SCHEDULED_RESUME, REPEAT, INDEFINITE_PAUSE" .
231
                   " FROM RELEASE_MANAGER.RUN_LEVEL_SCHEDULE";
232
 
233
    my $sth = $RM_DB->prepare($m_sqlstr);
234
    if ( defined($sth) )
235
    {
236
        if ( $sth->execute( ) )
237
        {
238
            if ( $sth->rows )
239
            {
240
                while ( @row = $sth->fetchrow_array )
241
                {
242
                    $indefinite = 1 if ( $row[3] )
243
#                    print "@row\n";
244
                }
245
            }
246
            $sth->finish();
247
        }
248
        else
249
        {
250
        Error("Execute failure" );
251
        }
252
    }
253
    else
254
    {
255
        Error("Prepare failure" );
256
    }
257
}
258
 
259
#-------------------------------------------------------------------------------
260
# Function        : GetConfigData
261
#
262
# Description     : Build up a list of all releases that have daemons
263
#                   configured
264
#
265
# Inputs          : 
266
#
267
# Returns         : 
268
#
269
sub  GetConfigData
270
{
271
    my $foundDetails = 0;
272
    my (@row);
273
 
274
    # if we are not or cannot connect then return 0 as we have not found anything
275
    connectRM( \$RM_DB) unless $RM_DB;
276
 
277
    # First get details from pv_id
278
 
261 dpurdie 279
    my $m_sqlstr = "SELECT rc.RCON_ID, rc.RTAG_ID, rc.GBE_ID, rc.DAEMON_HOSTNAME, rc.DAEMON_MODE, rc.GBE_BUILDFILTER, rt.RTAG_NAME, p.PROJ_NAME, rt.OFFICIAL" .
255 dpurdie 280
                    " FROM release_config rc, RELEASE_TAGS rt, PROJECTS p" .
261 dpurdie 281
                    " WHERE rt.RTAG_ID = rc.RTAG_ID AND rt.PROJ_ID = p.PROJ_ID AND rt.OFFICIAL != 'A'";
255 dpurdie 282
 
283
 
284
    my $sth = $RM_DB->prepare($m_sqlstr);
285
    if ( defined($sth) )
286
    {
287
        if ( $sth->execute( ) )
288
        {
289
            if ( $sth->rows )
290
            {
291
                while ( @row = $sth->fetchrow_array )
292
                {
293
                    my $rcon_id = $row[0];
294
                    my $rtag_id = $row[1];
295
                    my $gbe_id =  $row[2];
296
                    my $hostname = $row[3];
297
                    my $hostmode = $row[4];
298
                    my $filter = $row[5];
299
                    my $rname = $row[6];
300
                    my $pname = $row[7];
261 dpurdie 301
                    my $official = $row[8];
255 dpurdie 302
 
303
                    next unless ( $hostname );
304
                    if ( @opt_rtag )
305
                    {
306
                        next unless ( defined $opt_rtag{$rtag_id} );
307
                    }
308
 
309
                    my %data;
310
                    $data{rcon_id}  = $rcon_id;
311
                    $data{hostname} = $hostname;
312
                    $data{hostname} = $hostname;
313
                    $data{hostmode} = $hostmode;
314
                    $data{filter}   = $filter;
315
 
316
                    $rc{$rtag_id}{$rcon_id} = \%data;
317
 
318
                    $rname{$rtag_id} = "$pname: $rname";
319
 
320
                    $pname{$pname}{$rname} = $rtag_id;
261 dpurdie 321
 
322
                    $official{$rtag_id} = $official;
323
 
255 dpurdie 324
#                    print "@row\n";
325
                }
326
            }
327
            $sth->finish();
328
        }
329
        else
330
        {
331
        Error("Execute failure" );
332
        }
333
    }
334
    else
335
    {
336
        Error("Prepare failure" );
337
    }
338
}
339
 
340
#-------------------------------------------------------------------------------
341
# Function        : GetRunData
342
#
343
# Description     : Build up data for each daemon
344
#
345
# Inputs          : 
346
#
347
# Returns         : 
348
#
349
sub  GetRunData
350
{
351
    my $foundDetails = 0;
352
    my (@row);
353
 
354
    # if we are not or cannot connect then return 0 as we have not found anything
355
    connectRM( \$RM_DB) unless $RM_DB;
356
 
357
    # First get details from pv_id
358
 
359
    my $m_sqlstr = "SELECT rl.RCON_ID, rl.CURRENT_BUILD_FILES, rl.CURRENT_RUN_LEVEL, rl.PAUSE, rl.CURRENT_PKG_ID_BEING_BUILT, pkg.PKG_NAME" .
360
                    " FROM RUN_LEVEL rl, PACKAGES pkg" .
361
                    " WHERE pkg.PKG_ID (+)= rl.CURRENT_PKG_ID_BEING_BUILT";
362
 
363
 
364
    my $sth = $RM_DB->prepare($m_sqlstr);
365
    if ( defined($sth) )
366
    {
367
        if ( $sth->execute( ) )
368
        {
369
            if ( $sth->rows )
370
            {
371
                while ( @row = $sth->fetchrow_array )
372
                {
373
#                    print "@row\n";
374
                    my $rcon_id = $row[0] || '';
375
                    my $cbf     = $row[1] || '';
376
                    my $crl     = $row[2] || '-';
377
                    my $pause   = $row[3] || '0';
378
                    my $cpid    = $row[5] || '';
379
 
380
                    $rl{$rcon_id}{crl} = $crl;
381
                    $rl{$rcon_id}{pause} = $pause;
382
                    $rl{$rcon_id}{cpid} = $cpid;
383
#                    printf "%10s, %10s, %10s, %10s, %10s\n", $rcon_id, $cbf, $crl, $pause, $cpid;
384
                }
385
            }
386
            $sth->finish();
387
        }
388
        else
389
        {
390
        Error("Execute failure: GetRunData", $m_sqlstr );
391
        }
392
    }
393
    else
394
    {
395
        Error("Prepare failure" );
396
    }
397
}
398
 
399
#-------------------------------------------------------------------------------
400
# Function        : getState
401
#
402
# Description     : Convert number into a nice state string
403
#
404
# Inputs          : 
405
#
406
# Returns         : 
407
#
408
sub getState
409
{
410
    my ($num) = @_;
411
    return "Undefined" unless ( defined $num );
412
    if ( exists ($StateData{$num}) )
413
    {
414
        return $StateData{$num};
415
    }
416
    return "Unknown:$num";
417
}
418
 
419
#-------------------------------------------------------------------------------
420
#   Documentation
421
#
422
 
423
=pod
424
 
425
=head1 NAME
426
 
427
dstatus - Display Daemon Status
428
 
429
=head1 SYNOPSIS
430
 
261 dpurdie 431
  jats dstatus [options]
255 dpurdie 432
 
433
 Options:
434
    -help              - brief help message
435
    -help -help        - Detailed help message
436
    -man               - Full documentation
437
    -repeat=num        - Repeat display every n seconds
438
    -short             - Fold up inactive releases
439
    -color             - Pretty color display
440
    -rtag=num[,num]    - List of RTAG Ids to display
441
    -filter            - Display GBE_BUILDFILTER
442
 
443
=head1 OPTIONS
444
 
445
=over 8
446
 
447
=item B<-help>
448
 
449
Print a brief help message and exits.
450
 
451
=item B<-help -help>
452
 
453
Print a detailed help message with an explanation for each option.
454
 
455
=item B<-man>
456
 
457
Prints the manual page and exits.
458
 
459
=item B<-repeat=num>
460
 
461
This option will cause the program to re-display the status page every B<num>
462
seconds. The default option is to display the status once and exit.
463
 
464
If the user specifies a repeat time of less than 10 seconds, then it will be set
465
to 10 seconds - to avoid heavy loads on the Release Manager database.
466
 
467
This option works best with -color on a non-windows console as the screen
468
will be cleared before the display is refreshed.
469
 
470
=item B<-short>
471
 
472
This option will generate a short display. The body of inactive releases will
473
not be displayed. This option is useful in conjunction with a repeating display
474
to limit the display space used.
475
 
476
=item B<-color>
477
 
478
This option will enable a colored display. This will not work on Windoes.
479
The default is for a non-colored display.
480
 
481
=item B<-rtag=num[,num]>
482
 
483
This option will limit the display to the specified rtag Id's (Numeric Release ID).
484
This option can be used multiple times to specify a list, or the ID's can be comma seperated.
485
 
486
The default option is to display all Releases.
487
 
488
=item B<-filter>
489
 
490
This optionwill alter the display such that the GBE_BUILDFILTER for each platform
491
is displayed instead of the normal status information. This may result in a very
492
wide display.
493
 
494
=back
495
 
496
=head1 DESCRIPTION
497
 
498
This program will display the status of the build daemons on all daemon enabled
499
releases.
500
 
501
=cut
502