本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient.addOrModifyPilotCache方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceManagementClient.addOrModifyPilotCache方法的具体用法?Python ResourceManagementClient.addOrModifyPilotCache怎么用?Python ResourceManagementClient.addOrModifyPilotCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient
的用法示例。
在下文中一共展示了ResourceManagementClient.addOrModifyPilotCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PilotCommand
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import addOrModifyPilotCache [as 别名]
class PilotCommand( Command ):
"""
Pilot "master" Command.
"""
def __init__( self, args = None, clients = None ):
super( PilotCommand, self ).__init__( args, clients )
if 'WMSAdministrator' in self.apis:
self.wmsAdmin = self.apis[ 'WMSAdministrator' ]
else:
self.wmsAdmin = RPCClient( 'WorkloadManagement/WMSAdministrator' )
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 pilotDict in result:
resQuery = self.rmClient.addOrModifyPilotCache( pilotDict[ 'Site' ],
pilotDict[ 'CE' ],
pilotDict[ 'PilotsPerJob' ],
pilotDict[ 'PilotJobEff' ],
pilotDict[ 'Status' ] )
if not resQuery[ 'OK' ]:
return resQuery
return S_OK()
def _prepareCommand( self ):
"""
JobCommand requires one arguments:
- name : <str>
"""
if not 'name' in self.args:
return S_ERROR( '"name" not found in self.args' )
name = self.args[ 'name' ]
if not 'element' in self.args:
return S_ERROR( 'element is missing' )
element = self.args[ 'element' ]
if element not in [ 'Site', 'Resource' ]:
return S_ERROR( '"%s" is not Site nor Resource' % element )
return S_OK( ( element, name ) )
def doNew( self, masterParams = None ):
if masterParams is not None:
element, name = masterParams
else:
params = self._prepareCommand()
if not params[ 'OK' ]:
return params
element, name = params[ 'Value' ]
wmsDict = {}
if element == 'Site':
wmsDict = { 'GridSite' : name }
elif element == 'Resource':
wmsDict = { 'ExpandSite' : name }
else:
# You should never see this error
return S_ERROR( '"%s" is not Site nor Resource' % element )
wmsResults = self.wmsAdmin.getPilotSummaryWeb( wmsDict, [], 0, 0 )
if not wmsResults[ 'OK' ]:
return wmsResults
wmsResults = wmsResults[ 'Value' ]
if not 'ParameterNames' in wmsResults:
return S_ERROR( 'Wrong result dictionary, missing "ParameterNames"' )
params = wmsResults[ 'ParameterNames' ]
if not 'Records' in wmsResults:
return S_ERROR( 'Wrong formed result dictionary, missing "Records"' )
records = wmsResults[ 'Records' ]
uniformResult = []
for record in records:
# This returns a dictionary with the following keys:
# 'Site', 'CE', 'Submitted', 'Ready', 'Scheduled', 'Waiting', 'Running',
# 'Done', 'Aborted', 'Done_Empty', 'Aborted_Hour', 'Total', 'PilotsPerJob',
# 'PilotJobEff', 'Status', 'InMask'
pilotDict = dict( zip( params, record ) )
pilotDict[ 'PilotsPerJob' ] = float( pilotDict[ 'PilotsPerJob' ] )
#.........这里部分代码省略.........
示例2: PilotCommand
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import addOrModifyPilotCache [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,
#.........这里部分代码省略.........