本文整理匯總了Python中DIRAC.Core.LCG.GOCDBClient.GOCDBClient.getCurrentDTLinkList方法的典型用法代碼示例。如果您正苦於以下問題:Python GOCDBClient.getCurrentDTLinkList方法的具體用法?Python GOCDBClient.getCurrentDTLinkList怎麽用?Python GOCDBClient.getCurrentDTLinkList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DIRAC.Core.LCG.GOCDBClient.GOCDBClient
的用法示例。
在下文中一共展示了GOCDBClient.getCurrentDTLinkList方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DowntimeCommand
# 需要導入模塊: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 別名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getCurrentDTLinkList [as 別名]
class DowntimeCommand( Command ):
'''
Downtime "master" Command or removed DTs.
'''
def __init__( self, args = None, clients = None ):
super( DowntimeCommand, self ).__init__( args, clients )
if 'GOCDBClient' in self.apis:
self.gClient = self.apis[ 'GOCDBClient' ]
else:
self.gClient = GOCDBClient()
if 'ResourceManagementClient' in self.apis:
self.rmClient = self.apis[ 'ResourceManagementClient' ]
else:
self.rmClient = ResourceManagementClient()
def _storeCommand( self, result ):
'''
Stores the results of doNew method on the database.
'''
for dt in result:
resQuery = self.rmClient.addOrModifyDowntimeCache( downtimeID = dt[ 'DowntimeID' ],
element = dt[ 'Element' ],
name = dt[ 'Name' ],
startDate = dt[ 'StartDate' ],
endDate = dt[ 'EndDate' ],
severity = dt[ 'Severity' ],
description = dt[ 'Description' ],
link = dt[ 'Link' ],
gocdbServiceType = dt[ 'GOCDBServiceType' ] )
return resQuery
def _cleanCommand( self, element, elementNames):
'''
Clear Cache from expired DT.
'''
resQuery = []
for elementName in elementNames:
#get the list of all DTs stored in the cache
result = self.rmClient.selectDowntimeCache( element = element,
name = elementName )
if not result[ 'OK' ]:
return result
uniformResult = [ dict( zip( result[ 'Columns' ], res ) ) for res in result[ 'Value' ] ]
currentDate = datetime.utcnow()
if len(uniformResult) == 0:
return S_OK( None )
#get the list of all ongoing DTs from GocDB
gDTLinkList = self.gClient.getCurrentDTLinkList()
if not gDTLinkList[ 'OK' ]:
return gDTLinkList
for dt in uniformResult:
#if DT expired or DT not in the list of current DTs, then we remove it from the cache
if dt[ 'EndDate' ] < currentDate or dt[ 'Link' ] not in gDTLinkList[ 'Value' ]:
result = self.rmClient.deleteDowntimeCache (
downtimeID = dt[ 'DowntimeID' ]
)
resQuery.append(result)
return S_OK( resQuery )
def _prepareCommand( self ):
'''
DowntimeCommand requires four arguments:
- name : <str>
- element : Site / Resource
- elementType: <str>
If the elements are Site(s), we need to get their GOCDB names. They may
not have, so we ignore them if they do not have.
'''
if 'name' not in self.args:
return S_ERROR( '"name" not found in self.args' )
elementName = self.args[ 'name' ]
if 'element' not in self.args:
return S_ERROR( '"element" not found in self.args' )
element = self.args[ 'element' ]
if 'elementType' not in self.args:
return S_ERROR( '"elementType" not found in self.args' )
elementType = self.args[ 'elementType' ]
if not element in [ 'Site', 'Resource' ]:
return S_ERROR( 'element is neither Site nor Resource' )
#.........這裏部分代碼省略.........
示例2: DowntimeCommand
# 需要導入模塊: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 別名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getCurrentDTLinkList [as 別名]
class DowntimeCommand(Command):
'''
Downtime "master" Command or removed DTs.
'''
def __init__(self, args=None, clients=None):
super(DowntimeCommand, self).__init__(args, clients)
if 'GOCDBClient' in self.apis:
self.gClient = self.apis['GOCDBClient']
else:
self.gClient = GOCDBClient()
if 'ResourceManagementClient' in self.apis:
self.rmClient = self.apis['ResourceManagementClient']
else:
self.rmClient = ResourceManagementClient()
def _storeCommand(self, result):
'''
Stores the results of doNew method on the database.
'''
for dt in result:
resQuery = self.rmClient.addOrModifyDowntimeCache(downtimeID=dt['DowntimeID'],
element=dt['Element'],
name=dt['Name'],
startDate=dt['StartDate'],
endDate=dt['EndDate'],
severity=dt['Severity'],
description=dt['Description'],
link=dt['Link'],
gOCDBServiceType=dt['gOCDBServiceType'])
return resQuery
def _cleanCommand(self, element, elementNames):
'''
Clear Cache from expired DT.
'''
resQuery = []
for elementName in elementNames:
# get the list of all DTs stored in the cache
result = self.rmClient.selectDowntimeCache(element=element,
name=elementName)
if not result['OK']:
return result
uniformResult = [dict(zip(result['Columns'], res)) for res in result['Value']]
currentDate = datetime.utcnow()
if not uniformResult:
continue
# get the list of all ongoing DTs from GocDB
gDTLinkList = self.gClient.getCurrentDTLinkList()
if not gDTLinkList['OK']:
return gDTLinkList
for dt in uniformResult:
# if DT expired or DT not in the list of current DTs, then we remove it from the cache
if dt['EndDate'] < currentDate or dt['Link'] not in gDTLinkList['Value']:
result = self.rmClient.deleteDowntimeCache(downtimeID=dt['DowntimeID'])
resQuery.append(result)
return S_OK(resQuery)
def _prepareCommand(self):
'''
DowntimeCommand requires four arguments:
- name : <str>
- element : Site / Resource
- elementType: <str>
If the elements are Site(s), we need to get their GOCDB names. They may
not have, so we ignore them if they do not have.
'''
if 'name' not in self.args:
return S_ERROR('"name" not found in self.args')
elementName = self.args['name']
if 'element' not in self.args:
return S_ERROR('"element" not found in self.args')
element = self.args['element']
if 'elementType' not in self.args:
return S_ERROR('"elementType" not found in self.args')
elementType = self.args['elementType']
if element not in ['Site', 'Resource']:
return S_ERROR('element is neither Site nor Resource')
hours = None
if 'hours' in self.args:
hours = self.args['hours']
#.........這裏部分代碼省略.........