Subversion Repositories DevTools

Rev

Rev 4466 | Blame | Compare with Previous | Last modification | View Log | RSS feed

########################################################################
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
#
# Module name   : test_rmconnection.pl
# Module type   : Makefile system
# Compiler(s)   : Perl
# Environment(s): jats
#
# Description   : Test the connectivity to the Release Manager Database
#                 test_rmconnection.pl
#
# Usage         : See POD
#
#......................................................................#

require 5.008_002;
use strict;
use warnings;

use JatsEnv;
use JatsError;
use Pod::Usage;                             # required for help support
use Getopt::Long;
use JatsRmApi;

use DBI;
use Cwd;

#
#   The LWP is a part of the Active State Perl, but not the solaris perl
#   If the user has not read the installation doco that insists we use
#   ActiveState perl...
#
my $UserAgentAvailable = eval "require LWP::UserAgent";

#
#   Global data
#
my $VERSION      = "1.0.0";                 # Update this
my $opt_debug    = $ENV{'GBE_DEBUG'};        # Allow global debug
my $opt_verbose  = $ENV{'GBE_VERBOSE'};      # Allow global verbose
my $opt_help = 0;

#
#   Release Manager Connection Information
#   Deployment manager Connection information
#
my $RM_URL = $ENV{GBE_RM_URL};
my $DM_URL = $ENV{GBE_DM_URL};
my $RM_DB;
my $DM_DB;

#-------------------------------------------------------------------------------
# Function        : Mainline Entry Point
#
# Description     :
#
# Inputs          :
#
my $result = GetOptions (
                "help+"         => \$opt_help,              # flag, multiple use allowed
                "manual:3"      => \$opt_help,
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
                );

                #
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
                #

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
pod2usage(-verbose => 1) if ($opt_help == 2 );
pod2usage(-verbose => 2) if ($opt_help > 2);

#
#   Configure the error reporting process now that we have the user options
#
ErrorConfig( 'name'    =>'RMTEST',
             'verbose' => $opt_verbose,
            );


#
#   Open the connection and display some data
#
getOracleData();
getDeployData();
getHttpData();
Message "Test Complete\n";
exit;


#-------------------------------------------------------------------------------
# Function        : getOracleData
#
# Description     : Extract Release Names from the database
#
# Inputs          :
#
# Returns         :
#
sub getOracleData
{
    my $count = 0;
    my (@row);

    Message("Test Oracle Interface");

    #
    #   Connect to database
    #
    connectRM(\$RM_DB, $opt_verbose);

    # First get details from pv_id
    Message("Extract data");
    my $m_sqlstr = "SELECT rt.RTAG_ID, rt.RTAG_NAME, rt.DESCRIPTION, pj.PROJ_ID, pj.PROJ_NAME, rt.OFFICIAL" .
                    " FROM RELEASE_MANAGER.RELEASE_TAGS rt, RELEASE_MANAGER.PROJECTS pj" .
                    " WHERE rt.PROJ_ID = pj.PROJ_ID" .
                    " ORDER BY pj.PROJ_NAME";
    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            if ( $sth->rows )
            {
                while ( @row = $sth->fetchrow_array )
                {
                    $count++;
                    if ( $opt_verbose > 1 )
                    {
                        printf "%20s, %8s(%s), %40s\n", $row[4], $row[0], $row[5], $row[1];
                    }
                }
            }
            $sth->finish();
        }
        else
        {
            Error("Execute failure" );
        }
    }
    else
    {
        Error("Prepare failure" );
    }

    #
    #   Report the data extracted
    #
    Error("No data extracted from the database") unless ( $count );
    Message "Extracted $count records\n";

    #
    #   Close down the connection
    #
    disconnectRM(\$RM_DB);
}

#-------------------------------------------------------------------------------
# Function        : getDeployData
#
# Description     : Ensure we can communicate with the Deployment database
#
# Inputs          : None
#
# Returns         :
#
sub getDeployData
{
    connectDM ( \$DM_DB, $opt_verbose );
    disconnectDM(\$DM_DB);
}

#-------------------------------------------------------------------------------
# Function        : getHttpData
#
# Description     : Test the Http interface to release manager
#
# Inputs          :
#
# Returns         :
#
sub getHttpData
{
    Message("Test HTTP Interface");

    unless ( $UserAgentAvailable )
    {
        Warning ("The perl installation does not contain the LWP module",
                 "The test to extract data from Release Manager will be skipped",
                 "The deployment scripts will not run properly");
        return 0;
    }

    my $user_agent = LWP::UserAgent->new( timeout => 30 );
    if ( $RM_URL )
    {
        Verbose("RM URL: $RM_URL");
        my $response = $user_agent->head( $RM_URL );
        Verbose ("Http Message: " . $response->status_line);
        if ( $response->is_success )
        {
            Message("Retrieved Release Manager Data");
        }
        else
        {
            Error("Unable to retrieve Release Manager Data", "Status: " . $response->status_line);
        }
    }
    else
    {
        Warning("Release Manager URL not defined: GBE_RM_URL");
    }

    if ( $DM_URL )
    {
        Verbose("DM URL: $DM_URL");
        my $response = $user_agent->head( $DM_URL );
        Verbose ("Http Message: " . $response->status_line);
        if ( $response->is_success )
        {
            Message("Retrieved Deployment Manager Data");
        }
        else
        {
            Error("Unable to retrieve Deployment Manager Data", "Status: " . $response->status_line);
        }
    }
    else
    {
        Warning("Deployment Manager URL not defined: GBE_DM_URL");
    }

    return 1;
}

#-------------------------------------------------------------------------------
#   Documentation
#

=pod

=head1 NAME

test_rmconnection - Test the connection to the Release Manager Database

=head1 SYNOPSIS

jats etool test_rmconnection [options]

 Options:
    -help              - Brief help message
    -help -help        - Detailed help message
    -man               - Full documentation
    -verbose           - Display additional information

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-help -help>

Print a detailed help message with an explanation for each option.

=item B<-man>

Prints the manual page and exits.

=item B<-verbose>

Prints additional information on the progress of the program.

=back

=head1 DESCRIPTION

This program is provided to test the connection between the users computer and
the Release Manager Database. It does this by querying the database in the
same manner as many of the deployments scripts.

=head1 EXAMPLE

jats etool test_rmconnection

=cut