Changeset 33684 for trunk/ippToPsps
- Timestamp:
- Apr 3, 2012, 4:41:21 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/ipptopspsdb.py (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/ipptopspsdb.py
r33573 r33684 25 25 Returns a list of merged batch IDs that are merged but not yet deleted 26 26 ''' 27 def getMergedButNotDeletedBatchIDs(self, batchType, epoch, dvoGpc1Label,column):27 def getMergedButNotDeletedBatchIDs(self, batchType, column): 28 28 29 29 sql = "SELECT DISTINCT batch_id \ 30 30 FROM batch \ 31 WHERE timestamp > '" + epoch + "' \31 WHERE timestamp > '" + self.config.epoch + "' \ 32 32 AND batch_type = '" + batchType + "' \ 33 AND dvo_db = '" + dvoGpc1Label + "' \33 AND dvo_db = '" + self.config.dvoLabel + "' \ 34 34 AND merged = 1 \ 35 35 AND " + column + " = 0" … … 50 50 Returns a list of batch IDs marked as 'purged' but not yet deleted 51 51 ''' 52 def getPurgedButNotDeletedBatchIDs(self, batchType, epoch, dvoGpc1Label,column):52 def getPurgedButNotDeletedBatchIDs(self, batchType, column): 53 53 54 54 sql = "SELECT DISTINCT batch_id \ 55 55 FROM batch \ 56 WHERE timestamp > '" + epoch + "' \56 WHERE timestamp > '" + self.config.epoch + "' \ 57 57 AND batch_type = '" + batchType + "' \ 58 AND dvo_db = '" + dvoGpc1Label + "' \58 AND dvo_db = '" + self.config.dvoLabel + "' \ 59 59 AND purged = 1 \ 60 60 AND " + column + " = 0" … … 76 76 Returns a list of processed batch IDs that have been loaded to the ODM but not yet deleted 77 77 ''' 78 def getLoadedToODMButNotDeletedBatchIDs(self, batchType, epoch, dvoGpc1Label,column):78 def getLoadedToODMButNotDeletedBatchIDs(self, batchType, column): 79 79 80 80 sql = "SELECT DISTINCT batch_id \ 81 81 FROM batch \ 82 WHERE timestamp > '" + epoch + "' \82 WHERE timestamp > '" + self.config.epoch + "' \ 83 83 AND batch_type = '" + batchType + "' \ 84 AND dvo_db = '" + dvoGpc1Label + "' \84 AND dvo_db = '" + self.config.dvoLabel + "' \ 85 85 AND (loaded_to_ODM = -1 OR merge_worthy = 1) \ 86 86 AND " + column + " = 0" … … 101 101 Returns a list of merged batch IDs that are not deleted from local disk 102 102 ''' 103 def getMergedButNotDeletedFromLocalDisk(self, batchType , epoch, dvoGpc1Label):104 return self.getMergedButNotDeletedBatchIDs(batchType, epoch, dvoGpc1Label,"deleted_local")103 def getMergedButNotDeletedFromLocalDisk(self, batchType): 104 return self.getMergedButNotDeletedBatchIDs(batchType, "deleted_local") 105 105 106 106 ''' 107 107 Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from local disk 108 108 ''' 109 def getLoadedToODMButNotDeletedFromLocalDisk(self, batchType , epoch, dvoGpc1Label):110 return self.getLoadedToODMButNotDeletedBatchIDs(batchType, epoch, dvoGpc1Label,"deleted_local")109 def getLoadedToODMButNotDeletedFromLocalDisk(self, batchType): 110 return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_local") 111 111 112 112 ''' 113 113 Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from datastore 114 114 ''' 115 def getLoadedToODMButNotDeletedFromDatastore(self, batchType , epoch, dvoGpc1Label):116 return self.getLoadedToODMButNotDeletedBatchIDs(batchType, epoch, dvoGpc1Label,"deleted_datastore")115 def getLoadedToODMButNotDeletedFromDatastore(self, batchType): 116 return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_datastore") 117 117 118 118 ''' 119 119 Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from DXLayer 120 120 ''' 121 def getLoadedToODMButNotDeletedFromDXLayer(self, batchType , epoch, dvoGpc1Label):122 return self.getLoadedToODMButNotDeletedBatchIDs(batchType, epoch, dvoGpc1Label,"deleted_dxlayer")121 def getLoadedToODMButNotDeletedFromDXLayer(self, batchType): 122 return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_dxlayer") 123 123 124 124 ''' 125 125 Returns a list of purged batch IDs that not deleted from local disk 126 126 ''' 127 def getPurgedButNotDeletedFromLocalDisk(self, batchType , epoch, dvoGpc1Label):128 return self.getPurgedButNotDeletedBatchIDs(batchType, epoch, dvoGpc1Label,"deleted_local")127 def getPurgedButNotDeletedFromLocalDisk(self, batchType): 128 return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_local") 129 129 130 130 ''' 131 131 Returns a list of purged batch IDs that are not deleted from datastore 132 132 ''' 133 def getPurgedButNotDeletedFromDatastore(self, batchType , epoch, dvoGpc1Label):134 return self.getPurgedButNotDeletedBatchIDs(batchType, epoch, dvoGpc1Label,"deleted_datastore")133 def getPurgedButNotDeletedFromDatastore(self, batchType): 134 return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_datastore") 135 135 136 136 … … 144 144 publish something simulataneously with the client that it producing it 145 145 ''' 146 def getProcessedButFailedDatastoreBatchIDs(self, epoch, dvoGpc1Label,batchType):146 def getProcessedButFailedDatastoreBatchIDs(self, batchType): 147 147 148 148 sql = "SELECT DISTINCT batch_id \ 149 149 FROM batch \ 150 WHERE timestamp > '" + epoch + "' \150 WHERE timestamp > '" + self.config.epoch + "' \ 151 151 AND batch_type = '" + batchType + "' \ 152 AND dvo_db = '" + dvoGpc1Label + "' \152 AND dvo_db = '" + self.config.dvoLabel + "' \ 153 153 AND processed = 1\ 154 154 AND loaded_to_datastore != 1 \ … … 173 173 NOTE we exclude batches already deleted from the datastore, as sometimes we delete stuff prior to loading to ODM if there is a known problem with the batch 174 174 ''' 175 def getUnloadedBatchIDs(self, epoch, dvoGpc1Label,batchType):175 def getUnloadedBatchIDs(self, batchType): 176 176 177 177 sql = "SELECT batch_id \ 178 178 FROM batch \ 179 WHERE timestamp > '" + epoch + "' \180 AND dvo_db = '" + dvoGpc1Label + "' \179 WHERE timestamp > '" + self.config.epoch + "' \ 180 AND dvo_db = '" + self.config.dvoLabel + "' \ 181 181 AND loaded_to_datastore = 1 \ 182 182 AND batch_type = '" + batchType + "' \ … … 191 191 except: 192 192 self.logger.exception("Can't query for unloaded batch ids in ipptopsps Db") 193 194 rs.close()193 finally: 194 rs.close() 195 195 196 196 self.logger.debug("Found %d unloaded items" % len(ids)) … … 202 202 NOTE we exclude batches already deleted from the datastore, as sometimes we delete stuff prior to loading to ODM if there is a known problem with the batch 203 203 ''' 204 def getUnmergeWorthyBatchIDs(self, epoch, dvoGpc1Label,batchType):204 def getUnmergeWorthyBatchIDs(self, batchType): 205 205 206 206 sql = "SELECT batch_id \ 207 207 FROM batch \ 208 WHERE timestamp > '" + epoch + "' \209 AND dvo_db = '" + dvoGpc1Label + "' \208 WHERE timestamp > '" + self.config.epoch + "' \ 209 AND dvo_db = '" + self.config.dvoLabel + "' \ 210 210 AND loaded_to_datastore = 1 \ 211 211 AND batch_type = '" + batchType + "' \ … … 221 221 except: 222 222 self.logger.exception("Can't query for un-mergeworthy batch ids in ipptopsps Db") 223 224 rs.close()223 finally: 224 rs.close() 225 225 226 226 self.logger.debug("Found %d unloaded items" % len(ids)) … … 231 231 Returns a list of processed batch IDs that are merge_worthy, but not yet merged, for this epoch and dvo label 232 232 ''' 233 def getUnmergedBatchIDs(self, epoch, dvoGpc1Label,batchType):233 def getUnmergedBatchIDs(self, batchType): 234 234 235 235 sql = "SELECT batch_id \ 236 236 FROM batch \ 237 WHERE timestamp > '" + epoch + "' \238 AND dvo_db = '" + dvoGpc1Label + "' \237 WHERE timestamp > '" + self.config.epoch + "' \ 238 AND dvo_db = '" + self.config.dvoLabel + "' \ 239 239 AND merge_worthy = 1 \ 240 240 AND batch_type = '" + batchType + "' \ … … 248 248 except: 249 249 self.logger.exception("Can't query for unmerged batch ids in ipptopsps Db") 250 251 rs.close()250 finally: 251 rs.close() 252 252 253 253 self.logger.debug("Found %d un-merged items" % len(ids)) … … 258 258 Returns a list of batch IDs for this epoch and dvo label for which the specified column is set to value 259 259 ''' 260 def getBatchIDs(self, epoch, dvoGpc1Label,column, value):260 def getBatchIDs(self, column, value): 261 261 262 262 sql = "SELECT DISTINCT batch_id \ 263 263 FROM batch \ 264 WHERE timestamp > '" + epoch + "' \265 AND dvo_db = '" + dvoGpc1Label + "' \264 WHERE timestamp > '" + self.config.epoch + "' \ 265 AND dvo_db = '" + self.config.dvoLabel + "' \ 266 266 AND " + column + " = " + str(value) 267 267 … … 283 283 Returns the total detections published to the datastore for this epoch, dvo label and batch type 284 284 ''' 285 def getTotalDetectionsPublished(self, batchType, epoch, dvoGpc1Label,interval="10 YEAR"):285 def getTotalDetectionsPublished(self, batchType, interval="10 YEAR"): 286 286 287 287 sql = "SELECT SUM(total_detections) \ 288 288 FROM batch \ 289 289 WHERE batch_type = '" + batchType + "' \ 290 AND timestamp > '" + epoch + "' \291 AND dvo_db = '" + dvoGpc1Label + "' \290 AND timestamp > '" + self.config.epoch + "' \ 291 AND dvo_db = '" + self.config.dvoLabel + "' \ 292 292 AND processed = 1 \ 293 293 AND loaded_to_datastore = 1 \ … … 300 300 total = rs.getLong(1) 301 301 except: 302 self.logger.e xception("Can't query for total detections published")302 self.logger.errorPair("Can't get total detections published", sql) 303 303 finally: 304 304 rs.close() 305 306 self.logger.debug("Found %d detections" % total)307 305 308 306 return total … … 312 310 cam_ids or stack_ids) for which the specified column is set to value 313 311 ''' 314 def getStageIDs(self, batchType, epoch, dvoGpc1Label,column, value):312 def getStageIDs(self, batchType, column, value): 315 313 316 314 sql = "SELECT DISTINCT stage_id \ 317 315 FROM batch \ 318 316 WHERE batch_type = '" + batchType + "' \ 319 AND timestamp > '" + epoch + "' \320 AND dvo_db = '" + dvoGpc1Label + "' \317 AND timestamp > '" + self.config.epoch + "' \ 318 AND dvo_db = '" + self.config.dvoLabel + "' \ 321 319 AND " + column + " = " + str(value) 322 320 … … 328 326 except: 329 327 self.logger.exception("Can't query for ids with " + column + " = " + str(value) + " in ipptopsps Db") 330 331 rs.close() 332 333 self.logger.debug("Found %d batches with %s = 1 for batch type='%s'" % (len(ids), column, batchType)) 328 finally: 329 rs.close() 334 330 335 331 return ids … … 338 334 Series of getter methods that utilise getBatchIDs() method above 339 335 ''' 340 def getloadedToDatastoreBatchIDs(self , epoch, dvoGpc1Label):341 return self.getBatchIDs( epoch, dvoGpc1Label,"loaded_to_datastore", 1)342 def getFailedLoadedToODMBatchIDs(self , epoch, dvoGpc1Label):343 return self.getBatchIDs( epoch, dvoGpc1Label,"loaded_to_ODM", -1)336 def getloadedToDatastoreBatchIDs(self): 337 return self.getBatchIDs("loaded_to_datastore", 1) 338 def getFailedLoadedToODMBatchIDs(self): 339 return self.getBatchIDs("loaded_to_ODM", -1) 344 340 345 341 ''' … … 347 343 Series of getter methods that utilise getStageIDs() method above 348 344 ''' 349 def getProcessedIDs(self, batchType , epoch, dvoGpc1Label):350 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"processed", 1)351 def getFailedProcessedIDs(self, batchType , epoch, dvoGpc1Label):352 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"processed", -1)353 def getLoadedToDatastoreIDs(self, batchType , epoch, dvoGpc1Label):354 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"loaded_to_datastore", 1)355 def getFailedLoadedToDatastoreIDs(self, batchType , epoch, dvoGpc1Label):356 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"loaded_to_datastore", -1)357 def getLoadedToODMIDs(self, batchType , epoch, dvoGpc1Label):358 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"loaded_to_ODM", 1)359 def getFailedLoadedToODMIDs(self, batchType , epoch, dvoGpc1Label):360 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"loaded_to_ODM", -1)361 def getMergeWorthyIDs(self, batchType , epoch, dvoGpc1Label):362 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"merge_worthy", 1)363 def getFailedMergeWorthyIDs(self, batchType , epoch, dvoGpc1Label):364 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"merge_worthy", -1)365 def getMergedIDs(self, batchType , epoch, dvoGpc1Label):366 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"merged", 1)367 def getFailedMergedIDs(self, batchType , epoch, dvoGpc1Label):368 return self.getStageIDs(batchType, epoch, dvoGpc1Label,"merged", -1)345 def getProcessedIDs(self, batchType): 346 return self.getStageIDs(batchType, "processed", 1) 347 def getFailedProcessedIDs(self, batchType): 348 return self.getStageIDs(batchType, "processed", -1) 349 def getLoadedToDatastoreIDs(self, batchType): 350 return self.getStageIDs(batchType, "loaded_to_datastore", 1) 351 def getFailedLoadedToDatastoreIDs(self, batchType): 352 return self.getStageIDs(batchType, "loaded_to_datastore", -1) 353 def getLoadedToODMIDs(self, batchType): 354 return self.getStageIDs(batchType, "loaded_to_ODM", 1) 355 def getFailedLoadedToODMIDs(self, batchType): 356 return self.getStageIDs(batchType, "loaded_to_ODM", -1) 357 def getMergeWorthyIDs(self, batchType): 358 return self.getStageIDs(batchType, "merge_worthy", 1) 359 def getFailedMergeWorthyIDs(self, batchType): 360 return self.getStageIDs(batchType, "merge_worthy", -1) 361 def getMergedIDs(self, batchType): 362 return self.getStageIDs(batchType, "merged", 1) 363 def getFailedMergedIDs(self, batchType): 364 return self.getStageIDs(batchType, "merged", -1) 369 365 370 366 ''' … … 385 381 Returns a count of batches processed in the specified time period. 386 382 ''' 387 def countBatches(self, batchType, epoch, dvoGpc1Label,interval="10 YEAR"):383 def countBatches(self, batchType, interval="10 YEAR"): 388 384 389 385 sql = "SELECT COUNT(batch_id) \ … … 391 387 WHERE batch_type = '" + batchType + "' \ 392 388 AND processed = 1 \ 393 AND timestamp > '" + epoch + "' \394 AND dvo_db = '" + dvoGpc1Label + "' \389 AND timestamp > '" + self.config.epoch + "' \ 390 AND dvo_db = '" + self.config.dvoLabel + "' \ 395 391 AND timestamp BETWEEN now() - INTERVAL " + interval + " AND now()" 396 392 … … 408 404 this epoch, dvo label and batch type 409 405 ''' 410 def getTimeOfLastBatchPublished(self, batchType , epoch, dvoGpc1Label):406 def getTimeOfLastBatchPublished(self, batchType): 411 407 412 408 seconds = None … … 416 412 WHERE batch_type = '" + batchType + "' \ 417 413 AND loaded_to_datastore = 1 \ 418 AND timestamp > '" + epoch + "' \419 AND dvo_db = '" + dvoGpc1Label + "' \414 AND timestamp > '" + self.config.epoch + "' \ 415 AND dvo_db = '" + self.config.dvoLabel + "' \ 420 416 ORDER BY timestamp DESC LIMIT 1" 421 417 … … 601 597 Returns a list of stage_ids that have failed the max number of times 602 598 ''' 603 def getConsistentlyFailedIDs(self, batchType , epoch, dvoGpc1Label):599 def getConsistentlyFailedIDs(self, batchType): 604 600 605 601 sql = "SELECT DISTINCT stage_id, COUNT(stage_id) AS numoccur \ 606 602 FROM batch \ 607 603 WHERE batch_type = '" + batchType + "' \ 608 AND timestamp > '" + epoch + "' \609 AND dvo_db = '" + dvoGpc1Label + "' \604 AND timestamp > '" + self.config.epoch + "' \ 605 AND dvo_db = '" + self.config.dvoLabel + "' \ 610 606 AND processed = -1 \ 611 607 GROUP BY stage_id HAVING numoccur >= " + str(self.MAX_FAILS) … … 706 702 self.execute(sql) 707 703 704 ''' 705 Inserts some object metadata for this batch ID 706 ''' 707 def insertObjectMeta(self, batchID, region): 708 709 sql = "INSERT INTO object ( \ 710 batch_id \ 711 ,region \ 712 ) VALUES ( \ 713 " + str(batchID) + " \ 714 ,'" + region + "' \ 715 )" 716 717 self.execute(sql) 708 718 ''' 709 719 Resets a batch ready for re-loading to the datastore … … 864 874 ,queue_P2 = " + self.config.queuingThisBatchType("P2") + " \ 865 875 ,queue_ST = " + self.config.queuingThisBatchType("ST") + " \ 876 ,queue_OB = " + self.config.queuingThisBatchType("OB") + " \ 866 877 WHERE name = '" + self.config.name + "'" 867 878 … … 910 921 ,queue_P2 \ 911 922 ,queue_ST \ 923 ,queue_OB \ 912 924 FROM config \ 913 925 WHERE name = '" + self.config.name + "'" … … 942 954 if rs.getInt(19) == 1: self.config.batchTypes.append("P2") 943 955 if rs.getInt(20) == 1: self.config.batchTypes.append("ST") 956 if rs.getInt(21) == 1: self.config.batchTypes.append("OB") 944 957 self.config.force = False # TODO 945 958 self.config.test = False # TODO … … 1009 1022 1010 1023 for id in ids: 1011 sql = "INSERT I NTO pending \1024 sql = "INSERT IGNORE INTO pending \ 1012 1025 (box_id, batch_type, stage_id) \ 1013 1026 VALUES \ … … 1132 1145 Returns ids for pending items for this config 1133 1146 ''' 1134 def getPendingIds(self): 1135 1136 sql = "SELECT DISTINCT stage_id FROM pending JOIN box ON (box_id = id) WHERE config = '" + self.config.name + "'" 1147 def getPendingIds(self, batchType): 1148 1149 sql = "SELECT DISTINCT stage_id \ 1150 FROM pending \ 1151 JOIN box ON (box_id = id) \ 1152 WHERE config = '" + self.config.name + "' \ 1153 AND batch_type = '" + batchType + "'" 1137 1154 1138 1155 ids = [] … … 1282 1299 1283 1300 ''' 1284 Purges old clients that may have die , i.e. those with a timestamp older than n hours1301 Purges old clients that may have died, i.e. those with a timestamp older than n hours 1285 1302 ''' 1286 1303 def purgeDeadClients(self): 1287 self.execute("DELETE FROM clients WHERE timestamp < now() - INTERVAL 6HOUR")1304 self.execute("DELETE FROM clients WHERE timestamp < now() - INTERVAL 14 HOUR") 1288 1305 1289 1306 '''
Note:
See TracChangeset
for help on using the changeset viewer.
