Subversion Repositories DevTools

Rev

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