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