Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
6887 dpurdie 1
########################################################################
2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
3
#
4
# Module name   : rmMerge_process.pl
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Transfer a package from rmNew to rmOld with a bunch
10
#                 of assumptions
11
#                 
12
#
13
# Usage         : See POD at the end of this file
14
#
15
#......................................................................#
16
 
17
require 5.008_002;
18
use strict;
19
use warnings;
20
 
21
use Pod::Usage;
22
use Getopt::Long;
23
 
24
use JatsError;
25
use JatsRmApi;
26
use JatsSystem;
27
use FileUtils;
28
use ConfigurationFile;
29
use JatsProperties;
30
use File::Copy;
31
use DBI;
32
my $RM_DB;
33
 
34
my $opt_help=0;
35
my $opt_verbose=0;
36
my $opt_debug=0;
37
my $opt_replace;
38
 
39
my $VERSION = "1.0";
40
my @oldRMCred = ('OLD', 'jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RM_READONLY', 'RM_READONLY');
41
my @newRMCred = ('NEW', 'jdbc:oracle:thin:@auawsards002:1521:RELEASEM', 'RM_READONLY', 'Tp8WmmDKMq2Z');
42
 
43
my $pname;
44
my $pversion;
45
my %oldData;
46
my %newData;
47
my $data;
48
 
49
#-------------------------------------------------------------------------------
50
# Function        : Mainline Entry Point
51
#
52
# Description     :
53
#
54
# Inputs          :
55
#
56
my $result = GetOptions (
57
                "help:+"        => \$opt_help,
58
                "manual:3"      => \$opt_help,
59
                "verbose:+"     => \$opt_verbose,
60
                "debug:+"       => \$opt_debug,
61
                "replace!"      => \$opt_replace,
62
                );
63
 
64
                #
65
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
66
                #
67
 
68
#
69
#   Process help and manual options
70
#
71
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
72
pod2usage(-verbose => 1) if ( $opt_help == 2 );
73
pod2usage(-verbose => 2) if ( $opt_help > 2 );
74
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV != 1 );
75
 
76
#
77
#   Configure the error reporting rmMerge_process now that we have the user options
78
#
79
ErrorConfig( 'name'    =>'TRANSFER',
80
             'verbose' => $opt_verbose,
81
             'debug' => $opt_debug,
82
            );
83
 
84
#
85
# 
86
$pname = $ARGV[0];  
87
$pversion = $ARGV[1];
88
 
89
#
90
#   Determine matching Release Names
91
#
92
getReleaseData(\%oldData, @oldRMCred);
93
getReleaseData(\%newData, @newRMCred);
94
 
95
DebugDumpData("oldData", \%oldData);
96
DebugDumpData("newData", \%newData);
97
 
98
#
99
#   Sanity tests
100
Error ("Package version not found in old RM") unless exists $oldData{PV_ID};
101
Error ("Package version not found in new RM") unless exists $newData{PV_ID};
102
Error ("Package looks as though its been transferred. Source path contains a valid SVN server name") if (($oldData{SRC_PATH} =~ m~AUPERASVN01~) && !$opt_replace);
103
 
104
#
105
#   Extract the 'new' package files into a known area
106
#   Don't need the .svn info - just the files
107
# 
108
my $newWs = "${pname}_${pversion}.new";
109
$newWs =~ s~[()]~_~g;
110
 
111
RmDirTree($newWs);
112
my $rv = JatsCmd('-logfile', "${pname}_${pversion}.new.log",'jats_vcsrelease.pl', '-extractfiles', '-noprefix', '-root=.', '-view', $newWs ,'-label', $newData{VCS_TAG} );
113
Error ("Cound not extract package from New RM") if $rv;
114
 
115
#
116
#   Extract the 'old' package files into a known area
117
#   Need svn info
118
#   Need to massage the newVcs to extract the tip of the package in the old system
119
#       Assume its in the same location
120
#       Assume we are simply appending the new version to the tip of the old version
121
#       
122
my $oldVcs = $newData{VCS_TAG};
123
$oldVcs =~ s~AUPERASVN02~AUPERASVN01~;
124
$oldVcs =~ m~SVN::(.*)::~;
125
$oldVcs = $1;
126
$oldVcs =~ s~/trunk$~~;
127
 
128
#
129
#   Use the 'jats svn import' utility
130
#       It will do most of the hard work as it was developed to support the ClearCase to Subversion migration
131
#
132
my $dataFile = "${pname}_${pversion}.dat";
133
 
134
my @args;
135
push (@args, '-replace') if $opt_replace;
136
 
137
if ($oldData{COMMENTS}) {
138
    push @args, '-log', $oldData{COMMENTS}
139
}
140
 
141
if ($oldData{MODIFIER_NAME}) {
142
    push @args, '-author', $oldData{MODIFIER_NAME}
143
}
144
 
145
my $created = $oldData{MODIFIED_STAMP};
146
if ( $created )
147
{
148
    $created =~ s~ ~T~;
149
    $created .= '00000Z';
150
    push @args, '-date', $created;
151
}
152
 
153
if ($oldVcs =~ m~(.*)/branches/(.*)~) {
154
    $oldVcs = $1;
155
    push @args, '-branch', $2;
156
}
157
 
158
 
159
Message ('-logfile', "${pname}_${pversion}.old.log", 'jats_svn', 'import', $oldVcs, '-dir' , $newWs, '-datafile' ,  $dataFile, '-label', "${pname}_${pversion}", @args);
160
$rv = JatsCmd ('-logfile', "${pname}_${pversion}.old.log", 'jats_svn', 'import', $oldVcs, '-dir' , $newWs, '-datafile' ,  $dataFile, '-label', "${pname}_${pversion}", @args);
161
Error ("Cound not import package from OLD RM") if $rv;
162
 
