本文整理汇总了Python中DIRAC.ResourceStatusSystem.Utilities.Utils.voimport方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.voimport方法的具体用法?Python Utils.voimport怎么用?Python Utils.voimport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Utilities.Utils
的用法示例。
在下文中一共展示了Utils.voimport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initializeResourceStatusHandler
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def initializeResourceStatusHandler( _serviceInfo ):
'''
Handler initialization, where we set the ResourceStatusDB as global db, and
we instantiate the synchronizer.
'''
global db
db = ResourceStatusDB()
# Publisher is on boxes right now
#
# rmDB = ResourceStatusDB()
# cc = CommandCaller()
# global VOExtension
# VOExtension = getExt()
# ig = InfoGetter( VOExtension )
# WMSAdmin = RPCClient( "WorkloadStatus/WMSAdministrator" )
# global publisher
# publisher = Publisher( VOExtension, dbIn = db, commandCallerIn = cc,
# infoGetterIn = ig, WMSAdminIn = WMSAdmin )
syncModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Utilities.Synchronizer' )
syncObject = syncModule.Synchronizer()
gConfig.addListenerToNewVersionEvent( syncObject.sync )
return S_OK()
示例2: __init__
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def __init__( self ):
"""c'tor
:param self: self reference
"""
self.log = gLogger.getSubLogger( 'ResourceStatusDB' )
#These are the list of tables that will be created.
#They can be extended in an extension module
self.tablesList = getattr(Utils.voimport( 'DIRAC.ResourceStatusSystem.DB.ResourceStatusDB' ),
'TABLESLIST')
self.tablesListWithID = getattr(Utils.voimport( 'DIRAC.ResourceStatusSystem.DB.ResourceStatusDB' ),
'TABLESLISTWITHID')
self.extensions = gConfig.getValue( 'DIRAC/Extensions', [] )
self.__initializeConnection( 'ResourceStatus/ResourceStatusDB' )
self.__initializeDB()
示例3: policyInvocation
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def policyInvocation( self, granularity = None, name = None,
status = None, policy = None, args = None, pName = None,
pModule = None, extraArgs = None, commandIn = None ):
'''
Invokes a policy:
1. If :attr:`policy` is None, import the policy module specified
with :attr:`pModule` (e.g. 'DT_Policy').
1.1. Create a policy object.
2. Set the policy arguments (usually :attr:`granularity`,
:attr:`name`) + :attr:`extraArgs`.
3. If commandIn is specified (normally it is), use
:meth:`DIRAC.ResourceStatusSystem.Command.CommandCaller.CommandCaller.setCommandObject`
to get a command object
'''
if not policy:
try:
policyModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Policy.%s' % pModule )
except ImportError:
_msg = 'Unable to import a policy module named %s, falling back on AlwaysFalse_Policy.' % pModule
gLogger.warn( _msg )
policyModule = __import__( 'DIRAC.ResourceStatusSystem.Policy.AlwaysFalse_Policy',
globals(), locals(), ['*'] )
pModule = 'AlwaysFalse_Policy'
try:
policy = getattr( policyModule, pModule )()
except AttributeError as exc:
print policyModule, pModule
raise exc
if not args:
args = ( granularity, name )
if extraArgs:
args = args + tuple( extraArgs )
if commandIn:
commandIn = self.cCaller.setCommandObject( commandIn )
for clientName, clientInstance in self.clients.items():
self.cCaller.setAPI( commandIn, clientName, clientInstance )
res = self._innerEval( policy, args, commandIn = commandIn )
# Just adding the PolicyName to the result of the evaluation of the policy
res[ 'PolicyName' ] = pName
return res
示例4: __init__
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def __init__(self, VOExtension):
"""
Standard constructor
:params:
:attr:`VOExtension`: string - VO extension (e.g. 'LHCb')
"""
configModule = Utils.voimport("DIRAC.ResourceStatusSystem.Policy.Configurations", VOExtension)
self.C_Policies = copy.deepcopy(configModule.Policies)
示例5: __init__
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def __init__(self, VOExtension, rsDBIn = None, commandCallerIn = None, infoGetterIn = None,
WMSAdminIn = None):
"""
Standard constructor
:params:
:attr:`VOExtension`: string, VO Extension (e.g. 'LHCb')
:attr:`rsDBIn`: optional ResourceStatusDB object
(see :class: `DIRAC.ResourceStatusSystem.DB.ResourceStatusDB.ResourceStatusDB`)
:attr:`commandCallerIn`: optional CommandCaller object
(see :class: `DIRAC.ResourceStatusSystem.Command.CommandCaller.CommandCaller`)
:attr:`infoGetterIn`: optional InfoGetter object
(see :class: `DIRAC.ResourceStatusSystem.Utilities.InfoGetter.InfoGetter`)
:attr:`WMSAdminIn`: optional RPCClient object for WMSAdmin
(see :class: `DIRAC.Core.DISET.RPCClient.RPCClient`)
"""
self.configModule = Utils.voimport("DIRAC.ResourceStatusSystem.Policy.Configurations", VOExtension)
if rsDBIn is not None:
self.rsDB = rsDBIn
else:
from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB
self.rsDB = ResourceStatusDB()
from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB
self.rmDB = ResourceManagementDB()
if commandCallerIn is not None:
self.cc = commandCallerIn
else:
from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller
self.cc = CommandCaller()
if infoGetterIn is not None:
self.ig = infoGetterIn
else:
from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter
self.ig = InfoGetter(VOExtension)
if WMSAdminIn is not None:
self.WMSAdmin = WMSAdminIn
else:
from DIRAC.Core.DISET.RPCClient import RPCClient
self.WMSAdmin = RPCClient("WorkloadManagement/WMSAdministrator")
self.threadPool = ThreadPool( 2, 5 )
self.lockObj = threading.RLock()
self.infoForPanel_res = {}
示例6: __init__
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def __init__( self ):
""" Constructor. Imports the policy configurations containing the command
information, among other things.
examples:
>>> iGetter = InfoGetter()
"""
configModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Policy.Configurations' )
self.policies = copy.deepcopy( configModule.POLICIESMETA )
示例7: policyInvocation
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def policyInvocation( self, decisionParams, policyDict ):
'''
Invokes a policy:
1. If :attr:`policy` is None, import the policy module specified
with :attr:`pModule` (e.g. 'DT_Policy').
1.1. Create a policy object.
2. Set the policy arguments (usually :attr:`granularity`,
:attr:`name`) + :attr:`extraArgs`.
3. If commandIn is specified (normally it is), use
:meth:`DIRAC.ResourceStatusSystem.Command.CommandCaller.CommandCaller.setCommandObject`
to get a command object
'''
if not 'module' in policyDict:
return S_ERROR( 'Malformed policyDict %s' % policyDict )
pModuleName = policyDict[ 'module' ]
if not 'command' in policyDict:
return S_ERROR( 'Malformed policyDict %s' % policyDict )
pCommand = policyDict[ 'command' ]
if not 'args' in policyDict:
return S_ERROR( 'Malformed policyDict %s' % policyDict )
pArgs = policyDict[ 'args' ]
try:
policyModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Policy.%s' % pModuleName )
except ImportError:
return S_ERROR( 'Unable to import DIRAC.ResourceStatusSystem.Policy.%s' % pModuleName )
if not hasattr( policyModule, pModuleName ):
return S_ERROR( '%s has no attibute %s' % ( policyModule, pModuleName ) )
policy = getattr( policyModule, pModuleName )()
command = self.cCaller.commandInvocation( pCommand, pArgs, decisionParams, self.clients )
if not command[ 'OK' ]:
return command
command = command[ 'Value' ]
evaluationResult = self.policyEvaluation( policy, command )
if evaluationResult[ 'OK' ]:
evaluationResult[ 'Value' ][ 'Policy' ] = policyDict
return evaluationResult
示例8: initializeResourceStatusHandler
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def initializeResourceStatusHandler( _serviceInfo ):
'''
Handler initialization, where we set the ResourceStatusDB as global db, and
we instantiate the synchronizer.
'''
global db
db = ResourceStatusDB()
syncModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Utilities.Synchronizer' )
syncObject = syncModule.Synchronizer()
gConfig.addListenerToNewVersionEvent( syncObject.sync )
return S_OK()
示例9: __loadTestObj
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def __loadTestObj(self):
_module_pre = 'DIRAC.ResourceStatusSystem.SAM.SAMTest.'
for testType, testDict in self.tests.items():
moduleName = testDict[ 'module' ]
args = testDict.get( 'args', {} )
args.update( testDict[ 'match' ] )
args[ 'TestType' ] = testType
try:
testModule = Utils.voimport( _module_pre + moduleName )
except ImportError, e:
gLogger.error( "Unable to import %s, %s" % ( _module_pre + moduleName, e ) )
continue
testClass = getattr( testModule, moduleName )
obj = testClass(args, self.apis)
testDict[ 'object' ] = obj
示例10: setCommandObject
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def setCommandObject( self, comm ):
"""
Returns a command object, given comm
:params:
`comm`: a tuple, where comm[0] is a module name and comm[1] is a class name (inside the module)
"""
try:
cModule = comm[0]
cClass = comm[1]
commandModule = Utils.voimport("DIRAC.ResourceStatusSystem.Command." + cModule)
except ImportError:
gLogger.warn("Command %s/%s not found, using dummy command DoNothing_Command." % (cModule, cClass))
cClass = "DoNothing_Command"
commandModule = __import__("DIRAC.ResourceStatusSystem.Command.DoNothing_Command", globals(), locals(), ['*'])
c = getattr(commandModule, cClass)()
return c
示例11: commandInvocation
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def commandInvocation( commandTuple, pArgs = None, decissionParams = None, clients = None ):
'''
Returns a command object, given commandTuple
:params:
`commandTuple`: a tuple, where commandTuple[0] is a module name and
commandTuple[1] is a class name (inside the module)
'''
if commandTuple is None:
return S_OK( None )
# decission params can be a dictionary passed with all the element parameters
# used mostly by the PDP to inject all relevant information
if decissionParams is None:
decissionParams = {}
# arguments hardcoded on Configurations.py for the policy
if pArgs is None:
pArgs = {}
try:
cModule = commandTuple[ 0 ]
cClass = commandTuple[ 1 ]
commandModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Command.' + cModule )
except ImportError:
return S_ERROR( "Import error for command %s." % ( cModule ) )
if not hasattr( commandModule, cClass ):
return S_ERROR( '%s has no %s' % ( cModule, cClass ) )
# We merge decision parameters and policy arguments.
newArgs = copy.deepcopy( decissionParams )
newArgs.update( pArgs )
commandObject = getattr( commandModule, cClass )( newArgs, clients )
return S_OK( commandObject )
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
示例12: __init__
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def __init__( self ):
self.log = gLogger.getSubLogger( 'PilotsLoggingDB' )
result = getDBParameters( 'WorkloadManagement/PilotsLoggingDB' )
if not result['OK']:
raise RuntimeError( 'Cannot get database parameters: %s' % result['Message'] )
dbParameters = result['Value']
self.dbHost = dbParameters['Host']
self.dbPort = dbParameters['Port']
self.dbUser = dbParameters['User']
self.dbPass = dbParameters['Password']
self.dbName = dbParameters['DBName']
#These are the list of tables that will be created.
#They can be extended in an extension module
self.tablesList = getattr(Utils.voimport( 'DIRAC.WorkloadManagementSystem.DB.PilotsLoggingDB' ),
'TABLESLIST')
self.__initializeConnection()
resp = self.__initializeDB( )
if not resp['OK']:
raise Exception( "Couldn't create tables: " + resp['Message'] )
示例13: getPoliciesThatApply
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
def getPoliciesThatApply( decisionParams ):
"""
Method that sanitizes the input parameters and returns the policies that
match them. Matches the input dictionary with the policies configuration in
the CS. It returns a list of policy dictionaries that matched.
"""
decisionParams = _sanitizedecisionParams( decisionParams )
gLogger.debug("Sanitized decisionParams: %s" % str(decisionParams))
policiesThatApply = []
# Get policies configuration metadata from CS.
policiesConfig = RssConfiguration.getPolicies()
if not policiesConfig[ 'OK' ]:
return policiesConfig
policiesConfig = policiesConfig[ 'Value' ]
gLogger.debug("All policies: %s" %str(policiesConfig))
# Each policy, has the following format
# <policyName>
# \
# policyType = <policyType>
# matchParams
# \
# ...
# configParams
# \
# ...
# Get policies that match the given decisionParameters
for policyName, policySetup in policiesConfig.items():
# The parameter policyType replaces policyName, so if it is not present,
# we pick policyName
try:
policyType = policySetup[ 'policyType' ][ 0 ]
except KeyError:
policyType = policyName
#continue
# The section matchParams is not mandatory, so we set {} as default.
policyMatchParams = policySetup.get( 'matchParams', {} )
gLogger.debug("matchParams of %s: %s" %(policyName, str(policyMatchParams)))
# FIXME: make sure the values in the policyConfigParams dictionary are typed !!
policyConfigParams = {}
#policyConfigParams = policySetup.get( 'configParams', {} )
policyMatch = Utils.configMatch( decisionParams, policyMatchParams )
gLogger.debug("PolicyMatch for decisionParams %s: %s" %(decisionParams, str(policyMatch)))
policyFilter = _filterPolicies( decisionParams, policyMatchParams )
#WARNING: we need an additional filtering function when the matching
#is not straightforward (e.g. when the policy specify a 'domain', while
#the decisionParams has only the name of the element)
if policyMatch and policyFilter:
policiesThatApply.append( ( policyName, policyType, policyConfigParams ) )
gLogger.debug("policies that apply: %s" %str(policiesThatApply))
policiesToBeLoaded = []
# Gets policies parameters from code.
for policyName, policyType, _policyConfigParams in policiesThatApply:
try:
configModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Policy.Configurations' )
policies = copy.deepcopy( configModule.POLICIESMETA )
policyMeta = policies[ policyType ]
except KeyError:
continue
# We are not going to use name / type anymore, but we keep them for debugging
# and future usage.
policyDict = { 'name' : policyName,
'type' : policyType,
'args' : {}
}
# args is one of the parameters we are going to use on the policies. We copy
# the defaults and then we update if with whatever comes from the CS.
policyDict.update( policyMeta )
policiesToBeLoaded.append( policyDict )
return S_OK( policiesToBeLoaded )
示例14: getattr
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
"""
__RCSID__ = '$Id$'
# pylint: disable=no-self-use
from datetime import datetime, timedelta
from types import NoneType
# DIRAC
from DIRAC import gLogger, S_OK, gConfig, S_ERROR
from DIRAC.Core.DISET.RequestHandler import RequestHandler
from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient
from DIRAC.ResourceStatusSystem.Utilities import CSHelpers, Utils
ResourceManagementClient = getattr(
Utils.voimport('DIRAC.ResourceStatusSystem.Client.ResourceManagementClient'),
'ResourceManagementClient')
# RSS Clients
rsClient = None
rmClient = None
def initializePublisherHandler(_serviceInfo):
"""
Handler initialization in the usual horrible way.
"""
global rsClient
rsClient = ResourceStatusClient()
示例15: enforce
# 需要导入模块: from DIRAC.ResourceStatusSystem.Utilities import Utils [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Utilities.Utils import voimport [as 别名]
#.........这里部分代码省略.........
:attr:`rmDBIn`: a custom (management) database object (optional)
:attr:`setupIn`: a string with the present setup (optional)
:attr:`ncIn`: a custom notification client object (optional)
:attr:`daIn`: a custom DiracAdmin object (optional)
:attr:`csAPIIn`: a custom CSAPI object (optional)
:attr:`knownInfo`: a string of known provided information (optional)
"""
#PDP
if pdpIn is not None:
pdp = pdpIn
else:
# Use standard DIRAC PDP
from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP
pdp = PDP( self.VOExtension, granularity = self.__granularity, name = self.__name,
status = self.__status, formerStatus = self.__formerStatus, reason = self.__reason,
siteType = self.__siteType, serviceType = self.__serviceType,
resourceType = self.__resourceType, useNewRes = self.useNewRes )
#DB
if rsDBIn is not None:
rsDB = rsDBIn
else:
# Use standard DIRAC DB
from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB
rsDB = ResourceStatusDB()
if rmDBIn is not None:
rmDB = rmDBIn
else:
# Use standard DIRAC DB
from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB
rmDB = ResourceManagementDB()
#setup
if setupIn is not None:
setup = setupIn
else:
# get present setup
setup = CS.getSetup()[ 'Value' ]
#notification client
if ncIn is not None:
nc = ncIn
else:
from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient
nc = NotificationClient()
#DiracAdmin
if daIn is not None:
da = daIn
else:
from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
da = DiracAdmin()
#CSAPI
if csAPIIn is not None:
csAPI = csAPIIn
else:
from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI
csAPI = CSAPI()
###################
# policy decision #
###################
resDecisions = pdp.takeDecision( knownInfo = knownInfo )
assert(type(resDecisions) == dict and resDecisions != {})
res = resDecisions[ 'PolicyCombinedResult' ]
actionBaseMod = "DIRAC.ResourceStatusSystem.PolicySystem.Actions"
# Security mechanism in case there is no PolicyType returned
if res == {}:
EmptyPolTypeActions( self.__granularity, self.__name, resDecisions, res )
else:
policyType = res[ 'PolicyType' ]
if 'Resource_PolType' in policyType:
m = Utils.voimport(actionBaseMod + ".Resource_PolType", self.VOExtension)
m.ResourcePolTypeActions( self.__granularity, self.__name, resDecisions, res, rsDB, rmDB )
if 'Alarm_PolType' in policyType:
m = Utils.voimport(actionBaseMod + ".Alarm_PolType", self.VOExtension)
m.AlarmPolTypeActions(self.__name, res, nc, setup, rsDB, rmDB,
Granularity=self.__granularity,
SiteType=self.__siteType,
ServiceType=self.__serviceType,
ResourceType=self.__resourceType)
if 'RealBan_PolType' in policyType and self.__realBan == True:
m = Utils.voimport(actionBaseMod + ".RealBan_PolType", self.VOExtension)
m.RealBanPolTypeActions( self.__granularity, self.__name, res, da, csAPI, setup )