Subversion Repositories DevTools

Rev

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