Subversion Repositories DevTools

Rev

Rev 6887 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6887 dpurdie 1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : cc2svn_updatermKludge.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Update RM with ClearCase to Subversion conversion info
10
#
11
#                 Kludged to handle lost data from the TRACS package
12
#                 where the DATA file got messed up with an aborted
13
#                 -resume.
14
#
15
#                 Extract data from the importsummary.txt
16
#
17
# Usage:
18
#
19
# Version   Who      Date        Description
20
#
21
#......................................................................#
22
 
23
require 5.008_002;
24
use strict;
25
use warnings;
26
 
27
use Pod::Usage;
28
use Getopt::Long;
29
 
30
use JatsError;
31
use JatsRmApi;
32
 
33
#
34
#   Globals
35
#
36
my $RM_DB;
37
my $VERSION = "1.0.0";                      # Update this
38
my %packageVcs;
39
my %pkgInfo;
40
my %importData;
41
#
42
#   Options
43
#
44
my $opt_verbose = 0;
45
my $opt_help = 0;
46
my $opt_package;
47
my $opt_rm = 'RELMANU1';
48
my $opt_test = 1;
49
my $opt_force;
50
my $opt_checkOperation;
51
my $opt_report = 0;
52
my $opt_live;
53
my $opt_grep;
54
 
55
#-------------------------------------------------------------------------------
56
# Function        : Main Entry
57
#
58
# Description     :
59
#
60
# Inputs          :
61
#
62
# Returns         :
63
#
64
my $result = GetOptions (
65
                "help+"         => \$opt_help,          # flag, multiple use allowed
66
                "manual:3"      => \$opt_help,
67
                "verbose:+"     => \$opt_verbose,       # flag
68
                'package:s'     => \$opt_package,
69
                'database:s'    => \$opt_rm,
70
                'test!'         => \$opt_test,
71
                'force!'        => \$opt_force,
72
                'check:s'       => \$opt_checkOperation,
73
                'report:+'      => \$opt_report,
74
                'live!'         => \$opt_live,
75
                'grep'          => \$opt_grep,          # Grep friendly - display pkg name
76
                );
77
 
78
#
79
#   Process help and manual options
80
#
81
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
82
pod2usage(-verbose => 1)  if ($opt_help == 2);
83
pod2usage(-verbose => 2)  if ($opt_help > 2);
84
 
85
ErrorConfig( 'name'    =>'CC2SVN_UPDATERM',
86
             'verbose' => $opt_verbose,
87
              );
88
 
