Subversion Repositories DevTools

Rev

Rev 2476 | Rev 2635 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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