IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2014, 4:05:27 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ps2-tc3-20130727

  • branches/eam_branches/ps2-tc3-20130727/ippToPsps/jython/ipptopspsdb.py

    r36680 r37403  
    166166
    167167        return ids
    168 
    169     ## '''
    170     ## XXX EAM : removed this function and made it more explicit (with an additional block)
    171     ## Returns a list of merged batch IDs that are merged but not yet deleted
    172     ## '''
    173     ## def getMergedButNotDeletedBatchIDs(self, batchType, column):
    174     ##
    175     ##     sql = "SELECT DISTINCT batch_id \
    176     ##            FROM batch \
    177     ##            WHERE timestamp > '" + self.skychunk.epoch + "' \
    178     ##            AND batch_type = '" + batchType + "' \
    179     ##            AND dvo_db = '" + self.skychunk.dvoLabel + "' \
    180     ##            AND merged = 1 \
    181     ##            AND " + column + " = 0"
    182     ##
    183     ##     ids = []
    184     ##     try:
    185     ##         rs = self.executeQuery(sql)
    186     ##         while (rs.next()): ids.append(rs.getInt(1))
    187     ##         rs.close()
    188     ##     except:
    189     ##         self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
    190     ##
    191     ##     self.logger.debug("Found %d merged but un-deleted items" % len(ids))
    192     ##
    193     ##     return ids
    194 
    195     ## '''
    196     ## Returns a list of batch IDs marked as 'purged' but not yet deleted
    197     ## XXX EAM : removed this function and made it more explicit (with an additional block)
    198     ## '''
    199     ## def getPurgedButNotDeletedBatchIDs(self, batchType, column):
    200     ##
    201     ##     sql = "SELECT DISTINCT batch_id \
    202     ##            FROM batch \
    203     ##            WHERE timestamp > '" + self.skychunk.epoch + "' \
    204     ##            AND batch_type = '" + batchType + "' \
    205     ##            AND dvo_db = '" + self.skychunk.dvoLabel + "' \
    206     ##            AND purged = 1 \
    207     ##            AND " + column + " = 0"
    208     ##
    209     ##     ids = []
    210     ##     try:
    211     ##         rs = self.executeQuery(sql)
    212     ##         while (rs.next()): ids.append(rs.getInt(1))
    213     ##         rs.close()
    214     ##     except:
    215     ##         self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
    216     ##
    217     ##
    218     ##     self.logger.debug("Found %d merged but un-deleted items" % len(ids))
    219     ##
    220     ##     return ids
    221 
    222     ## '''
    223     ## Returns a list of processed batch IDs that have been loaded to the ODM but not yet deleted
    224     ## '''
    225     ## def getLoadedToODMButNotDeletedBatchIDs(self, batchType, column):
    226     ##
    227     ##     sql = "SELECT DISTINCT batch_id \
    228     ##            FROM batch \
    229     ##            WHERE timestamp > '" + self.skychunk.epoch + "' \
    230     ##            AND batch_type = '" + batchType + "' \
    231     ##            AND dvo_db = '" + self.skychunk.dvoLabel + "' \
    232     ##            AND (loaded_to_ODM = -1 OR merge_worthy = 1) \
    233     ##            AND " + column + " = 0"
    234     ##
    235     ##     ids = []
    236     ##     try:
    237     ##         rs = self.executeQuery(sql)
    238     ##         while (rs.next()): ids.append(rs.getInt(1))
    239     ##         rs.close()
    240     ##     except:
    241     ##         self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
    242     ##
    243     ##     self.logger.debug("Found %d merged but un-deleted items" % len(ids))
    244     ##
    245     ##     return ids
    246 
    247     # '''
    248     # Returns a list of merged batch IDs that are not deleted from local disk
    249     # '''
    250     # def getMergedButNotDeletedFromLocalDisk(self, batchType):
    251     #     return self.getMergedButNotDeletedBatchIDs(batchType, "deleted_local")
    252 
    253     ## '''
    254     ## Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from local disk
    255     ## '''
    256     ## def getLoadedToODMButNotDeletedFromLocalDisk(self, batchType):
    257     ##     return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_local")
    258     ##
    259     ## '''
    260     ## Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from datastore
    261     ## '''
    262     ## def getLoadedToODMButNotDeletedFromDatastore(self, batchType):
    263     ##     return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_datastore")
    264     ##
    265     ## '''
    266     ## Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from DXLayer
    267     ## '''
    268     ## def getLoadedToODMButNotDeletedFromDXLayer(self, batchType):
    269     ##     return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_dxlayer")
    270 
    271     ## '''
    272     ## Returns a list of purged  batch IDs that not deleted from local disk
    273     ## '''
    274     ## def getPurgedButNotDeletedFromLocalDisk(self, batchType):
    275     ##     return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_local")
    276     ##
    277     ## '''
    278     ## Returns a list of purged batch IDs that are not deleted from datastore
    279     ## '''
    280     ## def getPurgedButNotDeletedFromDatastore(self, batchType):
    281     ##     return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_datastore")
    282 
    283168
    284169    '''
     
    786671            and not self.consistentlyFailed(batchType, stageID)):
    787672           
    788             self.logger.infoPair("heather:","passed logic")
     673            # self.logger.infoPair("heather:","passed logic")
    789674
    790675            sql = "INSERT INTO batch ( \
     
    803688                       '" + self.skychunk.name + "' \
    804689                       )"
    805             self.logger.infoPair("heather:","sql")
     690 
     691            # self.logger.infoPair("heather:",sql)
    806692
    807693            self.execute(sql)
     
    816702            except:
    817703                self.logger.exception("Unable to get batch ID")
     704                self.logger.infoPair("sql:",sql)
     705
    818706                batchID = -1
    819707
     
    1017905       response = raw_input(" * Name for new skychunk, or existing skychunk to edit? ")
    1018906       if response == "": return
     907       response = response.strip()
    1019908       self.skychunk.name = response
    1020909
     
    1056945           question = question +  "? "
    1057946           response = raw_input(question)
     947           response = response.strip()
     948           print "response: '" + response + "'"
    1058949           if response != "":
    1059950               if type.find("varchar") != -1 or type.find("timestamp") != -1: quotes = "'"
    1060951               else: quotes = ""
     952               # print "UPDATE skychunk SET " + field + " = " + quotes + response + quotes + " WHERE name = '" + self.skychunk.name + "'"
    1061953               self.execute("UPDATE skychunk SET " + field + " = " + quotes + response + quotes + " WHERE name = '" + self.skychunk.name + "'")
    1062954       
     
    11161008        ,queue_ST \
    11171009        ,queue_OB \
     1010        ,queue_DF \
     1011        ,queue_DO \
     1012        ,queue_FW \
     1013        ,queue_FO \
    11181014        ,parallel \
    11191015        ,P2_smf_version \
     
    11251021
    11261022        self.skychunk.batchTypes = []
    1127         try:
    1128             rs = self.executeQuery(sql)
    1129 
    1130             rs.first()
    1131             self.skychunk.datastoreProduct = rs.getString(1)
    1132             self.skychunk.datastoreType = rs.getString(2)
    1133             if rs.getInt(3) == 1: self.skychunk.datastorePublishing = True
    1134             else: self.skychunk.datastorePublishing = False
    1135             self.skychunk.dvoLabel = rs.getString(4)
    1136 
    1137             # if dvoLabel is null is can break queries, so set to something
    1138             if not self.skychunk.dvoLabel: self.skychunk.dvoLabel = "none"
    1139             self.skychunk.dvoLocation = rs.getString(5)
    1140             self.skychunk.minRa = rs.getDouble(6)
    1141             self.skychunk.maxRa = rs.getDouble(7)
    1142             self.skychunk.minDec = rs.getDouble(8)
    1143             self.skychunk.maxDec = rs.getDouble(9)
    1144 
    1145             self.skychunk.boxSize = rs.getDouble(10)
    1146             # self.skychunk.halfBox = self.skychunk.boxSize/2.0
    1147             # self.skychunk.boxSizeWithBorder = self.skychunk.boxSize + (self.skychunk.BORDER * 2)
    1148 
    1149             self.skychunk.basePath = rs.getString(11)
    1150             self.skychunk.dataRelease = rs.getInt(12)
    1151 
    1152             self.skychunk.deleteLocal = rs.getInt(13)
    1153             self.skychunk.deleteDatastore = rs.getInt(14)
    1154             self.skychunk.deleteDxLayer = rs.getInt(15)
    1155 
    1156             self.skychunk.epoch = rs.getString(16)
    1157 
    1158             self.skychunk.survey = rs.getString(17)
    1159             self.skychunk.pspsSurvey = rs.getString(18)
    1160 
    1161             if rs.getInt(19) == 1: self.skychunk.batchTypes.append("P2")
    1162             if rs.getInt(20) == 1: self.skychunk.batchTypes.append("ST")
    1163             if rs.getInt(21) == 1: self.skychunk.batchTypes.append("OB")
    1164 
    1165             self.skychunk.force = True # TODO
    1166             self.skychunk.parallel = False # TODO
    1167 
    1168             if rs.getInt(22) == 1: self.skychunk.parallel = True
    1169             self.skychunk.P2_smf_version = rs.getString(23)
    1170             self.skychunk.ST_cmf_version = rs.getString(24)
    1171             self.skychunk.trange_start = rs.getString(25)
    1172             self.skychunk.trange_end = rs.getString(26)
    1173 
    1174             if self.skychunk.parallel: print "USING parallel"
    1175             self.skychunk.isLoaded = True
    1176         except:
     1023
     1024        try:
     1025            rs = self.executeQuery("show tables")
     1026        except:
     1027            self.logger.errorPair("cannot even show tables?", "Boo hoo")
     1028            sys.exit(1)
     1029
     1030        # while rs.next():
     1031        #     print "table row"
     1032        #     print rs.getString(1)
     1033        #
     1034        # rs = self.executeQuery("select * from skychunk")
     1035        # while rs.next():
     1036        #     print "skychunk row"
     1037        #     print rs.getString(1)
     1038        #
     1039        # print "SQL (2): " + sql
     1040
     1041        try:
     1042            rs = self.executeQuery(sql)
     1043
     1044        except:
     1045            self.logger.errorPair("problem with sql query for skychunk", sql)
     1046            sys.exit(1)
     1047
     1048        if not rs.next():
    11771049            self.logger.errorPair("Could not read skychunk with name", self.skychunk.name)
    11781050            self.skychunk.isLoaded = False
     1051            return False
     1052
     1053        self.skychunk.datastoreProduct = rs.getString(1)
     1054        self.skychunk.datastoreType = rs.getString(2)
     1055        if rs.getInt(3) == 1: self.skychunk.datastorePublishing = True
     1056        else: self.skychunk.datastorePublishing = False
     1057        self.skychunk.dvoLabel = rs.getString(4)
     1058
     1059        # if dvoLabel is null is can break queries, so set to something
     1060        if not self.skychunk.dvoLabel: self.skychunk.dvoLabel = "none"
     1061        self.skychunk.dvoLocation = rs.getString(5)
     1062        self.skychunk.minRa = rs.getDouble(6)
     1063        self.skychunk.maxRa = rs.getDouble(7)
     1064        self.skychunk.minDec = rs.getDouble(8)
     1065        self.skychunk.maxDec = rs.getDouble(9)
     1066
     1067        self.skychunk.boxSize = rs.getDouble(10)
     1068        # self.skychunk.halfBox = self.skychunk.boxSize/2.0
     1069        # self.skychunk.boxSizeWithBorder = self.skychunk.boxSize + (self.skychunk.BORDER * 2)
     1070
     1071        self.skychunk.basePath = rs.getString(11)
     1072        self.skychunk.dataRelease = rs.getInt(12)
     1073
     1074        self.skychunk.deleteLocal = rs.getInt(13)
     1075        self.skychunk.deleteDatastore = rs.getInt(14)
     1076        self.skychunk.deleteDxLayer = rs.getInt(15)
     1077
     1078        self.skychunk.epoch = rs.getString(16)
     1079
     1080        self.skychunk.survey = rs.getString(17)
     1081        self.skychunk.pspsSurvey = rs.getString(18)
     1082
     1083        if rs.getInt(19) == 1: self.skychunk.batchTypes.append("P2")
     1084        if rs.getInt(20) == 1: self.skychunk.batchTypes.append("ST")
     1085        if rs.getInt(21) == 1: self.skychunk.batchTypes.append("OB")
     1086        if rs.getInt(22) == 1: self.skychunk.batchTypes.append("DF")
     1087        if rs.getInt(23) == 1: self.skychunk.batchTypes.append("DO")
     1088        if rs.getInt(24) == 1: self.skychunk.batchTypes.append("FW")
     1089        if rs.getInt(25) == 1: self.skychunk.batchTypes.append("FO")
     1090
     1091        self.skychunk.force = True # TODO
     1092        self.skychunk.parallel = False # TODO
     1093
     1094        if rs.getInt(26) == 1: self.skychunk.parallel = True
     1095        self.skychunk.P2_smf_version = rs.getString(27)
     1096        # options: "use_new", "not_reproc", "use_original"
     1097
     1098        self.skychunk.ST_cmf_version = rs.getString(28)
     1099        # options: not used?
     1100
     1101        # NOTE : the rs (ResultSet) class is somewhat annoying and finicky esp about timestamp values
     1102        # for example, rs.getTimestamp(N) fails silently if the value is not a valid time.  this is
     1103        # also true to getString() on the same column.  Docs for the ResultSet class can be found here:
     1104        # http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/ResultSet.html?is-external=true
     1105
     1106        # rsmd = rs.getMetaData()
     1107        # print "got metadata"
     1108        # print "number of columns: " + str(rsmd.getColumnCount())
     1109        # print "label: " + rsmd.getColumnLabel(25)
     1110        # print "label: " + rsmd.getColumnLabel(29)
     1111        # print "name: " + rsmd.getColumnName(25)
     1112        # print "name: " + rsmd.getColumnName(29)
     1113        # print "typename: " + rsmd.getColumnTypeName(25)
     1114        # print "typename: " + rsmd.getColumnTypeName(29)
     1115
     1116        # epochStamp = rs.getTimestamp(16)
     1117        # print "epoch: " + epochStamp.toString()
     1118
     1119        # print "label: " + rsmd.getColumnLabel(16)
     1120        # print "name: " + rsmd.getColumnName(16)
     1121        # print "typename: " + rsmd.getColumnTypeName(16)
     1122
     1123        self.skychunk.trange_start = rs.getString(29)
     1124        # options: "YYYY-MM-DD,HH:MM:SS" or "0000-00-00 00:00:00"
     1125
     1126        self.skychunk.trange_end = rs.getString(30)
     1127        # options: "YYYY-MM-DD,HH:MM:SS" or "0000-00-00 00:00:00"
     1128
     1129        if self.skychunk.parallel: print "USING parallel"
     1130        self.skychunk.isLoaded = True
    11791131
    11801132        return self.skychunk.isLoaded
     
    13001252    def insertPending(self, box_id, batchType, ids):
    13011253
    1302         # print "starting insert pending"
     1254        print "starting insert pending"
    13031255
    13041256        # first delete old pending items
     
    13061258                WHERE box_id = " + str(box_id) + " \
    13071259                AND batch_type = '" + batchType + "'")
    1308 
    1309         # print "deleted old items"
    13101260
    13111261        for id in ids:
     
    13151265               (" + str(box_id) + ", '" + batchType + "', " + str(id) + ")"
    13161266
    1317             # print "sql: ", sql
    1318             self.execute(sql)
     1267            try: self.execute(sql)
     1268            except:
     1269                print "failed to insert into pending"
     1270                print "sql: " + sql
     1271                raise
    13191272
    13201273    '''
     
    13401293               GROUP BY ra_center LIMIT 1"
    13411294
    1342         # XXX print "sql: ", sql               
    1343 
    1344         try:
    1345             rs = self.executeQuery(sql)
    1346             rs.first()
    1347             raCenter = rs.getFloat(1)
    1348             rs.close()
    1349         except:
    1350             self.logger.errorPair("No free stripes", "trying to steal boxes from other client...")
    1351             sql = "SELECT ra_center, COUNT(*) AS numPending\
    1352                    FROM box \
    1353                    JOIN pending ON (id = box_id) \
    1354                    WHERE skychunk = '" + self.skychunk.name + "' \
    1355                    AND batch_type = '" + batchType + "' \
    1356                    GROUP BY ra_center \
    1357                    ORDER BY numPending \
    1358                    DESC LIMIT 1"
    1359 
    1360             try:
    1361                 rs = self.executeQuery(sql)
    1362                 rs.first()
    1363                 raCenter = rs.getFloat(1)
    1364                 rs.close()
    1365             except:
    1366                 self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained")
     1295        try: rs = self.executeQuery(sql)
     1296        except:
     1297            self.logger.errorPair("Problem querying for outstanding boxes", "error in sql?")
     1298            print "SQL: " + sql
     1299
     1300        if not rs.next():
     1301            self.logger.errorPair("No outstanding boxes", "nothing to do here")
     1302            rs.close()
     1303            self.unlockTables()
     1304            return ids
     1305
     1306        raCenter = rs.getFloat(1)
     1307        rs.close()
     1308
     1309        #except:
     1310        #    self.logger.errorPair("No free stripes", "trying to steal boxes from other client...")
     1311        #    sql = "SELECT ra_center, COUNT(*) AS numPending\
     1312        #           FROM box \
     1313        #           JOIN pending ON (id = box_id) \
     1314        #           WHERE skychunk = '" + self.skychunk.name + "' \
     1315        #           AND batch_type = '" + batchType + "' \
     1316        #           GROUP BY ra_center \
     1317        #           ORDER BY numPending \
     1318        #           DESC LIMIT 1"
     1319        #
     1320        #    try:
     1321        #        rs = self.executeQuery(sql)
     1322        #        rs.first()
     1323        #        raCenter = rs.getFloat(1)
     1324        #        rs.close()
     1325        #    except:
     1326        #        self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained")
    13671327
    13681328        # tests against ra_center need to use a finite box
     
    14131373               GROUP BY ra_center LIMIT 1"
    14141374
    1415         try:
    1416             rs = self.executeQuery(sql)
    1417             rs.first()
    1418             raCenter = rs.getFloat(1)
    1419             rs.close()
    1420         except:
    1421             self.logger.errorPair("No free stripes", "trying to steal boxes from other client...")
    1422             sql = "SELECT ra_center, COUNT(*) AS numPending\
    1423                    FROM box \
    1424                    JOIN pending ON (id = box_id) \
    1425                    WHERE skychunk = '" + self.skychunk.name + "' \
    1426                    GROUP BY ra_center \
    1427                    ORDER BY numPending \
    1428                    DESC LIMIT 1"
    1429 
    1430             try:
    1431                 rs = self.executeQuery(sql)
    1432                 rs.first()
    1433                 raCenter = rs.getFloat(1)
    1434                 rs.close()
    1435             except:
    1436                 self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained")
     1375        try: rs = self.executeQuery(sql)
     1376        except:
     1377            self.logger.errorPair("Problem querying for outstanding boxes", "error in sql?")
     1378            print "SQL: " + sql
     1379
     1380        if not rs.next():
     1381            self.logger.infoPair("No outstanding boxes", "nothing to do here")
     1382            rs.close()
     1383            self.unlockTables()
     1384            return ids
     1385
     1386        raCenter = rs.getFloat(1)
     1387        rs.close()
     1388
     1389        # except:
     1390        #     self.logger.errorPair("No free stripes", "trying to steal boxes from other client...")
     1391        #     sql = "SELECT ra_center, COUNT(*) AS numPending\
     1392        #            FROM box \
     1393        #            JOIN pending ON (id = box_id) \
     1394        #            WHERE skychunk = '" + self.skychunk.name + "' \
     1395        #            GROUP BY ra_center \
     1396        #            ORDER BY numPending \
     1397        #            DESC LIMIT 1"
     1398        #
     1399        #     try:
     1400        #         rs = self.executeQuery(sql)
     1401        #         rs.first()
     1402        #         raCenter = rs.getFloat(1)
     1403        #         rs.close()
     1404        #     except:
     1405        #         self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained")
    14371406
    14381407        # tests against ra_center need to use a finite box
     
    16261595        self.logger.infoPair("Items written to Db", "%d" % count)
    16271596
    1628         # try:
    1629         #     self.execute("DROP TABLE all_pending_alt")
    1630         # except:
    1631         #     pass
    1632         #
    1633         # self.execute("CREATE TABLE all_pending_alt (stage_id bigint(20), ra_bore float, dec_bore float)")
    1634         # for row in rows:
    1635         #     try:
    1636         #         sql = "INSERT INTO all_pending_alt (stage_id, ra_bore, dec_bore) \
    1637         #                VALUES (%d, %f, %f)" % (row[0], row[1], row[2])
    1638         #         print "sql 2: ", sql
    1639         #         self.execute(sql)
    1640         #     except: continue
    1641         #
    1642         # count = self.getRowCount("all_pending_alt")
    1643         # self.logger.infoPair("Items written to alt Db", "%d" % count)
     1597    '''
     1598    Creates a temporary table and shoves it full of stage_ids and ra/dec coords
     1599    '''
     1600    def storeAllItemsInDvodb(self, rows, dvo_db, batchType):
     1601
     1602        #try:
     1603        #    self.execute("DROP TABLE all_pending")
     1604        #except:
     1605        #    pass
     1606
     1607        #self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)")
     1608        for row in rows:
     1609
     1610            try:
     1611                uniq = dvo_db + "."+ batchType + "." + str(row[0])
     1612                sql = "INSERT INTO dvodb (dvo_db, batch_type, stage_id, ra_center, dec_center, uniq_key) \
     1613                       VALUES ( '" + dvo_db + "', '" + batchType + "'," + str(row[0]) + "," + str(row[1]) + " \
     1614                       , " + str(row[2]) + ", '"+uniq+"' ) "
     1615                # print "sql 1: ", sql
     1616                self.execute(sql)
     1617            except: continue
     1618
     1619        #count = self.getRowCount("all_pending")
     1620        #self.logger.infoPair("Items written to Db", "%d" % count)
     1621
     1622
    16441623
    16451624    '''
     
    16471626    '''
    16481627    def getItemsInThisBox(self, minRA, maxRA, minDEC, maxDEC):
    1649 
    1650         # the old linear size is ill-conceived
    1651         ## XX halfSide = self.skychunk.boxSize/2.0
    1652         ## XX minRa =  ra-halfSide
    1653         ## XX maxRa = ra+halfSide
    1654         ## XX minDec = dec-halfSide
    1655         ## XX maxDec = dec+halfSide
    16561628
    16571629        ids = []
     
    16621634               AND dec_bore BETWEEN " + str(minDEC) + " AND " + str(maxDEC)
    16631635
    1664         print "items: ", sql
    1665 
    1666         try:
    1667             rs = self.executeQuery(sql)
    1668             while (rs.next()): ids.append(rs.getInt(1))
     1636        try:
     1637            rs = self.executeQuery(sql)
     1638            while (rs.next()):
     1639                ids.append(rs.getInt(1))
    16691640        except:
    16701641            self.logger.errorPair("Can't get items in this box", sql)
Note: See TracChangeset for help on using the changeset viewer.