本文整理汇总了Python中DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient.getReport方法的典型用法代码示例。如果您正苦于以下问题:Python ReportsClient.getReport方法的具体用法?Python ReportsClient.getReport怎么用?Python ReportsClient.getReport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient
的用法示例。
在下文中一共展示了ReportsClient.getReport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPlotData
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
def getPlotData( self ):
retVal = self.__parseFormParams()
if not retVal[ 'OK' ]:
c.error = retVal[ 'Message' ]
return render( "/error.mako" )
params = retVal[ 'Value' ]
repClient = ReportsClient( rpcClient = getRPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.getReport( *params )
if not retVal[ 'OK' ]:
c.error = retVal[ 'Message' ]
return render( "/error.mako" )
rawData = retVal[ 'Value' ]
groupKeys = rawData[ 'data' ].keys()
groupKeys.sort()
if 'granularity' in rawData:
granularity = rawData[ 'granularity' ]
data = rawData['data']
tS = int( Time.toEpoch( params[2] ) )
timeStart = tS - tS % granularity
strData = "epoch,%s\n" % ",".join( groupKeys )
for timeSlot in range( timeStart, int( Time.toEpoch( params[3] ) ), granularity ):
lineData = [ str( timeSlot ) ]
for key in groupKeys:
if timeSlot in data[ key ]:
lineData.append( str( data[ key ][ timeSlot ] ) )
else:
lineData.append( "" )
strData += "%s\n" % ",".join( lineData )
else:
strData = "%s\n" % ",".join( groupKeys )
strData += ",".join( [ str( rawData[ 'data' ][ k ] ) for k in groupKeys ] )
response.headers['Content-type'] = 'text/csv'
response.headers['Content-Disposition'] = 'attachment; filename="%s.csv"' % md5( str( params ) ).hexdigest()
response.headers['Content-Length'] = len( strData )
return strData
示例2: test_addAndRemove
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
def test_addAndRemove():
# just inserting one record
record = createAccountingRecord()
record.setStartTime()
record.setEndTime()
res = gDataStoreClient.addRegister(record)
assert res['OK']
res = gDataStoreClient.commit()
assert res['OK']
rc = ReportsClient()
res = rc.listReports('DataOperation')
assert res['OK']
res = rc.listUniqueKeyValues('DataOperation')
assert res['OK']
res = rc.getReport('DataOperation', 'Successful transfers',
datetime.datetime.utcnow(), datetime.datetime.utcnow(),
{}, 'Destination')
assert res['OK']
# now removing that record
res = gDataStoreClient.remove(record)
assert res['OK']
示例3: web_getPlotData
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
def web_getPlotData(self):
callback = {}
retVal = self.__parseFormParams()
if not retVal[ 'OK' ]:
callback = {"success":"false", "error":retVal[ 'Message' ]}
self.finish( callback )
params = retVal[ 'Value' ]
'''self.finish({'success' : 'true', 'result' : params})'''
repClient = ReportsClient( rpcClient = RPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.getReport(*params)
if not retVal[ 'OK' ]:
callback = {"success":"false", "error":retVal[ 'Message' ]}
self.finish( callback )
rawData = retVal[ 'Value' ]
groupKeys = rawData[ 'data' ].keys()
self.finish({'success' : 'true', 'result' : groupKeys})
示例4: getJobsHistory
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
def getJobsHistory():
result = gOAManager.authorize()
if not result[ 'OK' ]:
bottle.abort( 401, result[ 'Message' ] )
condDict = {}
if 'allOwners' not in bottle.request.params:
condDict[ 'User' ] = gOAData.userName
timeSpan = 86400
if 'timeSpan' in bottle.request.params:
try:
timeSpan = max( 86400, int( bottle.request.params[ 'timeSpan' ] ) )
except ValueError:
bottle.abort( 400, "timeSpan has to be an integer!" )
print "[DEBUG] condDict is %s" % condDict
rpg = ReportsClient( rpcClient = getRPCClient("Accounting/ReportGenerator"), transferClient = getTransferClient("Accounting/ReportGenerator") )
end = datetime.datetime.utcnow()
start = end - datetime.timedelta( seconds = timeSpan )
result = rpg.getReport( "WMSHistory", "NumberOfJobs", start, end, condDict, 'Status' )
if not result[ 'OK' ]:
bottle.abort( 500, "Server Error: %s" % result[ 'Message' ] )
return result[ 'Value' ]
示例5: _getHistoryData
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
def _getHistoryData(self, timeSpan, groupToUse):
""" Get history data from Accounting WMSHistory database
:param int timeSpan: time span
:param str groupToUse: requested user group
:return: dictionary with history data
"""
reportsClient = ReportsClient()
reportCondition = {'Status': ['Running']}
if not groupToUse:
reportGrouping = 'UserGroup'
else:
reportGrouping = 'User'
reportCondition = {'UserGroup': groupToUse}
now = Time.dateTime()
result = reportsClient.getReport('WMSHistory', 'AverageNumberOfJobs',
now - datetime.timedelta(seconds=timeSpan), now,
reportCondition, reportGrouping,
{'lastSeconds': timeSpan})
return result
示例6: FailedPilotsByCESplitted_Command
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class FailedPilotsByCESplitted_Command(Command):
def doCommand(self, CEs = None):
"""
Returns failed pilots using the DIRAC accounting system for every CE
for the last self.args[0] hours
:params:
:attr:`CEs`: list of CEs (when not given, take every CE)
:returns:
"""
if CEs is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
RPC_RSS = RPCClient("ResourceStatus/ResourceStatus")
CEs = RPC_RSS.getCEsList()
if not CEs['OK']:
raise RSSException, where(self, self.doCommand) + " " + CEs['Message']
else:
CEs = CEs['Value']
if self.RPC is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
self.RPC = RPCClient("Accounting/ReportGenerator", timeout = self.timeout)
if self.client is None:
from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient
self.client = ReportsClient(rpcClient = self.RPC)
fromD = datetime.datetime.utcnow()-datetime.timedelta(hours = self.args[0])
toD = datetime.datetime.utcnow()
try:
failed_pilots = self.client.getReport('Pilot', 'NumberOfPilots', fromD, toD,
{'GridStatus':['Aborted'], 'GridCE':CEs}, 'GridCE')
if not failed_pilots['OK']:
raise RSSException, where(self, self.doCommand) + " " + failed_pilots['Message']
else:
failed_pilots = failed_pilots['Value']
except:
gLogger.exception("Exception when calling FailedPilotsByCESplitted_Command")
return {}
listOfCEs = failed_pilots['data'].keys()
plotGran = failed_pilots['granularity']
singlePlots = {}
for CE in listOfCEs:
if CE in CEs:
plot = {}
plot['data'] = {CE: failed_pilots['data'][CE]}
plot['granularity'] = plotGran
singlePlots[CE] = plot
resToReturn = {'Pilot': singlePlots}
return resToReturn
doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
示例7: FailedTransfersBySourceSplitted_Command
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class FailedTransfersBySourceSplitted_Command(Command):
def doCommand(self, sources = None, SEs = None):
"""
Returns failed transfer using the DIRAC accounting system for every SE
for the last self.args[0] hours
:params:
:attr:`sources`: list of source sites (when not given, take every site)
:attr:`SEs`: list of storage elements (when not given, take every SE)
:returns:
"""
if SEs is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
RPC_RSS = RPCClient("ResourceStatus/ResourceStatus")
SEs = RPC_RSS.getStorageElementsList()
if not SEs['OK']:
raise RSSException, where(self, self.doCommand) + " " + SEs['Message']
else:
SEs = SEs['Value']
if sources is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
RPC_RSS = RPCClient("ResourceStatus/ResourceStatus")
sources = RPC_RSS.getSitesList()
if not sources['OK']:
raise RSSException, where(self, self.doCommand) + " " + sources['Message']
else:
sources = sources['Value']
if self.RPC is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
self.RPC = RPCClient("Accounting/ReportGenerator", timeout = self.timeout)
if self.client is None:
from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient
self.client = ReportsClient(rpcClient = self.RPC)
fromD = datetime.datetime.utcnow()-datetime.timedelta(hours = self.args[0])
toD = datetime.datetime.utcnow()
try:
ft_source = self.client.getReport('DataOperation', 'FailedTransfers',
fromD, toD,
{'OperationType':'putAndRegister',
'Source':sources + SEs, 'Destination':sources + SEs,
'FinalStatus':['Failed']},
'Source')
if not ft_source['OK']:
raise RSSException, where(self, self.doCommand) + " " + ft_source['Message']
else:
ft_source = ft_source['Value']
except:
gLogger.exception("Exception when calling FailedTransfersBySourceSplitted_Command")
return {}
listOfSources = ft_source['data'].keys()
plotGran = ft_source['granularity']
singlePlots = {}
for source in listOfSources:
if source in sources:
plot = {}
plot['data'] = {source: ft_source['data'][source]}
plot['granularity'] = plotGran
singlePlots[source] = plot
resToReturn = {'DataOperation': singlePlots}
return resToReturn
doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
示例8: TransferCommand
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
#.........这里部分代码省略.........
def doNew( self, masterParams = None ):
'''
Gets the parameters to run, either from the master method or from its
own arguments.
For every elementName ( cannot process bulk queries.. ) contacts the
accounting client. It reurns dictionaries like { 'X -> Y' : { id: 100%.. } }
If there are ggus tickets, are recorded and then returned.
'''
if masterParams is not None:
hours, name, direction, metric = masterParams
else:
params = self._prepareCommand()
if not params[ 'OK' ]:
return params
hours, name, direction, metric = params[ 'Value' ]
toD = datetime.utcnow()
fromD = toD - timedelta( hours = hours )
# dictionary with conditions for the accounting
transferDict = {
'OperationType' : 'putAndRegister',
direction : name
}
if metric == 'FailedTransfers':
transferDict[ 'FinalStatus' ] = [ 'Failed' ]
transferResults = self.rClient.getReport( 'DataOperation', metric, fromD,
toD, transferDict, 'Channel' )
if not transferResults[ 'OK' ]:
return transferResults
transferResults = transferResults[ 'Value' ]
if not 'data' in transferResults:
return S_ERROR( 'Missing data key' )
transferResults = transferResults[ 'data' ]
uniformResult = []
for channel, elementDict in transferResults.items():
try:
source, destination = channel.split( ' -> ' )
except ValueError:
continue
channelDict = {}
channelDict[ 'SourceName' ] = source
channelDict[ 'DestinationName' ] = destination
channelDict[ 'Metric' ] = metric
channelDict[ 'Value' ] = sum( elementDict.values() ) / len( elementDict.values() )
uniformResult.append( channelDict )
storeRes = self._storeCommand( uniformResult )
if not storeRes[ 'OK' ]:
return storeRes
# Compute mean of all transfer channels
示例9: TransferQualityCommand
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class TransferQualityCommand( Command ):
def __init__( self, args = None, clients = None ):
super( TransferQualityCommand, self ).__init__( args, clients )
if 'ReportGenerator' in self.apis:
self.rgClient = self.apis[ 'ReportGenerator' ]
else:
self.rgClient = RPCClient( 'Accounting/ReportGenerator' )
if 'ReportsClient' in self.apis:
self.rClient = self.apis[ 'ReportsClient' ]
else:
self.rClient = ReportsClient()
self.rClient.rpcClient = self.rgClient
def doCommand( self ):
"""
Return getQuality from DIRAC's accounting ReportsClient
`args`: a tuple
- args[0]: string: should be a ValidElement
- args[1]: string should be the name of the ValidElement
- args[2]: optional dateTime object: a "from" date
- args[3]: optional dateTime object: a "to" date
:returns:
{'Result': None | a float between 0.0 and 100.0}
"""
if not 'fromDate' in self.args:
fromDate = datetime.utcnow() - timedelta( hours = 2 )
else:
fromDate = self.args[ 'fromDate' ]
if not 'toDate' in self.args:
toDate = datetime.utcnow()
else:
toDate = self.args[ 'toDate' ]
if not 'name' in self.args:
return S_ERROR( 'name not specified' )
name = self.args[ 'name' ]
results = self.rClient.getReport( 'DataOperation', 'Quality', fromDate, toDate,
{ 'OperationType' : 'putAndRegister',
'Destination' : [ name ]
}, 'Channel' )
if not results[ 'OK' ]:
return results
pr_q_d = results[ 'Value' ][ 'data' ]
#FIXME: WHAT the hell is this doing ?
values = []
if len( pr_q_d ) == 1:
for k in pr_q_d.keys():
for n in pr_q_d[ k ].values():
values.append( n )
res = sum( values ) / len( values )
else:
for n in pr_q_d[ 'Total' ].values():
values.append(n)
res = sum( values ) / len( values )
return S_OK( res )
示例10: DIRACAccountingCommand
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class DIRACAccountingCommand( Command ):
def __init__( self, args = None, clients = None ):
super( DIRACAccountingCommand, self ).__init__( args, clients )
if 'ReportGenerator' in self.apis:
self.rgClient = self.apis[ 'ReportGenerator' ]
else:
self.rgClient = RPCClient( 'Accounting/ReportGenerator' )
if 'ReportsClient' in self.apis:
self.rClient = self.apis[ 'ReportsClient' ]
else:
self.rClient = ReportsClient()
self.rClient.rpcClient = self.rgClient
def doCommand( self ):
"""
Returns jobs accounting info for sites in the last 24h
`args`:
- args[0]: string - should be a ValidElement
- args[1]: string - should be the name of the ValidElement
- args[2]: string - should be 'Job' or 'Pilot' or 'DataOperation'
or 'WMSHistory' (??) or 'SRM' (??)
- args[3]: string - should be the plot to generate (e.g. CPUEfficiency)
- args[4]: dictionary - e.g. {'Format': 'LastHours', 'hours': 24}
- args[5]: string - should be the grouping
- args[6]: dictionary - optional conditions
"""
granularity = self.args[0]
name = self.args[1]
accounting = self.args[2]
plot = self.args[3]
period = self.args[4]
grouping = self.args[5]
if period[ 'Format' ] == 'LastHours':
fromT = datetime.utcnow() - timedelta( hours = period[ 'hours' ] )
toT = datetime.utcnow()
elif period[ 'Format' ] == 'Periods':
#TODO
pass
if self.args[6] is not None:
conditions = self.args[6]
else:
conditions = {}
if accounting == 'Job' or accounting == 'Pilot':
if granularity == 'Resource':
conditions[ 'GridCE' ] = [ name ]
elif granularity == 'Service':
conditions[ 'Site' ] = [ name.split('@').pop() ]
elif granularity == 'Site':
conditions[ 'Site' ] = [ name ]
else:
return S_ERROR( '%s is not a valid granularity' % granularity )
elif accounting == 'DataOperation':
conditions[ 'Destination' ] = [ name ]
return self.rClient.getReport( accounting, plot, fromT, toT, conditions, grouping )
示例11: DIRACAccounting_Command
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class DIRACAccounting_Command(Command):
def doCommand(self):
"""
Returns jobs accounting info for sites in the last 24h
`args`:
- args[0]: string - should be a ValidRes
- args[1]: string - should be the name of the ValidRes
- args[2]: string - should be 'Job' or 'Pilot' or 'DataOperation'
or 'WMSHistory' (??) or 'SRM' (??)
- args[3]: string - should be the plot to generate (e.g. CPUEfficiency)
- args[4]: dictionary - e.g. {'Format': 'LastHours', 'hours': 24}
- args[5]: string - should be the grouping
- args[6]: dictionary - optional conditions
"""
super(DIRACAccounting_Command, self).doCommand()
if self.RPC is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
self.RPC = RPCClient("Accounting/ReportGenerator", timeout = self.timeout)
if self.client is None:
from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient
self.client = ReportsClient(rpcClient = self.RPC)
granularity = self.args[0]
name = self.args[1]
accounting = self.args[2]
plot = self.args[3]
period = self.args[4]
if period['Format'] == 'LastHours':
fromT = datetime.datetime.utcnow()-datetime.timedelta(hours = period['hours'])
toT = datetime.datetime.utcnow()
elif period['Format'] == 'Periods':
#TODO
pass
grouping = self.args[5]
try:
if self.args[6] is not None:
conditions = self.args[6]
else:
raise Exception
except:
conditions = {}
if accounting == 'Job' or accounting == 'Pilot':
if granularity == 'Resource':
conditions['GridCE'] = [name]
elif granularity == 'Service':
conditions['Site'] = [name.split('@').pop()]
elif granularity == 'Site':
conditions['Site'] = [name]
else:
raise InvalidRes, where(self, self.doCommand)
elif accounting == 'DataOperation':
conditions['Destination'] = [name]
try:
res = self.client.getReport(accounting, plot, fromT, toT, conditions, grouping)
if res['OK']:
return {'Result':res['Value']}
else:
raise RSSException, where(self, self.doCommand) + ' ' + res['Message']
except:
gLogger.exception("Exception when calling ReportsClient for " + granularity + " " + name )
return {'Result':'Unknown'}
doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
示例12: FailedPilotsByCESplittedCommand
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class FailedPilotsByCESplittedCommand(Command):
def __init__(self, args=None, clients=None):
super(FailedPilotsByCESplittedCommand, self).__init__(args, clients)
if 'ReportsClient' in self.apis:
self.rClient = self.apis['ReportsClient']
else:
self.rClient = ReportsClient()
if 'ReportGenerator' in self.apis:
self.rgClient = self.apis['ReportGenerator']
else:
self.rgClient = RPCClient('Accounting/ReportGenerator')
self.rClient.rpcClient = self.rgClient
def doCommand(self):
"""
Returns failed pilots using the DIRAC accounting system for every CE
for the last self.args[0] hours
:params:
:attr:`CEs`: list of CEs (when not given, take every CE)
:returns:
"""
if 'hours' not in self.args:
return S_ERROR('Number of hours not specified')
hours = self.args['hours']
ces = None
if 'ces' in self.args:
ces = self.args['ces']
if ces is None:
# FIXME: pointing to the CSHelper instead
# meta = {'columns':'ResourceName'}
# CEs = self.rsClient.getResource( resourceType = [ 'CE','CREAMCE' ], meta = meta )
# if not CEs['OK']:
# return CEs
# CEs = [ ce[0] for ce in CEs['Value'] ]
ces = CSHelpers.getComputingElements()
if not ces['OK']:
return ces
ces = ces['Value']
if not ces:
return S_ERROR('CEs is empty')
fromD = datetime.utcnow() - timedelta(hours=hours)
toD = datetime.utcnow()
failedPilots = self.rClient.getReport('Pilot', 'NumberOfPilots', fromD, toD,
{'GridStatus': ['Aborted'],
'GridCE': ces
}, 'GridCE')
if not failedPilots['OK']:
return failedPilots
failedPilots = failedPilots['Value']
if 'data' not in failedPilots:
return S_ERROR('Missing data key')
if 'granularity' not in failedPilots:
return S_ERROR('Missing granularity key')
singlePlots = {}
for ce, value in failedPilots['data'].items():
if ce in ces:
plot = {}
plot['data'] = {ce: value}
plot['granularity'] = failedPilots['granularity']
singlePlots[ce] = plot
return S_OK(singlePlots)
示例13: FailedPilotsBySiteSplittedCommand
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class FailedPilotsBySiteSplittedCommand( Command ):
def __init__( self, args = None, clients = None ):
super( FailedPilotsBySiteSplittedCommand, self ).__init__( args, clients )
if 'ReportsClient' in self.apis:
self.rClient = self.apis[ 'ReportsClient' ]
else:
self.rClient = ReportsClient()
if 'ReportGenerator' in self.apis:
self.rgClient = self.apis[ 'ReportGenerator' ]
else:
self.rgClient = RPCClient( 'Accounting/ReportGenerator' )
self.rClient.rpcClient = self.rgClient
def doCommand( self ):
"""
Returns failed jobs using the DIRAC accounting system for every site
for the last self.args[0] hours
:params:
:attr:`sites`: list of sites (when not given, take every site)
:returns:
"""
if 'hours' not in self.args:
return S_ERROR( 'Number of hours not specified' )
hours = self.args[ 'hours' ]
sites = None
if 'sites' in self.args:
sites = self.args[ 'sites' ]
if sites is None:
#FIXME: pointing to the CSHelper instead
# sources = self.rsClient.getSite( meta = {'columns': 'SiteName'} )
# if not sources[ 'OK' ]:
# return sources
# sources = [ si[0] for si in sources[ 'Value' ] ]
sites = CSHelpers.getSites()
if not sites[ 'OK' ]:
return sites
sites = sites[ 'Value' ]
if not sites:
return S_ERROR( 'Sites is empty' )
fromD = datetime.utcnow() - timedelta( hours = hours )
toD = datetime.utcnow()
failedPilots = self.rClient.getReport( 'Pilot', 'NumberOfPilots', fromD, toD,
{ 'GridStatus' : [ 'Aborted' ],
'Site' : sites
}, 'Site' )
if not failedPilots[ 'OK' ]:
return failedPilots
failedPilots = failedPilots[ 'Value' ]
if not 'data' in failedPilots:
return S_ERROR( 'Missing data key' )
if not 'granularity' in failedPilots:
return S_ERROR( 'Missing granularity key' )
singlePlots = {}
for site, value in failedPilots[ 'data' ].items():
if site in sites:
plot = {}
plot[ 'data' ] = { site: value }
plot[ 'granularity' ] = failedPilots[ 'granularity' ]
singlePlots[ site ] = plot
return S_OK( singlePlots )
示例14: TransferQualityEverySEs_Command
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class TransferQualityEverySEs_Command( Command ):
def doCommand( self, SEs = None ):
"""
Returns transfer quality using the DIRAC accounting system for every SE
:params:
:attr:`SEs`: list of storage elements (when not given, take every SE)
:returns:
{'SiteName': {TQ : 'Good'|'Fair'|'Poor'|'Idle'|'Bad'} ...}
"""
if SEs is None:
# from DIRAC.Core.DISET.RPCClient import RPCClient
RPC_RSS = RPCClient( "ResourceStatus/ResourceStatus" )
SEs = RPC_RSS.getStorageElementsList()
if not SEs['OK']:
raise RSSException, where( self, self.doCommand ) + " " + SEs['Message']
else:
SEs = SEs['Value']
if self.RPC is None:
# from DIRAC.Core.DISET.RPCClient import RPCClient
self.RPC = RPCClient( "Accounting/ReportGenerator", timeout = self.timeout )
if self.client is None:
from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient
self.client = ReportsClient( rpcClient = self.RPC )
fromD = datetime.datetime.utcnow() - datetime.timedelta( hours = 2 )
toD = datetime.datetime.utcnow()
try:
qualityAll = self.client.getReport( 'DataOperation', 'Quality', fromD, toD,
{'OperationType':'putAndRegister',
'Destination':SEs}, 'Channel' )
if not qualityAll['OK']:
raise RSSException, where( self, self.doCommand ) + " " + qualityAll['Message']
else:
qualityAll = qualityAll['Value']['data']
except:
gLogger.exception( "Exception when calling TransferQualityEverySEs_Command" )
return {}
listOfDestSEs = []
for k in qualityAll.keys():
try:
key = k.split( ' -> ' )[1]
if key not in listOfDestSEs:
listOfDestSEs.append( key )
except:
continue
meanQuality = {}
for destSE in listOfDestSEs:
s = 0
n = 0
for k in qualityAll.keys():
try:
if k.split( ' -> ' )[1] == destSE:
n = n + len( qualityAll[k] )
s = s + sum( qualityAll[k].values() )
except:
continue
meanQuality[destSE] = s / n
resToReturn = {}
for se in meanQuality:
resToReturn[se] = {'TQ': meanQuality[se]}
return resToReturn
doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
示例15: TransferQualityCommand
# 需要导入模块: from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient [as 别名]
# 或者: from DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient import getReport [as 别名]
class TransferQualityCommand(Command):
def __init__(self, args=None, clients=None):
super(TransferQualityCommand, self).__init__(args, clients)
if "ReportGenerator" in self.apis:
self.rgClient = self.apis["ReportGenerator"]
else:
self.rgClient = RPCClient("Accounting/ReportGenerator")
if "ReportsClient" in self.apis:
self.rClient = self.apis["ReportsClient"]
else:
self.rClient = ReportsClient()
self.rClient.rpcClient = self.rgClient
def doCommand(self):
"""
Return getQuality from DIRAC's accounting ReportsClient
`args`: a tuple
- args[0]: string: should be a ValidElement
- args[1]: string should be the name of the ValidElement
- args[2]: optional dateTime object: a "from" date
- args[3]: optional dateTime object: a "to" date
:returns:
{'Result': None | a float between 0.0 and 100.0}
"""
if "fromDate" not in self.args:
fromDate = datetime.utcnow() - timedelta(hours=2)
else:
fromDate = self.args["fromDate"]
if "toDate" not in self.args:
toDate = datetime.utcnow()
else:
toDate = self.args["toDate"]
if "name" not in self.args:
return S_ERROR("name not specified")
name = self.args["name"]
results = self.rClient.getReport(
"DataOperation",
"Quality",
fromDate,
toDate,
{"OperationType": "putAndRegister", "Destination": [name]},
"Channel",
)
if not results["OK"]:
return results
pr_q_d = results["Value"]["data"]
# FIXME: WHAT the hell is this doing ?
values = []
if len(pr_q_d) == 1:
for k in pr_q_d.keys():
for n in pr_q_d[k].values():
values.append(n)
res = sum(values) / len(values)
else:
for n in pr_q_d["Total"].values():
values.append(n)
res = sum(values) / len(values)
return S_OK(res)