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