89
Error ("Must specify a package name") unless ( defined $opt_package || $#ARGV >= 0 );
90
 
91
if ( $opt_live )
92
{
93
    $opt_rm = 'RELEASEM';
94
}
95
 
96
 
97
$ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaprm01:1521:' . $opt_rm;
98
unless ( $opt_rm eq 'RELEASEM' )
99
{
100
    Warning ("Using internal user/password - Test Database");
101
    $ENV{GBE_RM_USERNAME} = 'RELEASE_MANAGER';
102
    $ENV{GBE_RM_PASSWORD} = 'RELEASE_MANAGER';
103
    $ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaora07.vix.local:1521:' . $opt_rm;
104
}
105
else
106
{
107
    $ENV{GBE_RM_USERNAME} = 'RM_READONLY';
108
    $ENV{GBE_RM_PASSWORD} = 'RM_READONLY';
109
}
110
 
111
#
112
#   Check operation
113
#
114
if ( $opt_checkOperation )
115
{
116
    Message ("Check RM operation");
117
    Error ("PVID must be specified via -package option") unless $opt_package;
118
    intoReleaseManager ($opt_package, $opt_checkOperation);
119
    Message ("Check Complete OK");
120
    exit 0;
121
}
122
 
123
 
124
foreach my $fileName ( $opt_package, @ARGV )
125
{
126
    next unless ( defined $fileName );
127
    next if ( $fileName eq 'Dataman' );
128
 
129
    $fileName =~ s~\.data$~~;
130
    $fileName =~ s~\.svg$~~;
131
    $fileName =~ s~\.importlog$~~;
132
 
133
    readImportData($fileName);
134
    readPackageDataFile($fileName);
135
 
136
    foreach my $packageName( sort keys %pkgInfo )
137
    {
138
        getVcsData($packageName) if ( $opt_report <= 1 || $opt_report == 6 );
139
        processPackage($packageName);
140
    }
141
}
142
exit 0;
143
 
144
#-------------------------------------------------------------------------------
145
# Function        : getVcsData
146
#
147
# Description     : Get existing VCS data from the release Manager
148
#
149
# Inputs          : 
150
#
151
# Returns         : 
152
#
153
sub getVcsData
154
{
155
    my ($packageName) = @_;
156
    %packageVcs = ();
157
    my $pkg_id = GetPkgIdByName ( $packageName );
158
    GetData_by_pkg_id ( $pkg_id, $packageName  );
159
    #DebugDumpData("packageVcs", \%packageVcs );
160
}
161
 
162
#-------------------------------------------------------------------------------
163
# Function        : readPackageDataFile
164
#
165
# Description     : Read in the data file. It may contain data for more
166
#                   than one package - but this is rare
167
#
168
# Inputs          : 
169
#
170
# Returns         : Fills in %pkgInfo
171
#
172
#
173
our %ScmVersions;
174
sub readPackageDataFile
175
{
176
    %pkgInfo = ();
177
    my ($pname) = @_;
178
    my $fname = $pname . '.data';
179
    Verbose2 ('Reading Package Data: ' . $fname);
180
return unless ( -f $fname );
181
    Error "Cannot locate $fname" unless ( -f $fname );
182
    %ScmVersions = ();
183
    require $fname;
184
 
185
    Error "Data in $fname is not valid\n"
186
        unless ( keys(%ScmVersions) >= 0 );
187
 
188
    foreach (keys %ScmVersions)
189
    {
190
        my $entry = $ScmVersions{$_};
191
        $pkgInfo{$entry->{name}}{$_} = $entry;
192
    }
193
 
194
    %ScmVersions = ();
195
}
196
 
197
#-------------------------------------------------------------------------------
198
# Function        : processPackage
199
#
200
# Description     : Process data for one package
201
#
202
# Inputs          : Name of the package
203
#
204
# Returns         : 
205
#
206
sub processPackage
207
{
208
    my ($pname) = @_;
209
    Error ("Internal: Hash data not found")
210
        unless ( exists $pkgInfo{$pname});
211
    my $pkgData = $pkgInfo{$pname};
212
 
213
    my @updateList;
214
    my $essentialCount = 0;
215
    my $errorCount = 0;
216
    my $ecount = 0;
217
    my $notOk = 0;
218
    my $transferred = 0;
219
    my $totalCount = 0;
220
    my $diffCount = 0;
221
    my $missingPVID = 0;
222
    my $rippleProcessed = 0;
223
    my $globalErrors = 0;
224
    my $notProcessed = 0;
225
    my $prjBase = 0;
226
    my $pkgProject = 0;
227
    my $badPaths = 0;
228
    my $adjustedPath = 0;
229
#    my $rtCount = 0;
230
    my $rtErrorCount = 0;
231
    my $importTagCount = 0;
232
 
233
 
234
    foreach (sort {$a <=> $b}  keys(%{$pkgInfo{$pname}} ) )
235
    {
236
        my $pkgEntry = $pkgInfo{$pname}{$_};
237
 
238
        $totalCount ++;
239
        $notProcessed++ unless $pkgEntry->{Scanned};
240
        $essentialCount++ if ( $pkgEntry->{Essential}  );
241
        $rippleProcessed++ if ( $pkgEntry->{rippleProcessed} );
242
 
243
        my $pvid = $_;
244
        if ( $pkgEntry->{rmRef} eq 'ERROR' && exists $importData{$pvid} )
245
        {
246
          $pkgEntry->{rmRef} =  $importData{$pvid};
247
          $importTagCount++;
248
print "--- Found: $importData{$pvid}\n";
249
        }
250
        else
251
        {
252
            $globalErrors++ if ( ($pkgEntry->{data}{errFlags} || '') eq 'e' );
253
            $prjBase++ if ( $pkgEntry->{data}{BadProjectBase} );
254
            $pkgProject++ if ( $pkgEntry->{data}{BadMakeProject} );
255
            $badPaths++ if ( $pkgEntry->{data}{BadPath} );
256
            $adjustedPath++ if ( $pkgEntry->{data}{adjustedPath} );
257
        }
258
 
259
        unless ( $pkgEntry->{TagCreated} )
260
        {
261
            $errorCount++ if ( $pkgEntry->{Essential}  );
262
            $ecount++;
263
            Verbose ("Package Not Processed: " . $pkgEntry->{vname} . ' - ' . ($pkgEntry->{data}{errStr} || 'Unspecified Error')  );
264
 
265
            unless ( $pkgEntry->{DeadWood} ||  $pkgEntry->{locked} eq 'N' )
266
            {
267
                $notOk++;
268
#Warning ("Package Not OK: " . $pkgEntry->{vname} . ' - ' . ($pkgEntry->{data}{errStr} || 'Unspecified Error')  );
269
            }
270
 
271
        }
272
 
273
#        $rtCount += $pkgEntry->{data}{ReleaseTag}{tCount} || 0;
274
#        $rtErrorCount += $pkgEntry->{data}{ReleaseTag}{eCount} || 0;
275
    }
276
 
277
    foreach my $pvid (sort {$a <=> $b}  keys(%{$pkgInfo{$pname}} ) )
278
    {
279
        my $pkgEntry = $pkgInfo{$pname}{$pvid};
280
        if ( $pkgEntry->{TagCreated} )
281
        {
282
            $transferred++;
283
            my $done = '';
284
            my $rmRef = $pkgEntry->{rmRef} ;
285
 
286
            my $include = 1;
287
            if ( exists $packageVcs{$pvid} )
288
            {
289
                if ( $opt_report == 6 )
290
                {
291
                    $include = 0 if ( $packageVcs{$pvid} =~ m~^SVN::~ );
292
                }
293
                else
294
                {
295
                    $include = 0 if ( ($packageVcs{$pvid} eq $rmRef) );
296
                }
297
            }
298
            else
299
            {
300
                $missingPVID++;
301
                $done = ' < Missing' unless $done;
302
                $include = 0 ;
303
            }
304
 
305
            if ( $include || $opt_force)
306
            {
307
                    $diffCount++;
308
                    $done = ' *' unless $done;
309
                    push @updateList, $pvid;
310
            }
311
 
312
            Verbose ("Processed: " . $pkgEntry->{vname} . ' :: ' . ($rmRef || '???') . $done );
313
 
314
        }
315
    }
316
 
317
    if ( $opt_report == 6 )
318
    {
319
        # Display missing updates
320
        foreach my $entry ( @updateList )
321
        {
322
            print "$pname : $pkgData->{$entry}{vname}\n";
323
        }
324
        return;
325
    }
326
 
327
    if ( $opt_report == 5 )
328
    {
329
        #
330
        #   Packages that use MakeProject
331
        #
332
        return unless ( $pkgProject );
333
        print ("$pname\n");
334
        return;
335
    }
336
 
337
    if ( $opt_report == 3 )
338
    {
339
        #
340
        #   Just the packages that have no problems
341
        #   Short form
342
        #
343
#Debug0("$pname", $notOk ,$globalErrors ,$prjBase ,$pkgProject ,$errorCount ,$notProcessed ,$rtErrorCount);
344
        return if ( $notOk ||$globalErrors || $prjBase || $pkgProject ||  $errorCount || $notProcessed || $rtErrorCount || $badPaths);
345
        print ("$pname\n");
346
        return;
347
    }
348
 
349
    if ( $opt_report == 4 )
350
    {
351
        #
352
        #   Just the packages that Global Errors
353
        #   Short form
354
        #
355
        return if (  !$globalErrors);
356
        print ("$pname\n");
357
        return;
358
    }
359
 
360
 
361
    if ( $opt_report )
362
    {
363
        return unless ($globalErrors || $prjBase || $pkgProject ||  $errorCount || $notProcessed || $rtErrorCount || $badPaths);
364
    }
365
 
366
    sub highlight
367
    {
368
        my ($value) = @_;
369
        return $value ? ' <------' : '';
370
    }
371
 
372
    my $rmTotal = scalar keys %packageVcs;
373
    my $tpref = $opt_grep ? "$pname: " : '';
374
    Message ("Transfer Stats",
375
            ,"${tpref}Package                   : $pname"
376
            ,"${tpref}Total RM Versions         : $rmTotal"
377
            ,"${tpref}Total Packages Processed  : $totalCount"
378
            ,"${tpref}Packages NOT Processed    : $notProcessed" . highlight($notProcessed)
379
            ,"${tpref}Packages pruned           : " . ($rmTotal - $totalCount)
380
            ,"${tpref}Essential Packages        : $essentialCount"
381
            ,"${tpref}Essential Packages Errors : $errorCount" . highlight($errorCount)
382
            ,"${tpref}Global Import Errors      : $globalErrors" . highlight($globalErrors)
383
 
384
            ,"${tpref}Bad Source Paths          : $badPaths" . highlight($badPaths)
385
            ,"${tpref}ProjectBase Error         : $prjBase" . highlight($prjBase)
386
            ,"${tpref}MakeProject Error         : $pkgProject" . highlight($pkgProject)
387
            ,"${tpref}Adjusted Paths            : $adjustedPath" . highlight($adjustedPath && ($transferred - $adjustedPath))
388
            ,"${tpref}Not Transferred Packages  : $ecount"
389
            ,"${tpref}Transferred Packages      : $transferred" . highlight(!$transferred)
390
#            ,"${tpref}Release Tags applied      : $rtCount"
391
#            ,"${tpref}Release Tag errors        : $rtErrorCount" . highlight($rtErrorCount)
392
            ,"${tpref}Transfer to RM            : $diffCount"
393
            ,"${tpref}Missing PackageVersions   : $missingPVID" . highlight($missingPVID)
394
            ,"${tpref}Ripple Processed Early    : $rippleProcessed" . highlight($rippleProcessed)
395
            ,"${tpref}Tags from import file     : $importTagCount" . highlight($importTagCount)
396
            );
397
 
398
    if ( $opt_report )
399
    {
400
        return;
401
    }
402
 
403
 
404
    if ( $opt_test )
405
    {
406
        Message('Test Mode : No changes made to RM');
407
        return;
408
    }
409
 
410
    unless ( $diffCount )
411
    {
412
        Message ('Release Manager entries are all upto date');
413
        return;
414
    }
415
 
416
    #
417
    #   Now do the RM Update
418
    #
419
    Message('Updating Release Manager: ' . $opt_rm);
420
    foreach my $entry ( @updateList )
421
    {
422
        intoReleaseManager ( $entry, $pkgData->{$entry}{vname}  ,$pkgData->{$entry}{rmRef} );
423
    }
424
}
425
 
426
#-------------------------------------------------------------------------------
427
# Function        : intoReleaseManager
428
#
429
# Description     : Update VCS tags in RM
430
#
431
# Inputs          : $pvid           - PVId
432
#                   $name           - Package Version (text)
433
#                   $tag            - New Tag
434
#
435
# Returns         : 
436
#
437
sub intoReleaseManager
438
{
439
    my ($pvid, $name, $new_tag ) = @_;
440
    my @row;
441
    my $user = 3768;            # buildadm
442
 
443
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;
444
 
445
    Verbose ("ToRm: $pvid, $name  - $new_tag");
446
    my $m_sqlstr =  "begin release_manager.PK_RMAPI.update_vcs_details($pvid, '$new_tag', $user); end;";
447
    my $sth = $RM_DB->prepare($m_sqlstr);
448
    if ( defined($sth) )
449
    {
450
        if ( $sth->execute( ) )
451
        {
452
            if ( $sth->rows )
453
            {
454
                while ( @row = $sth->fetchrow_array )
455
                {
456
                    print "Data: @row\n";
457
                }
458
            }
459
            $sth->finish();
460
        }
461
        else
462
        {
463
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
464
        }
465
    }
466
    else
467
    {
468
        Error("Prepare failure" );
469
    }
470
}
471
 
472
#-------------------------------------------------------------------------------
473
# Function        : GetPkgIdByName
474
#
475
# Description     :
476
#
477
# Inputs          : pkg_name
478
#
479
# Returns         : pkg_id
480
#
481
sub GetPkgIdByName
482
{
483
    my ( $pkg_name ) = @_;
484
    my (@row);
485
    my $pv_id;
486
    my $pkg_id;
487
 
488
    #
489
    #   Establish a connection to Release Manager
490
    #
491
    connectRM(\$RM_DB) unless ( $RM_DB );
492
 
493
    #
494
    #   Extract data from Release Manager
495
    #
496
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
497
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
498
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
499
 
500
    my $sth = $RM_DB->prepare($m_sqlstr);
501
    if ( defined($sth) )
502
    {
503
        if ( $sth->execute( ) )
504
        {
505
            if ( $sth->rows )
506
            {
507
                while ( @row = $sth->fetchrow_array )
508
                {
509
                    Verbose3( "DATA: " . join(',', @row) );
510
                    $pkg_id = $row[1] || 0;
511
                    last;
512
                }
513
            }
514
            else
515
            {
516
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
517
            }
518
            $sth->finish();
519
        }
520
    }
521
    else
522
    {
523
        Error("GetPkgIdByName:Prepare failure" );
524
    }
525
 
526
    return $pkg_id;
527
}
528
 
529
#-------------------------------------------------------------------------------
530
# Function        : GetData_by_pkg_id
531
#
532
# Description     : Create a hash of VCS tags for a given package
533
#
534
# Inputs          : pv_id
535
#
536
# Returns         :
537
#
538
sub GetData_by_pkg_id
539
{
540
    my ( $pkg_id, $packageName ) = @_;
541
    my (@row);
542
 
543
    #
544
    #   Establish a connection to Release Manager
545
    #
546
    Verbose2("Extract package versions from Release Manager: $packageName");
547
    connectRM(\$RM_DB) unless ( $RM_DB );
548
 
549
    #
550
    #   Extract data from Release Manager
551
    #
552
    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)".
553
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv" .
554
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID";
555
 
556
 
557
    my $sth = $RM_DB->prepare($m_sqlstr);
558
    if ( defined($sth) )
559
    {
560
        if ( $sth->execute( ) )
561
        {
562
            if ( $sth->rows )
563
            {
564
                while ( @row = $sth->fetchrow_array )
565
                {
566
                    Verbose3( "DATA: " . join(',', @row) );
567
                    $packageVcs{$row[3]} = $row[4];
568
                }
569
            }
570
            else
571
            {
572
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
573
            }
574
            $sth->finish();
575
        }
576
        else
577
        {
578
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
579
        }
580
    }
581
    else
582
    {
583
        Error("GetData_by_pkg_id:Prepare failure" );
584
    }
585
}
586
 
