Subversion Repositories DevTools

Rev

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