本文整理汇总了Python中DIRAC.ConfigurationSystem.Client.PathFinder类的典型用法代码示例。如果您正苦于以下问题:Python PathFinder类的具体用法?Python PathFinder怎么用?Python PathFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathFinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
def initialize( self ):
#Build the URLs
self._url = self._cfg.getURL()
if not self._url:
return S_ERROR( "Could not build service URL for %s" % self._name )
gLogger.verbose( "Service URL is %s" % self._url )
#Load handler
result = self._loadHandlerInit()
if not result[ 'OK' ]:
return result
self._handler = result[ 'Value' ]
#Initialize lock manager
self._lockManager = LockManager( self._cfg.getMaxWaitingPetitions() )
self._initMonitoring()
self._threadPool = ThreadPool( max( 1, self._cfg.getMinThreads() ),
max( 0, self._cfg.getMaxThreads() ),
self._cfg.getMaxWaitingPetitions() )
self._threadPool.daemonize()
self._msgBroker = MessageBroker( "%sMSB" % self._name, threadPool = self._threadPool )
#Create static dict
self._serviceInfoDict = { 'serviceName' : self._name,
'serviceSectionPath' : PathFinder.getServiceSection( self._name ),
'URL' : self._cfg.getURL(),
'messageSender' : MessageSender( self._name, self._msgBroker ),
'validNames' : self._validNames,
'csPaths' : [ PathFinder.getServiceSection( svcName ) for svcName in self._validNames ]
}
#Call static initialization function
try:
self._handler[ 'class' ]._rh__initializeClass( dict( self._serviceInfoDict ),
self._lockManager,
self._msgBroker,
self._monitor )
if self._handler[ 'init' ]:
for initFunc in self._handler[ 'init' ]:
gLogger.verbose( "Executing initialization function" )
try:
result = initFunc( dict( self._serviceInfoDict ) )
except Exception as excp:
gLogger.exception( "Exception while calling initialization function", lException = excp )
return S_ERROR( "Exception while calling initialization function: %s" % str( excp ) )
if not isReturnStructure( result ):
return S_ERROR( "Service initialization function %s must return S_OK/S_ERROR" % initFunc )
if not result[ 'OK' ]:
return S_ERROR( "Error while initializing %s: %s" % ( self._name, result[ 'Message' ] ) )
except Exception as e:
errMsg = "Exception while initializing %s" % self._name
gLogger.exception( e )
gLogger.exception( errMsg )
return S_ERROR( errMsg )
#Load actions after the handler has initialized itself
result = self._loadActions()
if not result[ 'OK' ]:
return result
self._actions = result[ 'Value' ]
gThreadScheduler.addPeriodicTask( 30, self.__reportThreadPoolContents )
return S_OK()
示例2: __init__
def __init__( self, useCertificates = False ):
"""c'tor
:param self: self reference
:param bool useCertificates: flag to enable/disable certificates
"""
Client.__init__( self )
## setup logger
self.log = gLogger.getSubLogger( "RequestManagement/RequestClient" )
## dict to store all RPC clients for easy reuse
self.__requestRPCClientsDict = {}
## local if any defined
local = PathFinder.getServiceURL( "RequestManagement/localURL" )
if local:
self.__requestRPCClientsDict.setdefault( "local" , [ self.__requestRPCClient( local ) ] )
## central if any defined
central = PathFinder.getServiceURL( "RequestManagement/centralURL" )
if central:
self.__requestRPCClientsDict.setdefault( "central", [ self.__requestRPCClient( central ) ] )
## voboxes if any defined
voBoxUrls = fromChar( PathFinder.getServiceURL( "RequestManagement/voBoxURLs" ) )
if voBoxUrls:
self.__requestRPCClientsDict.setdefault( "voboxes", [] )
for voBoxURL in randomize( voBoxUrls ):
self.__requestRPCClientsDict["voboxes"].append( self.__requestRPCClient( voBoxURL ) )
self.setServer( 'RequestManagement/centralURL' )
示例3: _ex_initialize
def _ex_initialize( cls, exeName, loadName ):
cls.__properties = { 'fullName' : exeName,
'loadName' : loadName,
'section' : PathFinder.getExecutorSection( exeName ),
'loadSection' : PathFinder.getExecutorSection( loadName ),
'messagesProcessed' : 0,
'reconnects' : 0,
'setup' : gConfig.getValue( "/DIRAC/Setup", "Unknown" ) }
cls.__basePath = gConfig.getValue( '/LocalSite/InstancePath', rootPath )
cls.__defaults = {}
cls.__defaults[ 'MonitoringEnabled' ] = True
cls.__defaults[ 'Enabled' ] = True
cls.__defaults[ 'ControlDirectory' ] = os.path.join( cls.__basePath,
'control',
*exeName.split( "/" ) )
cls.__defaults[ 'WorkDirectory' ] = os.path.join( cls.__basePath,
'work',
*exeName.split( "/" ) )
cls.__defaults[ 'ReconnectRetries' ] = 10
cls.__defaults[ 'ReconnectSleep' ] = 5
cls.__properties[ 'shifterProxy' ] = ''
cls.__properties[ 'shifterProxyLocation' ] = os.path.join( cls.__defaults[ 'WorkDirectory' ],
'.shifterCred' )
cls.__mindName = False
cls.__mindExtraArgs = False
cls.__freezeTime = 0
cls.__fastTrackEnabled = True
cls.log = gLogger.getSubLogger( exeName, child = False )
try:
result = cls.initialize()
except Exception, excp:
gLogger.exception( "Exception while initializing %s" % loadName )
return S_ERROR( "Exception while initializing: %s" % str( excp ) )
示例4: export_sendMail
def export_sendMail( self, address, subject, body, fromAddress, avoidSpam = False ):
""" Send an email with supplied body to the specified address using the Mail utility.
if avoidSpam is True, then emails are first added to a set so that duplicates are removed,
and sent every hour.
"""
gLogger.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % ( address, subject, body ) )
eMail = Mail()
notificationSection = PathFinder.getServiceSection( "Framework/Notification" )
csSection = notificationSection + '/SMTP'
eMail._smtpHost = gConfig.getValue( '%s/Host' % csSection )
eMail._smtpPort = gConfig.getValue( '%s/Port' % csSection )
eMail._smtpLogin = gConfig.getValue( '%s/Login' % csSection )
eMail._smtpPasswd = gConfig.getValue( '%s/Password' % csSection )
eMail._smtpPtcl = gConfig.getValue( '%s/Protocol' % csSection )
eMail._subject = subject
eMail._message = body
eMail._mailAddress = address
if not fromAddress == 'None':
eMail._fromAddress = fromAddress
if gConfig.getValue( '%s/FromAddress' % csSection ):
eMail._fromAddress = gConfig.getValue( '%s/FromAddress' % csSection )
if avoidSpam:
gMailSet.add(eMail)
return S_OK("Mail added to gMailSet")
else:
result = eMail._send()
if not result['OK']:
gLogger.warn( 'Could not send mail with the following message:\n%s' % result['Message'] )
else:
gLogger.info( 'Mail sent successfully to %s with subject %s' % ( address, subject ) )
gLogger.debug( result['Value'] )
return result
示例5: export_sendSMS
def export_sendSMS( self, userName, body, fromAddress ):
""" Send an SMS with supplied body to the specified DIRAC user using the Mail utility via an SMS switch.
"""
gLogger.verbose( 'Received signal to send the following SMS to %s:\n%s' % ( userName, body ) )
mobile = gConfig.getValue( '/Registry/Users/%s/Mobile' % userName, '' )
if not mobile:
return S_ERROR( 'No registered mobile number for %s' % userName )
csSection = PathFinder.getServiceSection( 'Framework/Notification' )
smsSwitch = gConfig.getValue( '%s/SMSSwitch' % csSection, '' )
if not smsSwitch:
return S_ERROR( 'No SMS switch is defined in CS path %s/SMSSwitch' % csSection )
address = '%[email protected]%s' % ( mobile, smsSwitch )
subject = 'DIRAC SMS'
m = Mail()
m._subject = subject
m._message = body
m._mailAddress = address
if not fromAddress == 'None':
m._fromAddress = fromAddress
result = m._send()
if not result['OK']:
gLogger.warn( 'Could not send SMS to %s with the following message:\n%s' % ( userName, result['Message'] ) )
else:
gLogger.info( 'SMS sent successfully to %s ' % ( userName ) )
gLogger.debug( result['Value'] )
return result
示例6: initializeReportGeneratorHandler
def initializeReportGeneratorHandler( serviceInfo ):
global gAccountingDB
gAccountingDB = AccountingDB( readOnly = True )
#Get data location
reportSection = PathFinder.getServiceSection( "Accounting/ReportGenerator" )
dataPath = gConfig.getValue( "%s/DataLocation" % reportSection, "data/accountingGraphs" )
dataPath = dataPath.strip()
if "/" != dataPath[0]:
dataPath = os.path.realpath( "%s/%s" % ( gConfig.getValue( '/LocalSite/InstancePath', rootPath ), dataPath ) )
gLogger.info( "Data will be written into %s" % dataPath )
try:
os.makedirs( dataPath )
except:
pass
try:
testFile = "%s/acc.jarl.test" % dataPath
fd = file( testFile, "w" )
fd.close()
os.unlink( testFile )
except IOError:
gLogger.fatal( "Can't write to %s" % dataPath )
return S_ERROR( "Data location is not writable" )
gDataCache.setGraphsLocation( dataPath )
gMonitor.registerActivity( "plotsDrawn", "Drawn plot images", "Accounting reports", "plots", gMonitor.OP_SUM )
gMonitor.registerActivity( "reportsRequested", "Generated reports", "Accounting reports", "reports", gMonitor.OP_SUM )
return S_OK()
示例7: initialize
def initialize( self ):
self.RequestDBClient = RequestClient()
backend = self.am_getOption( 'Backend', '' )
self.RequestDB = False
if backend == 'mysql':
from DIRAC.RequestManagementSystem.DB.RequestDBMySQL import RequestDBMySQL
requestDB = RequestDBMySQL()
if requestDB._connected:
self.RequestDB = requestDB
gMonitor.registerActivity( "Iteration", "Agent Loops", "DISETForwardingAgent", "Loops/min", gMonitor.OP_SUM )
gMonitor.registerActivity( "Attempted", "Request Processed", "DISETForwardingAgent", "Requests/min", gMonitor.OP_SUM )
gMonitor.registerActivity( "Successful", "Request Forward Successful", "DISETForwardingAgent", "Requests/min", gMonitor.OP_SUM )
gMonitor.registerActivity( "Failed", "Request Forward Failed", "DISETForwardingAgent", "Requests/min", gMonitor.OP_SUM )
self.local = PathFinder.getServiceURL( "RequestManagement/localURL" )
if not self.local:
self.local = AgentModule.am_getOption( self, 'localURL', '' )
if not self.local:
errStr = 'The RequestManagement/localURL option must be defined.'
gLogger.fatal( errStr )
return S_ERROR( errStr )
return S_OK()
示例8: initializeMonitoringHandler
def initializeMonitoringHandler( serviceInfo ):
#Check that the path is writable
monitoringSection = PathFinder.getServiceSection( "Framework/Monitoring" )
#Get data location
dataPath = gConfig.getValue( "%s/DataLocation" % monitoringSection, "data/monitoring" )
dataPath = dataPath.strip()
if "/" != dataPath[0]:
dataPath = os.path.realpath( "%s/%s" % ( gConfig.getValue( '/LocalSite/InstancePath', rootPath ), dataPath ) )
gLogger.info( "Data will be written into %s" % dataPath )
try:
os.makedirs( dataPath )
except:
pass
try:
testFile = "%s/mon.jarl.test" % dataPath
fd = file( testFile, "w" )
fd.close()
os.unlink( testFile )
except IOError:
gLogger.fatal( "Can't write to %s" % dataPath )
return S_ERROR( "Data location is not writable" )
#Define globals
gServiceInterface.initialize( dataPath )
if not gServiceInterface.initializeDB():
return S_ERROR( "Can't start db engine" )
gMonitor.registerActivity( "cachedplots", "Cached plot images", "Monitoring plots", "plots", gMonitor.OP_SUM )
gMonitor.registerActivity( "drawnplots", "Drawn plot images", "Monitoring plots", "plots", gMonitor.OP_SUM )
return S_OK()
示例9: __init__
def __init__( self, nameList ):
self.serviceName = nameList[0]
self.serviceURL = False
self.nameList = nameList
self.pathList = []
for svcName in nameList:
self.pathList.append( PathFinder.getServiceSection( svcName ) )
示例10: initializePlottingHandler
def initializePlottingHandler( serviceInfo ):
#Get data location
plottingSection = PathFinder.getServiceSection( "Framework/Plotting" )
dataPath = gConfig.getValue( "%s/DataLocation" % plottingSection, "data/graphs" )
dataPath = dataPath.strip()
if "/" != dataPath[0]:
dataPath = os.path.realpath( "%s/%s" % ( gConfig.getValue( '/LocalSite/InstancePath', rootPath ), dataPath ) )
gLogger.info( "Data will be written into %s" % dataPath )
try:
os.makedirs( dataPath )
except:
pass
try:
testFile = "%s/plot__.test" % dataPath
fd = file( testFile, "w" )
fd.close()
os.unlink( testFile )
except IOError:
gLogger.fatal( "Can't write to %s" % dataPath )
return S_ERROR( "Data location is not writable" )
gPlotCache.setPlotsLocation( dataPath )
gMonitor.registerActivity( "plotsDrawn", "Drawn plot images", "Plotting requests", "plots", gMonitor.OP_SUM )
return S_OK()
示例11: initializeDataLoggingHandler
def initializeDataLoggingHandler( serviceInfo ):
global dataPath
global logDB
logDB = DataLoggingDB()
monitoringSection = PathFinder.getServiceSection( "DataManagement/DataLogging" )
#Get data location
retDict = gConfig.getOption( "%s/DataLocation" % monitoringSection, "dataLoggingPlots" )
if not retDict[ 'OK' ]:
return retDict
dataPath = retDict[ 'Value' ].strip()
if "/" != dataPath[0]:
dataPath = os.path.realpath( "%s/%s" % ( gConfig.getValue( '/LocalSite/InstancePath', rootPath ), dataPath ) )
gLogger.info( "Data will be written into %s" % dataPath )
try:
os.makedirs( dataPath )
except:
pass
try:
testFile = "%s/mon.jarl.test" % dataPath
fd = file( testFile, "w" )
fd.close()
os.unlink( testFile )
except IOError:
gLogger.fatal( "Can't write to %s" % dataPath )
return S_ERROR( "Data location is not writable" )
return S_OK()
示例12: initialize
def initialize(self):
# Build the URLs
self._url = self._cfg.getURL()
if not self._url:
return S_ERROR("Could not build service URL for %s" % self._name)
gLogger.verbose("Service URL is %s" % self._url)
# Load handler
result = self._loadHandlerInit()
if not result["OK"]:
return result
self._handler = result["Value"]
# Initialize lock manager
self._lockManager = LockManager(self._cfg.getMaxWaitingPetitions())
self._initMonitoring()
self._threadPool = ThreadPool(1, max(0, self._cfg.getMaxThreads()), self._cfg.getMaxWaitingPetitions())
self._threadPool.daemonize()
self._msgBroker = MessageBroker("%sMSB" % self._name, threadPool=self._threadPool)
# Create static dict
self._serviceInfoDict = {
"serviceName": self._name,
"serviceSectionPath": PathFinder.getServiceSection(self._name),
"URL": self._cfg.getURL(),
"messageSender": MessageSender(self._name, self._msgBroker),
"validNames": self._validNames,
"csPaths": [PathFinder.getServiceSection(svcName) for svcName in self._validNames],
}
# Call static initialization function
try:
self._handler["class"]._rh__initializeClass(
dict(self._serviceInfoDict), self._lockManager, self._msgBroker, self._monitor
)
if self._handler["init"]:
for initFunc in self._handler["init"]:
gLogger.verbose("Executing initialization function")
try:
result = initFunc(dict(self._serviceInfoDict))
except Exception, excp:
gLogger.exception("Exception while calling initialization function")
return S_ERROR("Exception while calling initialization function: %s" % str(excp))
if not isReturnStructure(result):
return S_ERROR("Service initialization function %s must return S_OK/S_ERROR" % initFunc)
if not result["OK"]:
return S_ERROR("Error while initializing %s: %s" % (self._name, result["Message"]))
except Exception, e:
errMsg = "Exception while initializing %s" % self._name
gLogger.exception(errMsg)
return S_ERROR(errMsg)
示例13: requestManager
def requestManager( self, timeout = 120 ):
""" facade for RequestManager RPC client """
if not self.__requestManager:
url = PathFinder.getServiceURL( "RequestManagement/ReqManager" )
if not url:
raise RuntimeError( "CS option RequestManagement/ReqManager URL is not set!" )
self.__requestManager = RPCClient( url, timeout = timeout )
return self.__requestManager
示例14: __init__
def __init__( self):
Client.__init__( self )
self.setServer( "DataManagement/Test" )
url = PathFinder.getServiceURL( "DataManagement/Test" )
if not url:
raise RuntimeError( "CS option DataManagement/Test URL is not set!" )
self.testManager = RPCClient( url )
示例15: ftsManager
def ftsManager( cls, timeout = 300 ):
""" get FTSManager instance """
if not cls.__ftsManager:
url = PathFinder.getServiceURL( "DataManagement/FTSManager" )
if not url:
raise RuntimeError( "CS option DataManagement/FTSManager URL is not set!" )
cls.__ftsManager = RPCClient( url, timeout = timeout )
return cls.__ftsManager