587
#-------------------------------------------------------------------------------
588
# Function        : readImportData
589
#
590
# Description     : Read data from importsummary.txt
591
#
592
# Inputs          : tag     - Name fo package
593
#
594
# Returns         : 
595
#
596
sub readImportData
597
{
598
    my ($tag) = @_;
599
    %importData = ();
600
 
601
    open (IS, '<', 'importsummary.txt' ) || Error ("Cant read importsummart.txt: $!");
602
    while ( <IS> )
603
    {
604
        my @data = split (';', $_);
605
        next unless ( $data[1] eq 'G' );
606
        next unless ( $data[3] eq  $tag );
607
#DebugDumpData('data', \@data );
608
 
609
        $importData{ $data[2] } = $data[5];
610
    }
611
    close IS;
612
#    DebugDumpData('%importData', \%importData );
613
}
614
 
615
 
616
#-------------------------------------------------------------------------------
617
#   Documentation
618
#
619
 
620
=pod
621
 
622
=for htmltoc    SYSUTIL::cc2svn::
623
 
624
=head1 NAME
625
 
626
cc2svn_updaterm - Update Release Manager with CC2SVN information
627
 
628
=head1 SYNOPSIS
629
 
630
  jats cc2svn_updaterm [options] [PackageName]*
631
 
