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