Subversion Repositories DevTools

Rev

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