File: migrate_RLS_entries

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (167 lines) | stat: -rwxr-xr-x 5,130 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/perl

#
# Script that migrates the entries from the EDG Replica Location Service (RLS)
# database to the new LCG File Catalog (LFC).
#

use strict;
use warnings;
use Getopt::Long;
use DBI;
use Env qw(ORACLE_HOME);

use FindBin;
use lib "$FindBin::Bin/../lib";
use Common;
use QueryAndUpdate;
use Atlas;

sub usage($) {
  my $reason = shift(@_);
  print <<EOF and   die "\nWrong usage of the script: $reason.\n";
usage: $0 --db-vendor db_vendor --host db --lrc-user lrc_user --lrc-passwd lrc_passwd --rmc-user rmc_user --rmc-passwd rmc_passwd --path path --lfc-sid lfc_sid --lfc-user lfc_user --lfc-passwd lfc_passwd [--verbose]

The RLS entries will all be migrated to the <path> directory.

If the LFN stored in the RMC is of the form "/path/to/LFN", it will be parsed, 
and the corresponding directories will be created.  
EOF
}

# Create arguments variables...
my ($vo, $db_vendor, $host, $lrc_user, $lrc_passwd, $rmc_user, $rmc_passwd, $path, $lfc_sid, $lfc_user, $lfc_passwd, $verbose);

# ... and read the arguments
GetOptions("db-vendor:s", => \$db_vendor,
	   "host:s", => \$host,
	   "lrc-user:s", => \$lrc_user,
	   "lrc-passwd:s", => \$lrc_passwd,
	   "rmc-user:s", => \$rmc_user,
	   "rmc-passwd:s", => \$rmc_passwd,
	   "path:s", => \$path,
	   "lfc-sid:s", => \$lfc_sid,
	   "lfc-user:s", => \$lfc_user,
	   "lfc-passwd:s", => \$lfc_passwd,
	   "verbose" => \$verbose );

# check CLI consistency
usage("The Database type must be specified. It can either be \'Oracle\' or \'MySQL\'") unless(defined $db_vendor);
usage("The LRC database user must be specified") unless(defined $lrc_user);
usage("The LRC user password must be specified") unless(defined $lrc_passwd);
usage("The RMC database user must be specified") unless(defined $rmc_user);
usage("The RMC user password must be specified") unless(defined $rmc_passwd);
usage("The path where to migrate the RLS entries must be specified") unless(defined $path);
usage("The LRC/RMC database host or Oracle SID must be specified") unless(defined $host);
usage("The LFC Oracle SID be specified") unless(defined $lfc_sid);
usage("The LFC database user must be specified") unless(defined $rmc_user);
usage("The LFC user password must be specified") unless(defined $rmc_passwd);


if ($db_vendor eq "Oracle") {
	usage("The RLS database Oracle SID must be specified") unless(defined $host);
} elsif ($db_vendor eq "MySQL") { 
	usage("The host where the MySQL server resides must be specified") unless(defined $host);
} else {
	usage("The Database type can only be \'Oracle\' or \'MySQL\'");
}

# useful variables
my ($start_time, $time, $end_time);
my ($dbh_lrc, $dbh_rmc, $dbh_lfc);
my ($lrc, $rmc);
my $select;
my $count;

eval {

$start_time = localtime();
print "$start_time : Starting to migrate data from the RLS to the LFC.\n"; 
print "Please wait...\n";

if ($db_vendor eq "Oracle") {
        $lrc = $lrc_user;
	$rmc = $rmc_user;

	#
	# Check ORACLE_HOME is defined
	#
	if (!defined($ORACLE_HOME) ) {
	    print STDERR "Error: ORACLE_HOME is not set! Check your Oracle installation.\n";
	    exit(1);
	}

	my @drivers = DBI->available_drivers;
	if ((my $result = grep  /Oracle/ , @drivers) == 0){
	    print STDERR "Error: Oracle DBD Module is not installed.\n";
	    exit(1);
	}

} elsif ($db_vendor eq "MySQL") {
        $lrc = "edg_lrcdb";
	$rmc = "edg_rmcdb";
}


#
# First grant select privileges to the RMC user on the LRC tables
#
    $dbh_lrc = Common::connectToDatabase("edg_lrcdb", $lrc_user, $lrc_passwd, $db_vendor, $host);

    Common::grantSelectPrivileges($dbh_lrc, "guid", $rmc_user);
    Common::grantSelectPrivileges($dbh_lrc, "pfn", $rmc_user);

    $dbh_lrc->disconnect;


#
# Connect to the LFC database
# -> to directly add the creation time, as the C API only allows to set the time to the current time)
#

    $dbh_lfc = Common::connectToDatabase("cns_db", $lfc_user, $lfc_passwd, "Oracle", $lfc_sid);


#
# Then, connect to the RMC database and query all the information from the LRC and RMC tables
#
    $dbh_rmc = Common::connectToDatabase("edg_rmcdb", $rmc_user, $rmc_passwd, $db_vendor, $host);

    #$count = QueryAndUpdate::queryFromRLSAndUpdateLFC($dbh_rmc, $lrc, $rmc, $path);
    $count = Atlas::queryFromRLSAndUpdateLFC($dbh_lfc, $dbh_rmc, $lrc_user, $rmc_user);

    $dbh_rmc->disconnect;

    $dbh_lfc->disconnect;

#
# Finally, revoke the select privileges
#
    $dbh_lrc = Common::connectToDatabase("edg_lrcdb", $lrc_user, $lrc_passwd, $db_vendor, $host);

    Common::revokeSelectPrivileges($dbh_lrc, "guid", $rmc_user);
    Common::revokeSelectPrivileges($dbh_lrc, "pfn", $rmc_user);

    $dbh_lrc->disconnect;


#
# The migration is over
#

$end_time = localtime();
print "$end_time : The data migration from the RLS to the LFC is over : $count entries have been migrated.\n";

if ($verbose) {
	print "db vendor = $db_vendor";
	print "host = $host\n"; 
	print "lrc user = $lrc_user\n";
	print "rmc user = $rmc_user\n";
	print "lrc password = $lrc_passwd\n";
	print "rmc password = $rmc_passwd\n";
        print "path= $path\n";
}

};
die ("failed to query information from the LRC and RMC tables : $@") if ($@);