def activeSiteJobs(): ## returns a dictionary with ce_queue regexp and number of active jobs. ## portnumbers are not available, hope they are unique per ce bossLiteDB = BossLiteDB( 'MySQL', dbConfig ) ce_act = {} act_re = re.compile(r"\s*(?P<dest_ce>\S+)\s+(?P<dest_queue>\S+)\s+(?P<count>\d+)") found_scheds = all_sched() for sched in found_scheds: ## select the names for states that are considered waiting for this scheduler if waiting_name.has_key(sched): wnames = waiting_name[sched] else: wnames = waiting_name['default'] ## select the names for states that are considered running for this scheduler if running_name.has_key(sched): rnames = running_name[sched] else: rnames = running_name['default'] ## get the number of waiting jobs sql = \ "select destination,count(*) from bl_runningjob where scheduler='"\ + sched + "' and " for name in wnames: sql += 'status_scheduler = \''+name+'\' or ' sql = re.sub(' or $', '', sql) sql += 'group by destination;' answ = bossLiteDB.select( sql ) for ce in answ: if act_re.search(ce[0]): reggy = ce[0] if not ce_act.has_key(reggy): ce_act[reggy] = {'Idle':0, 'Running':0} ## prepare regexp for ce matching ce_act[reggy]['Idle'] += int(ce[1]) ## get the number of running jobs sql = \ "select destination,count(*) from bl_runningjob where scheduler='"\ + sched + "' and " for name in rnames: sql += 'status_scheduler = \'' + name + '\' or ' sql = re.sub(' or $', '', sql) sql += 'group by destination;' answ = bossLiteDB.select( sql ) for ce in answ: if act_re.search(ce[0]): reggy = ce[0] if not ce_act.has_key(reggy): ce_act[reggy] = {'Idle':0, 'Running':0} ## prepare regexp for ce matching ce_act[reggy]['Running'] += int(ce[1]) return ce_act
def activeJobs(): ## returns a simple dictionary with total number of jobs, running and waiting bossLiteDB = BossLiteDB( 'MySQL', dbConfig ) act_re = re.compile(r"\s*(?P<count>\d+)") ce_act = {'Idle':0, 'Running':0} found_scheds = all_sched() for sched in found_scheds: ## select the names for states that are considered waiting for this scheduler if waiting_name.has_key(sched): wnames = waiting_name[sched] else: wnames = waiting_name['default'] ## select the names for states that are considered running for this scheduler if running_name.has_key(sched): rnames = running_name[sched] else: rnames = running_name['default'] ## get the number of waiting jobs sql = "select count(*) from bl_runningjob where scheduler='" \ + sched + "' and " for name in wnames: sql += 'status_scheduler = \'' + name + '\' or ' sql = re.sub(' or $', '', sql) sql += 'group by destination;' bossLiteDB = BossLiteDB( 'MySQL', dbConfig ) answ = bossLiteDB.select( sql ) for count in answ : if act_re.search(count[0]): ce_act['Idle'] += int(act_re.search(count[0]).group('count')) ## get the number of running jobs sql = "select count(*) from bl_runningjob where scheduler='" \ + sched + "' and " for name in rnames: sql += 'status_scheduler = \'' + name + '\' or ' sql = re.sub(' or $', '', sql) sql += 'group by destination;' answ = bossLiteDB.select( sql ) for count in answ : if act_re.search(count[0]): ce_act['Running'] += int(act_re.search(count[0]).group('count')) return ce_act
def bossAdmin(sql): bossLiteDB = BossLiteDB( 'MySQL', dbConfig ) answ = bossLiteDB.select( sql ) if answ is None : return [] return [ line for line in answ ]
def all_sched(): sql = 'select scheduler from bl_runningjob group by scheduler where scheduler is not NULL;' bossLiteDB = BossLiteDB( 'MySQL', dbConfig ) answ = bossLiteDB.select( sql ) if answ is None : return [] return [ line[0] for line in answ ]