Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:19

0001 #!/usr/bin/perl
0002 
0003 use warnings;
0004 use strict;
0005 use File::Basename;
0006 use Getopt::Long;
0007 use Data::Dumper;
0008 
0009 my $cmssw_base = $ENV{'CMSSW_BASE'};
0010 unless ($cmssw_base) {
0011     die "CMSSW_BASE is not set.  Be sure to eval `scramv1 runtime` first!\n";
0012 }
0013 
0014 # Manually including library
0015 push @INC, "${cmssw_base}/src/CondTools/OracleDBA/perllib";
0016 require CMSDBA;
0017 
0018 # Directories used
0019 my $o2o_dbconfigdir = $cmssw_base.'/src/CondTools/O2OFramework/dbconfig';
0020 my $dba_dbconfigdir = $cmssw_base.'/src/CondTools/OracleDBA/dbconfig';
0021 my $dba_xmldir = $cmssw_base.'/src/CondTools/OracleDBA/xml';
0022 
0023 my $usage = basename($0)." [options] [[--all] | [object1 object2 ...]]\n".
0024     "Options:\n".
0025     "--dbaconfig       Offline DB configuration file (hardcoded default in project area)\n".
0026     "--o2oconfig       O2O configuration file (hardcoded default in project area)\n".
0027     "--auth            DB connection file (hardcoded default in project area)\n".
0028     "--general_connect Connect string to the offline DB general schema (default in dbaconfig)\n".
0029     "--offline_connect Connect string to the offline DB detector schema (default in dbaconfig)\n".
0030     "--all             Setup all objects in O2O configuration file\n".
0031     "--fake            Don't actually do anything, only print commands\n".
0032     "--debug           Print additional debug information\n".
0033     "--log             Log file\n".
0034     "--help, -h        Print this message and exit\n";
0035 
0036 
0037 my $cmd_general_connect = '';
0038 my $cmd_offline_connect = '';
0039 my $o2o_configfile = $o2o_dbconfigdir.'/o2oconfiguration.xml';
0040 my $dba_configfile = $dba_dbconfigdir.'/dbconfiguration.xml';
0041 my $authfile = $dba_dbconfigdir.'/authentication.xml';
0042 my $doall = 0;
0043 my $fake = 0;
0044 my $debug = 0;
0045 my $log = '';
0046 my $help = 0;
0047 
0048 GetOptions('o2oconfig=s' => \$o2o_configfile,
0049        'dbaconfig=s' => \$dba_configfile,
0050        'auth=s' => \$authfile,
0051        'all' => \$doall,
0052        'general_connect=s' => \$cmd_general_connect,
0053        'offline_connect=s' => \$cmd_offline_connect,
0054        'fake' => \$fake,
0055        'help|h' => \$help,
0056        'debug' => \$debug,
0057        'log=s' => \$log);
0058 
0059 if ($help) {
0060     print "$usage";
0061     exit;
0062 }
0063 
0064 
0065 # Parse config files
0066 foreach($o2o_configfile, $dba_configfile, $authfile) {
0067     unless (-e $_) { die "Configuration file $_ does not exist!\n"; }
0068     else { print "Using config file $_\n"; }
0069 }
0070 
0071 my $o2o_config = CMSDBA::parse_o2oconfiguration($o2o_configfile);
0072 print "Result of parsing $o2o_configfile:\n".Dumper($o2o_config) if $debug;
0073 
0074 my $dba_config = CMSDBA::parse_dbconfiguration($dba_configfile);
0075 print "Result of parsing $dba_configfile:\n".Dumper($dba_config) if $debug;
0076 
0077 my $auth = CMSDBA::parse_authentication($authfile);
0078 print "Result of parsing $authfile:\n".Dumper($auth) if $debug;
0079 
0080 # Determine General Connect
0081 my $general_connect;
0082 if (!$cmd_general_connect && exists $dba_config->{general}->{general_connect}) {
0083     $general_connect = $dba_config->{general}->{general_connect};
0084 } elsif ($cmd_general_connect) {
0085     $general_connect = $cmd_general_connect;
0086 } else {
0087     die "general_connect not defined at command line or at $dba_configfile";
0088 }
0089 
0090 # Get connection info
0091 my ($general_user, $general_pass, $general_db, $general_schema) = CMSDBA::connection_test($auth, $general_connect);
0092 
0093 my $catalog = "relationalcatalog_oracle://".$general_db.'/'.$general_schema; # XXX Add to config?
0094 
0095 
0096 my @commands;
0097 my $cmd;
0098 
0099 # Determine what objects to set up
0100 my $objects = {}; # Build hash $objects->{$detector}->[ @objects ]
0101 
0102 die "Must provide object name(s) or --all" unless(@ARGV || $doall);
0103 my @userobjects = @ARGV;
0104 
0105 if ($doall) {
0106     foreach my $detector (keys %{$o2o_config->{detector}}) {
0107     $objects->{$detector} = [keys %{$o2o_config->{detector}->{$detector}->{object}}];
0108     }
0109 } else {
0110     foreach my $object (@userobjects) {
0111     my $foundit = 0;
0112     foreach my $detector (keys %{$o2o_config->{detector}}) {
0113         my @det_objects = keys %{$o2o_config->{detector}->{$detector}->{object}};
0114 
0115         if (grep {$_ eq $object} @det_objects) {
0116         $foundit = 1;
0117         unless (exists $objects->{$detector}) {
0118             $objects->{$detector} = [];
0119         }
0120         push @{$objects->{$detector}}, $object;
0121         }
0122     }
0123     if (!$foundit) {
0124         die "Object $object is not defined in $o2o_configfile";
0125     }
0126     }
0127 }
0128 
0129 print "Object array:  ", Dumper($objects), "\n" if $debug;
0130 
0131 # Begin O2O of objects
0132 foreach my $detector (keys %{$objects}) {
0133 
0134     my $offline_connect;
0135     if (!$cmd_offline_connect && exists $dba_config->{detector}->{$detector}->{offline_connect}) {
0136     $offline_connect = $dba_config->{detector}->{$detector}->{offline_connect};
0137     } elsif ($cmd_offline_connect) {
0138     $offline_connect = $cmd_offline_connect;
0139     } else {
0140     die "offline_connect not defined at command line or at $dba_configfile";
0141     }
0142 
0143     my ($offline_user, $offline_pass, $offline_db, $offline_schema) = CMSDBA::connection_test($auth, $offline_connect);
0144 
0145     foreach my $object (@{$objects->{$detector}}) {
0146     # Transfer the payload data
0147     my $sql = qq[call master_payload_o2o('$object')];
0148     $cmd = CMSDBA::get_sqlplus_cmd('user' => $general_user, 'pass' => $general_pass, 'db' => $general_db, 
0149                        'sql' => $sql);
0150     push(@commands, { 'info' => "Executing master_payload_o2o('$object')",
0151               'cmd'  => $cmd });
0152     }
0153 
0154     # Register the new objects to POOL
0155     my $library = $dba_config->{detector}->{$detector}->{poolsetup}->{library};
0156     
0157     my $dbsetup = $dba_xmldir.'/'.
0158     $dba_config->{detector}->{$detector}->{poolsetup}->{dbsetup};
0159 
0160 
0161     CMSDBA::check_files($dbsetup);
0162     
0163     $cmd = "pool_setup_database -f $dbsetup -d $library -c $offline_connect -u $offline_user -p $offline_pass";
0164     push(@commands, { 'info' => "Registering new $detector objects to POOL",
0165               'cmd'  => $cmd });
0166 
0167     foreach my $object (@{$objects->{$detector}}) {
0168     my $objref = $o2o_config->{detector}->{$detector}->{object}->{$object};
0169 
0170     # Build the IOV
0171     my $table = $objref->{table};
0172     my $tagsuffix = $objref->{tagsuffix};
0173 
0174     unless ($table && $tagsuffix) {
0175         die "Attributes table and tagsuffix are required for object name='$object' in $o2o_configfile";
0176     }
0177 
0178     my $tag = $object.'_'.$tagsuffix;
0179     my $timetype = '';
0180     my $infiniteiov = '';
0181     my $append = '-a';
0182     my $query = '';
0183 
0184     if (exists $objref->{timetype} &&
0185         $objref->{timetype} eq 'timestamp') {
0186         $timetype = '-t';
0187     } 
0188     
0189     if (exists $objref->{infiniteiov} &&
0190         $objref->{infiniteiov} eq 'true') {
0191         $infiniteiov = '-i';
0192         $append = '';
0193     }
0194 
0195     if (exists $objref->{query}) {
0196         $query = '-q '.$objref->{query};
0197     }
0198      
0199     $cmd = "cmscond_build_iov -c $offline_connect -f $catalog -u $offline_user -p $offline_pass -d $library -t $table -o $object $timetype $query $append $infiniteiov $tag";
0200     push(@commands, { 'info' => "Building IOV for $object using tag '$tag'",
0201               'cmd'  => $cmd });
0202     
0203     }
0204 }
0205 
0206 # Execution of commands
0207 CMSDBA::execute_commands('cmd_array' => \@commands, 'fake' => $fake, 'debug' => $debug, 'log' => $log);