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