Changeset 38281
- Timestamp:
- May 15, 2015, 3:50:54 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/tools/stsci_disks/p2_check.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/stsci_disks/p2_check.pl
r38279 r38281 33 33 ) || pod2usage(2 ); 34 34 35 36 my $server = $ENV{'NEB_SERVER'}; 37 my $neb = Nebulous::Client->new( 38 proxy => "$server", 39 ); 40 35 41 my $camera = 'GPC1'; 36 42 my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set_up", $stage, $stage_id); 37 43 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 38 44 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); 39 52 40 53 # Define which things we want to look at, and where and how many of each. … … 58 71 'PPSTACK.UNCONV.EXPWT' => { 'local' => 2, 'stsci' => 1 }, 59 72 'PSPHOT.PSF.SKY.SAVE' => { 'local' => 2, 'stsci' => 1 }, 60 'PSPHOT. OUT.CMF.MEF' => { 'local' => 2, 'stsci' => 1 },73 'PSPHOT.STACK.OUTPUT' => { 'local' => 2, 'stsci' => 1 }, 61 74 'PPSTACK.CONFIG' => { 'local' => 2, 'stsci' => 1} 62 75 … … 85 98 my @keylist = (); 86 99 100 87 101 my $otime = $time; 88 102 $time = time(); … … 97 111 98 112 foreach my $component (keys %components) { 99 my $key = $ipprc->filename($component,$path_base); 113 my $key; 114 if (($stage eq 'stack')&&($component eq 'PSPHOT.STACK.OUTPUT')) { 115 # Do special things to get to skycalresult 116 my $ss_command = "$staticskytool -skycalresult -stack_id $stage_id -label LAP.PV3.20140730.skycal01 -dbname $dbname"; 117 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 118 run(command => $command, verbose => $verbose); 119 unless ($success) { 120 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 121 &my_die("Unable to run STAGEtool -liststagestuff ", $stage,$stage_id); 122 } 123 my $SS_MDlist = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to run STAGEtool -liststagestuff ", $stage,$stage_id); 124 my $SS_data = parse_md_list($MDlist); 125 my $SSRun = ${ $SS_data }[0]; 126 my $SS_pb = $SSRun->{path_base}; 127 $key = $ipprc->filename($component,$SS_pb); 128 } 129 else { 130 $key = $ipprc->filename($component,$path_base); 131 } 100 132 101 133 # Stealing most of neb-stat here … … 117 149 $md5sum_uniq{$md5sums[$i]} = 1; 118 150 if ($volume =~ /stsci/) { 119 $stsci_count++; 120 $stsci_copies[$i] = 1; 121 $local_copies[$i] = 0; 151 push @stsci_copies, $files[$i]; 122 152 } 123 153 elsif ($volume =~ /ipp/) { 124 $local_count++; 125 $stsci_copies[$i] = 0; 126 $local_copies[$i] = 1; 154 push @local_copies, $files[$i]; 127 155 } 128 156 else { &my_die("You can't exist somewhere not ipp and not stsci",$stage,$stage_id,$files[$i]); } 129 130 } 131 } 132 157 } 158 } 159 160 # Check that we have only one md5sum value. 161 if (scalar(keys %md5sum_uniq) != 1) { 162 &my_die("Key $key has inconsistent md5sum values", $stage,$stage_id); 163 } 164 $md5sum{$key} = (keys %md5sum_uniq)[0]; 165 133 166 # Do the logic at what we found 134 135 136 137 138 139 140 141 142 143 my $server = $ENV{'NEB_SERVER'}; 144 my $neb = Nebulous::Client->new( 145 proxy => "$server", 146 ); 147 148 149 foreach my $subdir (@subdirectories) { 150 my @files = <${subdir}/*>; 151 152 my @belongs; 153 my @keys; 154 my @vols; 155 my @md5sums; 156 157 # Pre scan 158 for (my $i = 0; $i <= $#files; $i++) { 159 my $f = $files[$i]; 160 my ($ins_id, $belongs); 161 $ins_id = $f; 162 $ins_id =~ s/^$subdir\///; 163 $ins_id =~ s/\..*//; 164 165 $belongs[$i] = 0; 166 167 if ($ins_id > 4956576912) { 168 if ($f =~ /LAP.PV3.20140730/) { # Only PV3 169 if (($f =~ /wrp/)) { 170 if (($f =~ /fits/)||($f =~ /cmf/)||($f =~ /psf/)) { 171 $belongs[$i] = 1; 172 } 173 } 174 if (($f =~ /stk/)&&($f =~ /fits/)&&($f =~ /unconv/)) { 175 $belongs[$i] = 1; 176 } 177 } 178 } 179 180 if ($belongs[$i] == 0) { 181 $keys[$i] = $f; 182 $keys[$i] =~ s/.*\/${ins_id}\.//; 183 $keys[$i] =~ s%:%/%g; 184 # Compressed fits 185 if ($keys[$i] =~ /.fits.fz$/) { 186 $keys[$i] =~ s/.fits.fz$/.fits/; 187 } 188 189 $md5sums[$i] = local_md5sum($f); 190 # Get a target 191 $vols[$i] = get_volume($keys[$i]); 192 if (defined($vols[$i])) { 193 $vols[$i] = $vols[$i] . ".0"; 194 } 195 } 196 elsif ($belongs[$i] == 1) { 197 $md5sums[$i] = 'NOT_CALCULATED'; 198 $vols[$i] = 'ippXXX.Y'; 199 $keys[$i] = 'NO_REPLICATE'; 200 } 201 if (defined($vols[$i])) { 202 print "## $ins_id $md5sums[$i] $vols[$i] $belongs[$i] $f $keys[$i] \n"; 203 } 204 else { 205 print "## $ins_id $md5sums[$i] NOVOL_BECAUSE_UNKNOWN $belongs[$i] $f $keys[$i] \n"; 206 } 207 } 167 if ($#stsci_copies + 1 < $components{$component}{stsci}) { 168 # We need to make an stsci copy. 169 my $vol = choose_random_stsci(); 170 push @{ $replicates{$key} }, $vol; 171 } 172 if ($#local_copies + 1 < $components{$component}{local}) { 173 my $vol = get_volume($key); 174 while ($vol =~ /stsci/) { 175 $vol = get_volume($key); 176 } 177 push @{ $replicates{$key} }, $vol; 178 } 179 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 192 foreach my $key (keys %replicates) { 193 foreach my $vol (@{ $replicates{$key} }) { 194 $neb->replicate($key,$vol) or &my_die "failed to replicate a copy of $key to $vol"; 195 if ($@) { die $@; } 196 } 197 } 198 system("sync") == 0 or die "Couldn't sync?"; 199 log_print("REPL $stage $stage_id $path_base"); 200 201 foreach my $key (keys %replicates) { 202 foreach my $vol (@{ $replicates{$key} }) { 203 my $uris = $neb->find_instances($key,$vol); 204 @$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"); 213 foreach my $key (keys %culls) { 214 foreach my $vol (@{ $culls{$key} }) { 215 $neb->cull($key,$vol); 216 } 217 } 218 log_print("CULL $stage $stage_id $path_base"); 219 } 220 221 222 223 224 sub log_print { 225 my $msg = shift; 208 226 $otime = $time; 209 227 $time = time(); 210 228 $dtime = $time - $otime; 211 print "LOG SCAN $subdir $time $dtime\n"; 212 # die; 213 # Do a replication pass 214 for (my $i = 0; $i <= $#files; $i++) { 215 if ($belongs[$i] == 0) { 216 if (defined($vols[$i])) { 217 $neb->replicate($keys[$i],$vols[$i]) or die "failed to replicate a copy to the backup node"; 218 if ($@) { die $@; } 219 } 220 else { 221 # Key wasn't defiend 222 my $dir = dirname($keys[$i]); 223 system("mkdir -p ${unknown_dir}/${dir}"); 224 system("cp -a $files[$i] ${unknown_dir}/$keys[$i]"); 225 } 226 system("sync") == 0 or die "Couldn't sync?"; 227 } 228 } 229 $otime = $time; 230 $time = time(); 231 $dtime = $time - $otime; 232 print "LOG REPL $subdir $time $dtime\n"; 233 234 # Do the check pass 235 for (my $i = 0; $i <= $#files; $i++) { 236 my $uri; 237 if ($belongs[$i] == 0) { 238 if (defined($vols[$i])) { 239 my $uris = $neb->find_instances($keys[$i],$vols[$i]); 240 @$uris = map {URI->new($_)->file if $_} @$uris; 241 $uri = ${ $uris }[0]; 242 } 243 else { 244 $uri = "${unknown_dir}/$keys[$i]"; 245 } 246 247 my $tmpmd5 = local_md5sum($uri); 248 if ($tmpmd5 ne $md5sums[$i]) { 249 die "Post-replication md5sum does not match! $tmpmd5 != $md5sums[$i]"; 250 } 251 # End my best validation thought. 252 253 if (defined($vols[$i])) { 254 $neb->cull($keys[$i],$host . "." . $volume); 255 } 256 else { 257 system("rm $files[$i]"); 258 } 259 } 260 } 261 262 $otime = $time; 263 $time = time(); 264 $dtime = $time - $otime; 265 print "LOG END $subdir $time $dtime\n"; 266 die; 229 print "LOG $msg $time $dtime\n"; 267 230 } 268 231 … … 319 282 } 320 283 321 322 sub secure_replicull {323 my $key = shift;324 my $md5sum = shift;325 my $rep_vol = shift;326 my $del_vol = shift;327 328 $neb->replicate($key,$rep_vol) or die "failed to replicate a copy to the backup node";329 if ($@) { die $@; }330 331 # Begin my best validation thought332 system("sync") == 0 or die "Couldn't sync?";333 my $uris = $neb->find_instances($key,$rep_vol);334 @$uris = map {URI->new($_)->file if $_} @$uris;335 my $tmpmd5 = local_md5sum(${ $uris }[0]);336 if ($tmpmd5 ne $md5sum) {337 sleep(2);338 $tmpmd5 = local_md5sum(${ $uris }[0]);339 if ($tmpmd5 ne $md5sum) {340 die "Post-replication md5sum does not match! $tmpmd5 != $md5sum";341 }342 }343 # End my best validation thought.344 345 $neb->cull($key,$del_vol);346 }347 284 348 285 sub local_md5sum {
Note:
See TracChangeset
for help on using the changeset viewer.
