Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
4466 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 3
#
4466 dpurdie 4
# Module name   : test_rmconnection.pl
227 dpurdie 5
# Module type   : Makefile system
4466 dpurdie 6
# Compiler(s)   : Perl
227 dpurdie 7
# Environment(s): jats
8
#
9
# Description   : Test the connectivity to the Release Manager Database
10
#                 test_rmconnection.pl
11
#
4466 dpurdie 12
# Usage         : See POD
227 dpurdie 13
#
14
#......................................................................#
15
 
4466 dpurdie 16
require 5.008_002;
227 dpurdie 17
use strict;
18
use warnings;
4466 dpurdie 19
 
227 dpurdie 20
use JatsEnv;
21
use JatsError;
22
use Pod::Usage;                             # required for help support
23
use Getopt::Long;
24
use JatsRmApi;
25
 
26
use DBI;
27
use Cwd;
28
 
29
#
30
#   The LWP is a part of the Active State Perl, but not the solaris perl
31
#   If the user has not read the installation doco that insists we use
32
#   ActiveState perl...
33
#
34
my $UserAgentAvailable = eval "require LWP::UserAgent";
35
 
36
#
37
#   Global data
38
#
39
my $VERSION      = "1.0.0";                 # Update this
40
my $opt_debug    = $ENV{'GBE_DEBUG'};        # Allow global debug
41
my $opt_verbose  = $ENV{'GBE_VERBOSE'};      # Allow global verbose
42
my $opt_help = 0;
43
 
44
#
45
#   Release Manager Connection Information
46
#   Deployment manager Connection information
47
#
48
my $RM_URL = $ENV{GBE_RM_URL};
49
my $DM_URL = $ENV{GBE_DM_URL};
50
my $RM_DB;
51
my $DM_DB;
52
 
53
#-------------------------------------------------------------------------------
54
# Function        : Mainline Entry Point
55
#
56
# Description     :
57
#
58
# Inputs          :
59
#
60
my $result = GetOptions (
61
                "help+"         => \$opt_help,              # flag, multiple use allowed
4466 dpurdie 62
                "manual:3"      => \$opt_help,
63
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
227 dpurdie 64
                );
65
 
66
                #
67
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
68
                #
69
 
70
#
71
#   Process help and manual options
72
#
73
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
74
pod2usage(-verbose => 1) if ($opt_help == 2 );
4466 dpurdie 75
pod2usage(-verbose => 2) if ($opt_help > 2);
227 dpurdie 76
 
77
#
78
#   Configure the error reporting process now that we have the user options
79
#
80
ErrorConfig( 'name'    =>'RMTEST',
81
             'verbose' => $opt_verbose,
82
            );
83
 
84
 
85
#
86
#   Open the connection and display some data
87
#
88
getOracleData();
89
getDeployData();
90
getHttpData();
91
Message "Test Complete\n";
92
exit;
93
 
94
 
95
#-------------------------------------------------------------------------------
96
# Function        : getOracleData
97
#
98
# Description     : Extract Release Names from the database
99
#
100
# Inputs          :
101
#
102
# Returns         :
103
#
104
sub getOracleData
105
{
106
    my $count = 0;
107
    my (@row);
108
 
109
    Message("Test Oracle Interface");
110
 
111
    #
112
    #   Connect to database
113
    #
114
    connectRM(\$RM_DB, $opt_verbose);
115
 
116
    # First get details from pv_id
117
    Message("Extract data");
118
    my $m_sqlstr = "SELECT rt.RTAG_ID, rt.RTAG_NAME, rt.DESCRIPTION, pj.PROJ_ID, pj.PROJ_NAME, rt.OFFICIAL" .
295 dpurdie 119
                    " FROM RELEASE_MANAGER.RELEASE_TAGS rt, RELEASE_MANAGER.PROJECTS pj" .
227 dpurdie 120
                    " WHERE rt.PROJ_ID = pj.PROJ_ID" .
121
                    " ORDER BY pj.PROJ_NAME";
122
    my $sth = $RM_DB->prepare($m_sqlstr);
123
    if ( defined($sth) )
124
    {
125
        if ( $sth->execute( ) )
126
        {
127
            if ( $sth->rows )
128
            {
129
                while ( @row = $sth->fetchrow_array )
130
                {
131
                    $count++;
132
                    if ( $opt_verbose > 1 )
133
                    {
134
                        printf "%20s, %8s(%s), %40s\n", $row[4], $row[0], $row[5], $row[1];
135
                    }
136
                }
137
            }
138
            $sth->finish();
139
        }
140
        else
141
        {
142
            Error("Execute failure" );
143
        }
144
    }
145
    else
146
    {
147
        Error("Prepare failure" );
148
    }
149
 
150
    #
151
    #   Report the data extracted
152
    #
153
    Error("No data extracted from the database") unless ( $count );
154
    Message "Extracted $count records\n";
155
 
156
    #
157
    #   Close down the connection
158
    #
159
    disconnectRM(\$RM_DB);
160
}
161
 
