本文整理汇总了Python中WMCore.Services.RequestDB.RequestDBReader.RequestDBReader.getStatusAndTypeByRequest方法的典型用法代码示例。如果您正苦于以下问题:Python RequestDBReader.getStatusAndTypeByRequest方法的具体用法?Python RequestDBReader.getStatusAndTypeByRequest怎么用?Python RequestDBReader.getStatusAndTypeByRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Services.RequestDB.RequestDBReader.RequestDBReader
的用法示例。
在下文中一共展示了RequestDBReader.getStatusAndTypeByRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CleanCouchPoller
# 需要导入模块: from WMCore.Services.RequestDB.RequestDBReader import RequestDBReader [as 别名]
# 或者: from WMCore.Services.RequestDB.RequestDBReader.RequestDBReader import getStatusAndTypeByRequest [as 别名]
#.........这里部分代码省略.........
if db == "JobDump":
couchDB = self.jobsdatabase
view = "jobsByWorkflowName"
elif db == "FWJRDump":
couchDB = self.fwjrdatabase
view = "fwjrsByWorkflowName"
elif db == "SummaryStats":
couchDB = self.statsumdatabase
view = None
elif db == "WMStatsAgent":
couchDB = self.wmstatsCouchDB.getDBInstance()
view = "allWorkflows"
options = {"key": workflowName, "reduce": False}
if view == None:
try:
committed = couchDB.delete_doc(workflowName)
except CouchNotFoundError as ex:
return {'status': 'warning', 'message': "%s: %s" % (workflowName, str(ex))}
else:
try:
jobs = couchDB.loadView(db, view, options = options)['rows']
except Exception as ex:
errorMsg = "Error on loading jobs for %s" % workflowName
logging.warning("%s/n%s" % (str(ex), errorMsg))
return {'status': 'error', 'message': errorMsg}
for j in jobs:
doc = {}
doc["_id"] = j['value']['id']
doc["_rev"] = j['value']['rev']
couchDB.queueDelete(doc)
committed = couchDB.commit()
if committed:
#create the error report
errorReport = {}
deleted = 0
status = "ok"
for data in committed:
if 'error' in data:
errorReport.setdefault(data['error'], 0)
errorReport[data['error']] += 1
status = "error"
else:
deleted += 1
return {'status': status, 'delete': deleted, 'message': errorReport}
else:
return {'status': 'warning', 'message': "no %s exist" % workflowName}
def cleanAllLocalCouchDB(self, workflowName):
logging.info("Deleting %s from JobCouch" % workflowName)
jobReport = self.deleteWorkflowFromJobCouch(workflowName, "JobDump")
logging.debug("%s docs deleted from JobDump", jobReport)
fwjrReport = self.deleteWorkflowFromJobCouch(workflowName, "FWJRDump")
logging.debug("%s docs deleted from FWJRDump", fwjrReport)
summaryReport = self.deleteWorkflowFromJobCouch(workflowName, "SummaryStats")
logging.debug("%s docs deleted from SummaryStats", summaryReport)
wmstatsReport = self.deleteWorkflowFromJobCouch(workflowName, "WMStatsAgent")
logging.debug("%s docs deleted from wmagent_summary", wmstatsReport)
# if one of the procedure fails return False
if (jobReport["status"] == "error" or fwjrReport["status"] == "error" or
wmstatsReport["status"] == "error"):
return False
# other wise return True.
return True
def cleanAlreadyArchivedWorkflows(self):
"""
loop through the workflows in couchdb, if archived delete all the data in couchdb
"""
numDeletedRequests = 0
try:
localWMStats = self.wmstatsCouchDB.getDBInstance()
options = {"group_level": 1, "reduce": True}
results = localWMStats.loadView("WMStatsAgent", "allWorkflows", options = options)['rows']
requestNames = [x['key'] for x in results]
logging.info("There are %s workfows to check for archived status" % len(requestNames))
workflowDict = self.centralRequestDBReader.getStatusAndTypeByRequest(requestNames)
for request, value in workflowDict.items():
if value[0].endswith("-archived"):
self.cleanAllLocalCouchDB(request)
numDeletedRequests += 1
except Exception as ex:
errorMsg = "Error on loading workflow list from wmagent_summary db"
logging.warning("%s/n%s" % (errorMsg, str(ex)))
return numDeletedRequests
示例2: RequestDBTest
# 需要导入模块: from WMCore.Services.RequestDB.RequestDBReader import RequestDBReader [as 别名]
# 或者: from WMCore.Services.RequestDB.RequestDBReader.RequestDBReader import getStatusAndTypeByRequest [as 别名]
class RequestDBTest(unittest.TestCase):
"""
"""
def setUp(self):
"""
_setUp_
"""
self.schema = []
self.couchApps = ["ReqMgr"]
self.testInit = TestInitCouchApp('RequestDBServiceTest')
self.testInit.setLogging()
self.testInit.setDatabaseConnection()
self.testInit.setSchema(customModules = self.schema,
useDefault = False)
dbName = 'requsetdb_t'
self.testInit.setupCouch(dbName, *self.couchApps)
reqDBURL = "%s/%s" % (self.testInit.couchUrl, dbName)
self.requestWriter = RequestDBWriter(reqDBURL)
self.requestReader = RequestDBReader(reqDBURL)
self.requestWriter.defaultStale = {}
self.requestReader.defaultStale = {}
return
def tearDown(self):
"""
_tearDown_
Drop all the WMBS tables.
"""
self.testInit.tearDownCouch()
def testRequestDBWriter(self):
# test getWork
schema = generate_reqmgr_schema(3)
result = self.requestWriter.insertGenericRequest(schema[0])
self.assertEqual(len(result), 1, 'insert fail');
self.assertEqual(self.requestWriter.updateRequestStatus(schema[0]['RequestName'], "failed"), 'OK', 'update fail')
self.assertEqual(self.requestWriter.updateRequestStatus("not_exist_schema", "assigned"),
'Error: document not found')
result = self.requestWriter.updateRequestProperty(schema[0]['RequestName'],
{'Teams': ['teamA']})
self.assertEqual(self.requestWriter.updateRequestProperty(schema[0]['RequestName'],
{'Teams': ['teamA']}), 'OK', 'update fail')
self.assertEqual(self.requestWriter.updateRequestProperty("not_exist_schema", {'Teams': 'teamA'}),
'Error: document not found')
result = self.requestReader.getRequestByNames([schema[0]['RequestName']])
self.assertEqual(len(result), 1, "should be 1")
result = self.requestReader.getRequestByStatus(["failed"], False, 1)
self.assertEqual(len(result), 1, "should be 1")
result = self.requestReader.getStatusAndTypeByRequest([schema[0]['RequestName']])
self.assertEqual(result[schema[0]['RequestName']][0], 'failed', "should be failed")
result = self.requestWriter.insertGenericRequest(schema[1])
time.sleep(2)
result = self.requestWriter.insertGenericRequest(schema[2])
endTime = int(time.time()) - 1
result = self.requestReader.getRequestByStatusAndEndTime("new", False, endTime)
self.assertEqual(len(result), 1, "should be 1")
endTime = int(time.time()) + 1
result = self.requestReader.getRequestByStatusAndEndTime("new", False, endTime)
self.assertEqual(len(result), 2, "should be 2")