Subversion Repositories DevTools

Rev

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