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


Python ResourceStatusClient.addOrModifyStatusElement方法代码示例

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


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

示例1: LogStatusAction

# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import addOrModifyStatusElement [as 别名]
class LogStatusAction(BaseAction):
  '''
    Action that registers on the database a new entry on the <element>Status table.
    It adds or modifies if the record exists on the table.
  '''

  def __init__(self, name, decisionParams, enforcementResult, singlePolicyResults,
               clients=None):

    super(LogStatusAction, self).__init__(name, decisionParams, enforcementResult,
                                          singlePolicyResults, clients)

    if clients is not None and 'ResourceStatusClient' in clients:
      self.rsClient = clients['ResourceStatusClient']
    else:
      self.rsClient = ResourceStatusClient()

  def run(self):
    '''
      Checks it has the parameters it needs and tries to addOrModify in the
      database.
    '''
    # Minor security checks

    element = self.decisionParams['element']
    if element is None:
      return S_ERROR('element should not be None')

    name = self.decisionParams['name']
    if name is None:
      return S_ERROR('name should not be None')

    statusType = self.decisionParams['statusType']
    if statusType is None:
      return S_ERROR('statusType should not be None')

    status = self.enforcementResult['Status']
    if status is None:
      return S_ERROR('status should not be None')

    elementType = self.decisionParams['elementType']
    if elementType is None:
      return S_ERROR('elementType should not be None')

    reason = self.enforcementResult['Reason']
    if reason is None:
      return S_ERROR('reason should not be None')

    # Truncate reason to fit in database column
    reason = (reason[:508] + '..') if len(reason) > 508 else reason

    resLogUpdate = self.rsClient.addOrModifyStatusElement(element, 'Status',
                                                          name=name, statusType=statusType,
                                                          status=status, elementType=elementType,
                                                          reason=reason
                                                          )

    return resLogUpdate
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:60,代码来源:LogStatusAction.py

示例2: TokenAgent

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

#.........这里部分代码省略.........
    for tokenElement in tokenElements:

      tokenElement = dict( zip( tokenColumns, tokenElement ) )

      if tokenElement[ 'TokenOwner' ] != self.__rssToken:
        interestingTokens.append( tokenElement )

    return S_OK( interestingTokens )

  def _processTokens( self, element, tokenElements ):
    '''
      Given an element and a list of interesting token elements, updates the
      database if the token is expired, logs a message and adds
    '''

    never = datetime.max

    for tokenElement in tokenElements:

      try:
        name = tokenElement[ 'Name' ]
        statusType = tokenElement[ 'StatusType' ]
        status = tokenElement[ 'Status' ]
        tokenOwner = tokenElement[ 'TokenOwner' ]
        tokenExpiration = tokenElement[ 'TokenExpiration' ]
      except KeyError as e:
        return S_ERROR( e )

      # If token has already expired
      if tokenExpiration < datetime.utcnow():
        _msg = '%s with statusType "%s" and owner %s EXPIRED'
        self.log.info( _msg % ( name, statusType, tokenOwner ) )

        result = self.rsClient.addOrModifyStatusElement( element, 'Status', name = name,
                                                         statusType = statusType,
                                                         tokenOwner = self.__rssToken,
                                                         tokenExpiration = never )
        if not result[ 'OK' ]:
          return result

      else:
        _msg = '%s with statusType "%s" and owner %s -> %s'
        self.log.info( _msg % ( name, statusType, tokenOwner, tokenExpiration ) )

      if tokenOwner not in self.tokenDict:
        self.tokenDict[ tokenOwner ] = []

      self.tokenDict[ tokenOwner ].append( [ tokenOwner, element, name, statusType, status, tokenExpiration ] )

    return S_OK()

  def _notifyOfTokens( self ):
    '''
      Splits interesing tokens between expired and expiring. Also splits them
      among users. It ends sending notifications to the users.
    '''

    now = datetime.utcnow()

    adminExpired = []
    adminExpiring = []

    for tokenOwner, tokenLists in self.tokenDict.items():

      expired = []
      expiring = []
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:70,代码来源:TokenAgent.py

