Changeset 29093
- Timestamp:
- Sep 1, 2010, 12:33:59 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/perl/checkOdmStatus.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/perl/checkOdmStatus.pl
r29082 r29093 5 5 6 6 use LWP::UserAgent; 7 use IPC::Cmd 0.36 qw( can_run run ); 8 use IPC::Cmd 0.36 qw( can_run run ); 7 9 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 8 10 use XML::LibXML; … … 17 19 my $toTime = undef; 18 20 my $product = undef; 21 my $filePath = undef; 19 22 20 23 … … 24 27 'to|t=s' => \$toTime, 25 28 'product|p=s' => \$product, 29 'location|l=s' => \$filePath, 26 30 'verbose|v' => \$verbose, 27 31 'save_temps|s' => \$save_temps … … 41 45 $toTime = "2099-12-31"; 42 46 print "* OPTIONAL: to time -t <dateTime> (default = $toTime)\n"; 47 } 48 if (!defined $filePath) { 49 print "* OPTIONAL: location for files to be deleted -l <path>\n"; 43 50 } 44 51 if (!defined $verbose) { … … 72 79 my $numOfBatches; 73 80 74 if (defined $singleBatch ) { $numOfBatches = $ippToPspsDb->get SingleBatchOnDatastore($singleBatch, \$batches);}75 else { $numOfBatches = $ippToPspsDb->get ListOfBatchesOnDatastore(\$batches, $fromTime, $toTime);}81 if (defined $singleBatch ) { $numOfBatches = $ippToPspsDb->getBatch($singleBatch, \$batches);} 82 else { $numOfBatches = $ippToPspsDb->getBatches(\$batches, $fromTime, $toTime);} 76 83 77 84 if ($numOfBatches < 1) {return 0;} … … 84 91 # loop round batches 85 92 my $batch; 93 my $numBatchesToCheck = 0; 86 94 my $numChecked = 0; 95 my $numRemovedFromDatastore = 0; 96 my $numDeleted = 0; 87 97 foreach $batch ( @{$batches} ) { 88 my ($timestamp, $expId, $batchId, $surveyType, $deleted) = @{$batch}; 89 90 if (checkBatch($timestamp, $expId, $batchId, $surveyType, $deleted)) {$numChecked++;} 91 98 my ($timestamp, $expId, $batchId, $surveyType, $deleted, $dvoDb, $processed, $onDatastore, $loadedToOdm, $mergeWorthy, $merged) = @{$batch}; 99 100 if (!$processed) {next;} 101 102 $numBatchesToCheck++; 103 104 my $batchName = getBatchName($batchId); 105 106 # if not merged then update by polling ODM for status 107 if (!$merged) { 108 109 if (checkODM($batchName, \$loadedToOdm, \$mergeWorthy, \$merged)) {$numChecked++;} 110 } 111 112 # delete from datastore 113 if (defined $product && !$deleted && $loadedToOdm && $mergeWorthy) { 114 115 $deleted = $datastore->remove($batchName); 116 if ($deleted) { 117 $ippToPspsDb->setBatchAsDeleted($batchId, $expId); 118 $numRemovedFromDatastore++; 119 } 120 } 121 122 # if merged and already removed from datastore then delete files 123 if (defined $filePath && $merged && $deleted) { 124 125 print "$command\n"; 126 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 127 run(command => $command, verbose => $verbose); 128 if (!$success) {print "* Unable to run: $command\n";} 129 else {$numDeleted++;} 130 } 131 132 # update database 133 $ippToPspsDb->updateODMStatus($batchId, $expId, $loadedToOdm, $mergeWorthy, $merged, $deleted); 134 printf( "| %18s | %11s | %10d | %6s | %6s | %6s | %5s |\n", 135 $timestamp, 136 $batchName, 137 $expId, 138 $loadedToOdm ? "yes" : "no", 139 $mergeWorthy ? "yes" : "no", 140 $merged ? "yes" : "no", 141 $deleted ? "yes" : "no"); 92 142 } 143 93 144 printf("+----------------------+--------------+--------------+----------------+---------------+---------+----------+\n"); 94 145 95 printf( "* Successfully checked %d batch%s out of %d\n", $numChecked, ($numChecked==1) ? "" : "es", $numOfBatches); 96 97 } 98 99 ######################################################################################y 146 printf( "* Successfully checked %d batch%s out of %d\n", $numChecked, ($numChecked==1) ? "" : "es", $numBatchesToCheck); 147 printf( "* Successfully removed %d batch%s from the datastore\n", $numRemovedFromDatastore, ($numRemovedFromDatastore==1) ? "" : "es"); 148 printf( "* Successfully deleted %d batch%s from local file system\n", $numDeleted, ($numDeleted==1) ? "" : "es"); 149 150 } 151 152 ######################################################################################## 153 # 154 # Returns batch name from batch_id TODO needs to be a batch class 155 # 156 ######################################################################################## 157 sub getBatchName { 158 my ($batchId) = @_; 159 160 return sprintf("B%08d", $batchId); 161 } 162 163 ######################################################################################## 100 164 # 101 165 # Check a single batch 102 166 # 103 167 ######################################################################################## 104 sub checkBatch { 105 my ($timestamp, $expId, $batchId, $surveyType, $deleted) = @_; 106 107 108 my $batchFilter = sprintf("B%08d", $batchId); 168 sub checkODM { 169 my ($batchName, $loadedToOdm, $mergeWorthy, $merged) = @_; 170 109 171 my $statusFilter = "*"; 110 172 111 173 my $response = $ua->post($odmUrl, 112 [batchNameFilter => "%".$batch Filter,174 [batchNameFilter => "%".$batchName, 113 175 statusFilter => $statusFilter, 114 176 fromFilter => "2010-01-01", … … 119 181 if ($response->code != 200) { 120 182 121 print "Problem connecting to web service for '$batch Filter', HTTP response status: ".$response->status_line."\n";122 return ;183 print "Problem connecting to web service for '$batchName', HTTP response status: ".$response->status_line."\n"; 184 return 0; 123 185 } 124 186 # print( "HTTP response status: ".$response->content."\n" ); … … 128 190 close($tempFile); 129 191 130 my $loadedToOdm = 0; 131 my $mergeWorthy = 0; 132 my $mergeCompleted = 0; 133 134 parseXml($tempName, \$loadedToOdm, \$mergeWorthy, \$mergeCompleted); 135 136 # delete from datastore 137 if(defined $product) { 138 139 if (!$deleted && $loadedToOdm && $mergeWorthy) { 140 141 $deleted = $datastore->remove($batchFilter); 142 if ($deleted) { 143 $ippToPspsDb->setBatchAsDeleted($batchId, $expId); 144 } 145 } 146 } 147 148 printf( "| %18s | %11s | %10d | %6s | %6s | %6s | %5s |\n", 149 $timestamp, 150 $batchFilter, 151 $expId, 152 $loadedToOdm ? "yes" : "no", 153 $mergeWorthy ? "yes" : "no", 154 $mergeCompleted ? "yes" : "no", 155 $deleted ? "yes" : "no"); 156 157 $ippToPspsDb->updateODMStatus($batchId, $expId, $loadedToOdm, $mergeWorthy, $mergeCompleted, $deleted); 158 192 ${$loadedToOdm} = 0; 193 ${$mergeWorthy} = 0; 194 ${$merged} = 0; 195 196 parseXml($tempName, $loadedToOdm, $mergeWorthy, $merged); 197 198 return 1; 159 199 } 160 200 … … 165 205 ######################################################################################## 166 206 sub parseXml { 167 my ($xmlFile, $loadedToOdm, $mergeWorthy, $merge Completed) = @_;207 my ($xmlFile, $loadedToOdm, $mergeWorthy, $merged) = @_; 168 208 169 209 my $parser = XML::LibXML->new; … … 174 214 ${$loadedToOdm} = 0; 175 215 ${$mergeWorthy} = 0; 176 ${$merge Completed} = 0;216 ${$merged} = 0; 177 217 178 218 if ($result =~ m/LoadStarted/) { ${$loadedToOdm} = 1;} 179 219 if ($result =~ m/MergeWorthy/) { ${$loadedToOdm} = 1; ${$mergeWorthy} = 1;} 180 if ($result =~ m/Merge[1-9]Completed/) { ${$loadedToOdm} = 1; ${$mergeWorthy} = 1; ${$merge Completed} = 1;}181 } 182 220 if ($result =~ m/Merge[1-9]Completed/) { ${$loadedToOdm} = 1; ${$mergeWorthy} = 1; ${$merged} = 1;} 221 } 222
Note:
See TracChangeset
for help on using the changeset viewer.
