Subversion Repositories DevTools

Rev

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