当前位置: 首页>>代码示例>>Python>>正文


Python ResourceStatusClient.deleteStatusElement方法代码示例

本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient.deleteStatusElement方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceStatusClient.deleteStatusElement方法的具体用法?Python ResourceStatusClient.deleteStatusElement怎么用?Python ResourceStatusClient.deleteStatusElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient的用法示例。


在下文中一共展示了ResourceStatusClient.deleteStatusElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SummarizeLogsAgent

# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import deleteStatusElement [as 别名]
class SummarizeLogsAgent( AgentModule ):
  """ SummarizeLogsAgent as extension of AgentModule.
  
  """

  def __init__( self, *args, **kwargs ):
    """ Constructor.
    
    """

    AgentModule.__init__( self, *args, **kwargs )
    
    self.rsClient = None


  def initialize( self ):
    """ Standard initialize.
    
    :return: S_OK
    
    """

    self.rsClient = ResourceStatusClient()
    return S_OK()


  def execute( self ):
    """ execute ( main method )
    
    The execute method runs over the three families of tables ( Site, Resource and
    Node ) performing identical operations. First, selects all logs for a given
    family ( and keeps track of which one is the last row ID ). It summarizes the
    logs and finally, deletes the logs from the database.
    
    :return: S_OK
    
    """

    # loop over the tables
    for element in ( 'Site', 'Resource', 'Node' ):

      self.log.info( 'Summarizing %s' % element )

      # get all logs to be summarized
      selectLogElements = self._summarizeLogs( element )
      if not selectLogElements[ 'OK' ]:
        self.log.error( selectLogElements[ 'Message' ] )
        continue
      
      lastID, logElements = selectLogElements[ 'Value' ]
      
      # logElements is a dictionary of key-value pairs as follows:
      # ( name, statusType ) : list( logs )
      for key, logs in logElements.iteritems():

        sumResult = self._registerLogs( element, key, logs )
        if not sumResult[ 'OK' ]:
          self.log.error( sumResult[ 'Message' ] )
          continue

      if lastID is not None:
        self.log.info( 'Deleting %sLog till ID %s' % ( element, lastID ) )
        deleteResult = self.rsClient.deleteStatusElement( element, 'Log', 
                                                        meta = { 'older' : ( 'ID', lastID ) } )
        if not deleteResult[ 'OK' ]:
          self.log.error( deleteResult[ 'Message' ] )
          continue

    return S_OK()


  #.............................................................................


  def _summarizeLogs( self, element ):
    """ given an element, selects all logs in table <element>Log.
    
    :Parameters:
      **element** - `string`
        name of the table family ( either Site, Resource and Node )
    
    :return: S_OK( lastID, listOfLogs ) / S_ERROR
    
    """
    
    selectResults = self.rsClient.selectStatusElement( element, 'Log' )
    
    if not selectResults[ 'OK' ]:
      return selectResults
  
    selectedItems = {}
    selectColumns = selectResults[ 'Columns' ]
    selectResults = selectResults[ 'Value' ]
    
    latestID = None
    if selectResults:
      latestID = dict( zip( selectColumns, selectResults[ -1 ] ) )[ 'ID' ]
    
    for selectResult in selectResults:
      
#.........这里部分代码省略.........
开发者ID:IgorPelevanyuk,项目名称:DIRAC,代码行数:103,代码来源:SummarizeLogsAgent.py

示例2: DatabaseCleanerAgent

# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import deleteStatusElement [as 别名]

#.........这里部分代码省略.........

    AgentModule.__init__( self, *args, **kwargs )

    self.maxCacheLifetime = self.__maxCacheLifetime
    self.maxHistoryLifetime = self.__maxHistoryLifetime
    self.maxLogLifetime = self.__maxLogLifetime

    self.rsClient = None
    self.rmClient = None

  def initialize( self ):
    ''' Standard initialize.
        Uses the ProductionManager shifterProxy to modify the ResourceStatus DB
    '''

    self.am_setOption( 'shifterProxy', 'ProductionManager' )

    self.maxCacheLifetime = self.am_getOption( 'maxCacheLifetime', self.maxCacheLifetime )
    self.maxHistoryLifetime = self.am_getOption( 'maxHistoryLifetime', self.maxHistoryLifetime )
    self.maxLogLifetime = self.am_getOption( 'maxLogLifetime', self.maxLogLifetime )

    self.rsClient = ResourceStatusClient()
    self.rmClient = ResourceManagementClient()

    return S_OK()

  def execute( self ):

