Subversion Repositories DevTools

Rev

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

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