Subversion Repositories DevTools

Rev

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

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