當前位置: 首頁>>代碼示例>>Python>>正文


Python PilotAgentsDB.getPilotSummaryShort方法代碼示例

本文整理匯總了Python中DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB.getPilotSummaryShort方法的典型用法代碼示例。如果您正苦於以下問題:Python PilotAgentsDB.getPilotSummaryShort方法的具體用法?Python PilotAgentsDB.getPilotSummaryShort怎麽用?Python PilotAgentsDB.getPilotSummaryShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB的用法示例。


在下文中一共展示了PilotAgentsDB.getPilotSummaryShort方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: PilotCommand

# 需要導入模塊: from DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB import PilotAgentsDB [as 別名]
# 或者: from DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB import getPilotSummaryShort [as 別名]
class PilotCommand( Command ):
  """ Pilot 'master' Command.    
  """

  def __init__( self, args = None, clients = None ):
    """ Constructor.
    
    :Parameters:
      **args** - [, `dict` ]
        arguments to be passed to be used in the _prepareCommand method ( name and
        timespan are the expected ones )
      **clients - [, `dict` ]
        clients from where information is fetched. Mainly used to avoid creating
        new connections on agents looping over clients. ResourceManagementClient
        and PilotsDB are most welcome.  
    """
    
    super( PilotCommand, self ).__init__( args, clients )

    if 'PilotsDB' in self.apis:
      self.pilotsDB = self.apis[ 'PilotsDB' ]
    else:
      self.pilotsDB = PilotAgentsDB()

    if 'ResourceManagementClient' in self.apis:
      self.rmClient = self.apis[ 'ResourceManagementClient' ]
    else:
      self.rmClient = ResourceManagementClient()

  def _storeCommand( self, result ):
    """ Stores the results of doNew method on the database.
    
    :Parameters:
      **result** - `list( dict )`
        list of dictionaries to be inserted on the DB. Unfortunately, there is no
        bulk insertion method on the database. The dictionaries are sanitized in
        doNew method so that they match the column names in the database.
      
    :return: S_OK / S_ERROR
    """
    
    for pilotDict in result:
      
      lowerCasePilotDict = {}
      for key, value in pilotDict.iteritems():
        lowerCasePilotDict[ key[0].lower() + key[1:] ] = value
      
      # I do not care about the **magic, it makes it cleaner
      resQuery = self.rmClient.addOrModifyPilotCache( **lowerCasePilotDict )
      if not resQuery[ 'OK' ]:
        return resQuery

    return S_OK()
  
  def _prepareCommand( self ):
    """ Method that parses command arguments to extract the ones needed:
      name : name of the computing element
      timespan ( seconds ) : time window
      
    :return: : S_OK( name, timespan ) / S_ERROR        
    """

    if not 'name' in self.args:
      return S_ERROR( '"name" not found in self.args' )
    name = self.args[ 'name' ]
  
    if not 'timespan' in self.args:
      return S_ERROR( '"timespan" not found in self.args' )
    timespan = self.args[ 'timespan' ]
  
    return S_OK( ( name, timespan ) )
  
  def doNew( self, masterParams = None ):
    """ doNew method. If is master execution, name is declared as '' so that 
    all ce's are asked. Once values are obtained, they are stored on the Database.
    The entries with name Unknown, NotAssigned and Total are skipped.

    :Parameters:
      **masterParams** - [, bool ]
        if True, it queries for all elements in the database for the given timespan
    
    :return: S_OK( list ( dict ) ) / S_ERROR
    """
    
    # Ask for all CEs
    if masterParams is True:
      self.args[ 'name' ] = ''

    params = self._prepareCommand()
    if not params[ 'OK' ]:
      return params
    computingElement, timespan = params[ 'Value' ]
  
    # Calculate time window from timespan and utcnow  
    endTimeWindow   = datetime.utcnow()
    startTimeWindow = endTimeWindow - timedelta( seconds = timespan )
  
    # Get pilots information from DB 
    pilotsRes = self.pilotsDB.getPilotSummaryShort( startTimeWindow, 
                                                    endTimeWindow, 
#.........這裏部分代碼省略.........
開發者ID:graciani,項目名稱:DIRAC,代碼行數:103,代碼來源:PilotCommand.py


注:本文中的DIRAC.WorkloadManagementSystem.DB.PilotAgentsDB.PilotAgentsDB.getPilotSummaryShort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。