Subversion Repositories DevTools

Rev

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