예제 #1
0
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
예제 #2
0
파일: gratia.py 프로젝트: djw8605/Gratia
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
예제 #3
0
                        self.log.debug("Query_And_Process: job_count is: " + str(job_count))

                        # Keep track of the max ID
                        if job['dbid'] > max_id:
                            max_id = job['dbid']
                    else:
                        #Job status is NOT valid was would have been quarantined already; No need to save it as a successful one...
                        return 0

                if job_count == 0:
                    max_id = gratia_max_dbid
                    self.log.debug("job_count is 0. max_id= " + str(max_id))
                txn[probename] = max_id
                self.log.debug("Query_And_Process: txn[probename] is: " + str(txn[probename]))
                try:
                    transaction.commit_txn(cp, txn)
                except Exception, e:
                    self.log.error("Caught an exception and the detail is: \n\"" + str(e) + "\" Exiting Now !")
                    sys.exit(1)
                curr_dbid = max_id
                self.log.debug("Query_And_Process: curr_dbid is: " + str(txn[probename]))


    def Validate_Job(self, job, probename, genericRules, blackList, quarantine):
        self.log.debug("Validate_Job method is called - job['dbid'] is: " + str(job['dbid']) + "\n")
        curr_qt={}      
        curr_pt={}      

        self.log.debug("quarantine_job_dbid is: " + str(quarantine.GetQuarantineDBID(probename)) + "\n")
        self.log.debug("job['dbid'] is: " + str(job['dbid']) + "\n")