Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

########################################################################
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
#
# Module name   : rmMerge_process.pl
# Module type   : JATS Utility
# Compiler(s)   : Perl
# Environment(s): jats
#
# Description   : Compare two releases 
#
# Usage         : See POD at the end of this file
#
#......................................................................#

require 5.008_002;
use strict;
use warnings;

use Pod::Usage;
use Getopt::Long;

use JatsError;
use JatsRmApi;
use JatsSystem;
use FileUtils;
use ConfigurationFile;
use File::Copy;
use DBI;
my $RM_DB;

my $opt_help=0;
my $opt_verbose=0;
my $opt_debug=0;
my $oldRtagId;
my $newRtagId;

my $VERSION = "1.0";
my @oldRMCred = ('OLD', 'jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RM_READONLY', 'RM_READONLY');
my @newRMCred = ('NEW', 'jdbc:oracle:thin:@auawsards002:1521:RELEASEM', 'RM_READONLY', 'Tp8WmmDKMq2Z');

my %oldData;
my %newData;

#-------------------------------------------------------------------------------
# Function        : Mainline Entry Point
#
# Description     :
#
# Inputs          :
#
my $result = GetOptions (
                "help:+"        => \$opt_help,
                "manual:3"      => \$opt_help,
                "verbose:+"     => \$opt_verbose,
                "debug:+"       => \$opt_debug,
                "oldRtag:n"     => \$oldRtagId,
                "newRtag:n"     => \$newRtagId,
                );

                #
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
                #

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
pod2usage(-verbose => 1) if ( $opt_help == 2 );
pod2usage(-verbose => 2) if ( $opt_help > 2 );
#pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV < 0 );

#
#   Configure the error reporting rmMerge_process now that we have the user options
#
ErrorConfig( 'name'    =>'RELCMP',
             'verbose' => $opt_verbose,
             'debug' => $opt_debug,
            );
Error("Need to provide two RTAGs") unless $oldRtagId && $newRtagId;

#
#   Determine matching Release Names
#
getReleaseData($oldRtagId, \%oldData, @oldRMCred);
getReleaseData($newRtagId, \%newData, @newRMCred);

#DebugDumpData("oldData", \%oldData);
#DebugDumpData("newData", \%newData);

#
#   Report differences
#
my %changedVersions;
foreach my $pname ( sort keys %oldData) {
    foreach my $pver ( sort keys %{$oldData{$pname}}) {
        next if exists $newData{$pname} && exists $newData{$pname}{$pver};
        next if exists $newData{$pname};
        print("Missing in new: $pname $pver\n");
    }
}

foreach my $pname ( sort keys %newData) {
    foreach my $pver ( sort keys %{$newData{$pname}}) {
        next if exists $oldData{$pname}{$pver};
        next if exists $oldData{$pname};
        print("Missing in old: $pname $pver\n");
    }
}

foreach my $pname ( sort keys %oldData) {
    foreach my $pver ( sort keys %{$oldData{$pname}}) {
        next if exists $newData{$pname} && exists $newData{$pname}{$pver};
        next unless exists $newData{$pname};
        my @versions = keys %{$newData{$pname}} ;
        printf("Changed: %30.30s %20.20s -> (N) %s\n", $pname, $pver, join(' ', @versions));
    }
}



#-------------------------------------------------------------------------------
# Function        : getReleaseData 
#
# Description     : Get Release Content and related data for a release
#
# Inputs          : rtagId
#                   dataRef
#                   RmCredentails 
#
# Returns         : 
#
sub getReleaseData
{
    my ($rtagId, $dataRef, $id, $url, $name, $passwd) = @_;

    my (@row);

    Message ("Extract data for $id: $rtagId");

    $ENV{GBE_RM_LOCATION} = $url;
    $ENV{GBE_RM_USERNAME} = $name;
    $ENV{GBE_RM_PASSWORD} = $passwd;

    connectRM(\$RM_DB);

    # First get details from pv_id

    my $m_sqlstr = <<"SQL_END";
        SELECT
            rc.pv_id,
            p.pkg_name,
            pv.pkg_version
        FROM
            release_content rc,
            package_versions pv,
            packages p
        WHERE
            rc.rtag_id = :rtag_id
            AND rc.pv_id = pv.pv_id
            AND p.pkg_id = pv.pkg_id
SQL_END
    $m_sqlstr =~ s~:rtag_id~$rtagId~g;
    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            if ( $sth->rows )
            {
                while ( @row = $sth->fetchrow_array )
                {
                    $dataRef->{$row[1]}{$row[2]}{pvid} = $row[0] 
                }
            }
            $sth->finish();
        }
        else
        {
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
        }
    }
    else
    {
        Error("Prepare failure" );
    }

    disconnectRM(\$RM_DB);
}