163
#
164
#   Extract the Release Manager tag
165
#   Needs to be inserted into the database
166
#   
167
if ( -f $dataFile  )
168
{
169
    my $rmData = JatsProperties::New($dataFile);
170
    if ( $rmData->getProperty('subversion.tag') ) {
171
        $data->{rmRef} = 'SVN::' . $rmData->getProperty('subversion.tag');
172
    } else {
173
        Warning ("Property files has no subversion.tag");
174
    }
175
    $data->{fileCount}    = $rmData->getProperty('files.base', 0);
176
    $data->{filesRemoved} = $rmData->getProperty('files.removed',0);
177
    $data->{filesAdded}   = $rmData->getProperty('files.added',0);
178
}
179
 
180
unless ( $data->{rmRef}  )
181
{
182
    $data->{errStr} = 'Failed to determine Rm Reference';
183
    Error ($data->{errStr});
184
}
185
intoReleaseManager( $oldData{PV_ID}, "${pname}_${pversion}", $data->{rmRef}, @oldRMCred);
186
 
187
#-------------------------------------------------------------------------------
188
# Function        : intoReleaseManager
189
#
190
# Description     : Update VCS tags in RM
191
#
192
# Inputs          : $pvid           - PVId
193
#                   $pvname         - Package Version (text)
194
#                   $tag            - New Tag
195
#
196
# Returns         : 
197
#
198
sub intoReleaseManager
199
{
200
    my ($pvid, $pvname, $new_tag, $id, $url, $name, $passwd ) = @_;
201
    my @row;
202
    my $user = 3768;            # buildadm
203
 
204
    $ENV{GBE_RM_LOCATION} = $url;
205
    $ENV{GBE_RM_USERNAME} = $name;
206
    $ENV{GBE_RM_PASSWORD} = $passwd;
207
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;
208
 
209
    Message ("ToRm: $pvid, $pvname  - $new_tag");
210
    my $m_sqlstr =  "begin release_manager.PK_RMAPI.update_vcs_details($pvid, '$new_tag', $user); end;";
211
    my $sth = $RM_DB->prepare($m_sqlstr);
212
    if ( defined($sth) )
213
    {
214
        if ( $sth->execute( ) )
215
        {
216
            if ( $sth->rows )
217
            {
218
                while ( @row = $sth->fetchrow_array )
219
                {
220
                    print "Data: @row\n";
221
                }
222
            }
223
            $sth->finish();
224
        }
225
        else
226
        {
227
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
228
        }
229
    }
230
    else
231
    {
232
        Error("Prepare failure" );
233
    }
234
    disconnectRM(\$RM_DB);
235
}
236
 
237
#-------------------------------------------------------------------------------
238
# Function        : getReleaseData 
239
#
240
# Description     : Get some essential data
241
#
242
# Inputs          : dataRef
243
#                   RmCredentails 
244
#
245
# Returns         : 
246
#
247
sub getReleaseData
248
{
249
    my ($dataRef, $id, $url, $name, $passwd) = @_;
250
 
251
    my (@row);
252
 
253
    Message ("Extract data for $id: $pname $pversion");
254
 
255
    $ENV{GBE_RM_LOCATION} = $url;
256
    $ENV{GBE_RM_USERNAME} = $name;
257
    $ENV{GBE_RM_PASSWORD} = $passwd;
258
 
259
    connectRM(\$RM_DB);
260
 
261
    # First get details from pv_id
262
 
263
    my $m_sqlstr = <<"SQL_END";
264
        SELECT
265
            pv.pv_id,
266
            pv.src_path,
267
            pv.pkg_label,
268
            release_manager.PK_RMAPI.return_vcs_tag(PV_ID) as vcsTag,
269
            pv.comments,
270
            u.user_name,
271
            pv.modified_stamp
272
        FROM
273
            package_versions pv,
274
            packages p,
275
            users u
276
        WHERE
277
            p.pkg_id = pv.pkg_id
278
            AND p.pkg_name = ':pname'
279
            AND pv.pkg_version = ':pversion'
280
            AND pv.modifier_id = u.user_id
281
SQL_END
282
    $m_sqlstr =~ s~:pname~$pname~g;
283
    $m_sqlstr =~ s~:pversion~$pversion~g;
284
    #Debug0("getReleaseData", $m_sqlstr);
285
    my $sth = $RM_DB->prepare($m_sqlstr);
286
    if ( defined($sth) )
287
    {
288
        if ( $sth->execute( ) )
289
        {
290
            if ( $sth->rows )
291
            {
292
                while ( @row = $sth->fetchrow_array )
293
                {
294
                    $dataRef->{PV_ID} = $row[0]; 
295
                    $dataRef->{SRC_PATH} = $row[1]; 
296
                    $dataRef->{PKG_LABEL} = $row[2]; 
297
                    $dataRef->{VCS_TAG} = $row[3]; 
298
                    $dataRef->{COMMENTS} = $row[4]; 
299
                    $dataRef->{MODIFIER_NAME} = $row[5]; 
300
                    $dataRef->{MODIFIED_STAMP} = $row[6]; 
301
                }
302
            }
303
            $sth->finish();
304
        }
305
        else
306
        {
307
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
308
        }
309
    }
310
    else
311
    {
312
        Error("Prepare failure" );
313
    }
314
 
315
    disconnectRM(\$RM_DB);
316
}
317
 
318