Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
########################################################################
7300 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
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;
5909 dpurdie 43
my $opt_database = 1;
44
my $opt_webserver = 1;
227 dpurdie 45
 
46
#
47
#   Release Manager Connection Information
48
#   Deployment manager Connection information
49
#
50
my $RM_URL = $ENV{GBE_RM_URL};
51
my $DM_URL = $ENV{GBE_DM_URL};
52
my $RM_DB;
53
my $DM_DB;
54
 
55
#-------------------------------------------------------------------------------
56
# Function        : Mainline Entry Point
57
#
58
# Description     :
59
#
60
# Inputs          :
61
#
62
my $result = GetOptions (
63
                "help+"         => \$opt_help,              # flag, multiple use allowed
4466 dpurdie 64
                "manual:3"      => \$opt_help,
65
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
5909 dpurdie 66
                "database!"     => \$opt_database,
67
                "webserver!"     => \$opt_webserver,
227 dpurdie 68
                );
69
 
70
                #
71
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
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 );
4466 dpurdie 79
pod2usage(-verbose => 2) if ($opt_help > 2);
227 dpurdie 80
 
81
#
82
#   Configure the error reporting process now that we have the user options
83
#
84
ErrorConfig( 'name'    =>'RMTEST',
85
             'verbose' => $opt_verbose,
86
            );
87
 
88
 
89
#
90
#   Open the connection and display some data
91
#
5909 dpurdie 92
getOracleData() if $opt_database;
93
getDeployData() if $opt_database;
94
getHttpData() if $opt_webserver;
95
Warning ("All test disabled") unless ($opt_database || $opt_webserver);
227 dpurdie 96
Message "Test Complete\n";
97
exit;
98
 
99
 
100
#-------------------------------------------------------------------------------
101
# Function        : getOracleData
102
#
103
# Description     : Extract Release Names from the database
104
#
105
# Inputs          :
106
#
107
# Returns         :
108
#
109
sub getOracleData
110
{
111
    my $count = 0;
112
    my (@row);
113
 
114
    Message("Test Oracle Interface");
115
 
116
    #
117
    #   Connect to database
118
    #
119
    connectRM(\$RM_DB, $opt_verbose);
120
 
121
    # First get details from pv_id
122
    Message("Extract data");
123
    my $m_sqlstr = "SELECT rt.RTAG_ID, rt.RTAG_NAME, rt.DESCRIPTION, pj.PROJ_ID, pj.PROJ_NAME, rt.OFFICIAL" .
295 dpurdie 124
                    " FROM RELEASE_MANAGER.RELEASE_TAGS rt, RELEASE_MANAGER.PROJECTS pj" .
227 dpurdie 125
                    " WHERE rt.PROJ_ID = pj.PROJ_ID" .
126
                    " ORDER BY pj.PROJ_NAME";
127
    my $sth = $RM_DB->prepare($m_sqlstr);
128
    if ( defined($sth) )
129
    {
130
        if ( $sth->execute( ) )
131
        {
132
            if ( $sth->rows )
133
            {
134
                while ( @row = $sth->fetchrow_array )
135
                {
136
                    $count++;
137
                    if ( $opt_verbose > 1 )
138
                    {
139
                        printf "%20s, %8s(%s), %40s\n", $row[4], $row[0], $row[5], $row[1];
140
                    }
141
                }
142
            }
143
            $sth->finish();
144
        }
145
        else
146
        {
147
            Error("Execute failure" );
148
        }
149
    }
150
    else
151
    {
152
        Error("Prepare failure" );
153
    }
154
 
155
    #
156
    #   Report the data extracted
157
    #
158
    Error("No data extracted from the database") unless ( $count );
159
    Message "Extracted $count records\n";
160
 
161
    #
162
    #   Close down the connection
163
    #
164
    disconnectRM(\$RM_DB);
165
}
166
 
