本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient.insertStatusElement方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceStatusClient.insertStatusElement方法的具体用法?Python ResourceStatusClient.insertStatusElement怎么用?Python ResourceStatusClient.insertStatusElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient
的用法示例。
在下文中一共展示了ResourceStatusClient.insertStatusElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SummarizeLogsAgent
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import insertStatusElement [as 别名]
#.........这里部分代码省略.........
# If there are no changes on the Status or the TokenOwner with respect
# the previous one, discards the log.
if lastStatus != elementDict['Status'] or lastToken != elementDict['TokenOwner']:
selectedItems[key].append(elementDict)
return S_OK((latestID, selectedItems))
def _registerLogs(self, element, key, logs):
""" Given an element, a key - which is a tuple ( <name>, <statusType> )
and a list of dictionaries, this method inserts them on the <element>History
table. Before inserting them, checks whether the first one is or is not on
the <element>History table. If it is, it is not inserted.
:Parameters:
**element** - `string`
name of the table family ( either Site, Resource and Node )
**key** - `tuple`
tuple with the name of the element and the statusType
**logs** - `list`
list of dictionaries containing the logs
:return: S_OK / S_ERROR
"""
if not logs:
return S_OK()
# Undo key
name, statusType = key
selectedRes = self.rsClient.selectStatusElement(element, 'History', name,
statusType,
meta={'columns': ['Status', 'TokenOwner'],
'limit': 1,
'order': ('DateEffective', 'desc')})
if not selectedRes['OK']:
return selectedRes
selectedRes = selectedRes['Value']
if not selectedRes:
return S_OK()
# We want from the <element>History table the last Status, and TokenOwner
lastStatus, lastToken = None, None
if selectedRes:
try:
lastStatus = selectedRes[0][0]
lastToken = selectedRes[0][1]
except IndexError:
pass
# If the first of the selected items has a different status than the latest
# on the history, we keep it, otherwise we remove it.
if logs[0]['Status'] == lastStatus and logs[0]['TokenOwner'] == lastToken:
logs.pop(0)
if logs:
self.log.info('%s ( %s ):' % (name, statusType))
self.log.debug(logs)
for selectedItemDict in logs:
res = self.__logToHistoryTable(element, selectedItemDict)
if not res['OK']:
return res
return S_OK()
def __logToHistoryTable(self, element, elementDict):
""" Given an element and a dictionary with all the arguments, this method
inserts a new entry on the <element>History table
:Parameters:
**element** - `string`
name of the table family ( either Site, Resource and Node )
**elementDict** - `dict`
dictionary returned from the DB to be inserted on the History table
:return: S_OK / S_ERROR
"""
name = elementDict.get('Name')
statusType = elementDict.get('StatusType')
status = elementDict.get('Status')
elementType = elementDict.get('ElementType')
reason = elementDict.get('Reason')
dateEffective = elementDict.get('DateEffective')
lastCheckTime = elementDict.get('LastCheckTime')
tokenOwner = elementDict.get('TokenOwner')
tokenExpiration = elementDict.get('TokenExpiration')
self.log.info(' %s %s %s %s' % (status, dateEffective, tokenOwner, reason))
return self.rsClient.insertStatusElement(element, 'History', name, statusType,
status, elementType, reason,
dateEffective, lastCheckTime,
tokenOwner, tokenExpiration)