Subversion Repositories DevTools

Rev

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