Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
392 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : cc2svn_updaterm.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Update RM with ClearCase to Subversion conversion info
10
#
11
# Usage:
12
#
13
# Version   Who      Date        Description
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
 
27
#
28
#   Globals
29
#
30
my $RM_DB;
31
my $VERSION = "1.0.0";                      # Update this
32
my %packageVcs;
33
 
34
#
35
#   Options
36
#
37
my $opt_verbose = 0;
38
my $opt_help = 0;
39
my $opt_package;
40
my $opt_rm = 'RELMANU1';
41
my $opt_test = 1;
42
my $opt_force;
43
my $opt_checkOperation;
44
 
45
#-------------------------------------------------------------------------------
46
# Function        : Main Entry
47
#
48
# Description     :
49
#
50
# Inputs          :
51
#
52
# Returns         :
53
#
54
my $result = GetOptions (
55
                "help+"         => \$opt_help,          # flag, multiple use allowed
56
                "manual:3"      => \$opt_help,
57
                "verbose:+"     => \$opt_verbose,       # flag
58
                'package:s'     => \$opt_package,
59
                'database:s'    => \$opt_rm,
60
                'test!'         => \$opt_test,
61
                'force!'        => \$opt_force,
62
                'check:s'       => \$opt_checkOperation,
63
                );
64
 
65
#
66
#   Process help and manual options
67
#
68
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
69
pod2usage(-verbose => 1)  if ($opt_help == 2);
70
pod2usage(-verbose => 2)  if ($opt_help > 2);
71
 
72
ErrorConfig( 'name'    =>'CC2SVN_UPDATERM',
73
             'verbose' => $opt_verbose,
74
              );
75
 
