本文整理匯總了Python中DIRAC.Core.LCG.GOCDBClient.GOCDBClient.getHostnameDowntime方法的典型用法代碼示例。如果您正苦於以下問題:Python GOCDBClient.getHostnameDowntime方法的具體用法?Python GOCDBClient.getHostnameDowntime怎麽用?Python GOCDBClient.getHostnameDowntime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DIRAC.Core.LCG.GOCDBClient.GOCDBClient
的用法示例。
在下文中一共展示了GOCDBClient.getHostnameDowntime方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: GOCDBSyncCommand
# 需要導入模塊: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 別名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getHostnameDowntime [as 別名]
class GOCDBSyncCommand(Command):
def __init__(self, args=None, clients=None):
super(GOCDBSyncCommand, self).__init__(args, clients)
if 'GOCDBClient' in self.apis:
self.gClient = self.apis['GOCDBClient']
else:
self.gClient = GOCDBClient()
if 'ResourceManagementClient' in self.apis:
self.rmClient = self.apis['ResourceManagementClient']
else:
self.rmClient = ResourceManagementClient()
self.seenHostnames = set()
def doNew(self, masterParams=None):
"""
Gets the downtime IDs and dates of a given hostname from the local database and compares the results
with the remote database of GOCDB. If the downtime dates have been changed it updates the local database.
:param: `masterParams` - string
:return: S_OK / S_ERROR
"""
if masterParams:
hostname = masterParams
else:
return S_ERROR(errno.EINVAL, 'masterParams is not provided')
result = self.rmClient.selectDowntimeCache(name=hostname)
if not result['OK']:
return result
for downtimes in result['Value']:
localDBdict = {'DowntimeID': downtimes[3],
'FORMATED_START_DATE': downtimes[6].strftime('%Y-%m-%d %H:%M'),
'FORMATED_END_DATE': downtimes[7].strftime('%Y-%m-%d %H:%M')}
response = self.gClient.getHostnameDowntime(hostname, ongoing=True)
if not response['OK']:
return response
doc = minidom.parseString(response['Value'])
downtimeElements = doc.getElementsByTagName("DOWNTIME")
for dtElement in downtimeElements:
GOCDBdict = _parseSingleElement(dtElement, ['PRIMARY_KEY', 'ENDPOINT',
'FORMATED_START_DATE', 'FORMATED_END_DATE'])
localDowntimeID = localDBdict['DowntimeID']
GOCDBDowntimeID = GOCDBdict['PRIMARY_KEY'] + ' ' + GOCDBdict['ENDPOINT']
if localDowntimeID == GOCDBDowntimeID:
if localDBdict['FORMATED_START_DATE'] != GOCDBdict['FORMATED_START_DATE']:
result = self.rmClient.addOrModifyDowntimeCache(downtimeID=localDBdict['DowntimeID'],
startDate=GOCDBdict['FORMATED_START_DATE'])
gLogger.verbose("The start date of %s has been changed!" % downtimes[3])
if not result['OK']:
return result
if localDBdict['FORMATED_END_DATE'] != GOCDBdict['FORMATED_END_DATE']:
result = self.rmClient.addOrModifyDowntimeCache(downtimeID=localDBdict['DowntimeID'],
endDate=GOCDBdict['FORMATED_END_DATE'])
gLogger.verbose("The end date of %s has been changed!" % downtimes[3])
if not result['OK']:
return result
return S_OK()
def doCache(self):
return S_OK()
def doMaster(self):
"""
This method calls the doNew method for each hostname that exists
in the DowntimeCache table of the local database.
:return: S_OK / S_ERROR
"""
# Query DB for all downtimes
result = self.rmClient.selectDowntimeCache()
if not result['OK']:
return result
for data in result['Value']:
# If already processed don't do it again
if data[0] in self.seenHostnames:
continue
# data[0] contains the hostname
#.........這裏部分代碼省略.........