- Timestamp:
- Sep 7, 2010, 9:16:10 AM (16 years ago)
- Location:
- branches/eam_branches/ipp-20100823
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/perl/checkOdmStatus.pl (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823
-
branches/eam_branches/ipp-20100823/ippToPsps/perl/checkOdmStatus.pl
r28954 r29124 10 10 use ippToPsps::IppToPspsDb; 11 11 use ippToPsps::Datastore; 12 use ippToPsps::BatchManager; 12 13 13 14 my $singleBatch = undef; … … 17 18 my $toTime = undef; 18 19 my $product = undef; 20 my $filePath = undef; 19 21 20 22 … … 24 26 'to|t=s' => \$toTime, 25 27 'product|p=s' => \$product, 28 'location|l=s' => \$filePath, 26 29 'verbose|v' => \$verbose, 27 30 'save_temps|s' => \$save_temps … … 32 35 } 33 36 if (!defined $singleBatch) { 34 print "* OPTIONAL: a single batch -b (default = none)\n";37 print "* OPTIONAL: a single batch -b <batchNum> (default = none)\n"; 35 38 } 36 39 if (!defined $fromTime) { 37 40 $fromTime = "2010-01-01"; 38 print "* OPTIONAL: from time -f (default = $fromTime)\n";41 print "* OPTIONAL: from time -f <dateTime> (default = $fromTime)\n"; 39 42 } 40 43 if (!defined $toTime) { 41 44 $toTime = "2099-12-31"; 42 print "* OPTIONAL: to time -t (default = $toTime)\n"; 45 print "* OPTIONAL: to time -t <dateTime> (default = $toTime)\n"; 46 } 47 if (!defined $filePath) { 48 print "* OPTIONAL: location for files to be deleted -l <path>\n"; 43 49 } 44 50 if (!defined $verbose) { … … 54 60 my $datastore = new ippToPsps::Datastore($product, 0, 0); 55 61 my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps); 62 my $batchManager = new ippToPsps::BatchManager($ippToPspsDb, $filePath, $verbose, $save_temps); 56 63 my $odmUrl = "http://web01.psps.ifa.hawaii.edu/a01/OdmWebService/OdmWebService.asmx/GetBatchStatus"; 57 64 my $ua = LWP::UserAgent->new; … … 72 79 my $numOfBatches; 73 80 74 if (defined $singleBatch ) { $numOfBatches = $ippToPspsDb->get SingleBatch($singleBatch, \$batches);}75 else { $numOfBatches = $ippToPspsDb->getBatch List(\$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 = $batchManager->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 # if merged and already removed from datastore then delete files 122 if (defined $filePath && $merged && $deleted) { 123 124 if($batchManager->deleteBatch($batchId)) {$numDeleted++;} 125 } 126 127 # update database 128 $ippToPspsDb->updateODMStatus($batchId, $expId, $loadedToOdm, $mergeWorthy, $merged, $deleted); 129 printf( "| %18s | %11s | %10d | %6s | %6s | %6s | %5s |\n", 130 $timestamp, 131 $batchName, 132 $expId, 133 $loadedToOdm ? "yes" : "no", 134 $mergeWorthy ? "yes" : "no", 135 $merged ? "yes" : "no", 136 $deleted ? "yes" : "no"); 92 137 } 138 93 139 printf("+----------------------+--------------+--------------+----------------+---------------+---------+----------+\n"); 94 140 95 printf( "* Successfully checked %d batch%s out of %d\n", $numChecked, ($numChecked==1) ? "" : "es", $numOfBatches); 96 97 } 98 99 ######################################################################################y 141 printf( "* Successfully checked %d batch%s out of %d\n", $numChecked, ($numChecked==1) ? "" : "es", $numBatchesToCheck); 142 printf( "* Successfully removed %d batch%s from the datastore\n", $numRemovedFromDatastore, ($numRemovedFromDatastore==1) ? "" : "es"); 143 printf( "* Successfully deleted %d batch%s from local file system\n", $numDeleted, ($numDeleted==1) ? "" : "es"); 144 145 } 146 147 ######################################################################################## 100 148 # 101 149 # Check a single batch 102 150 # 103 151 ######################################################################################## 104 sub checkBatch { 105 my ($timestamp, $expId, $batchId, $surveyType, $deleted) = @_; 106 107 108 my $batchFilter = sprintf("B%08d", $batchId); 152 sub checkODM { 153 my ($batchName, $loadedToOdm, $mergeWorthy, $merged) = @_; 154 109 155 my $statusFilter = "*"; 110 156 111 157 my $response = $ua->post($odmUrl, 112 [batchNameFilter => $batchFilter,158 [batchNameFilter => "%".$batchName, 113 159 statusFilter => $statusFilter, 114 160 fromFilter => "2010-01-01", … … 119 165 if ($response->code != 200) { 120 166 121 print "Problem connecting to web service for '$batch Filter', HTTP response status: ".$response->status_line."\n";122 return ;167 print "Problem connecting to web service for '$batchName', HTTP response status: ".$response->status_line."\n"; 168 return 0; 123 169 } 124 170 # print( "HTTP response status: ".$response->content."\n" ); … … 128 174 close($tempFile); 129 175 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 176 ${$loadedToOdm} = 0; 177 ${$mergeWorthy} = 0; 178 ${$merged} = 0; 179 180 parseXml($tempName, $loadedToOdm, $mergeWorthy, $merged); 181 182 return 1; 159 183 } 160 184 … … 165 189 ######################################################################################## 166 190 sub parseXml { 167 my ($xmlFile, $loadedToOdm, $mergeWorthy, $merge Completed) = @_;191 my ($xmlFile, $loadedToOdm, $mergeWorthy, $merged) = @_; 168 192 169 193 my $parser = XML::LibXML->new; … … 174 198 ${$loadedToOdm} = 0; 175 199 ${$mergeWorthy} = 0; 176 ${$merge Completed} = 0;200 ${$merged} = 0; 177 201 178 202 if ($result =~ m/LoadStarted/) { ${$loadedToOdm} = 1;} 179 203 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 204 if ($result =~ m/Merge[1-9]Completed/) { ${$loadedToOdm} = 1; ${$mergeWorthy} = 1; ${$merged} = 1;} 205 } 206
Note:
See TracChangeset
for help on using the changeset viewer.
