def initialize_txn(cp): ''' initialize the last_successful_id to be the maximum of the minimum dbid of the database and last_successful_id ''' info = {} _add_if_exists(cp, "user", info) _add_if_exists(cp, "passwd", info) _add_if_exists(cp, "db", info) _add_if_exists(cp, "host", info) _add_if_exists(cp, "port", info) if 'port' in info: info['port'] = int(info['port']) try: db = MySQLdb.connect(**info) except: log.error("Connection to database failed; and the reason is: "+str(db)) raise Exception("Failed to connect to database."); cursor = db.cursor() cursor.execute("select MIN(dbid), MAX(dbid) from JobUsageRecord"); row = cursor.fetchone() minimum_dbid = int(row[0]) maximum_dbid = int(row[1]) log.debug("minimum_dbid: " + str(minimum_dbid) + " maximum_dbid: " + str(maximum_dbid)) # now, we want to put it into the file. # we check the file, if the file is empty, then it is the # the minimum dbid, otherwise, we choose # to be the maximum of the "minimum dbid" and the last_successful_id in the file txn={} txn_previous = transaction.start_txn(cp) txn['last_successful_id']=max(minimum_dbid, txn_previous['last_successful_id']) txn['probename'] = cp.get("gratia", "probe") transaction.commit_txn(cp, txn) return minimum_dbid, maximum_dbid
def initialize_txn(cp, probename): ''' initialize the last_successful_id to be the maximum of the minimum dbid of the database and last_successful_id ''' info = {} _add_if_exists(cp, "user", info) _add_if_exists(cp, "passwd", info) _add_if_exists(cp, "db", info) _add_if_exists(cp, "host", info) _add_if_exists(cp, "port", info) if 'port' in info: info['port'] = int(info['port']) db = None try: db = MySQLdb.connect(**info) except: raise Exception("Failed to connect to database. Following parameters were used to connect: " + str(info)) cursor = db.cursor() #cursor.execute("select MIN(dbid), MAX(dbid) from JobUsageRecord"); log.debug("In initialize_txn method, probename is:" + probename) cursor.execute("select MIN(dbid), MAX(dbid) from JobUsageRecord_Meta WHERE ProbeName = '%s'" %probename) row = cursor.fetchone() log.debug("cursor.fetchone row is:" + str(row)) if not None in row: minimum_dbid = int(row[0]) maximum_dbid = int(row[1]) else: minimum_dbid = 0 maximum_dbid = 0 log.debug("minimum_dbid: " + str(minimum_dbid) + " maximum_dbid: " + str(maximum_dbid)) # now, we want to put it into the file. # we check the file, if the file is empty, then it is the # the minimum dbid, otherwise, we choose # to be the maximum of the "minimum dbid" and the last_successful_id in the file #txn={} txn_previous = transaction.start_txn(cp, probename) txn = txn_previous #Let txn have everything which was saved previously. We'd add/modify enty for the current probename #txn['last_successful_id']=max(minimum_dbid, txn_previous['last_successful_id']) #txn['probename'] = cp.get("gratia", "probe") #Check if the probename exists in txn_previous dictionary if probename in txn_previous: txn[probename] = max(minimum_dbid, txn_previous[probename]) else: log.debug("probename didn't exist in dictionary from before...") txn[probename] = minimum_dbid log.debug("txn[probename] is:" + str(txn[probename])) transaction.commit_txn(cp, txn) return minimum_dbid, maximum_dbid
def Query_And_Process(self, cp, genericRules, blackList, whiteList, quarantine, gcharge_machine): probename='condor:'+str(self.hostname) self.log.debug("probename is: " + str(probename)) gratia_min_dbid = gratia_max_dbid = rules_min_dbid = disk_min_dbid = None #If probename entry exists in quarantine, need to read the quarantine and the last query dbid from disk quarantine.ReadQuarantineDBIDFromDisk(probename) #read the last successful dbid from the disk curr_txn = {} try: curr_txn = transaction.start_txn(cp, probename) #Get the dictionary stored on disk except Exception, e: self.log.error("Caught an exception and the detail is: \n\"" + str(e) + ".\"\n Exiting now !") sys.exit(1)