本文整理汇总了Python中DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB.getPilotSummaryShort方法的典型用法代码示例。如果您正苦于以下问题:Python PilotAgentsDB.getPilotSummaryShort方法的具体用法?Python PilotAgentsDB.getPilotSummaryShort怎么用?Python PilotAgentsDB.getPilotSummaryShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB
的用法示例。
在下文中一共展示了PilotAgentsDB.getPilotSummaryShort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PilotCommand
# 需要导入模块: from DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB import PilotAgentsDB [as 别名]
# 或者: from DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB import getPilotSummaryShort [as 别名]
class PilotCommand( Command ):
""" Pilot 'master' Command.
"""
def __init__( self, args = None, clients = None ):
""" Constructor.
:Parameters:
**args** - [, `dict` ]
arguments to be passed to be used in the _prepareCommand method ( name and
timespan are the expected ones )
**clients - [, `dict` ]
clients from where information is fetched. Mainly used to avoid creating
new connections on agents looping over clients. ResourceManagementClient
and PilotsDB are most welcome.
"""
super( PilotCommand, self ).__init__( args, clients )
if 'PilotsDB' in self.apis:
self.pilotsDB = self.apis[ 'PilotsDB' ]
else:
self.pilotsDB = PilotAgentsDB()
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.
:Parameters:
**result** - `list( dict )`
list of dictionaries to be inserted on the DB. Unfortunately, there is no
bulk insertion method on the database. The dictionaries are sanitized in
doNew method so that they match the column names in the database.
:return: S_OK / S_ERROR
"""
for pilotDict in result:
lowerCasePilotDict = {}
for key, value in pilotDict.iteritems():
lowerCasePilotDict[ key[0].lower() + key[1:] ] = value
# I do not care about the **magic, it makes it cleaner
resQuery = self.rmClient.addOrModifyPilotCache( **lowerCasePilotDict )
if not resQuery[ 'OK' ]:
return resQuery
return S_OK()
def _prepareCommand( self ):
""" Method that parses command arguments to extract the ones needed:
name : name of the computing element
timespan ( seconds ) : time window
:return: : S_OK( name, timespan ) / S_ERROR
"""
if not 'name' in self.args:
return S_ERROR( '"name" not found in self.args' )
name = self.args[ 'name' ]
if not 'timespan' in self.args:
return S_ERROR( '"timespan" not found in self.args' )
timespan = self.args[ 'timespan' ]
return S_OK( ( name, timespan ) )
def doNew( self, masterParams = None ):
""" doNew method. If is master execution, name is declared as '' so that
all ce's are asked. Once values are obtained, they are stored on the Database.
The entries with name Unknown, NotAssigned and Total are skipped.
:Parameters:
**masterParams** - [, bool ]
if True, it queries for all elements in the database for the given timespan
:return: S_OK( list ( dict ) ) / S_ERROR
"""
# Ask for all CEs
if masterParams is True:
self.args[ 'name' ] = ''
params = self._prepareCommand()
if not params[ 'OK' ]:
return params
computingElement, timespan = params[ 'Value' ]
# Calculate time window from timespan and utcnow
endTimeWindow = datetime.utcnow()
startTimeWindow = endTimeWindow - timedelta( seconds = timespan )
# Get pilots information from DB
pilotsRes = self.pilotsDB.getPilotSummaryShort( startTimeWindow,
endTimeWindow,
#.........这里部分代码省略.........