Subversion Repositories DevTools

Rev

Rev 7299 | Details | Compare with Previous | Last modification | View Log | RSS feed

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