示例3: TokenAgent

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

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

    # Initialized here, as it is needed empty at the beginning of the execution
    self.tokenDict = {}

    # FIXME: probably this can be obtained from RssConfiguration instead
    elements = ( 'Site', 'Resource', 'Node' )

    for element in elements:

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

      interestingTokens = self._getInterestingTokens( element )
      if not interestingTokens[ 'OK' ]:
        self.log.error( interestingTokens[ 'Message' ] )
        continue
      interestingTokens = interestingTokens[ 'Value' ]

      processTokens = self._processTokens( element, interestingTokens )
      if not processTokens[ 'OK' ]:
        self.log.error( processTokens[ 'Message' ] )
        continue

    notificationResult = self._notifyOfTokens()
    if not notificationResult[ 'OK' ]:
      self.log.error( notificationResult[ 'Message' ] )

    return S_OK()

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

  def _getInterestingTokens( self, element ):
    '''
      Given an element, picks all the entries with TokenExpiration < now + X<hours>
      If the TokenOwner is not the rssToken ( rs_svc ), it is selected.
    '''

    tokenExpLimit = datetime.utcnow() + timedelta( hours = self.notifyHours )

    tokenElements = self.rsClient.selectStatusElement( element, 'Status',
                                                       meta = { 'older' : ( 'TokenExpiration', tokenExpLimit ) } )

    if not tokenElements[ 'OK' ]:
      return tokenElements

    tokenColumns = tokenElements[ 'Columns' ]
    tokenElements = tokenElements[ 'Value' ]

    interestingTokens = []

    for tokenElement in tokenElements:

      tokenElement = dict( zip( tokenColumns, tokenElement ) )

      if tokenElement[ 'TokenOwner' ] != self.__rssToken:
        interestingTokens.append( tokenElement )

    return S_OK( interestingTokens )

  def _processTokens( self, element, tokenElements ):
    '''
      Given an element and a list of interesting token elements, updates the
      database if the token is expired, logs a message and adds
    '''

    never = datetime.max

    for tokenElement in tokenElements:

      try:
        name = tokenElement[ 'Name' ]
        statusType = tokenElement[ 'StatusType' ]
        status = tokenElement[ 'Status' ]
        tokenOwner = tokenElement[ 'TokenOwner' ]
        tokenExpiration = tokenElement[ 'TokenExpiration' ]
      except KeyError, e:
        return S_ERROR( e )

      # If token has already expired
      if tokenExpiration < datetime.utcnow():
        _msg = '%s with statusType "%s" and owner %s EXPIRED'
        self.log.info( _msg % ( name, statusType, tokenOwner ) )

        result = self.rsClient.addOrModifyStatusElement( element, 'Status', name = name,
                                                         statusType = statusType,
                                                         tokenOwner = self.__rssToken,
                                                         tokenExpiration = never )
        if not result[ 'OK' ]:
          return result

      else:
        _msg = '%s with statusType "%s" and owner %s -> %s'
        self.log.info( _msg % ( name, statusType, tokenOwner, tokenExpiration ) )

      if not tokenOwner in self.tokenDict:
        self.tokenDict[ tokenOwner ] = []

      self.tokenDict[ tokenOwner ].append( [ tokenOwner, element, name, statusType, status, tokenExpiration ] )

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

示例4: ResourceStatus

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

#.........这里部分代码省略.........
    if not isinstance(elementName, list):
      elementName = [elementName]

    if not isinstance(statusType, list):
      statusType = [statusType]

    result = {}
    for element in elementName:

      for sType in statusType:
        # Look in standard location, 'Active' by default
        res = gConfig.getValue("%s/%s/%s" % (cs_path, element, sType), 'Active')
        result.setdefault(element, {})[sType] = res

    if result:
      return S_OK(result)

    if default is not None:
      defList = [[el, statusType, default] for el in elementName]
      return S_OK(getDictFromList(defList))

    _msg = "Element '%s', with statusType '%s' is unknown for CS."
    return S_ERROR(DErrno.ERESUNK, _msg % (elementName, statusType))

  def __setRSSElementStatus(self, elementName, elementType, statusType, status, reason, tokenOwner):
    """
    Sets on the RSS the Elements status
    """

    expiration = datetime.utcnow() + timedelta(days=1)

    self.rssCache.acquireLock()
    try:
      res = self.rssClient.addOrModifyStatusElement('Resource', 'Status', name=elementName,
                                                    elementType=elementType, status=status,
                                                    statusType=statusType, reason=reason,
                                                    tokenOwner=tokenOwner, tokenExpiration=expiration)

      if res['OK']:
        self.rssCache.refreshCache()

      if not res['OK']:
        _msg = 'Error updating Element (%s,%s,%s)' % (elementName, statusType, status)
        gLogger.warn('RSS: %s' % _msg)

      return res

    finally:
      # Release lock, no matter what.
      self.rssCache.releaseLock()

  def __setCSElementStatus(self, elementName, elementType, statusType, status):
    """
    Sets on the CS the Elements status
    """

    # DIRAC doesn't store the status of ComputingElements nor FTS in the CS, so here we can just do nothing
    if elementType in ('ComputingElement', 'FTS'):
      return S_OK()

    # If we are here it is because elementType is either 'StorageElement' or 'Catalog'
    statuses = self.rssConfig.getConfigStatusType(elementType)
    if statusType not in statuses:
      gLogger.error("%s is not a valid statusType" % statusType)
      return S_ERROR("%s is not a valid statusType: %s" % (statusType, statuses))
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:69,代码来源:ResourceStatus.py


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