Changeset 38475
- Timestamp:
- Jun 15, 2015, 2:33:16 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/tools/stsci_disks/p2_check.pl (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/stsci_disks/p2_check.pl
r38281 r38475 3 3 use DBI; 4 4 use Nebulous::Client; 5 use Nebulous::Server::SQL; 6 #use Nebulous::Util; 7 use Nebulous::Key qw( parse_neb_key parse_neb_volume ); 8 9 use SQL::Interp qw( sql_interp ); 10 5 11 6 12 use IPC::Cmd 0.36 qw( can_run run ); … … 20 26 my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1); 21 27 my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1); 28 my $staticskytool = can_run('staticskytool') or (warn "Can't find staticskytool" and $missing_tools = 1); 22 29 23 30 if ($missing_tools) { … … 26 33 } 27 34 35 my $verbose = 0; 36 my $debug = 0; 28 37 my ($stage,$stage_id,$dbname); 29 38 GetOptions( … … 34 43 35 44 45 my $camera = 'GPC1'; 46 my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set_up", $stage, $stage_id); 47 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 48 49 # Grab a volume to use for this pass. 50 my @volumes = (); 51 for (my $i = 0; $i <= 19; $i++) { 52 for (my $j = 0; $j < 3; $j++) { 53 push @volumes, sprintf("stsci%02d.%1d",$i,$j); 54 } 55 } 56 my $rand_vol = $volumes[rand @volumes]; 57 58 # Set up the logs 59 my $time = time(); 60 my $logDest = "neb://any/stsci_shuffle/${stage}/${stage}.${stage_id}.log.${time}"; 61 62 unless ($debug) { 63 $ipprc->redirect_output($logDest) or &my_die("Could not redirect output to logfile ${logDest}", $stage,$stage_id); 64 } 65 66 my $manifest_dir = "/data/${rand_vol}/MANIFEST/${stage}"; 67 system("mkdir -p ${manifest_dir}"); 68 open(MANIFEST,">${manifest_dir}/${stage}.${stage_id}.MANIFEST") || &my_die( "Could not open manifest file", $stage,$stage_id); 69 70 # Set up the nebulous database connection. 71 my ( $db, $dbhost, $dbpass, $dbuser); 72 my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config"; 73 if (-e $conffile) { 74 # printf STDERR "found config\n"; 75 open(IN,$conffile); 76 while(<IN>) { 77 chomp; 78 if ($_ =~ /NEB_DB\s+/) { 79 $db = (split /\s+/,$_)[2]; 80 } 81 elsif ($_ =~ /NEB_DBHOST/) { 82 $dbhost = (split /\s+/,$_)[2]; 83 } 84 elsif ($_ =~ /NEB_USER/) { 85 $dbuser = (split /\s+/,$_)[2]; 86 } 87 elsif ($_ =~ /NEB_PASS/) { 88 $dbpass = (split /\s+/,$_)[2]; 89 } 90 } 91 close(IN); 92 # print STDERR "$db $dbhost $dbuser $dbpass\n"; 93 } 94 95 pod2usage( -msg => "Cannot configure nebulous database", -exitval => 2) unless 96 defined $db && defined $dbhost && defined $dbuser && defined $dbpass; 97 98 my $dbh = DBI->connect( 99 "DBI:mysql:database=$db:host=$dbhost", 100 $dbuser, 101 $dbpass, 102 { 103 RaiseError => 1, 104 PrintError => 0, 105 AutoCommit => 0, 106 }, 107 ); 108 my $sql = Nebulous::Server::SQL->new(); 109 36 110 my $server = $ENV{'NEB_SERVER'}; 37 111 my $neb = Nebulous::Client->new( … … 39 113 ); 40 114 41 my $camera = 'GPC1';42 my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set_up", $stage, $stage_id);43 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files44 45 my $time = time();46 my $logDest = "neb://any/stsci_shuffle/${stage}/${stage}.${stage_id}.log.${time}";47 my $ipprc = PS::IPP::Config->new( "GPC1" ) or &my_die( "Could not create config object.", $stage,$stage_id);48 $ipprc->redirect_output($logDest) or &my_die("Could not redirect output to logfile ${logDest}", $stage,$stage_id);49 50 my $manifest_file = $ipprc->file_resolve("neb://any/stsci_shuffle/${stage}/${stage}.${stage_id}.MANIFEST",1);51 open(MANIFEST,">${manifest_file}") || &my_die( "Could not open manifest file", $stage,$stage_id);52 115 53 116 # Define which things we want to look at, and where and how many of each. … … 102 165 $time = time(); 103 166 my $dtime = $time - $otime; 104 print "LOG BEGIN $stage $stage_id $time $dtime\n";167 log_print ("LOG BEGIN $stage $stage_id $rand_vol"); 105 168 106 169 foreach my $stageEntry ( @{ $stageData } ) { … … 109 172 110 173 my $path_base = $stageEntry->{path_base}; 111 174 175 my %replicates; 176 my %culls; 177 my %md5sums_for_keys; 178 my %canonical_files; 112 179 foreach my $component (keys %components) { 113 180 my $key; … … 131 198 } 132 199 200 # I hate you, nebulous. 201 eval { 202 $key = parse_neb_key($key); 203 $key = $key->path; 204 }; 205 206 207 133 208 # Stealing most of neb-stat here 134 209 my %md5sum_uniq; … … 136 211 my @files = map {URI->new($_)->file if $_} @$instances; 137 212 my @stsci_copies = (); 213 my @stsci_volumes = (); 138 214 my @local_copies = (); 215 my @local_volumes = (); 139 216 my @existance; 140 217 my @md5sums; … … 149 226 $md5sum_uniq{$md5sums[$i]} = 1; 150 227 if ($volume =~ /stsci/) { 228 unless (defined($canonical_files{$key})) { 229 $canonical_files{$key} = $files[$i]; 230 } 151 231 push @stsci_copies, $files[$i]; 232 push @stsci_volumes, $volume; 152 233 } 153 234 elsif ($volume =~ /ipp/) { 154 235 push @local_copies, $files[$i]; 236 push @local_volumes, $volume; 155 237 } 156 238 else { &my_die("You can't exist somewhere not ipp and not stsci",$stage,$stage_id,$files[$i]); } … … 162 244 &my_die("Key $key has inconsistent md5sum values", $stage,$stage_id); 163 245 } 164 $md5sum {$key} = (keys %md5sum_uniq)[0];246 $md5sums_for_keys{$key} = (keys %md5sum_uniq)[0]; 165 247 166 248 # Do the logic at what we found 167 249 if ($#stsci_copies + 1 < $components{$component}{stsci}) { 168 250 # We need to make an stsci copy. 169 my $vol = choose_random_stsci(); 170 push @{ $replicates{$key} }, $vol; 251 push @{ $replicates{$key} }, $rand_vol; 171 252 } 172 253 if ($#local_copies + 1 < $components{$component}{local}) { 173 254 my $vol = get_volume($key); 174 while ($vol =~ /stsci/) {175 $vol = get_volume($key);176 }177 255 push @{ $replicates{$key} }, $vol; 178 256 } 179 257 if ($#stsci_copies + 1 > $components{$component}{stsci}) { 180 for (my $i = $components{$component}{stsci} + 1; $i <= $#stsci_copies; $i++) { 181 push @{ $culls{$key} }, $stsci_copies[$i]; 182 } 183 } 184 if ($#local_copies + 1 > $components{$component}{stsci}) { 185 for (my $i = $components{$component}{local} + 1; $i <= $#local_copies; $i++) { 186 push @{ $culls{$key} }, $local_copies[$i]; 187 } 188 } 189 } 190 log_print("SCAN $stage $stage_id $path_base"); 191 258 for (my $i = $components{$component}{stsci}; $i <= $#stsci_copies; $i++) { 259 push @{ $culls{$key} }, $stsci_volumes[$i]; # $stsci_copies[$i]; 260 } 261 } 262 if ($#local_copies + 1 > $components{$component}{local}) { 263 for (my $i = $components{$component}{local}; $i <= $#local_copies; $i++) { 264 push @{ $culls{$key} }, $local_volumes[$i]; # $local_copies[$i]; 265 } 266 } 267 268 my $copy_check = sprintf("ST: %d %d IPP: %d %d", 269 $#stsci_copies +1, $components{$component}{stsci}, 270 $#local_copies + 1, $components{$component}{local}); 271 log_print("SCAN $stage $stage_id $path_base $component $copy_check"); 272 } 273 274 275 if ($debug) { 276 foreach my $key (keys %replicates) { 277 foreach my $vol (@{ $replicates{$key} }) { 278 log_print("REP: $key to $vol"); 279 } 280 } 281 foreach my $key (keys %culls) { 282 foreach my $vol (@{ $culls{$key} }) { 283 log_print("CULL: $key from $vol"); 284 } 285 } 286 die; 287 } 288 192 289 foreach my $key (keys %replicates) { 193 290 foreach my $vol (@{ $replicates{$key} }) { 194 $neb->replicate($key,$vol) or &my_die "failed to replicate a copy of $key to $vol"; 291 log_print("REP: $key to $vol"); 292 $neb->replicate($key,$vol) or &my_die( "failed to replicate a copy of $key to $vol"); 195 293 if ($@) { die $@; } 196 294 } … … 203 301 my $uris = $neb->find_instances($key,$vol); 204 302 @$uris = map {URI->new($_)->file if $_} @$uris; 205 $uri = ${ $uris }[0]; 206 my $tmpmd5 = local_md5sum($uri); 207 if ($tmpmd5 ne $md5sums{$key}) { 208 &my_die "Post-replication md5sum does not match for $key on $vol! $tmpmd5 != $md5sums{$key}"; 209 } 210 } 211 } 212 log_print("CHECK $stage $stage_id $path_base"); 303 my $uri = ${ $uris }[0]; 304 my ($tmpmd5,undef) = local_md5sum($uri); 305 if ($tmpmd5 ne $md5sums_for_keys{$key}) { 306 &my_die("Post-replication md5sum does not match for $key on $vol! $tmpmd5 != $md5sums_for_keys{$key}"); 307 } 308 if ($vol =~ /stsci/) { 309 $canonical_files{$key} = $uri; 310 } 311 } 312 313 } 314 315 316 foreach my $key (keys %canonical_files) { 317 print MANIFEST "$key $canonical_files{$key} $md5sums_for_keys{$key}\n"; 318 } 319 320 log_print("CHCK $stage $stage_id $path_base"); 213 321 foreach my $key (keys %culls) { 214 322 foreach my $vol (@{ $culls{$key} }) { 323 log_print("CULL $key from $vol"); 215 324 $neb->cull($key,$vol); 216 325 } 217 326 } 218 log_print("CULL $stage $stage_id $path_base"); 219 } 327 log_print("STOP $stage $stage_id $path_base"); 328 } 329 close(MANIFEST); 220 330 221 222 331 332 sub my_die { 333 my $message = shift; 334 carp($message); 335 my $exit_code = $PS_EXIT_PROG_ERROR; 336 close(MANIFEST); 337 unlink("${manifest_dir}/${stage}.${stage_id}.MANIFEST"); 338 339 exit($exit_code); 340 } 223 341 224 342 sub log_print { 225 343 my $msg = shift; 226 $otime = $time; 344 227 345 $time = time(); 228 346 $dtime = $time - $otime; 229 print "LOG $ msg $time $dtime\n";347 print "LOG $time $dtime $msg\n"; 230 348 } 231 349 232 350 sub get_volume { 233 351 my $key = shift; 234 235 352 236 353 my ($vol_id, $vol_host, $vol_path, $xattr, $forbidden_cabinet); 237 354 my $max_used_space = 0.98; … … 278 395 $query->finish; 279 396 }; 280 281 return($vol_host); 397 &my_die($@) if $@; 398 399 if (defined($vol_host)) { 400 if ($vol_host eq 'ipp066') { 401 $vol_host = get_volume($key); 402 if ($vol_host eq 'ipp066') { 403 # Really? 404 $vol_host = get_volume($key); 405 # if ($vol_host eq 'ipp066') {} #fine. Be that way. Jerk. 406 # 407 } 408 } 409 } 410 411 return($vol_host . ".0"); 282 412 } 283 413 284 285 414 sub local_md5sum { 286 415 my $filename = shift; … … 289 418 $host =~ s/\.\d//; 290 419 # print "$filename $host $volume\n"; 291 my $response = `ssh $host md5sum $filename`;420 my $response = `ssh -x $host md5sum $filename`; 292 421 chomp($response); 293 422 my ($sum, undef) = split /\s+/, $response;
Note:
See TracChangeset
for help on using the changeset viewer.
