Subversion Repositories DevTools

Rev

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