76
Error ("Must specify a package name") unless ( defined $opt_package || $#ARGV >= 0 );
77
 
78
$ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaprm01:1521:' . $opt_rm;
79
unless ( $opt_rm eq 'RELEASEM' )
80
{
81
    Warning ("Using internal user/passowrd");
82
    $ENV{GBE_RM_USERNAME} = 'RELEASE_MANAGER';
83
    $ENV{GBE_RM_PASSWORD} = 'RELEASE_MANAGER';
84
}
85
else
86
{
87
    $ENV{GBE_RM_USERNAME} = 'RM_READONLY';
88
    $ENV{GBE_RM_PASSWORD} = 'RM_READONLY';
89
}
90
 
91
#
92
#   Check operation
93
#
94
if ( $opt_checkOperation )
95
{
96
    Message ("Check RM operation");
97
    Error ("PVID must be specified via -package option") unless $opt_package;
98
    intoReleaseManager ($opt_package, $opt_checkOperation);
99
    Message ("Check Complete OK");
100
    exit 0;
101
}
102
 
103
 
104
foreach my $packageName ( $opt_package, @ARGV )
105
{
106
    next unless ( defined $packageName );
107
    $packageName =~ s~\.data$~~;
108
    getVcsData($packageName);
109
    readPackageData($packageName);
110
}
111
exit 0;
112
 
113
#-------------------------------------------------------------------------------
114
# Function        : getVcsData
115
#
116
# Description     : Get existing VCS data from the release Manager
117
#
118
# Inputs          : 
119
#
120
# Returns         : 
121
#
122
sub getVcsData
123
{
124
    my ($packageName) = @_;
125
    %packageVcs = ();
126
    my $pkg_id = GetPkgIdByName ( $packageName );
127
    GetData_by_pkg_id ( $pkg_id, $packageName  );
128
#    DebugDumpData("packageVcs", \%packageVcs );
129
}
130
 
131
#-------------------------------------------------------------------------------
132
# Function        : readPackageData
133
#
134
# Description     : Read in package data
135
#
136
# Inputs          : Name of the package
137
#
138
# Returns         : 
139
#
140
our %ScmVersions;
141
sub readPackageData
142
{
143
    my ($pname) = @_;
144
    my $fname = $pname . '.data';
145
    my @updateList;
146
    Verbose2 ('Reading Package Data: ' . $fname);
147
    Error "Cannot locate $fname" unless ( -f $fname );
148
    %ScmVersions = ();
149
    require $fname;
150
 
151
    Error "Data in $fname is not valid\n"
152
        unless ( keys(%ScmVersions) >= 0 );
153
 
154
 
155
    my $essentialCount = 0;
156
    my $errorCount = 0;
157
    my $ecount = 0;
158
    my $transferred = 0;
159
    my $totalCount = 0;
160
    my $diffCount = 0;
161
    my $missingPVID = 0;
162
    my $rippleProcessed = 0;
163
    my $globalErrors = 0;
164
    my $notProcessed = 0;
165
    foreach my $entry (sort {$a <=> $b}  keys(%ScmVersions) )
166
    {
167
        $totalCount ++;
168
        $notProcessed++ unless $ScmVersions{$entry}{Scanned};
169
        $essentialCount++ if ( $ScmVersions{$entry}{Essential}  );
170
        $rippleProcessed++ if ( $ScmVersions{$entry}{rippleProcessed} );
171
        $globalErrors++ if ( $ScmVersions{$entry}{errFlags} eq 'e' );
172
        unless ( $ScmVersions{$entry}{TagCreated} )
173
        {
174
            $errorCount++ if ( $ScmVersions{$entry}{Essential}  );
175
            $ecount++;
176
            Verbose ("Package Not Processed: " . $ScmVersions{$entry}{vname} . ' - ' . ($ScmVersions{$entry}{errStr} || 'Unspecified Error')  );
177
        }
178
    }
179
 
180
    foreach my $entry (sort {$a <=> $b}  keys(%ScmVersions) )
181
    {
182
        if ( $ScmVersions{$entry}{TagCreated} )
183
        {
184
            $transferred++;
185
            my $done = '';
186
            my $rmRef = $ScmVersions{$entry}{rmRef} ;
187
 
188
            my $include = 1;
189
            if ( exists $packageVcs{$entry} )
190
            {
191
                $include = 0 if ( ($packageVcs{$entry} eq $rmRef) );
192
            }
193
            else
194
            {
195
                $missingPVID++;
196
                $done = ' < Missing' unless $done;
197
                $include = 0 ;
198
            }
199
 
200
            if ( $include || $opt_force)
201
            {
202
                    $diffCount++;
203
                    $done = ' *' unless $done;
204
                    push @updateList, $entry;
205
            }
206
 
207
            Verbose ("Processed: " . $ScmVersions{$entry}{vname} . ' :: ' . ($rmRef || '???') . $done );
208
 
209
        }
210
    }
211
 
212
    sub highlight
213
    {
214
        my ($value) = @_;
215
        return $value ? ' <------' : '';
216
    }
217
 
218
    my $rmTotal = scalar keys %packageVcs;
219
    Message ("Transfer Stats",
220
            ,"Package                   : $pname"
221
            ,"Total RM Versions         : $rmTotal"
222
            ,"Total Packages Processed  : $totalCount"
223
            ,"Packages NOT Processed    : $notProcessed" . highlight($notProcessed)
224
            ,"Packages pruned           : " . ($rmTotal - $totalCount)
225
            ,"Essential Packages        : $essentialCount"
226
            ,"Essential Packages Errors : $errorCount" . highlight($errorCount)
227
            ,"Global Import Errors      : $globalErrors" . highlight($globalErrors)
228
            ,"Not Transferred Packages  : $ecount"
229
            ,"Transferred Packages      : $transferred"
230
            ,"Transfer to RM            : $diffCount"
231
            ,"Missing PackageVersions   : $missingPVID" . highlight($missingPVID)
232
            ,"Ripple Processed Early    : $rippleProcessed" . highlight($rippleProcessed)
233
            );
234
 
235
    if ( $opt_test )
236
    {
237
        Message('Test Mode : No changes made to RM');
238
        return;
239
    }
240
 
241
    unless ( $diffCount )
242
    {
243
        Message ('Release Manager entries are all upto date');
244
        return;
245
    }
246
 
247
    #
248
    #   Now do the RM Update
249
    #
250
    Message('Updating Release Manager: ' . $opt_rm);
251
    foreach my $entry ( @updateList )
252
    {
253
        intoReleaseManager ( $entry, $ScmVersions{$entry}{rmRef} );
254
    }
255
}
256
 
257
#-------------------------------------------------------------------------------
258
# Function        : intoReleaseManager
259
#
260
# Description     : Update VCS tags in RM
261
#
262
# Inputs          : $pvid           - PVId
263
#                   $tag            - New Tag
264
#
265
# Returns         : 
266
#
267
sub intoReleaseManager
268
{
269
    my ($pvid, $new_tag ) = @_;
270
    my @row;
271
    my $user = 3768;            # buildadm
272
 
273
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;
274
 
275
    my $m_sqlstr =  "begin release_manager.update_vcs_details($pvid, '$new_tag', $user); end;";
276
    my $sth = $RM_DB->prepare($m_sqlstr);
277
    if ( defined($sth) )
278
    {
279
        if ( $sth->execute( ) )
280
        {
281
            if ( $sth->rows )
282
            {
283
                while ( @row = $sth->fetchrow_array )
284
                {
285
                    print "Data: @row\n";
286
                }
287
            }
288
            $sth->finish();
289
        }
290
        else
291
        {
292
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
293
        }
294
    }
295
    else
296
    {
297
        Error("Prepare failure" );
298
    }
299
}
300
 
301
#-------------------------------------------------------------------------------
302
# Function        : GetPkgIdByName
303
#
304
# Description     :
305
#
306
# Inputs          : pkg_name
307
#
308
# Returns         : pkg_id
309
#
310
sub GetPkgIdByName
311
{
312
    my ( $pkg_name ) = @_;
313
    my (@row);
314
    my $pv_id;
315
    my $pkg_id;
316
 
317
    #
318
    #   Establish a connection to Release Manager
319
    #
320
    connectRM(\$RM_DB) unless ( $RM_DB );
321
 
322
    #
323
    #   Extract data from Release Manager
324
    #
325
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
326
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
327
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
328
 
329
    my $sth = $RM_DB->prepare($m_sqlstr);
330
    if ( defined($sth) )
331
    {
332
        if ( $sth->execute( ) )
333
        {
334
            if ( $sth->rows )
335
            {
336
                while ( @row = $sth->fetchrow_array )
337
                {
338
                    Verbose3( "DATA: " . join(',', @row) );
339
                    $pkg_id = $row[1] || 0;
340
                    last;
341
                }
342
            }
343
            else
344
            {
345
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
346
            }
347
            $sth->finish();
348
        }
349
    }
350
    else
351
    {
352
        Error("GetPkgIdByName:Prepare failure" );
353
    }
354
 
355
    return $pkg_id;
356
}
357
 
358
#-------------------------------------------------------------------------------
359
# Function        : GetData_by_pkg_id
360
#
361
# Description     : Create a hash of VCS tags for a given package
362
#
363
# Inputs          : pv_id
364
#
365
# Returns         :
366
#
367
sub GetData_by_pkg_id
368
{
369
    my ( $pkg_id, $packageName ) = @_;
370
    my (@row);
371
 
372
    #
373
    #   Establish a connection to Release Manager
374
    #
375
    Verbose2("Extract package versions from Release Manager: $packageName");
376
    connectRM(\$RM_DB) unless ( $RM_DB );
377
 
378
    #
379
    #   Extract data from Release Manager
380
    #
381
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pkg.PKG_ID, pv.PV_ID, release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID)".
382
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv" .
383
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID";
384
 
385
 
386
    my $sth = $RM_DB->prepare($m_sqlstr);
387
    if ( defined($sth) )
388
    {
389
        if ( $sth->execute( ) )
390
        {
391
            if ( $sth->rows )
392
            {
393
                while ( @row = $sth->fetchrow_array )
394
                {
395
                    Verbose3( "DATA: " . join(',', @row) );
396
                    $packageVcs{$row[3]} = $row[4];
397
                }
398
            }
399
            else
400
            {
401
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
402
            }
403
            $sth->finish();
404
        }
405
        else
406
        {
407
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
408
        }
409
    }
410
    else
411
    {
412
        Error("GetData_by_pkg_id:Prepare failure" );
413
    }
414
}
415
 
