本文整理汇总了Python中DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB类的典型用法代码示例。如果您正苦于以下问题:Python PilotAgentsDB类的具体用法?Python PilotAgentsDB怎么用?Python PilotAgentsDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PilotAgentsDB类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__( self, pilotAgentsDB = None, jobDB = None, tqDB = None, jlDB = None, opsHelper = None ):
""" c'tor
"""
if pilotAgentsDB:
self.pilotAgentsDB = pilotAgentsDB
else:
self.pilotAgentsDB = PilotAgentsDB()
if jobDB:
self.jobDB = jobDB
else:
self.jobDB = JobDB()
if tqDB:
self.tqDB = tqDB
else:
self.tqDB = TaskQueueDB()
if jlDB:
self.jlDB = jlDB
else:
self.jlDB = JobLoggingDB()
if opsHelper:
self.opsHelper = opsHelper
else:
self.opsHelper = Operations()
self.log = gLogger.getSubLogger( "Matcher" )
self.limiter = Limiter( jobDB = self.jobDB, opsHelper = self.opsHelper )
示例2: PilotMonitorAgent
class PilotMonitorAgent( AgentModule ):
"""
The specific agents must provide the following methods:
- initialize() for initial settings
- beginExecution()
- execute() - the main method called in the agent cycle
- endExecution()
- finalize() - the graceful exit of the method, this one is usually used
for the agent restart
"""
#############################################################################
def initialize( self ):
"""Sets defaults
"""
self.am_setOption( 'PollingTime', 120 )
self.clearPilotsDelay = self.am_getOption( 'ClearPilotsDelay', 30 )
self.clearAbortedDelay = self.am_getOption( 'ClearAbortedPilotsDelay', 7 )
self.pilotDB = PilotAgentsDB()
return S_OK()
#############################################################################
def execute( self ):
"""
Remove from PilotDB pilots that:
- are older than self.clearPilotsDelay
- are Aborted and older than self.clearAbortedDelay
"""
result = self.pilotDB.clearPilots( self.clearPilotsDelay, self.clearAbortedDelay )
if not result['OK']:
self.log.warn( 'Failed to clear old pilots in the PilotAgentsDB' )
return S_OK( 'Monitoring cycle complete.' )
示例3: initialize
def initialize(self):
"""Sets defaults
"""
self.am_setOption("PollingTime", 120)
self.am_setOption("GridEnv", "")
self.am_setOption("PilotStalledDays", 3)
self.pilotDB = PilotAgentsDB()
return S_OK()
示例4: initialize
def initialize( self ):
"""Sets defaults
"""
self.am_setOption( 'PollingTime', 120 )
self.am_setOption( 'GridEnv', '' )
self.am_setOption( 'PilotStalledDays', 3 )
self.pilotDB = PilotAgentsDB()
return S_OK()
示例5: initialize
def initialize( self ):
"""Sets defaults
"""
self.am_setOption( 'PollingTime', 120 )
self.clearPilotsDelay = self.am_getOption( 'ClearPilotsDelay', 30 )
self.clearAbortedDelay = self.am_getOption( 'ClearAbortedPilotsDelay', 7 )
self.pilotDB = PilotAgentsDB()
return S_OK()
示例6: initialize
def initialize(self):
"""Sets defaults
"""
self.am_setOption('PollingTime', 120)
self.am_setOption('GridEnv', '')
self.am_setOption('PilotStalledDays', 3)
self.pilotDB = PilotAgentsDB()
self.diracadmin = DiracAdmin()
self.jobDB = JobDB()
self.clearPilotsDelay = self.am_getOption('ClearPilotsDelay', 30)
self.clearAbortedDelay = self.am_getOption('ClearAbortedPilotsDelay', 7)
self.WMSAdministrator = WMSAdministratorClient()
return S_OK()
示例7: __init__
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()
示例8: Matcher
class Matcher( object ):
""" Logic for matching
"""
def __init__( self, pilotAgentsDB = None, jobDB = None, tqDB = None, jlDB = None, opsHelper = None ):
""" c'tor
"""
if pilotAgentsDB:
self.pilotAgentsDB = pilotAgentsDB
else:
self.pilotAgentsDB = PilotAgentsDB()
if jobDB:
self.jobDB = jobDB
else:
self.jobDB = JobDB()
if tqDB:
self.tqDB = tqDB
else:
self.tqDB = TaskQueueDB()
if jlDB:
self.jlDB = jlDB
else:
self.jlDB = JobLoggingDB()
if opsHelper:
self.opsHelper = opsHelper
else:
self.opsHelper = Operations()
self.log = gLogger.getSubLogger( "Matcher" )
self.limiter = Limiter( jobDB = self.jobDB, opsHelper = self.opsHelper )
def selectJob( self, resourceDescription, credDict ):
""" Main job selection function to find the highest priority job matching the resource capacity
"""
startTime = time.time()
resourceDict = self._getResourceDict( resourceDescription, credDict )
negativeCond = self.limiter.getNegativeCondForSite( resourceDict['Site'] )
result = self.tqDB.matchAndGetJob( resourceDict, negativeCond = negativeCond )
if not result['OK']:
return result
result = result['Value']
if not result['matchFound']:
self.log.info( "No match found" )
raise RuntimeError( "No match found" )
jobID = result['jobId']
resAtt = self.jobDB.getJobAttributes( jobID, ['OwnerDN', 'OwnerGroup', 'Status'] )
if not resAtt['OK']:
raise RuntimeError( 'Could not retrieve job attributes' )
if not resAtt['Value']:
raise RuntimeError( "No attributes returned for job" )
if not resAtt['Value']['Status'] == 'Waiting':
self.log.error( 'Job matched by the TQ is not in Waiting state', str( jobID ) )
result = self.tqDB.deleteJob( jobID )
if not result[ 'OK' ]:
return result
raise RuntimeError( "Job %s is not in Waiting state" % str( jobID ) )
self._reportStatus( resourceDict, jobID )
result = self.jobDB.getJobJDL( jobID )
if not result['OK']:
raise RuntimeError( "Failed to get the job JDL" )
resultDict = {}
resultDict['JDL'] = result['Value']
resultDict['JobID'] = jobID
matchTime = time.time() - startTime
self.log.info( "Match time: [%s]" % str( matchTime ) )
gMonitor.addMark( "matchTime", matchTime )
# Get some extra stuff into the response returned
resOpt = self.jobDB.getJobOptParameters( jobID )
if resOpt['OK']:
for key, value in resOpt['Value'].items():
resultDict[key] = value
resAtt = self.jobDB.getJobAttributes( jobID, ['OwnerDN', 'OwnerGroup'] )
if not resAtt['OK']:
raise RuntimeError( 'Could not retrieve job attributes' )
if not resAtt['Value']:
raise RuntimeError( 'No attributes returned for job' )
if self.opsHelper.getValue( "JobScheduling/CheckMatchingDelay", True ):
self.limiter.updateDelayCounters( resourceDict['Site'], jobID )
pilotInfoReportedFlag = resourceDict.get( 'PilotInfoReportedFlag', False )
if not pilotInfoReportedFlag:
self._updatePilotInfo( resourceDict )
self._updatePilotJobMapping( resourceDict, jobID )
resultDict['DN'] = resAtt['Value']['OwnerDN']
resultDict['Group'] = resAtt['Value']['OwnerGroup']
#.........这里部分代码省略.........
示例9: PilotStatusAgent
class PilotStatusAgent(AgentModule):
"""
The specific agents must provide the following methods:
- initialize() for initial settings
- beginExecution()
- execute() - the main method called in the agent cycle
- endExecution()
- finalize() - the graceful exit of the method, this one is usually used
for the agent restart
"""
queryStateList = ["Ready", "Submitted", "Running", "Waiting", "Scheduled"]
finalStateList = ["Done", "Aborted", "Cleared", "Deleted", "Failed"]
identityFieldsList = ["OwnerDN", "OwnerGroup", "GridType", "Broker"]
eligibleGridTypes = ["gLite"]
#############################################################################
def initialize(self):
"""Sets defaults
"""
self.am_setOption("PollingTime", 120)
self.am_setOption("GridEnv", "")
self.am_setOption("PilotStalledDays", 3)
self.pilotDB = PilotAgentsDB()
return S_OK()
#############################################################################
def execute(self):
"""The PilotAgent execution method.
"""
self.pilotStalledDays = self.am_getOption("PilotStalledDays", 3)
self.gridEnv = self.am_getOption("GridEnv")
if not self.gridEnv:
# No specific option found, try a general one
setup = gConfig.getValue("/DIRAC/Setup", "")
if setup:
instance = gConfig.getValue("/DIRAC/Setups/%s/WorkloadManagement" % setup, "")
if instance:
self.gridEnv = gConfig.getValue("/Systems/WorkloadManagement/%s/GridEnv" % instance, "")
result = self.pilotDB._getConnection()
if result["OK"]:
connection = result["Value"]
else:
return result
result = self.pilotDB.getPilotGroups(self.identityFieldsList, {"Status": self.queryStateList})
if not result["OK"]:
self.log.error("Fail to get identities Groups", result["Message"])
return result
if not result["Value"]:
return S_OK()
pilotsToAccount = {}
for ownerDN, ownerGroup, gridType, broker in result["Value"]:
if not gridType in self.eligibleGridTypes:
continue
self.log.verbose("Getting pilots for %s:%s @ %s %s" % (ownerDN, ownerGroup, gridType, broker))
condDict1 = {
"Status": "Done",
"StatusReason": "Report from JobAgent",
"OwnerDN": ownerDN,
"OwnerGroup": ownerGroup,
"GridType": gridType,
"Broker": broker,
}
condDict2 = {
"Status": self.queryStateList,
"OwnerDN": ownerDN,
"OwnerGroup": ownerGroup,
"GridType": gridType,
"Broker": broker,
}
for condDict in [condDict1, condDict2]:
result = self.clearWaitingPilots(condDict)
if not result["OK"]:
self.log.warn("Failed to clear Waiting Pilot Jobs")
result = self.pilotDB.selectPilots(condDict)
if not result["OK"]:
self.log.warn("Failed to get the Pilot Agents")
return result
if not result["Value"]:
continue
refList = result["Value"]
ret = gProxyManager.getPilotProxyFromDIRACGroup(ownerDN, ownerGroup)
if not ret["OK"]:
self.log.error(ret["Message"])
self.log.error("Could not get proxy:", 'User "%s", Group "%s"' % (ownerDN, ownerGroup))
continue
proxy = ret["Value"]
#.........这里部分代码省略.........
示例10: PilotStatusAgent
class PilotStatusAgent(AgentModule):
"""
The specific agents must provide the following methods:
- initialize() for initial settings
- beginExecution()
- execute() - the main method called in the agent cycle
- endExecution()
- finalize() - the graceful exit of the method, this one is usually used
for the agent restart
"""
queryStateList = ['Ready', 'Submitted', 'Running', 'Waiting', 'Scheduled']
finalStateList = ['Done', 'Aborted', 'Cleared', 'Deleted', 'Failed']
def __init__(self, *args, **kwargs):
""" c'tor
"""
AgentModule.__init__(self, *args, **kwargs)
self.jobDB = None
self.pilotDB = None
self.diracadmin = None
#############################################################################
def initialize(self):
"""Sets defaults
"""
self.am_setOption('PollingTime', 120)
self.am_setOption('GridEnv', '')
self.am_setOption('PilotStalledDays', 3)
self.pilotDB = PilotAgentsDB()
self.diracadmin = DiracAdmin()
self.jobDB = JobDB()
self.clearPilotsDelay = self.am_getOption('ClearPilotsDelay', 30)
self.clearAbortedDelay = self.am_getOption('ClearAbortedPilotsDelay', 7)
self.WMSAdministrator = WMSAdministratorClient()
return S_OK()
#############################################################################
def execute(self):
"""The PilotAgent execution method.
"""
self.pilotStalledDays = self.am_getOption('PilotStalledDays', 3)
self.gridEnv = self.am_getOption('GridEnv')
if not self.gridEnv:
# No specific option found, try a general one
setup = gConfig.getValue('/DIRAC/Setup', '')
if setup:
instance = gConfig.getValue('/DIRAC/Setups/%s/WorkloadManagement' % setup, '')
if instance:
self.gridEnv = gConfig.getValue('/Systems/WorkloadManagement/%s/GridEnv' % instance, '')
result = self.pilotDB._getConnection()
if result['OK']:
connection = result['Value']
else:
return result
# Now handle pilots not updated in the last N days (most likely the Broker is no
# longer available) and declare them Deleted.
result = self.handleOldPilots(connection)
connection.close()
result = self.WMSAdministrator.clearPilots(self.clearPilotsDelay, self.clearAbortedDelay)
if not result['OK']:
self.log.warn('Failed to clear old pilots in the PilotAgentsDB')
return S_OK()
def clearWaitingPilots(self, condDict):
""" Clear pilots in the faulty Waiting state
"""
last_update = Time.dateTime() - MAX_WAITING_STATE_LENGTH * Time.hour
clearDict = {'Status': 'Waiting',
'OwnerDN': condDict['OwnerDN'],
'OwnerGroup': condDict['OwnerGroup'],
'GridType': condDict['GridType'],
'Broker': condDict['Broker']}
result = self.pilotDB.selectPilots(clearDict, older=last_update)
if not result['OK']:
self.log.warn('Failed to get the Pilot Agents for Waiting state')
return result
if not result['Value']:
return S_OK()
refList = result['Value']
for pilotRef in refList:
self.log.info('Setting Waiting pilot to Stalled: %s' % pilotRef)
result = self.pilotDB.setPilotStatus(pilotRef, 'Stalled', statusReason='Exceeded max waiting time')
return S_OK()
def clearParentJob(self, pRef, pDict, connection):
""" Clear the parameteric parent job from the PilotAgentsDB
"""
#.........这里部分代码省略.........
示例11: test_PilotsDB
def test_PilotsDB( self ):
wmsAdministrator = RPCClient( 'WorkloadManagement/WMSAdministrator' )
pilotAgentDB = PilotAgentsDB()
res = wmsAdministrator.addPilotTQReference( ['aPilot'], 1, '/a/ownerDN', 'a/owner/Group' )
self.assert_( res['OK'] )
res = wmsAdministrator.getCurrentPilotCounters( {} )
self.assert_( res['OK'] )
self.assertEqual( res['Value'], {'Submitted': 1L} )
res = pilotAgentDB.deletePilot( 'aPilot' )
self.assert_( res['OK'] )
res = wmsAdministrator.getCurrentPilotCounters( {} )
self.assert_( res['OK'] )
self.assertEqual( res['Value'], {} )
res = wmsAdministrator.addPilotTQReference( ['anotherPilot'], 1, '/a/ownerDN', 'a/owner/Group' )
self.assert_( res['OK'] )
res = wmsAdministrator.storePilotOutput( 'anotherPilot', 'This is an output', 'this is an error' )
self.assert_( res['OK'] )
res = wmsAdministrator.getPilotOutput( 'anotherPilot' )
self.assert_( res['OK'] )
self.assertEqual( res['Value'], {'OwnerDN': '/a/ownerDN',
'OwnerGroup': 'a/owner/Group',
'StdErr': 'this is an error',
'FileList': [],
'StdOut': 'This is an output'} )
# need a job for the following
# res = wmsAdministrator.getJobPilotOutput( 1 )
# self.assertEqual( res['Value'], {'OwnerDN': '/a/ownerDN', 'OwnerGroup': 'a/owner/Group',
# 'StdErr': 'this is an error', 'FileList': [], 'StdOut': 'This is an output'} )
# self.assert_( res['OK'] )
res = wmsAdministrator.getPilotInfo( 'anotherPilot' )
self.assert_( res['OK'] )
self.assertEqual( res['Value']['anotherPilot']['AccountingSent'], 'False' )
self.assertEqual( res['Value']['anotherPilot']['PilotJobReference'], 'anotherPilot' )
res = wmsAdministrator.selectPilots( {} )
self.assert_( res['OK'] )
# res = wmsAdministrator.getPilotLoggingInfo( 'anotherPilot' )
# self.assert_( res['OK'] )
res = wmsAdministrator.getPilotSummary( '', '' )
self.assert_( res['OK'] )
self.assertEqual( res['Value']['Total']['Submitted'], 1 )
res = wmsAdministrator.getPilotMonitorWeb( {}, [], 0, 100 )
self.assert_( res['OK'] )
self.assertEqual( res['Value']['TotalRecords'], 1 )
res = wmsAdministrator.getPilotMonitorSelectors()
self.assert_( res['OK'] )
self.assertEqual( res['Value'], {'GridType': ['DIRAC'],
'OwnerGroup': ['a/owner/Group'],
'DestinationSite': ['NotAssigned'],
'Broker': ['Unknown'], 'Status': ['Submitted'],
'OwnerDN': ['/a/ownerDN'],
'GridSite': ['Unknown'],
'Owner': []} )
res = wmsAdministrator.getPilotSummaryWeb( {}, [], 0, 100 )
self.assert_( res['OK'] )
self.assertEqual( res['Value']['TotalRecords'], 1 )
res = wmsAdministrator.setAccountingFlag( 'anotherPilot', 'True' )
self.assert_( res['OK'] )
res = wmsAdministrator.setPilotStatus( 'anotherPilot', 'Running' )
self.assert_( res['OK'] )
res = wmsAdministrator.getPilotInfo( 'anotherPilot' )
self.assert_( res['OK'] )
self.assertEqual( res['Value']['anotherPilot']['AccountingSent'], 'True' )
self.assertEqual( res['Value']['anotherPilot']['Status'], 'Running' )
res = wmsAdministrator.setJobForPilot( 123, 'anotherPilot' )
self.assert_( res['OK'] )
res = wmsAdministrator.setPilotBenchmark( 'anotherPilot', 12.3 )
self.assert_( res['OK'] )
res = wmsAdministrator.countPilots( {} )
self.assert_( res['OK'] )
# res = wmsAdministrator.getCounters()
# # getPilotStatistics
res = pilotAgentDB.deletePilot( 'anotherPilot' )
self.assert_( res['OK'] )
res = wmsAdministrator.getCurrentPilotCounters( {} )
self.assert_( res['OK'] )
self.assertEqual( res['Value'], {} )
示例12: PilotStatusAgent
class PilotStatusAgent( AgentModule ):
"""
The specific agents must provide the following methods:
- initialize() for initial settings
- beginExecution()
- execute() - the main method called in the agent cycle
- endExecution()
- finalize() - the graceful exit of the method, this one is usually used
for the agent restart
"""
queryStateList = ['Ready', 'Submitted', 'Running', 'Waiting', 'Scheduled']
finalStateList = [ 'Done', 'Aborted', 'Cleared', 'Deleted', 'Failed' ]
identityFieldsList = [ 'OwnerDN', 'OwnerGroup', 'GridType', 'Broker' ]
eligibleGridTypes = [ 'gLite' ]
#############################################################################
def initialize( self ):
"""Sets defaults
"""
self.am_setOption( 'PollingTime', 120 )
self.am_setOption( 'GridEnv', '' )
self.am_setOption( 'PilotStalledDays', 3 )
self.pilotDB = PilotAgentsDB()
self.diracadmin = DiracAdmin()
self.jobDB = JobDB()
return S_OK()
#############################################################################
def execute( self ):
"""The PilotAgent execution method.
"""
self.pilotStalledDays = self.am_getOption( 'PilotStalledDays', 3 )
self.gridEnv = self.am_getOption( 'GridEnv' )
if not self.gridEnv:
# No specific option found, try a general one
setup = gConfig.getValue( '/DIRAC/Setup', '' )
if setup:
instance = gConfig.getValue( '/DIRAC/Setups/%s/WorkloadManagement' % setup, '' )
if instance:
self.gridEnv = gConfig.getValue( '/Systems/WorkloadManagement/%s/GridEnv' % instance, '' )
result = self.pilotDB._getConnection()
if result['OK']:
connection = result['Value']
else:
return result
result = self.pilotDB.getPilotGroups( self.identityFieldsList,
{'Status': self.queryStateList } )
if not result['OK']:
self.log.error( 'Fail to get identities Groups', result['Message'] )
return result
if not result['Value']:
return S_OK()
pilotsToAccount = {}
for ownerDN, ownerGroup, gridType, broker in result['Value']:
if not gridType in self.eligibleGridTypes:
continue
self.log.verbose( 'Getting pilots for %s:%s @ %s %s' % ( ownerDN, ownerGroup, gridType, broker ) )
condDict1 = {'Status':'Done',
'StatusReason':'Report from JobAgent',
'OwnerDN':ownerDN,
'OwnerGroup':ownerGroup,
'GridType':gridType,
'Broker':broker}
condDict2 = {'Status':self.queryStateList,
'OwnerDN':ownerDN,
'OwnerGroup':ownerGroup,
'GridType':gridType,
'Broker':broker}
for condDict in [ condDict1, condDict2]:
result = self.clearWaitingPilots( condDict )
if not result['OK']:
self.log.warn( 'Failed to clear Waiting Pilot Jobs' )
result = self.pilotDB.selectPilots( condDict )
if not result['OK']:
self.log.warn( 'Failed to get the Pilot Agents' )
return result
if not result['Value']:
continue
refList = result['Value']
ret = gProxyManager.getPilotProxyFromDIRACGroup( ownerDN, ownerGroup )
if not ret['OK']:
self.log.error( ret['Message'] )
self.log.error( 'Could not get proxy:', 'User "%s", Group "%s"' % ( ownerDN, ownerGroup ) )
continue
proxy = ret['Value']
self.log.verbose( "Getting status for %s pilots for owner %s and group %s" % ( len( refList ),
#.........这里部分代码省略.........
示例13: printTable
labels = ['pilotUUID', 'timestamp', 'source', 'phase', 'status', 'messageContent']
for log in logs:
content.append([log[label] for label in labels])
printTable(labels, content, numbering=False, columnSeparator=' | ')
if uuid:
pilotsLogging = PilotsLoggingClient()
result = pilotsLogging.getPilotsLogging(uuid)
if not result['OK']:
print 'ERROR: %s' % result['Message']
DIRAC.exit(1)
printPilotsLogging(result['Value'])
DIRAC.exit(0)
else:
pilotDB = PilotAgentsDB()
pilotsLogging = PilotsLoggingClient()
pilots = pilotDB.getPilotsForJobID(jobid)
if not pilots['OK ']:
print pilots['Message']
for pilotID in pilots:
info = pilotDB.getPilotInfo(pilotID=pilotID)
if not info['OK']:
print info['Message']
for pilot in info:
logging = pilotsLogging.getPilotsLogging(pilot['PilotJobReference'])
if not logging['OK']:
print logging['Message']
printPilotsLogging(logging)
DIRAC.exit(0)
示例14: PilotCommand
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,
#.........这里部分代码省略.........