#    TODO: uncomment when ResourceMonitoring is ready
#    self._cleanCaches()
    self._cleanStatusTable( 'History', self.maxHistoryLifetime )
    self._cleanStatusTable( 'Log', self.maxLogLifetime )

    return S_OK()

  ## Protected methods #########################################################

  def _cleanCaches( self ):
    '''
      Method that iterates over all the caches in ResourceManagemetnDB deleting
      entries with a LastCheckTime parameter older than now - X( hours ). On theory,
      there should not be any parameter to be deleted. If there are, it means that
      by some reason that entry has not been updated.
    '''

    self.log.info( 'Cleaning cache entries older than %s minutes' % self.maxCacheLifetime )

    lastValidRecord = datetime.utcnow() - timedelta( minutes = self.maxCacheLifetime )

    for cache in self.__cacheNames:

      self.log.info( 'Inspecting %s' % cache )

      deleteCache = 'delete%s' % cache
      if not hasattr( self.rmClient, deleteCache ):
        self.log.warn( '%s not found' % deleteCache )
        continue

      deleteMethod = getattr( self.rmClient, deleteCache )
      deleteResults = deleteMethod( meta = { 'older' : ( 'LastCheckTime', lastValidRecord ) } )
      if not deleteResults[ 'OK' ]:
        self.log.error( deleteResults[ 'Message' ] )
        continue
      if deleteResults[ 'Value' ]:
        self.log.info( 'Deleted %s entries' % deleteResults[ 'Value' ] )
      else:
        self.log.info( '... nothing to delete' )

    return S_OK()

  def _cleanStatusTable( self, tableType, lifeTime ):
    '''
      Method that deletes all entries older than now - lifeTime ( days ) for all
      the elementType tables for a given tableType ( History / Log )
    '''

    self.log.info( 'Cleaning %s entries older than %s days' % ( tableType, lifeTime ) )

    # It is hard-coded, mainly because there are no more tables going to be added
    # to the schema for a long time.
    elements = ( 'Site', 'Resource', 'Node' )

    lastValidRecord = datetime.utcnow() - timedelta( days = lifeTime )
    meta = { 'older' : ( 'LastCheckTime', lastValidRecord ) }

    for element in elements:

      self.log.info( 'Inspecting %s%s' % ( element, tableType ) )

      deleteResults = self.rsClient.deleteStatusElement( element, tableType,
                                                         meta = meta )
      if not deleteResults[ 'OK' ]:
        self.log.error( deleteResults[ 'Message' ] )
        continue
      if deleteResults[ 'Value' ]:
        self.log.info( 'Deleted %s entries' % deleteResults[ 'Value' ] )
      else:
        self.log.info( '... nothing to delete' )

    return S_OK()
开发者ID:cgrefe,项目名称:DIRAC,代码行数:104,代码来源:DatabaseCleanerAgent.py

示例3: SummarizeLogsAgent

# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import deleteStatusElement [as 别名]
class SummarizeLogsAgent(AgentModule):
  """ SummarizeLogsAgent as extension of AgentModule.
  """

  def __init__(self, *args, **kwargs):
    """ Constructor.

    """

    AgentModule.__init__(self, *args, **kwargs)

    self.rsClient = None

  def initialize(self):
    """ Standard initialize.

    :return: S_OK

    """

    self.rsClient = ResourceStatusClient()
    return S_OK()

  def execute(self):
    """ execute ( main method )

    The execute method runs over the three families of tables ( Site, Resource and
    Node ) performing identical operations. First, selects all logs for a given
    family ( and keeps track of which one is the last row ID ). It summarizes the
    logs and finally, deletes the logs from the database.

    :return: S_OK

    """

    # loop over the tables
    for element in ('Site', 'Resource', 'Node'):

      self.log.info('Summarizing %s' % element)

      # get all logs to be summarized
      selectLogElements = self._summarizeLogs(element)
      if not selectLogElements['OK']:
        self.log.error(selectLogElements['Message'])
        continue

      lastID, logElements = selectLogElements['Value']

      # logElements is a dictionary of key-value pairs as follows:
      # ( name, statusType ) : list( logs )
      for key, logs in logElements.iteritems():

        sumResult = self._registerLogs(element, key, logs)
        if not sumResult['OK']:
          self.log.error(sumResult['Message'])
          continue

      if lastID is not None:
        self.log.info('Deleting %sLog till ID %s' % (element, lastID))
        deleteResult = self.rsClient.deleteStatusElement(element, 'Log',
                                                         meta={'older': ('ID', lastID)})
        if not deleteResult['OK']:
          self.log.error(deleteResult['Message'])
          continue

    return S_OK()

  def _summarizeLogs(self, element):
    """ given an element, selects all logs in table <element>Log.

    :Parameters:
      **element** - `string`
        name of the table family ( either Site, Resource or Node )

    :return: S_OK( lastID, listOfLogs ) / S_ERROR

    """

    selectResults = self.rsClient.selectStatusElement(element, 'Log')

    if not selectResults['OK']:
      return selectResults

    selectedItems = {}
    latestID = None

    if not selectResults['Value']:
      return S_OK((latestID, selectedItems))

    selectColumns = selectResults['Columns']
    selectResults = selectResults['Value']

    if selectResults:
      latestID = dict(zip(selectColumns, selectResults[-1]))['ID']

    for selectResult in selectResults:

      elementDict = dict(zip(selectColumns, selectResult))

      key = (elementDict['Name'], elementDict['StatusType'])
#.........这里部分代码省略.........
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:103,代码来源:SummarizeLogsAgent.py


注:本文中的DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient.deleteStatusElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。