416
 
417
#-------------------------------------------------------------------------------
418
#   Documentation
419
#
420
 
421
=pod
422
 
423
=for htmltoc    SYSUTIL::cc2svn::
424
 
425
=head1 NAME
426
 
427
cc2svn_updaterm - Update Release Manager with CC2SVN information
428
 
429
=head1 SYNOPSIS
430
 
431
  jats cc2svn_updaterm [options] [PackageName]*
432
 
433
 Options:
434
    -help              - brief help message
435
    -help -help        - Detailed help message
436
    -man               - Full documentation
437
    -verbose           - Enable verbosity
438
    -[no]test          - Test update. Default: -notest
439
    -package=name      - Specify single package to be processed
440
    -database=name     - Default: RELMANU1 (test db)
441
    -[no]force         - Force update of all entries
442
    -check=string      - Check operation with string
443
 
444
 
445
 
446
=head1 OPTIONS
447
 
448
=over 8
449
 
450
=item B<-help>
451
 
452
Print a brief help message and exits.
453
 
454
=item B<-help -help>
455
 
456
Print a detailed help message with an explanation for each option.
457
 
458
=item B<-man>
459
 
460
Prints the manual page and exits.
461
 
462
=item B<-[no]test>
463
 
464
Invoke the program in test mode. This is the default.
465
 
