
| Current Path : /var/www/web-klick.de/dsh/10_customer2017/1204__intel/OptiCM/ToolsAdmin/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/10_customer2017/1204__intel/OptiCM/ToolsAdmin/syncdbviews.pl |
#!/home/swmdev/bin/opticmperl
# This script will update the CCSITE, REGION[...], CLEARCASEID columns of the CCVIEWS table
# in the database with the Clearcase information available locally
use strict;
# use warnings;
# extend @INC to find the OptiCM modules (last one listed here is searched first)
use lib "$ENV{CMTOOLPATH}/cpan/lib"; # standard cpan modules (pure perl only!)
use lib "$ENV{CMTOOLPATH}"; # traditional opticm modules
use lib "$ENV{CMTOOLPATH}/lib"; # add new OO code
use Data::Dumper;
use App::Engine::multisite;
use Libs::OptiDb::CcView;
use Libs::OptiDb::Access;
use Text::Glob qw( match_glob);
use strict;
our $site;
# TODO: Riehm 2010-02-22 why wasn't this using App::Engine::CcView::getCcViewDetails()?
# TODO: Riehm 2010-02-22 getCcViewDetails() is deprecated - use getOrDefineViewDetails( getDataFrom => 'clearcase' ) instead
sub getCcViewDetails { # copied from App::Engine::CcView
my ($region, $viewtag , $view) = @_;
# OC 2008-11-14 RunCtNew calls RunCommand which runs "open ... |" .
# This open call make trouble since we switched to Perl 5.10
# Therefore, as a workaround, we use the system call here.
# This stuff will be obsolete by the new Cleartool interface soon anyway
my $ct = "cleartool";
my @ctargs = ('lsview', '-region' , $region, '-long', '-prop', '-full', $viewtag);
my $ctargsstr = join(" ",@ctargs);
my $stdout = `$ct $ctargsstr 2>error.txt`;
my $returncode = $? >> 8;
return 0 if ( $returncode ); # View not found probably
# Put all key/value pairs given back by Cleartool in the %viewdetails hash
my %viewdetails;
foreach my $line ( split('\n', $stdout) ) {
$line =~ /^\s*(.*?)\:\s*(.*)/;
$viewdetails{$1} = $2;
}
if ( $viewdetails{Tag} ) {
# The "tag" line contains the tag as well as the view comment, that we want to ignore
# Tag: kohlburk_opticm_dbtest2 "viewpath: NBGN0232:C:\UserData\kohlburk\sviews\kohlburk_opticm_dbtest2"
$viewdetails{Tag} =~ m/^(\S+)/;
$viewdetails{Tag} = $1;
}
return 0 if $viewdetails{Tag} ne $viewtag; # Something is wrong
$view->{ccviewtag} = $viewdetails{Tag};
if( $viewdetails{"View attributes"} =~ /snapshot/i
|| $viewdetails{"Properties"} =~ /snapshot/i ) {
$view->{ccviewtype} = "snapshot";
}
else {
$view->{ccviewtype} = "dynamic";
}
$view->{ccviewglobalpath} = $viewdetails{"Global path"};
$view->{ccviewserver} = $viewdetails{"Server host"};
$view->{ccviewid} = $viewdetails{"View tag uuid"} || $viewdetails{"View uuid"};
$view->{viewserveraccesspath} = $viewdetails{"View server access path"};
{
# BK 2008-07-24: Note: in case view has protection problems, Owner may not be set.
my $owner = ($viewdetails{Owner}) ? $viewdetails{Owner} : $viewdetails{'View owner'};
# extract name out of "EU\croquett : rwx (all)"
# or "urania.infineon.com/croquett : rwx (all)"
$owner =~ /^(?:.*[\\\/])?(\S+)/;
$view->{ccviewowner} = $1;
}
return 1;
}
sub update {
my ($pattern) = shift;
our $site;
my $dbviews = { };
# my $dbviews = Libs::OptiDb::Access::getTableAsHoH("VW_CCVIEWS");
my $logmsg;
# TODO: Riehm 2010-02-22 prefer Libs::OptiDb::CcView::getFilteredViewList()
my $ok = Libs::OptiDb::Access::getRows( tableName=> "VW_CCVIEWS", rhResult => $dbviews, resultKey=>"ID");
die "Failed to get views from DB: $logmsg" if ! $ok;
print "Got " . scalar(keys(%$dbviews)) . " views from the database\n";
DBVIEW: while ( my ($viewid, $dbview) = (each %$dbviews) ) {
my $viewtag = $dbview->{NAME};
next if ! match_glob( $pattern, $viewtag);
# next if $viewtag !~ /^croquett/;
# next if $viewtag ne "croquett_sandbox11";
# last if ($i++ > 10);
## print "\n\n$viewtag " . ($viewtag !~ /^croquett/) . "\n";
# print "$viewtag\n";
my %regions = ( "ccase_win" => "REGIONWINDOWS", "ccase_unix" => "REGIONUNIX");
my %ccinfo = ( "ccase_win" => { }, "ccase_unix" => { });
# Gather information from both regions, and check id
my $consistentccid = undef;
REGION: while ( my ($region,$column) = each(%regions) ) {
# TODO: Riehm 2010-02-22 refactor: use App::Engine::CcView::getOrDefineViewDetails( ... )
if ( ! getCcViewDetails($region, $dbview->{NAME}, $ccinfo{$region}) ){
$ccinfo{$region} = undef;
next REGION;
}
if ( defined($consistentccid) && $consistentccid ne $ccinfo{$region}->{id} ) { # Check id consistency
print STDERR "ERROR: $viewtag id inconsistency in Clearcase between the regions\n";
next DBVIEW;
}
$consistentccid = $ccinfo{$region}->{id};
# print Dumper($ccinfo{$region});
}
if ( ! defined($consistentccid) ) { # No corresponding CC view found
if ( $dbview->{CCSITE} eq $site ) {
print STDERR "WARNING: $viewtag view expected in clearcase but not found, skipping\n";
}
next;
}
if ( $dbview->{CCSITE} && $dbview->{CCSITE} ne $site ) {
print STDERR "ERROR: $viewtag wrong site " . $dbview->{CCSITE} ." ($site)\n";
next;
}
if ( ! $dbview->{CCSITE} ) {
# print "Libs::OptiDb::CcView::setSite($viewtag, $site)\n";
Libs::OptiDb::CcView::setSite($viewtag, $site);
print "INFO: site $site set for $viewtag\n";
}
if ( $dbview->{CLEARCASEID} && ( $dbview->{CLEARCASEID} ne $consistentccid ) ) {
print STDERR "WARNING: $viewtag wrong id in the database, correcting\n";
}
Libs::OptiDb::CcView::setClearcaseId($viewtag, $consistentccid);
while ( my ($region,$column) = each(%regions) ) {
if ( $dbview->{$column} && $dbview->{$column} ne $region ) {
print STDERR "ERROR: $viewtag wrong region (db=" . $dbview->{$column} ."/current=$region), skipping\n";
next;
}
my $setregion = ( $ccinfo{$region} ? $region : ""); # Clear the region in the database if necessary
my $dbLogMsg = "";
my $dbok;
$dbok = Libs::OptiDb::CcView::setUnixRegion($viewtag, $setregion, $dbLogMsg) if ($column eq "REGIONUNIX");
$dbok = Libs::OptiDb::CcView::setWindowsRegion($viewtag, $setregion, $dbLogMsg) if ($column eq "REGIONWINDOWS");
if ( ! $dbok ) {
print STDERR "ERROR: setting $column to $setregion for $viewtag : $dbLogMsg\n";
}
}
}
}
if ( ! $ARGV[0] || @ARGV != 1 ) {
print STDERR 'ERROR: Please provide a unique viewtag pattern on the command line (ie. "croquett_*" or "*")' ."\n";
}
my $sitemsg = "";
if ( ! App::Engine::multisite::getMyCcSite(\$site, \$sitemsg) ) {
die "Could not determine current site, exiting. $sitemsg\n";
}
update($ARGV[0]);