Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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