Changeset 33259 for trunk/ippToPsps/jython/load.py
- Timestamp:
- Feb 14, 2012, 12:02:48 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/load.py (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/load.py
r33237 r33259 10 10 import socket 11 11 import logging.config 12 from xml.etree.ElementTree import ElementTree, Element, tostring 13 12 13 from config import Config 14 14 from pslogger import PSLogger 15 15 from gpc1db import Gpc1Db … … 28 28 def publishAnyUnpublishedBatches(batchType): 29 29 30 batchIDs = ippToPspsDb.getProcessedButFailedDatastoreBatchIDs( EPOCH, DVOGPC1LABEL, batchType)30 batchIDs = ippToPspsDb.getProcessedButFailedDatastoreBatchIDs(config.epoch, config.dvoLabel, batchType) 31 31 logger.infoPair("%s batches" % batchType, "%d" % len(batchIDs)) 32 32 … … 34 34 35 35 batchName = Batch.getNameFromID(batchID) 36 subDir = Batch.getSubDir( BASEPATH, batchType, DVOGPC1LABEL)36 subDir = Batch.getSubDir(config.basePath, batchType, config.dvoLabel) 37 37 tarballFile = Batch.getTarballFile(batchID) 38 38 logger.infoPair("Batch name", batchName) … … 48 48 logger.infoPair("Box center and size", "%f/%f/%f" %(ra, dec, boxsize)) 49 49 50 allIDs = [] 51 52 # see if there are any IDs listed in the config 53 try: 54 for element in configDoc.findall('options/ids/id'): 55 allIDs.append(int(element.text)) 56 except: 57 logger.errorPair("Problem loading IDs from config under", "options/ids/id") 50 allIDs = config.ids 58 51 59 52 if len(allIDs) > 0: … … 63 56 64 57 allIDs = gpc1Db.getIDsInThisDVODbForThisStageInThisBox( 65 DVOGPC1LABEL,58 config.dvoLabel, 66 59 batchType, 67 60 ra, … … 71 64 logger.infoPair("All %s items in DVO" % batchType, "%d" % len(allIDs)) 72 65 73 # if in FORCEmode, then queue full list74 if FORCE: ids = allIDs75 76 # if not in TESTmode, then only queue un-processed items66 # if in force mode, then queue full list 67 if config.force: ids = allIDs 68 69 # if not in test mode, then only queue un-processed items 77 70 else: 78 processedIDs = ippToPspsDb.getProcessedIDs(batchType, EPOCH, DVOGPC1LABEL)79 consistaentlyFailedIDs = ippToPspsDb.getConsistentlyFailedIDs(batchType, EPOCH, DVOGPC1LABEL)71 processedIDs = ippToPspsDb.getProcessedIDs(batchType, config.epoch, config.dvoLabel) 72 consistaentlyFailedIDs = ippToPspsDb.getConsistentlyFailedIDs(batchType, config.epoch, config.dvoLabel) 80 73 ids = list(set(allIDs) - set(processedIDs) - set(consistaentlyFailedIDs)) 81 74 logger.infoPair("Processed items", "%d" % len(processedIDs)) … … 97 90 for id in ids: 98 91 99 batchID = ippToPspsDb.createNewBatch( 100 batchType, 101 id, 102 SURVEY, 103 EPOCH, 104 DVOGPC1LABEL, 105 datastore.product, 106 FORCE) 92 batchID = ippToPspsDb.createNewBatch(batchType, id, config) 107 93 108 94 if batchID < 0: continue; … … 112 98 if batchType == "P2": 113 99 batch = DetectionBatch(logger, 114 CONFIG, 115 configDoc, 100 config, 116 101 gpc1Db, 117 102 ippToPspsDb, … … 121 106 elif batchType == "ST": 122 107 batch = StackBatch(logger, 123 CONFIG, 124 configDoc, 108 config, 125 109 gpc1Db, 126 110 ippToPspsDb, … … 135 119 logger.infoSeparator() 136 120 137 # if in TESTmode, then quit after one batch138 if TEST: break121 # if in test mode, then quit after one batch 122 if config.test: break 139 123 140 124 ippToPspsDb.unlockTables() … … 143 127 Start of program. 144 128 ''' 145 if len(sys.argv) > 1: CONFIG = sys.argv[1]129 if len(sys.argv) > 1: CONFIGPATH = sys.argv[1] 146 130 else: 147 131 print "** Usage: " + sys.argv[0] + " <configPath> [init]" … … 154 138 155 139 # open config file 156 configDoc = ElementTree(file=CONFIG) 157 TEST = int(configDoc.find("options/testMode").text) 158 159 # set up logging 160 logging.setLoggerClass(PSLogger) 161 logger = logging.getLogger("ippToPspsLog") 162 163 # get hostnamee and PID for unique log naming 164 HOST = socket.gethostname() 165 PID = os.getpid() 166 167 # if in test mode, print log to screen, otherwise, only to file 168 #logger.setup(configDoc, "ippToPsps", TEST, not TEST, HOST, PID) TODO put back 169 logger.setup(configDoc, "ippToPsps") 140 config = Config(CONFIGPATH) 141 #logger = config.getLogger("load", 0, 1) 142 logger = config.getLogger("load") 170 143 171 144 # create various objects 172 dvo = Dvo(logger, config Doc)173 gpc1Db = Gpc1Db(logger, config Doc)174 ippToPspsDb = IppToPspsDb(logger, config Doc)175 datastore = Datastore(logger, config Doc, ippToPspsDb)145 dvo = Dvo(logger, config) 146 gpc1Db = Gpc1Db(logger, config) 147 ippToPspsDb = IppToPspsDb(logger, config) 148 datastore = Datastore(logger, config, ippToPspsDb) 176 149 177 150 # check we connected ok … … 181 154 # get values from the configutaion file 182 155 POLLPERIOD = 600 183 DVOGPC1LABEL = configDoc.find("dvo/gpc1Label").text 184 FORCE = int(configDoc.find("options/force").text) 185 EPOCH = configDoc.find("options/epoch").text 186 PUBLISH = int(configDoc.find("options/publishToDatastore").text) 187 BASEPATH = configDoc.find("localOutPath").text 188 SURVEY = configDoc.find("options/survey").text 189 190 # get batch types from config 191 batchTypes = [] 192 if int(configDoc.find("options/queueP2").text) == 1: batchTypes.append("P2") 193 if int(configDoc.find("options/queueST").text) == 1: batchTypes.append("ST") 194 195 # get equatorial coord limits, if any 196 try: MINRA = float(configDoc.find("dvo/minRA").text) 197 except: MINRA = 0.0 198 try: MAXRA = float(configDoc.find("dvo/maxRA").text) 199 except: MAXRA = 360.0 200 try: MINDEC = float(configDoc.find("dvo/minDec").text) 201 except: MINDEC = -30.0 202 try: MAXDEC = float(configDoc.find("dvo/maxDec").text) 203 except: MAXDEC = 90.0 204 try: BOXSIZE = float(configDoc.find("dvo/boxSize").text) 205 except: BOXSIZE = 4.0 206 207 # prompt user: FORCE and PUBLISH is a dangerous combination 208 if FORCE and PUBLISH and not QUEUE_IN: 156 157 # prompt user: force and publishing is a dangerous combination 158 if config.force and config.datastorePublishing and not QUEUE_IN: 209 159 response = raw_input("\n*** Are you sure you want to publish data with the 'force' option enabled (y/n)? ") 210 160 if response != "y": sys.exit(1) 211 161 212 # prompt user: TEST and PUBLISHis a dangerous combination213 if TEST and PUBLISHand not QUEUE_IN:162 # prompt user: test and publishing is a dangerous combination 163 if config.test and config.datastorePublishing and not QUEUE_IN: 214 164 response = raw_input("\n*** Are you sure you want to publish data with the 'testMode' option enabled (y/n)? ") 215 165 if response != "y": sys.exit(1) … … 218 168 logger.infoSeparator() 219 169 logger.infoTitle("ippToPsps loading started") 220 logger.infoPair("Configuration file", CONFIG)221 logger.infoPair("Loading epoch", EPOCH)222 logger.infoPair("DVO gpc1 label", DVOGPC1LABEL)223 for batchType in batchTypes: logger.infoPair("Queuing batch type", batchType)224 logger.infoBool("Forcing?", FORCE)225 logger.infoBool("Test mode?", TEST)226 logger.infoBool("Publishing?", PUBLISH)227 170 228 171 # if an IN batch is requested, create and quit 229 172 if QUEUE_IN: 230 batchID = ippToPspsDb.createNewBatch( 231 "IN", 232 0, 233 SURVEY, 234 EPOCH, 235 DVOGPC1LABEL, 236 datastore.product, 237 1) 173 batchID = ippToPspsDb.createNewBatch("IN", 0, config) 238 174 if batchID > 0: 239 batch = InitBatch(logger, CONFIG, configDoc, gpc1Db, ippToPspsDb, batchID)175 batch = InitBatch(logger, config, gpc1Db, ippToPspsDb, batchID) 240 176 batch.run() 241 177 … … 251 187 252 188 ''' 253 BORDER = 1.60254 HALFBOX = BOXSIZE/2.0255 BOXSIZEWITHBORDER = BOXSIZE + (BORDER * 2)256 189 257 190 # this outer while loop simply waits a few minutes then starts queuing againas more stuff may appear in DVO over time 258 191 while True: 259 192 193 config.refresh() 194 config.printAll() 195 260 196 # starting positions 261 ra = MINRA + HALFBOX262 dec = MINDEC + HALFBOX197 ra = config.minRa + config.halfBox 198 dec = config.minDec + config.halfBox 263 199 264 200 # queue up batches that are processed but not loaded to datastore 265 201 logger.infoTitle("Previous failed datastore loads") 266 for batchType in batchTypes: publishAnyUnpublishedBatches(batchType)267 268 # loop through full range of RA/Dec queueing stuff in boxes of size BOXSIZE269 while ra <= MAXRA:270 271 while dec <= MAXDEC:202 for batchType in config.batchTypes: publishAnyUnpublishedBatches(batchType) 203 204 # loop through full range of RA/Dec queueing stuff in boxes of size config.boxSize 205 while ra <= config.maxRa: 206 207 while dec <= config.maxDec: 272 208 273 209 # for each batch type … … 275 211 # - check if we should pre-load DVO region 276 212 # - process the items 277 for batchType in batchTypes: 278 ids = queueItemsInBox(batchType, ra, dec, BOXSIZE) 213 for batchType in config.batchTypes: 214 215 ids = queueItemsInBox(batchType, ra, dec, config.boxSize) 279 216 280 217 if len(ids) < 1: … … 282 219 continue 283 220 284 dvo.setSkyAreaAsBox(ra, dec, BOXSIZEWITHBORDER)221 dvo.setSkyAreaAsBox(ra, dec, config.boxSizeWithBorder) 285 222 dvo.printSummary() 286 223 … … 291 228 292 229 # do we pre-ingest stuff from DVO? 293 if smfsPerGB > 40:230 if smfsPerGB > 0: 294 231 if not dvo.sync(): 295 232 logger.errorPair("Could not sync DVO with MySQL", "skipping") … … 301 238 logger.infoBool("Using pre-ingested DVO data?", useFullTables) 302 239 processTheseItems(batchType, ids, useFullTables) 303 304 # in the TEST mode, we quit after submitting one batch 305 if TEST: break 306 307 dec = dec + BOXSIZE 308 if TEST: break 309 310 dec = MINDEC + HALFBOX 311 ra = ra + BOXSIZE 312 if TEST: break 240 sys.exit(1) 241 242 # in the test mode, we quit after submitting one batch 243 if config.test: break 244 245 dec = dec + config.boxSize 246 if config.test: break 247 248 dec = config.minDec + config.halfBox 249 ra = ra + config.boxSize 250 if config.test: break 313 251 314 252 # wait for the POLLPERIOD before checking for new ids
Note:
See TracChangeset
for help on using the changeset viewer.
