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