Skip to content

Commit

Permalink
add PlugIn structure in AnalyticsDataCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
ticoann authored and dballesteros7 committed Nov 13, 2012
1 parent d6c68d7 commit 2f5e7f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions etc/WMAgentConfig.py
Expand Up @@ -480,4 +480,5 @@
config.AnalyticsDataCollector.localWMStatsURL = "%s/%s" % (config.JobStateMachine.couchurl, config.JobStateMachine.jobSummaryDBName)
config.AnalyticsDataCollector.centralWMStatsURL = "Central WMStats URL"
config.AnalyticsDataCollector.summaryLevel = "task"
config.AnalyticsDataCollector.pluginName = None

18 changes: 16 additions & 2 deletions src/python/WMComponent/AnalyticsDataCollector/AnalyticsPoller.py
Expand Up @@ -14,6 +14,7 @@
from WMComponent.AnalyticsDataCollector.DataCollectAPI import LocalCouchDBData, \
WMAgentDBData, combineAnalyticsData, convertToRequestCouchDoc, \
convertToAgentCouchDoc
from WMCore.WMFactory import WMFactory

class AnalyticsPoller(BaseWorkerThread):
"""
Expand All @@ -35,10 +36,13 @@ def __init__(self, config):
# need to get campaign, user, owner info
self.agentDocID = "agent+hostname"
self.summaryLevel = (config.AnalyticsDataCollector.summaryLevel).lower()

self.pluginName = getattr(config.AnalyticsDataCollector.pluginName, None)
self.plugIn = None


def setup(self, parameters):
"""
set db connection(couchdb, wmbs) to prepare to gether information
set db connection(couchdb, wmbs) to prepare to gather information
"""

#
Expand All @@ -55,6 +59,12 @@ def setup(self, parameters):
self.localSummaryCouchDB = WMStatsWriter(self.config.AnalyticsDataCollector.localWMStatsURL)
logging.info("Setting the replication to central monitor ...")
self.localSummaryCouchDB.replicate(self.config.AnalyticsDataCollector.centralWMStatsURL)

self.centralWMStatsCouchDB = WMStatsWriter(self.config.AnalyticsDataCollector.centralWMStatsURL)

if self.pluginName != None:
pluginFactory = WMFactory("plugins", "WMComponent.AnalyticsDataCollector.PlugIns")
self.plugin = pluginFactory.loadObject(classname = self.pluginName)

def algorithm(self, parameters):
"""
Expand Down Expand Up @@ -94,6 +104,10 @@ def algorithm(self, parameters):
requestDocs = convertToRequestCouchDoc(combinedRequests, fwjrInfoFromCouch,
self.agentInfo, uploadTime, self.summaryLevel)


if self.plugIn != None:
self.plugIn(requestDocs, self.localSummaryCouchDB, self.centralWMStatsCouchDB)

self.localSummaryCouchDB.uploadData(requestDocs)
logging.info("Request data upload success\n %s request \n uploading agent data" % len(requestDocs))

Expand Down
@@ -0,0 +1,20 @@

class PlugInInterface(object):
"""Interface for policies"""
def __init__(self, **args):
""" initialize args if needed"""
pass

def __call__(self, requestDocs, localSummaryCouchDB, centralWMStatsCouchDB):
"""
this needs to be overwritten
requestDocs is request info collected from other resources, which has couchdb doc format.
localSummaryCouchDB, centralWMStatsCouchDB are WMCore.Services.WMStats.WMStatsWriter instances
for local wmagent_summary db and central wmstats couchdb respectfully.
If data needed to be written to wmstats, write to local it will be replicated,
Only in case data doesn't exist in local, write to central wmstats couchdb.
requestDocs can be modified and it will be updated outside the plug in,
So don't push requestDocs to couchdb directly here.
"""
msg = "%s.__call__ is not implemented" % self.__class__.__name__
raise NotImplementedError(msg)

0 comments on commit 2f5e7f8

Please sign in to comment.