Changeset 33259
- Timestamp:
- Feb 14, 2012, 12:02:48 PM (14 years ago)
- Location:
- trunk/ippToPsps/jython
- Files:
-
- 1 added
- 15 edited
-
batch.py (modified) (11 diffs)
-
config.py (added)
-
czardb.py (modified) (1 diff)
-
datastore.py (modified) (3 diffs)
-
detectionbatch.py (modified) (9 diffs)
-
dvo.py (modified) (12 diffs)
-
fits.py (modified) (2 diffs)
-
gpc1db.py (modified) (3 diffs)
-
initbatch.py (modified) (1 diff)
-
ipptopspsdb.py (modified) (3 diffs)
-
load.py (modified) (19 diffs)
-
metrics.py (modified) (10 diffs)
-
mysql.py (modified) (2 diffs)
-
pslogger.py (modified) (2 diffs)
-
scratchdb.py (modified) (3 diffs)
-
stackbatch.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/batch.py
r33235 r33259 30 30 def __init__(self, 31 31 logger, 32 configPath, 33 doc, 32 config, 34 33 gpc1Db, 35 34 ippToPspsDb, … … 42 41 self.everythingOK = False 43 42 self.readHeader = False 44 self.configPath = configPath 45 self.doc = doc 43 self.config = config 46 44 self.fits = fits 47 45 self.useFullTables = useFullTables … … 75 73 return 76 74 77 # get info from config 78 self.survey = self.doc.find("options/survey").text 79 self.pspsSurvey = self.doc.find("options/pspsSurvey").text 80 self.dvoGpc1Label = self.doc.find("dvo/gpc1Label").text 81 self.dvoLocation = self.doc.find("dvo/location").text 82 self.scratchDb = ScratchDb(logger, self.doc, self.useFullTables) 75 self.scratchDb = ScratchDb(logger, self.config, self.useFullTables) 83 76 84 77 if not self.scratchDb.everythingOK: return … … 87 80 self.tablesToExport = [] 88 81 89 if self. survey != "":90 self.surveyID = self.scratchDb.getSurveyID(self. survey)82 if self.config.survey != "": 83 self.surveyID = self.scratchDb.getSurveyID(self.config.survey) 91 84 else: 92 85 self.surveyID = -1; 93 86 94 # get some options from the config95 self.testMode = int(self.doc.find("options/testMode").text)96 self.dataRelease = int(self.doc.find("metadata/dataRelease").text)97 98 87 # create datastore object 99 self.datastore = Datastore(self.logger, self. doc, self.ippToPspsDb)88 self.datastore = Datastore(self.logger, self.config, self.ippToPspsDb) 100 89 101 90 # get local storage location from config 102 91 self.batchName = Batch.getNameFromID(self.batchID) 103 self.basePath = self.doc.find("localOutPath").text104 92 self.subDir = Batch.getSubDir( 105 self. basePath,93 self.config.basePath, 106 94 self.batchType, 107 self. dvoGpc1Label)95 self.config.dvoLabel) 108 96 109 97 self.localOutPath = Batch.getOutputPath( 110 self. basePath,98 self.config.basePath, 111 99 self.batchType, 112 self. dvoGpc1Label,100 self.config.dvoLabel, 113 101 self.batchID) 114 102 … … 125 113 self.logger.infoTitle("New " + self.batchType + " batch") 126 114 self.logger.infoPair("Batch name", self.batchName) 127 self.logger.infoPair("Survey", self.survey)128 115 self.logger.infoPair("Survey ID", "%d" % self.surveyID) 129 self.logger.infoPair("Publishing to PSPS as survey", self.pspsSurvey)130 self.logger.infoPair("DVO location", self.dvoLocation)131 116 self.logger.infoBool("Use full DVO tables?", self.useFullTables) 132 117 … … 227 212 if value != "NULL": return value 228 213 else: 229 if not self. testMode: return "NULL"214 if not self.config.test: return "NULL" 230 215 header[key] = default 231 216 self.logger.infoPair("Hardcoding " + key + " to", header[key]) … … 256 241 root.attrib['type'] = self.batchType 257 242 root.attrib['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 258 if self.batchType != "IN": root.attrib['survey'] = self. pspsSurvey243 if self.batchType != "IN": root.attrib['survey'] = self.config.pspsSurvey 259 244 try: self.minObjID 260 245 except: pass … … 287 272 # set up filenams and paths 288 273 tarFile = Batch.getTarFile(self.batchID) 289 tarPath = Batch.getTarPath(self. basePath, self.batchType, self.dvoGpc1Label, self.batchID)274 tarPath = Batch.getTarPath(self.config.basePath, self.batchType, self.config.dvoLabel, self.batchID) 290 275 tarballFile = Batch.getTarballFile(self.batchID) 291 tarballPath = Batch.getTarballPath(self. basePath, self.batchType, self.dvoGpc1Label, self.batchID)276 tarballPath = Batch.getTarballPath(self.config.basePath, self.batchType, self.config.dvoLabel, self.batchID) 292 277 293 278 # tar directory … … 498 483 499 484 # TODO path to DVO prog hardcoded temporarily 500 cmd = "../src/dvograbber " + self.config Path + " " + self.dvoLocation485 cmd = "../src/dvograbber " + self.config.path + " " + self.config.dvoLocation 501 486 self.logger.infoPair("Running DVO", cmd) 502 487 p = Popen(cmd, shell=True, stdout=PIPE) … … 537 522 else: 538 523 self.writeBatchManifest() 539 if int(self.doc.find("options/publishToDatastore").text):524 if self.config.datastorePublishing: 540 525 # tar and zip ready for publication to datastore 541 526 if self.tarAndZip(): … … 544 529 Batch.publishToDatastore(self.datastore, self.batchID, self.batchName, self.subDir, tarballFile) 545 530 546 if int(self.doc.find("options/reportNulls").text): self.reportNullsInAllPspsTables(False)531 if self.config.reportNulls: self.reportNullsInAllPspsTables(False) 547 532 548 533 from datastore import Datastore -
trunk/ippToPsps/jython/czardb.py
r32831 r33259 17 17 Constructor 18 18 ''' 19 def __init__(self, logger, doc):20 super(CzarDb, self).__init__(logger, doc, "czardatabase")19 def __init__(self, logger, config): 20 super(CzarDb, self).__init__(logger, config, "czardatabase") 21 21 22 22 -
trunk/ippToPsps/jython/datastore.py
r32835 r33259 19 19 20 20 ''' 21 def __init__(self, logger, doc, ippToPspsDb):21 def __init__(self, logger, config, ippToPspsDb): 22 22 23 23 # setup logger 24 24 self.logger = logger 25 self. doc = doc25 self.config = config 26 26 self.ippToPspsDb = ippToPspsDb 27 self.logger.debug("Datastore constructor")28 29 # open config30 self.product = doc.find("datastore/product").text31 self.type = doc.find("datastore/type").text32 33 self.logger.debug("Using product: '" + self.product + "' and type: '" + self.type + "'")34 27 35 28 ''' … … 49 42 command = "dsreg --add " + name + "\ 50 43 --link --datapath " + path + "\ 51 --type " + self. type + "\52 --product " + self. product + "\44 --type " + self.config.datastoreType + "\ 45 --product " + self.config.datastoreProduct + "\ 53 46 --list " + tempFile.name 54 47 … … 82 75 --del " + name + " \ 83 76 --rm \ 84 --product " + self. product77 --product " + self.config.datastoreProduct 85 78 86 79 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) -
trunk/ippToPsps/jython/detectionbatch.py
r33235 r33259 33 33 def __init__(self, 34 34 logger, 35 configPath, 36 configDoc, 35 config, 37 36 gpc1Db, 38 37 ippToPspsDb, … … 43 42 super(DetectionBatch, self).__init__( 44 43 logger, 45 configPath, 46 configDoc, 44 config, 47 45 gpc1Db, 48 46 ippToPspsDb, … … 75 73 76 74 # if test mode 77 if self. testMode:75 if self.config.test: 78 76 self.startX = 3 79 77 self.endX = 4 … … 221 219 self.scratchDb.updateFilterID("FrameMeta", self.filter) 222 220 self.scratchDb.updateAllRows("FrameMeta", "calibModNum", str(self.calibModNum)) 223 self.scratchDb.updateAllRows("FrameMeta", "dataRelease", str(self. dataRelease))221 self.scratchDb.updateAllRows("FrameMeta", "dataRelease", str(self.config.dataRelease)) 224 222 225 223 ''' … … 368 366 self.scratchDb.updateFilterID(tableName, self.filter) 369 367 self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum)) 370 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self. dataRelease))368 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease)) 371 369 if 'NASTRO' in header: self.totalNumPhotoRef = self.totalNumPhotoRef + int(header['NASTRO']) 372 370 self.scratchDb.replaceNullsInThisColumn(tableName, "polyOrder", "0") … … 455 453 , '" + self.dateStr + "' \ 456 454 , 0 \ 457 , " + str(self. dataRelease) + "\455 , " + str(self.config.dataRelease) + "\ 458 456 FROM " + ippTableName 459 457 self.scratchDb.execute(sql) … … 499 497 self.scratchDb.execute(sql) 500 498 501 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self. dataRelease))499 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease)) 502 500 503 501 ''' … … 528 526 529 527 self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum)) 530 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self. dataRelease))528 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease)) 531 529 532 530 … … 752 750 def importIppTables(self, filter=""): 753 751 754 if self. testMode: regex = "XY33.psf"752 if self.config.test: regex = "XY33.psf" 755 753 else : regex = ".*.psf" 756 754 -
trunk/ippToPsps/jython/dvo.py
r33234 r33259 16 16 from java.lang import * 17 17 from java.sql import * 18 from xml.etree.ElementTree import ElementTree, Element, tostring19 18 20 19 … … 35 34 36 35 ''' 37 def __init__(self, logger, doc):36 def __init__(self, logger, config): 38 37 39 38 # set up logging 40 39 self.logger = logger 41 self. doc = doc40 self.config = config 42 41 self.logger.infoSeparator() 43 self.dvoLocation = self.doc.find("dvo/location").text44 42 45 43 # create database object 46 self.scratchDb = ScratchDb(logger, self. doc, 1)44 self.scratchDb = ScratchDb(logger, self.config, 1) 47 45 48 46 # or decide if we are using the right DVO 49 self.correctDvo = self.scratchDb.isCorrectDvo(self. dvoLocation)47 self.correctDvo = self.scratchDb.isCorrectDvo(self.config.dvoLocation) 50 48 51 49 # set up empty lists … … 57 55 58 56 if not self.correctDvo: 59 response = raw_input("* Wrong DVO is use. Do you want to reset and use '" + self.dvoLocation + "' instead (y/n)? ") 57 print "*******************************************************************************" 58 response = raw_input("**** Wrong DVO in use. Do you want to reset and use '" + self.config.dvoLocation + "' instead (y/n)? ") 60 59 if response == "y": 61 response = raw_input("* Are you ABSOLUTELY sure you want to do this? (y/n)? ")60 response = raw_input("**** Are you ABSOLUTELY sure you want to do this? (y/n)? ") 62 61 if response == "y": 63 62 self.resetAllTables() … … 101 100 102 101 # check if we have up-to-date version 103 path = self. dvoLocation + "/Images.dat"102 path = self.config.dvoLocation + "/Images.dat" 104 103 if self.scratchDb.alreadyImportedThisDvoTable(path): 105 104 self.logger.infoPair("DVO Images.dat file", "up-to-date") … … 156 155 if not self.correctDvo: return 157 156 158 path = self. dvoLocation + "/SkyTable.fits"157 path = self.config.dvoLocation + "/SkyTable.fits" 159 158 if self.scratchDb.alreadyImportedThisDvoTable(path): 160 159 self.logger.infoPair("DVO SkyTable.fits file", "up-to-date") … … 173 172 174 173 self.scratchDb.setImportedThisDvoTable(path) 175 self.logger.infoPair("Finished importing SkyTable at", self. dvoLocation)174 self.logger.infoPair("Finished importing SkyTable at", self.config.dvoLocation) 176 175 177 176 ''' … … 181 180 182 181 halfSide = side/2.0 182 print "%f %f %f" % (ra, dec, side) 183 183 self.setSkyArea(ra-halfSide, ra+halfSide, dec-halfSide, dec+halfSide) 184 184 … … 208 208 209 209 # reset all lists 210 allRegions = self.scratchDb.getDvoRegions ForThisBox(minRa, maxRa, minDec, maxDec)210 allRegions = self.scratchDb.getDvoRegions(minRa, maxRa, minDec, maxDec) 211 211 allIngestedRegions = self.scratchDb.getIngestedDvoRegions() 212 212 self.regionsToIngest = [] … … 219 219 for region in allRegions: 220 220 221 cpmPath = self. dvoLocation + "/" + region + ".cpm"222 cptPath = self. dvoLocation + "/" + region + ".cpt"221 cpmPath = self.config.dvoLocation + "/" + region + ".cpm" 222 cptPath = self.config.dvoLocation + "/" + region + ".cpt" 223 223 224 224 # check for existence of cpm and cpt files … … 262 262 # go no further if we've already partly ingested a different DVO 263 263 if not self.correctDvo: 264 self.logger.infoPair("Wrong DVO in use", self. dvoLocation)264 self.logger.infoPair("Wrong DVO in use", self.config.dvoLocation) 265 265 return 266 266 … … 327 327 328 328 # get combined size of cpm and cpt files 329 size = size + self.getDiskSize(self. dvoLocation + "/" + region + ".cpm")330 size = size + self.getDiskSize(self. dvoLocation + "/" + region + ".cpt")329 size = size + self.getDiskSize(self.config.dvoLocation + "/" + region + ".cpm") 330 size = size + self.getDiskSize(self.config.dvoLocation + "/" + region + ".cpt") 331 331 332 332 return size … … 357 357 for region in self.regionsToIngest: 358 358 359 cpmPath = self. dvoLocation + "/" + region + ".cpm"360 cptPath = self. dvoLocation + "/" + region + ".cpt"359 cpmPath = self.config.dvoLocation + "/" + region + ".cpm" 360 cptPath = self.config.dvoLocation + "/" + region + ".cpt" 361 361 362 362 cpmTableName = self.scratchDb.getDbFriendlyTableName(region + ".cpm") -
trunk/ippToPsps/jython/fits.py
r32455 r33259 15 15 16 16 ''' 17 def __init__(self, logger, doc, originalPath):17 def __init__(self, logger, config, originalPath): 18 18 19 19 # set class variables 20 20 self.originalPath = originalPath 21 21 self.logger = logger 22 self. doc = doc22 self.config = config 23 23 self.header = None 24 self.localDir = self.doc.find("localOutPath").text25 24 26 25 # does this file even exist? … … 31 30 # ok, we have a file, now copy it locally to save on NFS overhead 32 31 self.logger.debugPair("FITS file", self.originalPath) 33 #self.localCopyPath = self. localDir+ "/temp.fits"32 #self.localCopyPath = self.config.basePath + "/temp.fits" 34 33 #shutil.copy2(self.originalPath, self.localCopyPath) 35 34 -
trunk/ippToPsps/jython/gpc1db.py
r33186 r33259 20 20 Constructor 21 21 ''' 22 def __init__(self, logger, doc):23 super(Gpc1Db, self).__init__(logger, doc, "gpc1database")22 def __init__(self, logger, config): 23 super(Gpc1Db, self).__init__(logger, config, "gpc1database") 24 24 25 25 ''' … … 227 227 if len(files) < 1: return None 228 228 229 return Fits(self.logger, self. doc, files[0]) # TODO just returning first file - check229 return Fits(self.logger, self.config, files[0]) # TODO just returning first file - check 230 230 231 231 … … 304 304 305 305 # if we get here, then the cmf is readable, now check the stack_id 306 fits = Fits(self.logger, self. doc, path)306 fits = Fits(self.logger, self.config, path) 307 307 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID): 308 308 # we have the right file! -
trunk/ippToPsps/jython/initbatch.py
r33235 r33259 27 27 def __init__(self, 28 28 logger, 29 configPath, 30 configDoc, 29 config, 31 30 gpc1Db, 32 31 ippToPspsDb, 33 32 batchID): 34 33 super(InitBatch, self).__init__(logger, 35 configPath, 36 configDoc, 34 config, 37 35 gpc1Db, 38 36 ippToPspsDb, -
trunk/ippToPsps/jython/ipptopspsdb.py
r32932 r33259 17 17 Constructor 18 18 ''' 19 def __init__(self, logger, doc):20 super(IppToPspsDb, self).__init__(logger, doc, "ipptopspsdatabase")19 def __init__(self, logger, config): 20 super(IppToPspsDb, self).__init__(logger, config, "ipptopspsdatabase") 21 21 22 22 self.MAX_FAILS = 5 … … 590 590 Creates a new batch. This is done with a locked table in order that no two clients can start work on the same item 591 591 ''' 592 def createNewBatch(self, batchType, stageID, survey, epoch, dvoDb, datastoreProduct, force):592 def createNewBatch(self, batchType, stageID, config): 593 593 594 594 batchID = -1; 595 595 596 if force or \597 (not self.alreadyProcessed(batchType, stageID, epoch, dvoDb) \598 and not self.processingNow(batchType, stageID, epoch, dvoDb) \599 and not self.consistentlyFailed(batchType, stageID, epoch, dvoDb)):596 if config.force or \ 597 (not self.alreadyProcessed(batchType, stageID, config.epoch, config.dvoLabel) \ 598 and not self.processingNow(batchType, stageID, config.epoch, config.dvoLabel) \ 599 and not self.consistentlyFailed(batchType, stageID, config.epoch, config.dvoLabel)): 600 600 601 601 sql = "INSERT INTO batch ( \ … … 608 608 '" + batchType + "', \ 609 609 " + str(stageID) + ", \ 610 '" + survey + "', \611 '" + dvoDb+ "', \612 '" + datastoreProduct + "' \610 '" + config.survey + "', \ 611 '" + config.dvoLabel + "', \ 612 '" + config.datastoreProduct + "' \ 613 613 )" 614 614 -
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 -
trunk/ippToPsps/jython/metrics.py
r33191 r33259 9 9 from xml.etree.ElementTree import ElementTree, Element, tostring 10 10 11 from config import Config 11 12 from pslogger import PSLogger 12 13 from ipptopspsdb import IppToPspsDb … … 19 20 def plotMe(batchType, file): 20 21 21 OUTPUTFILE = "plots/" + DVOLABEL+ "_" + batchType + ".png"22 OUTPUTFILE = "plots/" + config.dvoLabel + "_" + batchType + ".png" 22 23 f=os.popen('gnuplot', 'w') 23 24 … … 29 30 print >> f, "set term " + TERM + "; \ 30 31 set output \"" + OUTPUTFILE + "\"; \ 31 set title \"ippToPsps : " + batchType + " loading for " + DVOLABEL+ "\"; \32 set title \"ippToPsps : " + batchType + " loading for " + config.dvoLabel + "\"; \ 32 33 set boxwidth; \ 33 34 set xtic rotate by -90 scale 0; \ … … 54 55 55 56 # get a master list of IDs in DVO for this batch type 56 if MINRA and MAXRA and MINDEC and MAXDEC: 57 allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOLABEL, batchType, MINRA, MAXRA, MINDEC, MAXDEC) 58 else: 59 allIDs = gpc1Db.getIDsInThisDVODbForThisStage(DVOLABEL, batchType) 57 allIDs = gpc1Db.getIDsInThisDVODbForThisStage(config.dvoLabel, batchType, config.minRa, config.maxRa, config.minDec, config.maxDec) 60 58 prevList = allIDs 61 59 numEverything = len(allIDs) … … 69 67 70 68 # get lists. Use unions with prev list to make sure the right stuff is included 71 success = list(set(ippToPspsDb.getStageIDs(batchType, EPOCH, DVOLABEL, stage, 1)) & set(prevList))72 fail = list(set(ippToPspsDb.getStageIDs(batchType, EPOCH, DVOLABEL, stage, -1)) & set(prevList) - set(success))69 success = list(set(ippToPspsDb.getStageIDs(batchType, config.epoch, config.dvoLabel, stage, 1)) & set(prevList)) 70 fail = list(set(ippToPspsDb.getStageIDs(batchType, config.epoch, config.dvoLabel, stage, -1)) & set(prevList) - set(success)) 73 71 pending = list(set(prevList) - set(success) - set(fail)) 74 72 … … 87 85 print >> DATFILE, stage, numSuccess, numFail, numPending 88 86 89 czarDb.insertStats(stage, DVOLABEL, batchType, numPending, numSuccess, numFail)87 czarDb.insertStats(stage, config.dvoLabel, batchType, numPending, numSuccess, numFail) 90 88 91 89 if stage == 'processed': numPendingProcessed = numPending 92 90 93 91 sys.stdout.write("|\n") 94 plotMe(batchType, tempFilename)92 #plotMe(batchType, tempFilename) 95 93 DATFILE.close() 96 94 … … 111 109 def printStats(batchType): 112 110 113 rate = ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "1 HOUR") / 1.0111 rate = ippToPspsDb.countBatchesInLastPeriod(batchType, config.epoch, config.dvoLabel, "1 HOUR") / 1.0 114 112 115 113 logger.info("| %2s | %16.1f | %13d | %17.1f | %16d | %14s |" % 116 114 (batchType, 117 115 rate, 118 ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "24 HOUR"),119 ippToPspsDb.countBatchesInLastPeriod(batchType, EPOCH, DVOLABEL, "1 WEEK") / 7.0,120 ippToPspsDb.getTotalDetectionsPublished(batchType, EPOCH, DVOLABEL),121 ippToPspsDb.getTimeOfLastBatchPublished(batchType, EPOCH, DVOLABEL)))116 ippToPspsDb.countBatchesInLastPeriod(batchType, config.epoch, config.dvoLabel, "24 HOUR"), 117 ippToPspsDb.countBatchesInLastPeriod(batchType, config.epoch, config.dvoLabel, "1 WEEK") / 7.0, 118 ippToPspsDb.getTotalDetectionsPublished(batchType, config.epoch, config.dvoLabel), 119 ippToPspsDb.getTimeOfLastBatchPublished(batchType, config.epoch, config.dvoLabel))) 122 120 123 121 return rate … … 126 124 Start of program. 127 125 ''' 128 if len(sys.argv) > 1: CONFIG = sys.argv[1]126 if len(sys.argv) > 1: CONFIGPATH = sys.argv[1] 129 127 else: 130 128 print "** Usage: " + sys.argv[0] + " <configPath> [hours]" … … 137 135 SECONDS = None 138 136 139 140 141 # open config file 142 configDoc = ElementTree(file=CONFIG) 143 144 logging.setLoggerClass(PSLogger) 145 logger = logging.getLogger("metrics") 146 logger.setup(configDoc, "metrics") 147 148 # create database objects 149 ippToPspsDb = IppToPspsDb(logger, configDoc) 150 czarDb = CzarDb(logger, configDoc) 151 gpc1Db = Gpc1Db(logger, configDoc) 152 153 DVOLABEL = configDoc.find("dvo/gpc1Label").text 154 EPOCH = configDoc.find("options/epoch").text 137 # create objects 138 config = Config(CONFIGPATH) 139 logger = config.getLogger("metrics") 140 ippToPspsDb = IppToPspsDb(logger, config) 141 czarDb = CzarDb(logger, config) 142 gpc1Db = Gpc1Db(logger, config) 155 143 156 144 while True: … … 159 147 now = datetime.datetime.now() 160 148 logger.infoPair("Time now", now.strftime("%Y-%m-%d %H:%M:%S")) 161 logger.infoPair("Loading epoch", EPOCH) 162 logger.infoPair("DVO label", DVOLABEL) 163 164 # get equatorial coord constraints, if any 165 try: 166 MINRA = float(configDoc.find("dvo/minRA").text) 167 MAXRA = float(configDoc.find("dvo/maxRA").text) 168 MINDEC = float(configDoc.find("dvo/minDec").text) 169 MAXDEC = float(configDoc.find("dvo/maxDec").text) 170 except: 171 MINRA = 0.0 172 MAXRA = 360.0 173 MINDEC = -30.0 174 MAXDEC = 90.0 175 176 logger.infoPair("RA limits", "%.1f to %.1f" % (MINRA, MAXRA)) 177 logger.infoPair("Dec limits", "%.1f to %.1f" % (MINDEC, MAXDEC)) 149 logger.infoPair("Loading epoch", config.epoch) 150 logger.infoPair("DVO label", config.dvoLabel) 151 config.printBoxCoords() 178 152 179 153 logger.info("+----+------------------+---------------+-------------------+------------------+----------------+") -
trunk/ippToPsps/jython/mysql.py
r33181 r33259 21 21 22 22 ''' 23 def __init__(self, logger, doc, dbType):23 def __init__(self, logger, config, dbType): 24 24 25 25 # set up logging 26 26 self.logger = logger 27 self. doc = doc27 self.config = config 28 28 self.logger.debug("MySql class constructor") 29 29 30 30 # open config and grab database parameters 31 self.dbName = self.doc.find(dbType +"/name").text32 self.dbHost = self.doc.find(dbType +"/host").text33 self.dbUser = self.doc.find(dbType +"/user").text34 self.dbPass = self.doc.find(dbType +"/password").text31 self.dbName = config.getDbName(dbType) 32 self.dbHost = config.getDbHost(dbType) 33 self.dbUser = config.getDbUser(dbType) 34 self.dbPass = config.getDbPassword(dbType) 35 35 36 36 # set up JDBC connection … … 80 80 connectionID = self.getLastConnectionID() 81 81 if connectionID == self.connectionID: 82 self.logger. error("NOT going to kill THIS connection ID")82 self.logger.debug("NOT going to kill THIS connection ID") 83 83 return 84 84 -
trunk/ippToPsps/jython/pslogger.py
r33192 r33259 7 7 8 8 ''' 9 Sets up logging using values from the ippToPsps config file 9 Sets up logging using provided values and this process hostname and PID if sending to file 10 This will default to stout and no file output 10 11 ''' 11 def setup(self, doc, name, stdout=1, sendToFile=0, host="host", pid=1234):12 def setup(self, name, basePath, dvoLabel, stdout=1, sendToFile=0): 12 13 13 14 formatter = logging.Formatter('%(asctime)s | %(levelname)7s | %(message)s', '%Y-%m-%d %H:%M:%S') … … 15 16 16 17 if sendToFile: 17 PATH = doc.find("localOutPath").text + "/log" 18 19 HOST = socket.gethostname() 20 PID = os.getpid() 21 22 # generate path 23 PATH = basePath + "/log" 18 24 if not os.path.exists(PATH): os.makedirs(PATH) 19 DVOLABEL = doc.find("dvo/gpc1Label").text 20 FULLPATH = PATH + "/" + name + "_" + DVOLABEL + "_" + host + "_" + str(pid) + ".log" 25 FULLPATH = PATH + "/" + name + "_" + dvoLabel + "_" + HOST + "_" + str(PID) + ".log" 21 26 22 27 # opens file to be appended -
trunk/ippToPsps/jython/scratchdb.py
r33236 r33259 19 19 Constructor 20 20 ''' 21 def __init__(self, logger, doc, useFull=0):22 super(ScratchDb, self).__init__(logger, doc, "localdatabase")21 def __init__(self, logger, config, useFull=0): 22 super(ScratchDb, self).__init__(logger, config, "localdatabase") 23 23 24 24 if useFull: … … 484 484 485 485 ''' 486 Gets a list of PSPS image IDs for this stack ID487 ''' 488 def getDvoRegions ForThisBox(self, minRa, maxRa, minDec, maxDec):486 Gets a list of DVO regions that overlap with the defined box 487 ''' 488 def getDvoRegions(self, minRa, maxRa, minDec, maxDec): 489 489 490 490 self.logger.debug("Querying DVO SkyTable for FITS files in this region") 491 492 regions = [] 493 self.getDvoRegionsForThisBox(regions, minRa, maxRa, minDec, maxDec) 494 495 # deal with 0/360 boundary 496 if minRa < 0: self.getDvoRegionsForThisBox(regions, minRa + 360, 361 ,minDec, maxDec) 497 if maxRa > 360: self.getDvoRegionsForThisBox(regions, 0, maxRa - 360 ,minDec, maxDec) 498 499 return regions 500 501 ''' 502 Gets a list of DVO regions that overlap with the defined box 503 ''' 504 def getDvoRegionsForThisBox(self, regions, minRa, maxRa, minDec, maxDec): 491 505 492 506 sql = "SELECT name FROM " + self.dvoSkyTable + " \ … … 498 512 try: 499 513 rs = self.executeQuery(sql) 500 except: 501 self.logger.exception("Can't query for imageIDs") 502 503 files = [] 504 while (rs.next()): 505 files.append(rs.getString(1)) 506 rs.close() 507 508 return files 509 510 514 while (rs.next()): regions.append(rs.getString(1)) 515 rs.close() 516 except: 517 self.logger.exception("Can't query for DVO regions") 518 519 -
trunk/ippToPsps/jython/stackbatch.py
r33235 r33259 30 30 def __init__(self, 31 31 logger, 32 configPath, 33 configDoc, 32 config, 34 33 gpc1Db, 35 34 ippToPspsDb, … … 40 39 super(StackBatch, self).__init__( 41 40 logger, 42 configPath, 43 configDoc, 41 config, 44 42 gpc1Db, 45 43 ippToPspsDb, … … 47 45 batchID, 48 46 "ST", 49 gpc1Db.getStackStageCmf(config Doc.find("dvo/gpc1Label").text, stackID),47 gpc1Db.getStackStageCmf(config.dvoLabel, stackID), 50 48 useFullTables) 51 49 … … 307 305 self.scratchDb.updateAllRows("StackMeta", "surveyID", str(self.surveyID)) 308 306 self.scratchDb.updateFilterID("StackMeta", self.filter) 309 self.scratchDb.updateAllRows("StackMeta", "dataRelease", str(self. dataRelease))307 self.scratchDb.updateAllRows("StackMeta", "dataRelease", str(self.config.dataRelease)) 310 308 self.updateStackTypeID("StackMeta") 311 309 … … 403 401 self.scratchDb.updateAllRows("StackDetection", "surveyID", str(self.surveyID)) 404 402 self.scratchDb.updateFilterID("StackDetection", self.filter) 405 self.scratchDb.updateAllRows("StackDetection", "dataRelease", str(self. dataRelease))403 self.scratchDb.updateAllRows("StackDetection", "dataRelease", str(self.config.dataRelease)) 406 404 self.scratchDb.updateAllRows("StackDetection", "primaryF", "0") 407 405 self.scratchDb.updateAllRows("StackDetection", "activeFlag", "0") … … 467 465 self.scratchDb.updateAllRows("StackApFlx", "surveyID", str(self.surveyID)) 468 466 self.scratchDb.updateFilterID("StackApFlx", self.filter) 469 self.scratchDb.updateAllRows("StackApFlx", "dataRelease", str(self. dataRelease))467 self.scratchDb.updateAllRows("StackApFlx", "dataRelease", str(self.config.dataRelease)) 470 468 self.scratchDb.updateAllRows("StackApFlx", "primaryF", "0") 471 469 self.scratchDb.updateAllRows("StackApFlx", "activeFlag", "0")
Note:
See TracChangeset
for help on using the changeset viewer.
