Subversion Repositories DevTools

Rev

Rev 255 | Rev 5934 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
4466 dpurdie 3
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 4
#
4466 dpurdie 5
# Module name   : JatsRmApi
227 dpurdie 6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
4466 dpurdie 10
# Description   : Provides common access function to:
11
#                       The Release Manager
12
#                       The Deployment Manager Databases
13
#                       The ClearQuest Database    
227 dpurdie 14
#
15
#                 Note: The interface provided is constrained
16
#                       by the existing usage.
17
#
18
#                       This is an attempt to provide common accessor
19
#                       functions to open and close a connection
20
#
21
#                Note: This is not a class
22
#                      The connection WILL NOT be released if the
23
#                      containing variables go out of scope, BUT the
24
#                      underlying connection is a class and it WILL release
25
#                      the connection.
26
#
27
#......................................................................#
28
 
255 dpurdie 29
require 5.006_001;
227 dpurdie 30
 
31
use strict;
32
use warnings;
33
 
34
package JatsRmApi;
35
use JatsError;
36
use DBI;
37
 
38
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
39
use Exporter;
40
 
41
$VERSION = 1.00;
42
@ISA = qw(Exporter);
43
 
44
# Symbols to autoexport (:DEFAULT tag)
45
@EXPORT = qw(
46
            connectRM
47
            disconnectRM
48
 
49
            connectDM
50
            disconnectDM
4466 dpurdie 51
 
52
            connectCQ
53
            disconnectCQ
227 dpurdie 54
            );
55
 
56
#
57
#   Globals to contain connection information
58
#
59
our $GBE_RM_LOCATION;
60
our $GBE_RM_USERNAME;
61
our $GBE_RM_PASSWORD;
62
 
63
our $GBE_DM_LOCATION;
64
our $GBE_DM_USERNAME;
65
our $GBE_DM_PASSWORD;
66
 
4466 dpurdie 67
our $GBE_CQ_LOCATION;
68
our $GBE_CQ_USERNAME;
69
our $GBE_CQ_PASSWORD;
227 dpurdie 70
 
71
#-------------------------------------------------------------------------------
72
# Function        : ValidateRef
73
#
74
# Description     : Ensure that the user has passed a valid reference
75
#
76
# Inputs          : $fname      - Function name for error reporting
77
#                   $ref        - Data to test
78
#
79
# Returns         : Will error on error
80
#
81
 
82
sub ValidateRef
83
{
84
    my ($fname, $ref) = @_;
85
 
86
    Error("$fname: No parameter passed") unless ( $ref );
87
 
88
    my $rtype = ref($ref) || 'Simple Type';
89
    Error("$fname: Must pass a scalar REF, not a $rtype") unless ( $rtype =~ m/SCALAR|REF/ );
90
}
91
 
92
#-------------------------------------------------------------------------------
93
# Function        : GetConnData
94
#
95
# Description     : Determine the connection data for either RM or DM
96
#
97
# Inputs          : $fname  - Caller function
98
#                   @rest   - 3 EnvVars to process
99
#
100
# Returns         : An array of 3 variables
4466 dpurdie 101
#                   location, username, password
227 dpurdie 102
#
103
sub GetConnData
104
{
105
    my ($fname, @rest) = @_;
106
    my @result;
107
 
108
    foreach my $var ( @rest )
109
    {
110
        my $val = $ENV{$var};
111
        Error( "Environment Variable '$var' not defined." ) unless ( $val );
112
        push @result, $val;
113
    }
114
 
115
    Verbose ("$fname:",
116
             "Database: $result[0]",
117
             "Username: $result[1]",
118
             "Password: $result[2]");
119
 
120
    return @result;
121
}
122
 
123
#-------------------------------------------------------------------------------
124
# Function        : connectRM
125
# Function        : connectDM
126
#
127
# Description     : Connect to the RM/DM database
128
#
129
# Inputs          : gref        - Reference to a scalar that will hold
130
#                                 the database connection class data
131
#
132
#                                 If 'undef' this function will create
133
#                                 the connection. Otherwise the function
134
#                                 will simply return.
135
#
136
#                   opt_verbose - Verbose connection
137
#
138
# Returns         : 
139
#
140
sub connectRM
141
{
142
    my ($gref, $opt_verbose) = @_;
143
    connectDB('connectRM', $gref, $opt_verbose, 'GBE_RM_LOCATION', 'GBE_RM_USERNAME', 'GBE_RM_PASSWORD');
144
}
145
 
146
sub connectDM
147
{
148
    my ($gref, $opt_verbose) = @_;
149
    connectDB('connectDM', $gref, $opt_verbose, 'GBE_DM_LOCATION', 'GBE_DM_USERNAME', 'GBE_DM_PASSWORD');
150
}
151
 
4466 dpurdie 152
sub connectCQ
153
{
154
    my ($gref, $opt_verbose) = @_;
155
    connectDB('connectCQ', $gref, $opt_verbose, 'GBE_CQ_LOCATION', 'GBE_CQ_USERNAME', 'GBE_CQ_PASSWORD');
156
}
157
 
158
 
227 dpurdie 159
sub connectDB
160
{
161
    my ($fname, $gref, $opt_verbose, @parms) = @_;
162
 
163
    #
164
    #   Sanity Check user parameters
165
    #
166
    ValidateRef( $fname, $gref);
167
    my @condata = GetConnData( $fname , @parms);
168
    my $location = $condata[0];
169
 
170
    unless ( $$gref )
171
    {
172
        $$gref = DBI->connect(@condata, {verbose => $opt_verbose});
173
 
174
        unless ( defined $$gref )
175
        {
176
            Error("$fname: Database [$location]",
177
                  "Reported Error[$DBI::errstr]");
178
        }
179
 
180
        Verbose("$fname: Connected to database [$location]");
181
    }
182
    else
183
    {
184
        Warning ("$fname: Connection Already open");
185
    }
186
}
187
 
188
#-------------------------------------------------------------------------------
189
# Function        : disconnectRM
190
# Function        : disconnectDM
4466 dpurdie 191
# Function        : disconnectCQ
227 dpurdie 192
#
4466 dpurdie 193
# Description     : Disconnect from the DM/RM/CQ database
227 dpurdie 194
#
195
# Inputs          : gref        - Reference to a scalar that will hold
196
#                                 the database connection class data
197
#
198
#                                 If not 'undef' this function will disconnect
199
#                                 the connection. Otherwise the function
200
#                                 will simply return.
201
#
202
 
203
sub disconnectRM
204
{
205
    disconnectDB( 'disconnectRM', @_);
206
}
207
 
208
sub disconnectDM
209
{
210
    disconnectDB( 'disconnectDM', @_);
211
}
212
 
4466 dpurdie 213
sub disconnectCQ
214
{
215
    disconnectDB( 'disconnectCQ', @_);
216
}
217
 
227 dpurdie 218
sub disconnectDB
219
{
220
    my ($fname, $gref) = @_;
221
 
222
    #
223
    #   Sanity Check user parameters
224
    #
225
    ValidateRef( $fname, $gref);
226
 
227
    Verbose("$fname: Disconnect from database");
228
    if ( $$gref )
229
    {
230
        $$gref->disconnect() || Warning ("$fname:Disconnect failed");
231
        $$gref = undef;
232
    }
233
    else
234
    {
235
        Warning("$fname: Connection not open");
236
    }
237
}
238
 
239
1;
240