167
#-------------------------------------------------------------------------------
168
# Function        : getDeployData
169
#
170
# Description     : Ensure we can communicate with the Deployment database
171
#
172
# Inputs          : None
173
#
174
# Returns         :
175
#
176
sub getDeployData
177
{
178
    connectDM ( \$DM_DB, $opt_verbose );
179
    disconnectDM(\$DM_DB);
180
}
181
 
182
#-------------------------------------------------------------------------------
183
# Function        : getHttpData
184
#
185
# Description     : Test the Http interface to release manager
186
#
187
# Inputs          :
188
#
189
# Returns         :
190
#
191
sub getHttpData
192
{
193
    Message("Test HTTP Interface");
194
 
195
    unless ( $UserAgentAvailable )
196
    {
197
        Warning ("The perl installation does not contain the LWP module",
198
                 "The test to extract data from Release Manager will be skipped",
3832 dpurdie 199
                 "The deployment scripts will not run properly");
227 dpurdie 200
        return 0;
201
    }
202
 
203
    my $user_agent = LWP::UserAgent->new( timeout => 30 );
204
    if ( $RM_URL )
205
    {
206
        Verbose("RM URL: $RM_URL");
207
        my $response = $user_agent->head( $RM_URL );
208
        Verbose ("Http Message: " . $response->status_line);
209
        if ( $response->is_success )
210
        {
211
            Message("Retrieved Release Manager Data");
212
        }
213
        else
214
        {
215
            Error("Unable to retrieve Release Manager Data", "Status: " . $response->status_line);
216
        }
217
    }
218
    else
219
    {
220
        Warning("Release Manager URL not defined: GBE_RM_URL");
221
    }
222
 
223
    if ( $DM_URL )
224
    {
225
        Verbose("DM URL: $DM_URL");
226
        my $response = $user_agent->head( $DM_URL );
227
        Verbose ("Http Message: " . $response->status_line);
228
        if ( $response->is_success )
229
        {
230
            Message("Retrieved Deployment Manager Data");
231
        }
232
        else
233
        {
234
            Error("Unable to retrieve Deployment Manager Data", "Status: " . $response->status_line);
235
        }
236
    }
237
    else
238
    {
239
        Warning("Deployment Manager URL not defined: GBE_DM_URL");
240
    }
241
 
242
    return 1;
243
}
244
 
245
#-------------------------------------------------------------------------------
246
#   Documentation
247
#
248
 
249
=pod
250
 
251
=head1 NAME
252
 
4466 dpurdie 253
test_rmconnection - Test the connection to the Release Manager Database
227 dpurdie 254
 
255
=head1 SYNOPSIS
256
 
257
jats etool test_rmconnection [options]
258
 
259
 Options:
260
    -help              - Brief help message
261
    -help -help        - Detailed help message
262
    -man               - Full documentation
263
    -verbose           - Display additional information
5909 dpurdie 264
    -[no]database      - Test database connection
265
    -[no]webserver     - Test webserver connection
227 dpurdie 266
 
267
=head1 OPTIONS
268
 
269
=over 8
270
 
271
=item B<-help>
272
 
273
Print a brief help message and exits.
274
 
275
=item B<-help -help>
276
 
277
Print a detailed help message with an explanation for each option.
278
 
279
=item B<-man>
280
 
281
Prints the manual page and exits.
282
 
283
=item B<-verbose>
284
 
285
Prints additional information on the progress of the program.
286
 
5909 dpurdie 287
=item B<-[no]database>
288
 
289
This option can disable the testing of the database connection. 
290
 
291
The default is to enable testing of the database connection.
292
 
293
=item B<-[no]webserver>
294
 
295
This option can disable the testing of the webserver connection. 
296
 
297
The default is to enable testing of the webserver connection.
298
 
299
 
227 dpurdie 300
=back
301
 
302
=head1 DESCRIPTION
303
 
304
This program is provided to test the connection between the users computer and
305
the Release Manager Database. It does this by querying the database in the
306
same manner as many of the deployments scripts.
307
 
308
=head1 EXAMPLE
309
 
310
jats etool test_rmconnection
311
 
312
=cut
313