本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceStatus.ResourceStatus.getElementStatus方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceStatus.getElementStatus方法的具体用法?Python ResourceStatus.getElementStatus怎么用?Python ResourceStatus.getElementStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceStatus.ResourceStatus
的用法示例。
在下文中一共展示了ResourceStatus.getElementStatus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FTS3ServerPolicy
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatus import ResourceStatus [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatus.ResourceStatus import getElementStatus [as 别名]
class FTS3ServerPolicy(object):
"""
This class manages the policy for choosing a server
"""
def __init__(self, serverDict, serverPolicy="Random"):
"""
Call the init of the parent, and initialize the list of FTS3 servers
"""
self.log = gLogger.getSubLogger("FTS3ServerPolicy")
self._serverDict = serverDict
self._serverList = serverDict.keys()
self._maxAttempts = len(self._serverList)
self._nextServerID = 0
self._resourceStatus = ResourceStatus()
methName = "_%sServerPolicy" % serverPolicy.lower()
if not hasattr(self, methName):
self.log.error('Unknown server policy %s. Using Random instead' % serverPolicy)
methName = "_randomServerPolicy"
self._policyMethod = getattr(self, methName)
def _failoverServerPolicy(self, _attempt):
"""
Returns always the server at a given position (normally the first one)
:param attempt: position of the server in the list
"""
if _attempt >= len(self._serverList):
raise Exception(
"FTS3ServerPolicy.__failoverServerPolicy: attempt to reach non existing server index")
return self._serverList[_attempt]
def _sequenceServerPolicy(self, _attempt):
"""
Every time the this policy is called, return the next server on the list
"""
fts3server = self._serverList[self._nextServerID]
self._nextServerID = (self._nextServerID + 1) % len(self._serverList)
return fts3server
def _randomServerPolicy(self, _attempt):
"""
return a server from shuffledServerList
"""
if getattr(threadLocal, 'shuffledServerList', None) is None:
threadLocal.shuffledServerList = self._serverList[:]
random.shuffle(threadLocal.shuffledServerList)
fts3Server = threadLocal.shuffledServerList[_attempt]
if _attempt == self._maxAttempts - 1:
random.shuffle(threadLocal.shuffledServerList)
return fts3Server
def _getFTSServerStatus(self, ftsServer):
""" Fetch the status of the FTS server from RSS """
res = self._resourceStatus.getElementStatus(ftsServer, 'FTS')
if not res['OK']:
return res
result = res['Value']
if ftsServer not in result:
return S_ERROR("No FTS Server %s known to RSS" % ftsServer)
if result[ftsServer]['all'] == 'Active':
return S_OK(True)
return S_OK(False)
def chooseFTS3Server(self):
"""
Choose the appropriate FTS3 server depending on the policy
"""
fts3Server = None
attempt = 0
while not fts3Server and attempt < self._maxAttempts:
fts3Server = self._policyMethod(attempt)
res = self._getFTSServerStatus(fts3Server)
if not res['OK']:
self.log.warn("Error getting the RSS status for %s: %s" % (fts3Server, res))
fts3Server = None
attempt += 1
continue
ftsServerStatus = res['Value']
if not ftsServerStatus:
self.log.warn('FTS server %s is not in good shape. Choose another one' % fts3Server)
#.........这里部分代码省略.........
示例2: ResourceStatus
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatus import ResourceStatus [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatus.ResourceStatus import getElementStatus [as 别名]
STATUS_TYPES = [ "ReadAccess", "WriteAccess", "CheckAccess", "RemoveAccess" ]
ALLOWED_STATUSES = [ "Unknown", "InActive", "Banned", "Probing", "Degraded" ]
statusAllowedDict = {}
for statusType in STATUS_TYPES:
statusAllowedDict[statusType] = []
statusFlagDict = {}
statusFlagDict['ReadAccess'] = read
statusFlagDict['WriteAccess'] = write
statusFlagDict['CheckAccess'] = check
statusFlagDict['RemoveAccess'] = remove
resourceStatus = ResourceStatus()
res = resourceStatus.getElementStatus( ses, "StorageElement" )
if not res[ 'OK' ]:
gLogger.error( 'Storage Element %s does not exist' % ses )
DIRAC.exit( -1 )
reason = 'Forced with dirac-admin-allow-se by %s' % userName
for se, seOptions in res[ 'Value' ].iteritems():
# InActive is used on the CS model, Banned is the equivalent in RSS
for statusType in STATUS_TYPES:
if statusFlagDict[statusType]:
if seOptions.get( statusType ) == "Active":
gLogger.notice( '%s status of %s is already Active' % ( statusType, se ) )
continue
if statusType in seOptions:
示例3: FTS3Placement
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatus import ResourceStatus [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatus.ResourceStatus import getElementStatus [as 别名]
#.........这里部分代码省略.........
"""
Every time the this policy is called, return the next server on the list
"""
fts3server = self.__serverList[self.__nextServerID]
self.__nextServerID = ( self.__nextServerID + 1 ) % len( self.__serverList )
return fts3server
def __randomServerPolicy(self):
"""
return a random server from the list
"""
return random.choice( self.__serverList )
def __chooseFTS3Server( self ):
"""
Choose the appropriate FTS3 server depending on the policy
"""
fts3Server = None
attempt = 0
# FIXME : need to get real valeu from RSS
ftsServerStatus = True
while not fts3Server and attempt < self.maxAttempts:
if self.__serverPolicy == 'Random':
fts3Server = self.__randomServerPolicy()
elif self.__serverPolicy == 'Sequence':
fts3Server = self.__sequenceServerPolicy()
elif self.__serverPolicy == 'Failover':
fts3Server = self.__failoverServerPolicy( attempt = attempt )
else:
self.log.error( 'Unknown server policy %s. Using Random instead' % self.__serverPolicy )
fts3Server = self.__randomServerPolicy()
if not ftsServerStatus:
self.log.warn( 'FTS server %s is not in good shape. Choose another one' % fts3Server )
fts3Server = None
attempt += 1
# FIXME : I need to get the FTS server status from RSS
# ftsStatusFromRss = rss.ftsStatusOrSomethingLikeThat
if fts3Server:
return S_OK( fts3Server )
return S_ERROR ( "Could not find an FTS3 server (max attempt reached)" )
def findRoute( self, sourceSE, targetSE ):
""" Find the appropriate route from point A to B
:param sourceSE : source SE
:param targetSE : destination SE
:returns: S_OK(FTSRoute)
"""
fts3server = self.__chooseFTS3Server()
if not fts3server['OK']:
return fts3server
fts3server = fts3server['Value']
route = FTSRoute( sourceSE, targetSE, fts3server )
return S_OK( route )
def isRouteValid( self, route ):
"""
FIXME: until RSS is ready, I check manually the status
In FTS3, all routes are valid a priori.
If a route was not valid for some reason, then FTS would know it
thanks to the blacklist sent by RSS, and would deal with it itself.
:param route : FTSRoute
:returns: S_OK or S_ERROR(reason)
"""
rAccess = self.rssClient.getElementStatus( route.sourceSE, "StorageElement", "ReadAccess" )
self.log.debug( "se read %s %s" % ( route.sourceSE, rAccess ) )
if not rAccess["OK"]:
self.log.error( rAccess["Message"] )
return rAccess
if rAccess["Value"][route.sourceSE]["ReadAccess"] not in ( "Active", "Degraded" ):
return S_ERROR( "Source SE is not readable" )
wAccess = self.rssClient.getElementStatus( route.targetSE, "StorageElement", "WriteAccess" )
self.log.debug( "se write %s %s" % ( route.targetSE, wAccess ) )
if not wAccess["OK"]:
self.log.error( wAccess["Message"] )
return wAccess
if wAccess["Value"][route.targetSE]["WriteAccess"] not in ( "Active", "Degraded" ):
return S_ERROR( "Target SE is not writable" )
return S_OK()