本文整理汇总了Python中WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter类的典型用法代码示例。如果您正苦于以下问题:Python WMStatsWriter类的具体用法?Python WMStatsWriter怎么用?Python WMStatsWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WMStatsWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HeartbeatMonitorBase
class HeartbeatMonitorBase(CherryPyPeriodicTask):
def __init__(self, rest, config):
super(HeartbeatMonitorBase, self).__init__(config)
self.centralWMStats = WMStatsWriter(config.wmstats_url)
self.threadList = config.thread_list
def setConcurrentTasks(self, config):
"""
sets the list of function reference for concurrent tasks
"""
self.concurrentTasks = [{'func': self.reportToWMStats, 'duration': config.heartbeatCheckDuration}]
def reportToWMStats(self, config):
"""
report thread status and heartbeat.
Also can report additional mointoring information by rewriting addAdditionalMonitorReport method
"""
self.logger.info("Checking Thread status...")
downThreadInfo = self.logDB.wmstats_down_components_report(self.threadList)
monitorInfo = self.addAdditionalMonitorReport(config)
downThreadInfo.update(monitorInfo)
wqSummaryDoc = convertToServiceCouchDoc(downThreadInfo, config.log_reporter)
self.centralWMStats.updateAgentInfo(wqSummaryDoc)
self.logger.info("Uploaded to WMStats...")
return
def addAdditionalMonitorReport(self, config):
"""
add Additonal report with heartbeat report
overwite the method with each applications monitoring info. (Need to follow the format displayed in wmstats)
"""
return {}
示例2: assignRequest
def assignRequest(requestName, teamName, prodMgr=None, wmstatUrl=None):
"""
_assignRequest_
Assign a request to a team.
This does the following:
- Changes the status to assigned
- Creates an association to the team provided
- Optionally associates the request to a prod mgr instance
"""
factory = DBConnect.getConnection()
reqId = getRequestID(factory, requestName)
teamId = factory(classname="Team.ID").execute(teamName)
if teamId == None:
msg = "Team named %s not known in database" % teamName
msg += "Failed to assign request %s to team %s" % (requestName, teamName)
raise RuntimeError, msg
if wmstatUrl:
wmstatSvc = WMStatsWriter(wmstatUrl)
wmstatSvc.updateTeam(requestName, teamName)
assigner = factory(classname="Assignment.New")
assigner.execute(reqId, teamId)
changeRequestStatus(requestName, "assigned", priority=None, wmstatUrl=wmstatUrl)
if prodMgr != None:
addPM = factory(classname="Progress.ProdMgr")
addPM.execute(reqId, prodMgr)
示例3: saveWorkload
def saveWorkload(helper, workload, wmstatUrl = None):
""" Saves the changes to this workload """
if workload.startswith('http'):
helper.saveCouchUrl(workload)
if wmstatUrl:
wmstatSvc = WMStatsWriter(wmstatUrl)
wmstatSvc.updateFromWMSpec(helper)
else:
helper.save(workload)
示例4: CleanUpTask
class CleanUpTask(CherryPyPeriodicTask):
"""
This class is used for both T0WMStats and WMStats
controlled by config.reqdb_couch_app value
"""
def __init__(self, rest, config):
super(CleanUpTask, self).__init__(config)
self.wmstatsDB = WMStatsWriter(config.wmstats_url, reqdbURL=config.reqmgrdb_url,
reqdbCouchApp=config.reqdb_couch_app)
def setConcurrentTasks(self, config):
"""
sets the list of functions which runs concurrently
"""
self.concurrentTasks = [{'func': self.cleanUpOldRequests, 'duration': (config.DataKeepDays * 24 * 60 * 60)},
{'func': self.cleanUpArchivedRequests, 'duration': config.archivedCleanUpDuration}]
def cleanUpOldRequests(self, config):
"""
clean up wmstats data older then given days
"""
self.logger.info("deleting %s hours old docs", (config.DataKeepDays * 24))
result = self.wmstatsDB.deleteOldDocs(config.DataKeepDays)
self.logger.info("%s old doc deleted", result)
return
def cleanUpArchivedRequests(self, config):
"""
loop through the workflows in couchdb, if archived delete all the data in couchdb
"""
self.logger.info("getting archived data")
requestNames = self.wmstatsDB.getArchivedRequests()
self.logger.info("archived list %s", requestNames)
for req in requestNames:
self.logger.info("Deleting data for: %s", req)
try:
result = self.wmstatsDB.deleteDocsByWorkflow(req)
except Exception as ex:
self.logger.error("deleting %s failed: %s", req, str(ex))
for line in traceback.format_exc().rstrip().split("\n"):
self.logger.error(" " + line)
else:
if result is None:
self.logger.info("there were no documents to delete.")
else:
self.logger.info("%s docs deleted", len(result))
return
示例5: setup
def setup(self, parameters):
"""
Called at startup
"""
# set the connection for local couchDB call
self.useReqMgrForCompletionCheck = getattr(self.config.TaskArchiver, 'useReqMgrForCompletionCheck', True)
self.wmstatsCouchDB = WMStatsWriter(self.config.TaskArchiver.localWMStatsURL)
self.centralCouchDBWriter = WMStatsWriter(self.config.TaskArchiver.centralWMStatsURL)
self.centralCouchDBReader = WMStatsReader(self.config.TaskArchiver.centralWMStatsURL)
jobDBurl = sanitizeURL(self.config.JobStateMachine.couchurl)['url']
jobDBName = self.config.JobStateMachine.couchDBName
self.jobCouchdb = CouchServer(jobDBurl)
self.jobsdatabase = self.jobCouchdb.connectDatabase("%s/jobs" % jobDBName)
self.fwjrdatabase = self.jobCouchdb.connectDatabase("%s/fwjrs" % jobDBName)
示例6: processInboundWork
def processInboundWork(self, inbound_work = None, throw = False):
"""Retrieve work from inbox, split and store
If request passed then only process that request
"""
if self.params['LocalQueueFlag']:
self.backend.fixConflicts() # db should be consistent
result = []
if not inbound_work:
inbound_work = self.backend.getElementsForSplitting()
for inbound in inbound_work:
# Check we haven't already split the work
work = self.backend.getElementsForParent(inbound)
try:
if work:
self.logger.info('Request "%s" already split - Resuming' % inbound['RequestName'])
else:
work, totalStats = self._splitWork(inbound['WMSpec'], None, inbound['Inputs'], inbound['Mask'])
self.backend.insertElements(work, parent = inbound) # if this fails, rerunning will pick up here
# save inbound work to signal we have completed queueing
# add the total work on wmstat summary
self.backend.updateInboxElements(inbound.id, Status = 'Acquired')
if not self.params.get('LocalQueueFlag') and self.params.get('WMStatsCouchUrl'):
# only update global stats for global queue
try:
wmstatSvc = WMStatsWriter(self.params.get('WMStatsCouchUrl'))
wmstatSvc.insertTotalStats(inbound['WMSpec'].name(), totalStats)
except Exception, ex:
self.logger.info('Error publishing %s to WMStats: %s' % (inbound['RequestName'], str(ex)))
except TERMINAL_EXCEPTIONS, ex:
self.logger.info('Failing workflow "%s": %s' % (inbound['RequestName'], str(ex)))
self.backend.updateInboxElements(inbound.id, Status = 'Failed')
if throw:
raise
except Exception, ex:
# if request has been failing for too long permanently fail it.
# last update time was when element was assigned to this queue
if (float(inbound.updatetime) + self.params['QueueRetryTime']) < time.time():
self.logger.info('Failing workflow "%s" as not queued in %d secs: %s' % (inbound['RequestName'],
self.params['QueueRetryTime'],
str(ex)))
self.backend.updateInboxElements(inbound.id, Status = 'Failed')
else:
self.logger.info('Exception splitting work for wmspec "%s": %s' % (inbound['RequestName'], str(ex)))
if throw:
raise
continue
示例7: setup
def setup(self, parameters):
"""
set db connection(couchdb, wmbs) to prepare to gather information
"""
# set the connection to local queue
if not hasattr(self.config, "Tier0Feeder"):
self.localQueue = WorkQueueService(self.config.AnalyticsDataCollector.localQueueURL)
# set the connection for local couchDB call
self.localCouchDB = LocalCouchDBData(self.config.AnalyticsDataCollector.localCouchURL,
self.config.JobStateMachine.summaryStatsDBName,
self.summaryLevel)
# interface to WMBS/BossAir db
myThread = threading.currentThread()
# set wmagent db data
self.wmagentDB = WMAgentDBData(self.summaryLevel, myThread.dbi, myThread.logger)
# set the connection for local couchDB call
self.localSummaryCouchDB = WMStatsWriter(self.config.AnalyticsDataCollector.localWMStatsURL,
appName="WMStatsAgent")
if hasattr(self.config, "Tier0Feeder"):
#use local db for tier0
centralRequestCouchDBURL = self.config.AnalyticsDataCollector.localT0RequestDBURL
else:
centralRequestCouchDBURL = self.config.AnalyticsDataCollector.centralRequestDBURL
self.centralRequestCouchDB = RequestDBWriter(centralRequestCouchDBURL,
couchapp = self.config.AnalyticsDataCollector.RequestCouchApp)
#TODO: change the config to hold couch url
self.localCouchServer = CouchMonitor(self.config.JobStateMachine.couchurl)
if self.pluginName != None:
pluginFactory = WMFactory("plugins", "WMComponent.AnalyticsDataCollector.Plugins")
self.plugin = pluginFactory.loadObject(classname = self.pluginName)
示例8: setup
def setup(self, parameters):
"""
Called at startup
"""
# set the connection for local couchDB call
self.useReqMgrForCompletionCheck = getattr(self.config.TaskArchiver, 'useReqMgrForCompletionCheck', True)
self.wmstatsCouchDB = WMStatsWriter(self.config.TaskArchiver.localWMStatsURL)
#TODO: we might need to use local db for Tier0
self.centralRequestDBReader = RequestDBReader(self.config.AnalyticsDataCollector.centralRequestDBURL,
couchapp = self.config.AnalyticsDataCollector.RequestCouchApp)
if self.useReqMgrForCompletionCheck:
self.deletableStates = ["announced"]
self.centralRequestDBWriter = RequestDBWriter(self.config.AnalyticsDataCollector.centralRequestDBURL,
couchapp = self.config.AnalyticsDataCollector.RequestCouchApp)
#TODO: remove this for reqmgr2
self.reqmgrSvc = RequestManager({'endpoint': self.config.TaskArchiver.ReqMgrServiceURL})
else:
# Tier0 case
self.deletableStates = ["completed"]
# use local for update
self.centralRequestDBWriter = RequestDBWriter(self.config.AnalyticsDataCollector.localT0RequestDBURL,
couchapp = self.config.AnalyticsDataCollector.RequestCouchApp)
jobDBurl = sanitizeURL(self.config.JobStateMachine.couchurl)['url']
jobDBName = self.config.JobStateMachine.couchDBName
self.jobCouchdb = CouchServer(jobDBurl)
self.jobsdatabase = self.jobCouchdb.connectDatabase("%s/jobs" % jobDBName)
self.fwjrdatabase = self.jobCouchdb.connectDatabase("%s/fwjrs" % jobDBName)
statSummaryDBName = self.config.JobStateMachine.summaryStatsDBName
self.statsumdatabase = self.jobCouchdb.connectDatabase(statSummaryDBName)
示例9: setup
def setup(self, parameters):
"""
Called at startup
"""
# set the connection for local couchDB call
self.useReqMgrForCompletionCheck = getattr(self.config.TaskArchiver, 'useReqMgrForCompletionCheck', True)
self.wmstatsCouchDB = WMStatsWriter(self.config.TaskArchiver.localWMStatsURL)
self.centralCouchDBReader = WMStatsReader(self.config.TaskArchiver.centralWMStatsURL)
if self.useReqMgrForCompletionCheck:
self.deletableStates = ["announced"]
self.centralCouchDBWriter = WMStatsWriter(self.config.TaskArchiver.centralWMStatsURL)
self.reqmgrSvc = RequestManager({'endpoint': self.config.TaskArchiver.ReqMgrServiceURL})
else:
# Tier0 case
self.deletableStates = ["completed"]
self.centralCouchDBWriter = self.wmstatsCouchDB
jobDBurl = sanitizeURL(self.config.JobStateMachine.couchurl)['url']
jobDBName = self.config.JobStateMachine.couchDBName
self.jobCouchdb = CouchServer(jobDBurl)
self.jobsdatabase = self.jobCouchdb.connectDatabase("%s/jobs" % jobDBName)
self.fwjrdatabase = self.jobCouchdb.connectDatabase("%s/fwjrs" % jobDBName)
statSummaryDBName = self.config.JobStateMachine.summaryStatsDBName
self.statsumdatabase = self.jobCouchdb.connectDatabase(statSummaryDBName)
示例10: WMStatsTest
class WMStatsTest(unittest.TestCase):
"""
"""
def setUp(self):
"""
_setUp_
"""
self.schema = []
self.couchApps = ["WMStats"]
self.testInit = TestInitCouchApp('WorkQueueServiceTest')
self.testInit.setLogging()
self.testInit.setDatabaseConnection()
self.testInit.setSchema(customModules = self.schema,
useDefault = False)
self.testInit.setupCouch('wmstats_t', *self.couchApps)
self.wmstatsWriter = WMStatsWriter(self.testInit.couchUrl, 'wmstats_t');
return
def tearDown(self):
"""
_tearDown_
Drop all the WMBS tables.
"""
self.testInit.tearDownCouch()
def testWMStatsWriter(self):
# test getWork
schema = generate_reqmgr_schema()
self.assertEquals(self.wmstatsWriter.insertRequest(schema[0]), 'OK', 'insert fail');
self.assertEquals(self.wmstatsWriter.updateRequestStatus(schema[0]['RequestName'], "failed"), 'OK', 'update fail')
self.assertEquals(self.wmstatsWriter.updateRequestStatus("not_exist_schema", "assigned"),
'ERROR: request not found - not_exist_schema')
self.assertEquals(self.wmstatsWriter.updateTeam(schema[0]['RequestName'], 'teamA'), 'OK', 'update fail')
self.assertEquals(self.wmstatsWriter.updateTeam("not_exist_schema", 'teamA'),
'ERROR: request not found - not_exist_schema')
totalStats = {'total_jobs': 100, 'input_events': 1000, 'input_lumis': 1234, 'input_num_files': 5}
self.assertEquals(self.wmstatsWriter.insertTotalStats(schema[0]['RequestName'], totalStats), 'INSERTED', 'update fail')
self.assertEquals(self.wmstatsWriter.insertTotalStats(schema[0]['RequestName'], totalStats), 'UPDATED', 'update fail')
self.assertEquals(self.wmstatsWriter.insertTotalStats("not_exist_schema", totalStats),
'ERROR: request not found - not_exist_schema')
spec1 = newWorkload(schema[0]['RequestName'])
production = spec1.newTask("Production")
production.setTaskType("Merge")
production.setSiteWhitelist(['TEST_SITE'])
self.assertEquals(self.wmstatsWriter.updateFromWMSpec(spec1), 'OK', 'update fail')
spec2 = newWorkload("not_exist_schema")
production = spec2.newTask("Production")
production.setTaskType("Merge")
self.assertEquals(self.wmstatsWriter.updateFromWMSpec(spec2),
'ERROR: request not found - not_exist_schema')
示例11: setup
def setup(self, parameters):
"""
set db connection(couchdb, wmbs) to prepare to gather information
"""
# interface to WMBS/BossAir db
myThread = threading.currentThread()
# set wmagent db data
self.wmagentDB = WMAgentDBData(self.summaryLevel, myThread.dbi, myThread.logger)
if hasattr(self.config, "Tier0Feeder"):
self.centralWMStatsCouchDB = WMStatsWriter(self.config.AnalyticsDataCollector.localWMStatsURL,
appName= "WMStatsAgent")
else:
self.centralWMStatsCouchDB = WMStatsWriter(self.config.AnalyticsDataCollector.centralWMStatsURL)
self.localCouchMonitor = CouchMonitor(self.config.JobStateMachine.couchurl)
self.setUpCouchDBReplication()
示例12: __init__
def __init__(self, rest, config):
super(HeartbeatMonitorBase, self).__init__(config)
self.centralWMStats = WMStatsWriter(config.wmstats_url)
self.threadList = config.thread_list
self.userAMQ = getattr(config, "user_amq", None)
self.passAMQ = getattr(config, "pass_amq", None)
self.postToAMQ = getattr(config, "post_to_amq", False)
self.topicAMQ = getattr(config, "topic_amq", None)
self.hostPortAMQ = getattr(config, "host_port_amq", None)
示例13: CleanUpTask
class CleanUpTask(CherryPyPeriodicTask):
"""
This class is used for both T0WMStats and WMStats
controlled by config.reqdb_couch_app value
"""
def __init__(self, rest, config):
CherryPyPeriodicTask.__init__(self, config)
self.wmstatsDB = WMStatsWriter(
config.wmstats_url, reqdbURL=config.reqmgrdb_url, reqdbCouchApp=config.reqdb_couch_app
)
def setConcurrentTasks(self, config):
"""
sets the list of functions which
"""
self.concurrentTasks = [
{"func": self.cleanUpOldRequests, "duration": (config.DataKeepDays * 24 * 60 * 60)},
{"func": self.cleanUpArchivedRequests, "duration": config.archivedCleanUpDuration},
]
def cleanUpOldRequests(self, config):
"""
clean up wmstats data older then given days
"""
self.logger.info("deleting %s hours old docs" % (config.DataKeepDays * 24))
result = self.wmstatsDB.deleteOldDocs(config.DataKeepDays)
self.logger.info("%s old doc deleted" % result)
return
def cleanUpArchivedRequests(self, config):
"""
loop through the workflows in couchdb, if archived delete all the data in couchdb
"""
requestNames = self.wmstatsDB.getArchivedRequests()
for req in requestNames:
self.logger.info("deleting %s data" % req)
result = self.wmstatsDB.deleteDocsByWorkflow(req)
self.logger.info("%s deleted" % result)
return
示例14: changeRequestStatus
def changeRequestStatus(requestName, newState, priority=None, wmstatUrl=None):
"""
_changeRequestStatus_
Basic API to change a request to a new state, also
includes optional priority change for the request
- *requestName* : name of the request to be modified
- *newState* : name of the new status for the request
- *priority* : optional integer priority
Apparently when changing request state (on assignment page),
it's possible to change priority at one go. Hence the argument is here.
"""
# MySQL/Oracle
factory = DBConnect.getConnection()
reqId = getRequestID(factory, requestName)
changeRequestIDStatus(reqId, newState, priority)
# CouchDB
# have to first get information where the request Couch document is,
# extracting the information from reqmgr_request.workflow table field
reqData = factory(classname="Request.Get").execute(reqId)
# this would be something like this:
# http://localhost:5984/reqmgr_workload_cache/maxa_RequestString-OVERRIDE-ME_130306_205649_8066/spec
wfUrl = reqData["workflow"]
# cut off /maxa_RequestString-OVERRIDE-ME_130306_205649_8066/spec
couchUrl = wfUrl.replace("/" + requestName + "/spec", "")
couchDbName = couchUrl[couchUrl.rfind("/") + 1 :]
# cut off database name from the URL
url = couchUrl.replace("/" + couchDbName, "")
couchDb = Database(couchDbName, url)
fields = {"RequestStatus": newState}
couchDb.updateDocument(requestName, "ReqMgr", "updaterequest", fields=fields, useBody=True)
# TODO: should we make this mendatory?
if wmstatUrl:
wmstatSvc = WMStatsWriter(wmstatUrl)
wmstatSvc.updateRequestStatus(requestName, newState)
示例15: __init__
def __init__(self, config):
"""
_init_
"""
BaseWorkerThread.__init__(self)
myThread = threading.currentThread()
self.daoFactory = DAOFactory(package = "T0.WMBS",
logger = logging,
dbinterface = myThread.dbi)
self.tier0ConfigFile = config.Tier0Feeder.tier0ConfigFile
self.specDirectory = config.Tier0Feeder.specDirectory
self.dropboxuser = config.Tier0Feeder.dropboxuser
self.dropboxpass = config.Tier0Feeder.dropboxpass
self.transferSystemBaseDir = getattr(config.Tier0Feeder, "transferSystemBaseDir", None)
if self.transferSystemBaseDir != None:
if not os.path.exists(self.transferSystemBaseDir):
self.transferSystemBaseDir = None
self.dqmUploadProxy = config.WMBSService.proxy
self.localSummaryCouchDB = WMStatsWriter(config.AnalyticsDataCollector.localWMStatsURL)
hltConfConnectUrl = config.HLTConfDatabase.connectUrl
dbFactoryHltConf = DBFactory(logging, dburl = hltConfConnectUrl, options = {})
dbInterfaceHltConf = dbFactoryHltConf.connect()
daoFactoryHltConf = DAOFactory(package = "T0.WMBS",
logger = logging,
dbinterface = dbInterfaceHltConf)
self.getHLTConfigDAO = daoFactoryHltConf(classname = "RunConfig.GetHLTConfig")
storageManagerConnectUrl = config.StorageManagerDatabase.connectUrl
dbFactoryStorageManager = DBFactory(logging, dburl = storageManagerConnectUrl, options = {})
self.dbInterfaceStorageManager = dbFactoryStorageManager.connect()
self.getExpressReadyRunsDAO = None
if hasattr(config, "PopConLogDatabase"):
popConLogConnectUrl = getattr(config.PopConLogDatabase, "connectUrl", None)
if popConLogConnectUrl != None:
dbFactoryPopConLog = DBFactory(logging, dburl = popConLogConnectUrl, options = {})
dbInterfacePopConLog = dbFactoryPopConLog.connect()
daoFactoryPopConLog = DAOFactory(package = "T0.WMBS",
logger = logging,
dbinterface = dbInterfacePopConLog)
self.getExpressReadyRunsDAO = daoFactoryPopConLog(classname = "Tier0Feeder.GetExpressReadyRuns")
return