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