IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27775


Ignore:
Timestamp:
Apr 26, 2010, 2:25:29 PM (16 years ago)
Author:
rhenders
Message:

Now checks server status and differences between dist and stdscience labels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czartool.pl

    r27767 r27775  
    1111use File::Temp qw(tempfile);
    1212
    13 my $dbname = 'gpc1';
    14 my $dbserver = 'ippdb01';
    15 my $dbuser = 'ippuser';
    16 my $dbpass = 'ippuser';
    17 my $db = DBI->connect(
    18         "DBI:mysql:database=${dbname};host=${dbserver};mysql_socket=" .
    19         DB_SOCKET(),${dbuser},${dbpass},
    20         {
    21         RaiseError => 1, AutoCommit => 1}
    22         ) or die "Unable to connect to database $DBI::errstr\n";
    23 
    24 # get current labels from pantasks
    25 my @cmdOut = `echo "show.labels;quit" | pantasks_client -c ~ipp/stdscience/ptolemy.rc`;
    26 my $line;
    27 my @labels;
    28 my $passedHeader=0;
    29 foreach $line (@cmdOut) {
    30 
    31     chomp($line);
    32     if ($line =~ m/pantasks: dummy/) {$passedHeader=1; next;}
    33 
    34     if ($passedHeader){push(@labels, $line);}
    35 }
    36 
    37 # define set of states
    3813my @states = ("full", "new", "drop", "wait", "fault");
     14my $db = connectToDb();
     15
     16if (!$db) {die;}
     17
     18my @stdscienceLabels = loadLabels("stdscience");
     19my @distributionLabels = loadLabels("distribution");
     20showLabelDifferences();
    3921
    4022checkAllLabels("new");
    4123printInstructions();
    4224
    43 my $key;
    44 system "stty cbreak < /dev/tty > /dev/tty 2>&1";
    45 while (($key=getc) ) {
    46     last if $key eq "q";
    47 
    48     if ($key eq "f") {checkAllLabels("full");}
    49     elsif ($key eq "n") {checkAllLabels("new");}
    50     elsif ($key eq "d") {checkAllLabels("drop");}
    51     elsif ($key eq "w") {checkAllLabels("wait");}
    52     elsif ($key eq "l") {labelDetails();}
    53     elsif ($key =~ m/[0-9]/) {my $key2=getc; checkOneLabel($labels[$key.$key2]);}
    54     printInstructions();
    55 
    56 };
    57 system "stty -cbreak < /dev/tty > /dev/tty 2>&1";
     25poll();
    5826$db->disconnect();
    5927
    60 ##############
    61 #
    62 #
    63 ###############
     28###########################################################################
     29#
     30# Prints simple instructions
     31#
     32###########################################################################
    6433sub printInstructions {
    6534
    66     print "\n*** Enter: (f)ull (n)ew (d)rop (w)ait (q)uit (l)abel, or label number from table above: ";
    67 }
    68 
    69 ##############
    70 #
    71 #
    72 ###############
     35    print "\n### Enter: (s)ervers (f)ull (n)ew (d)rop (w)ait (q)uit (l)abel, or label number from table above: ";
     36}
     37
     38###########################################################################
     39#
     40# Polls waiting for input from user
     41#
     42###########################################################################
     43sub poll {
     44
     45    my $key;
     46    system "stty cbreak < /dev/tty > /dev/tty 2>&1";
     47    while (($key=getc) ) {
     48        last if $key eq "q";
     49
     50        if ($key eq "s") {checkServers();}
     51        elsif ($key eq "f") {checkAllLabels("full");}
     52        elsif ($key eq "n") {checkAllLabels("new");}
     53        elsif ($key eq "d") {checkAllLabels("drop");}
     54        elsif ($key eq "w") {checkAllLabels("wait");}
     55        elsif ($key eq "l") {labelDetails();}
     56        elsif ($key =~ m/[0-9]/) {my $key2=getc; checkOneLabel($stdscienceLabels[$key.$key2]);}
     57        printInstructions();
     58
     59    };
     60    system "stty -cbreak < /dev/tty > /dev/tty 2>&1";
     61}
     62
     63###########################################################################
     64#
     65# Connects to the database
     66#
     67###########################################################################
     68sub connectToDb {
     69
     70    my $dbname = 'gpc1';
     71    my $dbserver = 'ippdb01';
     72    my $dbuser = 'ippuser';
     73    my $dbpass = 'ippuser';
     74    my $db = DBI->connect(
     75            "DBI:mysql:database=${dbname};host=${dbserver};mysql_socket=" .
     76            DB_SOCKET(),${dbuser},${dbpass},
     77            {
     78            RaiseError => 1, AutoCommit => 1}
     79            ) or die "Unable to connect to database $DBI::errstr\n";
     80
     81    return $db;
     82}
     83
     84###########################################################################
     85#
     86# Display label differences between stdscience and distribution
     87#
     88###########################################################################
     89sub showLabelDifferences {
     90
     91    my @diffLabels = @{getArrayDifferences(\@stdscienceLabels, \@distributionLabels)};
     92
     93    printf("+-------------------------------------------------------+\n");
     94    printf("| Label differences between stdscience and distribution |\n");
     95    printf("+-------------------------------------------------------+\n");
     96
     97    my $item;
     98    foreach $item (@diffLabels) {
     99
     100        printf( "| %53s |\n", $item);
     101    }
     102    printf("+-------------------------------------------------------+\n");
     103}
     104
     105###########################################################################
     106#
     107# Compares two arrays and stores the differences
     108#
     109###########################################################################
     110sub getArrayDifferences {
     111
     112    my @array1 = @{$_[0]};
     113    my @array2 = @{$_[1]};
     114
     115    my @isect;
     116    my @diff;
     117    my %count;
     118
     119    my $item;
     120    foreach $item (@array1, @array2) { $count{$item}++;}
     121
     122    foreach $item (keys %count) {
     123        if ($count{$item} == 2) {
     124            push @isect, $item;
     125        } else {
     126            push @diff, $item;
     127        }
     128    }
     129
     130    return \@diff;
     131}
     132
     133###########################################################################
     134#
     135# Loads labels from a particular pantasks server
     136#
     137###########################################################################
     138sub loadLabels {
     139    my ($server) = @_;
     140
     141    my @cmdOut = `echo "show.labels;quit" | pantasks_client -c ~ipp/$server/ptolemy.rc 2>&1`;
     142    my $line;
     143    my @labels;
     144    my $passedHeader=0;
     145    foreach $line (@cmdOut) {
     146
     147        chomp($line);
     148        if ($line =~ m/pantasks:/) {$passedHeader=1; next;}
     149
     150        if ($passedHeader){push(@labels, $line);}
     151    }
     152
     153    return @labels;
     154}
     155
     156###########################################################################
     157#
     158# Checks all servers to see if they are alive and running
     159#
     160###########################################################################
     161sub checkServers {
     162
     163    my @servers = ("addstar", "cleanup", "detrend", "distribution", "pstamp", "publishing", "registration", "replication", "stdscience", "summitcopy");
     164    printf("\n+-----------------------------------------------+\n");
     165    printf("|                      Servers                  |\n");
     166    printf("+--------------+---------+----------------------+\n");
     167    printf("|    server    |  alive? |  Scheduler running?  |\n");
     168    printf("+--------------+---------+----------------------+\n");
     169    my $server;
     170    foreach $server (@servers) {
     171
     172        printf("| %12s ", $server);
     173
     174        my @cmdOut = `echo "status ;quit" | pantasks_client -c ~ipp/$server/ptolemy.rc 2>&1`;
     175
     176        my $line;
     177        my $foundStatus = 0;
     178        my $isRunning = 0;
     179        foreach $line (@cmdOut) {
     180
     181            chomp($line);
     182            if ($line =~ m/Scheduler is stopped/) {$isRunning = 0; $foundStatus=1;last;}
     183            if ($line =~ m/Scheduler is running/) {$isRunning = 1; $foundStatus=1;last;}
     184            if ($line =~ m/Task Staus/) {last;}
     185
     186        }
     187
     188        if (!$foundStatus){print "|    NO   ";} else {print "|   yes   ";}
     189        if (!$isRunning){print "|           NO         ";} else {print "|          yes         ";}
     190        printf("|\n");
     191    }
     192
     193    printf("+--------------+---------+----------------------+\n");
     194}
     195
     196###########################################################################
     197#
     198# Takes label name or number
     199#
     200###########################################################################
    73201sub labelDetails {
    74202
     
    77205    chomp($input);
    78206    if ($input =~ m/^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$/) {
    79        return checkOneLabel($labels[$input]);
     207       return checkOneLabel($stdscienceLabels[$input]);
    80208    }
    81209
     
    83211}
    84212
    85 ##############
    86 #
    87 #
    88 ###############
     213###########################################################################
     214#
     215# Checks one label and prints results in a table
     216#
     217###########################################################################
    89218sub checkOneLabel {
    90219    my ($label) = @_;
     
    121250    close(LOGFILE);
    122251}
    123 ##############
    124 #
    125 #
    126 ###############
     252
     253###########################################################################
     254#
     255# Checks all labels for a particular state and prints results in a table
     256#
     257###########################################################################
    127258sub checkAllLabels {
    128259    my ($state) = @_;
     
    136267    my $label;
    137268    my $i=0;
    138     foreach $label (@labels) {
     269    foreach $label (@stdscienceLabels) {
    139270
    140271        chomp($label);
     
    159290}
    160291
    161 ##############
    162 #
    163 #
    164 ###############
     292###########################################################################
     293#
     294# Returns state and fault-count (if new) as a string
     295#
     296###########################################################################
    165297sub getStateAndFaults {
    166298    my ($label, $table, $state, $stage) = @_;
     
    177309}
    178310
    179 ##############
    180 #
    181 #
    182 ###############
     311###########################################################################
     312#
     313# Returns count of exposures with this state for this label
     314#
     315###########################################################################
    183316sub checkLabel {
    184317    my ($label, $table, $state, $stage) = @_;
     
    198331}
    199332
    200 
    201 ##############
    202 #
    203 #
    204 ###############
     333###########################################################################
     334#
     335# Returns count of faults for this stage and label
     336#
     337###########################################################################
    205338sub countFaults {
    206339    my ($label, $table, $stage) = @_;
     
    236369}
    237370
    238 ##############
    239 #
    240 #
    241 ###############
     371###########################################################################
     372#
     373# Counts total distribution faults
     374#
     375###########################################################################
    242376sub countDistFaults {
    243377    my ($label) = @_;
Note: See TracChangeset for help on using the changeset viewer.