Subversion Repositories DevTools

Rev

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