本文整理汇总了Python中DIRAC.WorkloadManagementSystem.DB.JobDB.JobDB._query方法的典型用法代码示例。如果您正苦于以下问题:Python JobDB._query方法的具体用法?Python JobDB._query怎么用?Python JobDB._query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.WorkloadManagementSystem.DB.JobDB.JobDB
的用法示例。
在下文中一共展示了JobDB._query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doNew
# 需要导入模块: from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB [as 别名]
# 或者: from DIRAC.WorkloadManagementSystem.DB.JobDB.JobDB import _query [as 别名]
def doNew(self, masterParams=None):
hosts = masterParams
sql = """
select JP.Value, J.Status, J.Site, count(*) from Jobs J, JobParameters JP
where J.JobID = JP.JobID and JP.Name = 'HostName'
and J.EndExecTime >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR)
group by JP.Value, J.Status
"""
jobDB = JobDB()
queryRes = jobDB._query(sql)
if not queryRes["OK"]:
return queryRes
records = queryRes["Value"]
hostJobs = {}
for record in records:
hostName = record[0]
status = record[1]
if status != "Done" and status != "Failed":
continue
if hostName not in hostJobs:
hostJobs[hostName] = {"Site": record[2], "Done": 0, "Failed": 0}
hostJobs[hostName][record[1]] = record[3]
uniformResult = []
for host, hostDict in hostJobs.items():
hostDict["Host"] = host
try:
hosts.remove(host)
except ValueError:
pass
if hostDict["Done"] == 0 and hostDict["Failed"] == 0:
hostDict["Efficiency"] = 0.0
else:
hostDict["Efficiency"] = (
math.floor(float(hostDict["Done"]) / (hostDict["Done"] + hostDict["Failed"]) * 1000) / 10
)
uniformResult.append(hostDict)
if len(hosts) != 0:
deleteRes = self.rmClient.deleteWorkNodeCache(host=hosts)
if not deleteRes["OK"]:
return deleteRes
storeRes = self._storeCommand(uniformResult)
if not storeRes["OK"]:
return storeRes
return S_OK(uniformResult)
示例2: mysql_querry
# 需要导入模块: from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB [as 别名]
# 或者: from DIRAC.WorkloadManagementSystem.DB.JobDB.JobDB import _query [as 别名]
def mysql_querry(querry):
if USE_PURE_MYSQL:
import MySQLdb#@UnresolvedImport
db = MySQLdb.connect(host="diracdb2.ihep.ac.cn", # your host, usually localhost
user="monitor", # your username
passwd="###DIRAC_DB_PASS###", # your password
db="JobDB")
cur = db.cursor()
cur.execute(querry)
data = cur.fetchall()
cur.close()
return data
else:
db = JobDB()
return db._query( querry )['Value']
示例3: getDataFromDB
# 需要导入模块: from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB [as 别名]
# 或者: from DIRAC.WorkloadManagementSystem.DB.JobDB.JobDB import _query [as 别名]
def getDataFromDB(self):
db = JobDB()
cmd = 'SELECT * FROM Jobs'
res = db._query( cmd )
#Week data
cmd = "select J.Site, JP.Value, sum(1), S.total from Jobs J, JobParameters JP, (select JP.Value as host, sum(1) as total from Jobs J, JobParameters JP where J.JobID=JP.JobID and JP.Name='HostName' group by JP.Value) S where J.JobID=JP.JobID and JP.Name='HostName' and J.Status='Done' and S.host=JP.Value group by JP.Value order by J.Site asc"
result = mysql_querry( cmd )
#print result
data = {}
for i in result:
data[(i[0], i[1])]=[int(i[2]), int(i[3])]
#TwoDays data
cmd = "select J.Site, JP.Value, sum(1), S.total from Jobs J, JobParameters JP, (select JP.Value as host, sum(1) as total from Jobs J, JobParameters JP where J.JobID=JP.JobID and JP.Name='HostName' and J.SubmissionTime>= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 48 HOUR) group by JP.Value) S where J.JobID=JP.JobID and JP.Name='HostName' and J.Status='Done' and S.host=JP.Value and J.SubmissionTime>= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 48 HOUR) group by JP.Value order by J.Site asc"
result = mysql_querry( cmd )
for i in result:
if (i[0],i[1]) not in data:
data[(i[0],i[1])] = [0,0]
print "Strange behavior: for ", (i[0],i[1]), " was no week data"
data[(i[0], i[1])] += [int(i[2]), int(i[3])]
#OneDay data
cmd = "select J.Site, JP.Value, sum(1), S.total from Jobs J, JobParameters JP, (select JP.Value as host, sum(1) as total from Jobs J, JobParameters JP where J.JobID=JP.JobID and JP.Name='HostName' and J.SubmissionTime>= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR) group by JP.Value) S where J.JobID=JP.JobID and JP.Name='HostName' and J.Status='Done' and S.host=JP.Value and J.SubmissionTime>= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR) group by JP.Value order by J.Site asc"
result = mysql_querry( cmd )
for i in result:
if (i[0],i[1]) not in data:
data[(i[0],i[1])] = [0,0]
print "Strange behavior: for ", (i[0],i[1]), " was no week data"
data[(i[0], i[1])] += [int(i[2]), int(i[3])]
prejson = [[x[0], x[1]]+data[x] for x in data]
for i in range(0, len(prejson)):
prejson[i] += [0 for j in range(0, 8-len(prejson[i]))]
return prejson
示例4: doNew
# 需要导入模块: from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB [as 别名]
# 或者: from DIRAC.WorkloadManagementSystem.DB.JobDB.JobDB import _query [as 别名]
def doNew( self, masterParams = None ):
sql = """
select JP.Value, J.Status, J.Site, count(*) from Jobs J, JobParameters JP
where J.JobID = JP.JobID and JP.Name = 'HostName'
and J.LastUpdateTime >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR)
group by JP.Value, J.Status
"""
jobDB = JobDB()
queryRes = jobDB._query(sql)
if not queryRes[ 'OK' ]:
return queryRes
records = queryRes[ 'Value' ]
hostJobs = {}
for record in records:
hostName = record[ 0 ]
if hostName not in hostJobs:
hostJobs[ hostName ] = { 'Site' : record[ 2 ], 'Running' : 0, 'Done' : 0, 'Failed' : 0 }
hostJobs[ hostName ][ record[ 1 ] ] = record[ 3 ]
uniformResult = []
for host, hostDict in hostJobs.items():
hostDict[ 'Host' ] = host
if hostDict[ 'Done' ] == 0 and hostDict[ 'Failed' ] == 0:
hostDict[ 'Efficiency' ] = 0
else:
hostDict[ 'Efficiency' ] = float( hostDict[ 'Done' ] ) / ( hostDict[ 'Done' ] + hostDict[ 'Failed' ] )
uniformResult.append( hostDict )
storeRes = self._storeCommand( uniformResult )
if not storeRes[ 'OK' ]:
return storeRes
return S_OK( uniformResult )