IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2012, 12:02:48 PM (14 years ago)
Author:
rhenders
Message:

Big changes to support a new Config class that encapuslates the xml config file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/load.py

    r33237 r33259  
    1010import socket
    1111import logging.config
    12 from xml.etree.ElementTree import ElementTree, Element, tostring
    13 
     12
     13from config import Config
    1414from pslogger import PSLogger
    1515from gpc1db import Gpc1Db
     
    2828def publishAnyUnpublishedBatches(batchType):
    2929
    30     batchIDs = ippToPspsDb.getProcessedButFailedDatastoreBatchIDs(EPOCH, DVOGPC1LABEL, batchType)
     30    batchIDs = ippToPspsDb.getProcessedButFailedDatastoreBatchIDs(config.epoch, config.dvoLabel, batchType)
    3131    logger.infoPair("%s batches" % batchType, "%d" % len(batchIDs))
    3232
     
    3434
    3535        batchName = Batch.getNameFromID(batchID)
    36         subDir = Batch.getSubDir(BASEPATH, batchType, DVOGPC1LABEL)
     36        subDir = Batch.getSubDir(config.basePath, batchType, config.dvoLabel)
    3737        tarballFile = Batch.getTarballFile(batchID)
    3838        logger.infoPair("Batch name", batchName)
     
    4848    logger.infoPair("Box center and size", "%f/%f/%f" %(ra, dec, boxsize))
    4949
    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
    5851
    5952    if len(allIDs) > 0:
     
    6356
    6457        allIDs = gpc1Db.getIDsInThisDVODbForThisStageInThisBox(
    65                 DVOGPC1LABEL,
     58                config.dvoLabel,
    6659                batchType,
    6760                ra,
     
    7164        logger.infoPair("All %s items in DVO" % batchType, "%d" % len(allIDs))
    7265
    73     # if in FORCE mode, then queue full list
    74     if FORCE: ids = allIDs
    75 
    76     # if not in TEST mode, then only queue un-processed items
     66    # 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
    7770    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)
    8073        ids = list(set(allIDs) - set(processedIDs) - set(consistaentlyFailedIDs))
    8174        logger.infoPair("Processed items", "%d" % len(processedIDs))
     
    9790    for id in ids:
    9891
    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)
    10793       
    10894        if batchID < 0: continue;
     
    11298        if batchType == "P2":
    11399            batch = DetectionBatch(logger,
    114                     CONFIG,
    115                     configDoc,
     100                    config,
    116101                    gpc1Db,
    117102                    ippToPspsDb,
     
    121106        elif batchType == "ST":
    122107            batch = StackBatch(logger,
    123                     CONFIG,
    124                     configDoc,
     108                    config,
    125109                    gpc1Db,
    126110                    ippToPspsDb,
     
    135119        logger.infoSeparator()
    136120
    137         # if in TEST mode, then quit after one batch
    138         if TEST: break
     121        # if in test mode, then quit after one batch
     122        if config.test: break
    139123
    140124    ippToPspsDb.unlockTables()
     
    143127Start of program.
    144128'''
    145 if len(sys.argv) > 1: CONFIG = sys.argv[1]
     129if len(sys.argv) > 1: CONFIGPATH = sys.argv[1]
    146130else:
    147131    print "** Usage: " + sys.argv[0] + " <configPath> [init]"
     
    154138
    155139# 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")
     140config = Config(CONFIGPATH)
     141#logger = config.getLogger("load", 0, 1)
     142logger = config.getLogger("load")
    170143
    171144# create various objects
    172 dvo = Dvo(logger, configDoc)
    173 gpc1Db = Gpc1Db(logger, configDoc)
    174 ippToPspsDb = IppToPspsDb(logger, configDoc)
    175 datastore = Datastore(logger, configDoc, ippToPspsDb)
     145dvo = Dvo(logger, config)
     146gpc1Db = Gpc1Db(logger, config)
     147ippToPspsDb = IppToPspsDb(logger, config)
     148datastore = Datastore(logger, config, ippToPspsDb)
    176149
    177150# check we connected ok
     
    181154# get values from the configutaion file
    182155POLLPERIOD = 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
     158if config.force and config.datastorePublishing and not QUEUE_IN:
    209159   response = raw_input("\n*** Are you sure you want to publish data with the 'force' option enabled (y/n)? ")
    210160   if response != "y": sys.exit(1)
    211161
    212 # prompt user: TEST and PUBLISH is a dangerous combination
    213 if TEST and PUBLISH and not QUEUE_IN:
     162# prompt user: test and publishing is a dangerous combination
     163if config.test and config.datastorePublishing and not QUEUE_IN:
    214164   response = raw_input("\n*** Are you sure you want to publish data with the 'testMode' option enabled (y/n)? ")
    215165   if response != "y": sys.exit(1)
     
    218168logger.infoSeparator()
    219169logger.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)
    227170
    228171# if an IN batch is requested, create and quit
    229172if 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)
    238174   if batchID > 0:
    239        batch = InitBatch(logger, CONFIG, configDoc, gpc1Db, ippToPspsDb, batchID)
     175       batch = InitBatch(logger, config, gpc1Db, ippToPspsDb, batchID)
    240176       batch.run()
    241177
     
    251187
    252188'''
    253 BORDER = 1.60
    254 HALFBOX = BOXSIZE/2.0
    255 BOXSIZEWITHBORDER = BOXSIZE + (BORDER * 2)
    256189
    257190# this outer while loop simply waits a few minutes then starts queuing againas more stuff may appear in DVO over time
    258191while True:
    259192
     193    config.refresh()
     194    config.printAll()
     195
    260196    # starting positions
    261     ra = MINRA + HALFBOX
    262     dec = MINDEC + HALFBOX
     197    ra = config.minRa + config.halfBox
     198    dec = config.minDec + config.halfBox
    263199
    264200    # queue up batches that are processed but not loaded to datastore
    265201    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 BOXSIZE
    269     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:
    272208
    273209           # for each batch type
     
    275211           # - check if we should pre-load DVO region
    276212           # - 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)
    279216
    280217               if len(ids) < 1:
     
    282219                   continue
    283220
    284                dvo.setSkyAreaAsBox(ra, dec, BOXSIZEWITHBORDER)
     221               dvo.setSkyAreaAsBox(ra, dec, config.boxSizeWithBorder)
    285222               dvo.printSummary()
    286223
     
    291228
    292229               # do we pre-ingest stuff from DVO?
    293                if smfsPerGB > 40:
     230               if smfsPerGB > 0:
    294231                   if not dvo.sync():
    295232                       logger.errorPair("Could not sync DVO with MySQL", "skipping")
     
    301238               logger.infoBool("Using pre-ingested DVO data?", useFullTables)
    302239               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
    313251
    314252    # wait for the POLLPERIOD before checking for new ids
Note: See TracChangeset for help on using the changeset viewer.