Subversion Repositories DevTools

Rev

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