466
In test mode the program will examine each packages 'data' results file
467
and report status and errors.
468
 
469
In 'notest' the program will update the Release Manager database.
470
 
471
=item B<-package=name>
472
 
473
This option will name one package to be processed. Packages to be
474
processed can just be named on the command line.
475
 
476
=item B<-database=name>
477
 
478
This option specifies the target database. The default value is 'RELMANU1'.
479
This is a test database.
480
 
481
The production database is RELEASEM.
482
 
483
The user must specifically specify the database to update the production system.
484
 
485
=item B<-[no]force>
486
 
487
This option will force the Release Manager entries to be updated - even if the
488
current entry matches the desired result.
489
 
490
Useful in testing.
491
 
492
=item B<-check=string>
493
 
494
This option will pass a string directly to the Release Manager updating proceedure.
495
 
496
With this option no packages will be examined or processed.
497
 
498
It is only useful for testing.
499
 
500
=back
501
 
502
=head1 DESCRIPTION
503
 
504
This program is a tool used in the conversion of ClearCase VOBS to subversion.
505
It will:
506
 
507
=over 8
508
 
509
=item *
510
 
511
Process all packages named on the command line or with the -package option.
512
 
513
=item *
514
 
515
Examine the packages '.data' file, whcih is created as the package is inserted
516
into Subversion.
517
 
518
=item *
519
 
520
Report the status of the package import and highlight issues.
521
 
522
=item *
523
 
524
Read the Release Manager entry and ensure that the entry is not the same.
525
If the entry is the same then it will not be updated, unless the '-force'
526
option has been used.
527
 
528
=item *
529
 
530
Insert the new Version Control information into the Release Manager entry.
531
 
532
=back
533
 
534
The default operation of this utility is to test the import process. The
535
user needs to provide specific options in order to update the production
536
database. This is intentional.
537
 
538
=cut
539