162
#-------------------------------------------------------------------------------
163
# Function        : getDeployData
164
#
165
# Description     : Ensure we can communicate with the Deployment database
166
#
167
# Inputs          : None
168
#
169
# Returns         :
170
#
171
sub getDeployData
172
{
173
    connectDM ( \$DM_DB, $opt_verbose );
174
    disconnectDM(\$DM_DB);
175
}
176
 
177
#-------------------------------------------------------------------------------
178
# Function        : getHttpData
179
#
180
# Description     : Test the Http interface to release manager
181
#
182
# Inputs          :
183
#
184
# Returns         :
185
#
186
sub getHttpData
187
{
188
    Message("Test HTTP Interface");
189
 
190
    unless ( $UserAgentAvailable )
191
    {
192
        Warning ("The perl installation does not contain the LWP module",
193
                 "The test to extract data from Release Manager will be skipped",
3832 dpurdie 194
                 "The deployment scripts will not run properly");
227 dpurdie 195
        return 0;
196
    }
197
 
198
    my $user_agent = LWP::UserAgent->new( timeout => 30 );
199
    if ( $RM_URL )
200
    {
201
        Verbose("RM URL: $RM_URL");
202
        my $response = $user_agent->head( $RM_URL );
203
        Verbose ("Http Message: " . $response->status_line);
204
        if ( $response->is_success )
205
        {
206
            Message("Retrieved Release Manager Data");
207
        }
208
        else
209
        {
210
            Error("Unable to retrieve Release Manager Data", "Status: " . $response->status_line);
211
        }
212
    }
213
    else
214
    {
215
        Warning("Release Manager URL not defined: GBE_RM_URL");
216
    }
217
 
218
    if ( $DM_URL )
219
    {
220
        Verbose("DM URL: $DM_URL");
221
        my $response = $user_agent->head( $DM_URL );
222
        Verbose ("Http Message: " . $response->status_line);
223
        if ( $response->is_success )
224
        {
225
            Message("Retrieved Deployment Manager Data");
226
        }
227
        else
228
        {
229
            Error("Unable to retrieve Deployment Manager Data", "Status: " . $response->status_line);
230
        }
231
    }
232
    else
233
    {
234
        Warning("Deployment Manager URL not defined: GBE_DM_URL");
235
    }
236
 
237
    return 1;
238
}
239
 
240
#-------------------------------------------------------------------------------
241
#   Documentation
242
#
243
 
244
=pod
245
 
246
=head1 NAME
247
 
4466 dpurdie 248
test_rmconnection - Test the connection to the Release Manager Database
227 dpurdie 249
 
250
=head1 SYNOPSIS
251
 
252
jats etool test_rmconnection [options]
253
 
254
 Options:
255
    -help              - Brief help message
256
    -help -help        - Detailed help message
257
    -man               - Full documentation
258
    -verbose           - Display additional information
259
 
260
=head1 OPTIONS
261
 
262
=over 8
263
 
264
=item B<-help>
265
 
266
Print a brief help message and exits.
267
 
268
=item B<-help -help>
269
 
270
Print a detailed help message with an explanation for each option.
271
 
272
=item B<-man>
273
 
274
Prints the manual page and exits.
275
 
276
=item B<-verbose>
277
 
278
Prints additional information on the progress of the program.
279
 
280
=back
281
 
282
=head1 DESCRIPTION
283
 
284
This program is provided to test the connection between the users computer and
285
the Release Manager Database. It does this by querying the database in the
286
same manner as many of the deployments scripts.
287
 
288
=head1 EXAMPLE
289
 
290
jats etool test_rmconnection
291
 
292
=cut
293