Subversion Repositories DevTools

Rev

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