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


Python ResourceManagementClient.selectPilotCache方法代码示例

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


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

示例1: PilotCommand

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

#.........这里部分代码省略.........
    return S_OK( ( element, name ) ) 
  
  def doNew( self, masterParams = None ):
  
    if masterParams is not None:
      element, name = masterParams
    else:
      params = self._prepareCommand()
      if not params[ 'OK' ]:
        return params
      element, name = params[ 'Value' ]
    
    wmsDict = {}
      
    if element == 'Site':
      wmsDict = { 'GridSite' : name }
    elif element == 'Resource':
      wmsDict = { 'ExpandSite' : name }
    else:
      # You should never see this error
      return S_ERROR( '"%s" is not  Site nor Resource' % element  )
      
    wmsResults = self.wmsAdmin.getPilotSummaryWeb( wmsDict, [], 0, 0 )

    if not wmsResults[ 'OK' ]:
      return wmsResults
    wmsResults = wmsResults[ 'Value' ]
    
    if not 'ParameterNames' in wmsResults:
      return S_ERROR( 'Wrong result dictionary, missing "ParameterNames"' )
    params = wmsResults[ 'ParameterNames' ]
    
    if not 'Records' in wmsResults:
      return S_ERROR( 'Wrong formed result dictionary, missing "Records"' )
    records = wmsResults[ 'Records' ]
    
    uniformResult = [] 
       
    for record in records:
      
      # This returns a dictionary with the following keys:
      # 'Site', 'CE', 'Submitted', 'Ready', 'Scheduled', 'Waiting', 'Running', 
      # 'Done', 'Aborted', 'Done_Empty', 'Aborted_Hour', 'Total', 'PilotsPerJob', 
      # 'PilotJobEff', 'Status', 'InMask'
      pilotDict = dict( zip( params, record ) )
      
      pilotDict[ 'PilotsPerJob' ] = float( pilotDict[ 'PilotsPerJob' ] )
      pilotDict[ 'PilotJobEff' ]  = float( pilotDict[ 'PilotJobEff' ] )
      
      uniformResult.append( pilotDict )
    
    storeRes = self._storeCommand( uniformResult )
    if not storeRes[ 'OK' ]:
      return storeRes
    
    return S_OK( uniformResult )   

  def doCache( self ):
 
    params = self._prepareCommand()
    if not params[ 'OK' ]:
      return params
    element, name = params[ 'Value' ]   
    
    if element == 'Site':
      # WMS returns Site entries with CE = 'Multiple'
      site, ce = name, 'Multiple'
    elif element == 'Resource':
      site, ce = None, name
    else:  
      # You should never see this error
      return S_ERROR( '"%s" is not  Site nor Resource' % element  )      

    result = self.rmClient.selectPilotCache( site, ce )  
    if result[ 'OK' ]:
      result = S_OK( [ dict( zip( result[ 'Columns' ], res ) ) for res in result[ 'Value' ] ] )
      
    return result    

  def doMaster( self ):
    
    siteNames = CSHelpers.getSites()
    if not siteNames[ 'OK' ]:
      return siteNames
    siteNames = siteNames[ 'Value' ]
    
    ces = CSHelpers.getComputingElements()
    if not ces[ 'OK' ]:
      return ces
    ces = ces[ 'Value' ]
    
    pilotResults = self.doNew( ( 'Site', siteNames ) )
    if not pilotResults[ 'OK' ]:
      self.metrics[ 'failed' ].append( pilotResults[ 'Message' ] )
    
    pilotResults = self.doNew( ( 'Resource', ces ) )
    if not pilotResults[ 'OK' ]:
      self.metrics[ 'failed' ].append( pilotResults[ 'Message' ] )    
        
    return S_OK( self.metrics )    
开发者ID:JanEbbing,项目名称:DIRAC,代码行数:104,代码来源:PilotCommand.py

示例2: PilotCommand

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

#.........这里部分代码省略.........
    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, 
                                                    computingElement )
    if not pilotsRes[ 'OK' ]:
      return pilotsRes
 
    # This list matches the database schema in ResourceManagemntDB. It is used
    # to have a perfect match even it there are no pilots on a particular state
    pilotStatuses = [ 'Scheduled', 'Waiting', 'Submitted', 'Running', 'Done', 'Aborted', 
                      'Cancelled', 'Deleted', 'Failed', 'Held', 'Killed', 'Stalled' ]
 
    uniformResult = [] 
       
    for ceName, pilotDict in pilotsRes[ 'Value' ].items():
      
      if ceName in [ 'Total', 'Unknown', 'NotAssigned' ]:
        continue
      
      uniformPilotDict = dict.fromkeys( pilotStatuses, 0 )
      uniformPilotDict.update( pilotDict )
      uniformPilotDict[ 'Timespan' ] = timespan
      uniformPilotDict[ 'CE' ]       = ceName
            
      uniformResult.append( uniformPilotDict )
    
    # Store results
    storeRes = self._storeCommand( uniformResult )
    if not storeRes[ 'OK' ]:
      return storeRes
    
    return S_OK( uniformResult )   

  def doCache( self ):
    """ doCache gets values from the database instead from the PilotsDB tables.
    If successful, returns a list of dictionaries with the database records. 
     
    :return: S_OK( list( dict ) ) / S_ERROR 
    """
 
    params = self._prepareCommand()
    if not params[ 'OK' ]:
      return params
    computingElement, timespan = params[ 'Value' ]    

    # Make sure the records we obtain are NOT out of date
    lastValidRecord = datetime.utcnow() - timedelta( seconds = timespan )

    result = self.rmClient.selectPilotCache( cE = computingElement, timespan = timespan,
                                             meta = { 'older' : ( 'LastCheckTime', lastValidRecord ) } )  
    if result[ 'OK' ]:
      result = S_OK( [ dict( zip( result[ 'Columns' ], res ) ) for res in result[ 'Value' ] ] )
      
    return result    

  def doMaster( self ):
    """ Master method, asks for all information in the database for the given 
    timespan ( see _prepareCommand ).

    :return: : S_OK( failedMessages )
    """
    
    pilotResults = self.doNew( masterParams = True )
    if not pilotResults[ 'OK' ]:
      self.metrics[ 'failed' ].append( pilotResults[ 'Message' ] )    
        
    return S_OK( self.metrics )    
开发者ID:graciani,项目名称:DIRAC,代码行数:104,代码来源:PilotCommand.py


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