632
 Options:
633
    -help              - brief help message
634
    -help -help        - Detailed help message
635
    -man               - Full documentation
636
    -verbose           - Enable verbosity
637
    -[no]test          - Test update. Default: -notest
638
    -[no]live          - Select database. Default: -nolive
639
    -package=name      - Specify single package to be processed
640
    -database=name     - Default: RELMANU1 (test db) Live: RELEASEM
641
    -[no]force         - Force update of all entries
642
    -check=string      - Check operation with string
643
    -report            - Report on errors
644
    -report=1          - Report on errors
645
    -report=2          - Report on errors, don't access RM
646
    -report=3          - Packages that have no problems
647
    -report=4          - Packages that have global errors
648
    -report=5          - Packages that use MakeProject
649
    -report=6          - Display missing updates
650
 
651
=head1 OPTIONS
652
 
653
=over 8
654
 
655
=item B<-help>
656
 
657
Print a brief help message and exits.
658
 
659
=item B<-help -help>
660
 
661
Print a detailed help message with an explanation for each option.
662
 
663
=item B<-man>
664
 
665
Prints the manual page and exits.
666
 
667
=item B<-[no]test>
668
 
669
Invoke the program in test mode. This is the default.
670
 
671
In test mode the program will examine each packages 'data' results file
672
and report status and errors.
673
 
674
In 'notest' the program will update the Release Manager database.
675
 
676
=item B<-[no]live>
677
 
678
Invoke the program in live-database mode. This is the NOT the default.
679
 
680
In live mode the program will access the Live Release Manager database.
681
 
682
In non-live mode the program will access the test (RELMANU1) database
683
 
684
=item B<-package=name>
685
 
686
This option will name one package to be processed. Packages to be
687
processed can just be named on the command line.
688
 
689
=item B<-database=name>
690
 
691
This option specifies the target database. The default value is 'RELMANU1'.
692
This is a test database.
693
 
694
The production database is RELEASEM.
695
 
696
The user must specifically specify the database to update the production system.
697
 
698
=item B<-[no]force>
699
 
700
This option will force the Release Manager entries to be updated - even if the
701
current entry matches the desired result.
702
 
703
Useful in testing.
704
 
705
=item B<-check=string>
706
 
707
This option will pass a string directly to the Release Manager updating proceedure.
708
 
709
With this option no packages will be examined or processed.
710
 
711
It is only useful for testing.
712
 
713
=back
714
 
715
=head1 DESCRIPTION
716
 
717
This program is a tool used in the conversion of ClearCase VOBS to subversion.
718
It will:
719
 
720
=over 8
721
 
722
=item *
723
 
724
Process all packages named on the command line or with the -package option.
725
 
726
=item *
727
 
728
Examine the packages '.data' file, whcih is created as the package is inserted
729
into Subversion.
730
 
731
=item *
732
 
733
Report the status of the package import and highlight issues.
734
 
735
=item *
736
 
737
Read the Release Manager entry and ensure that the entry is not the same.
738
If the entry is the same then it will not be updated, unless the '-force'
739
option has been used.
740
 
741
=item *
742
 
743
Insert the new Version Control information into the Release Manager entry.
744
 
745
=back
746
 
747
The default operation of this utility is to test the import process. The
748
user needs to provide specific options in order to update the production
749
database. This is intentional.
750
 
751
=cut
752