예제 #1
0
class PilotsEffSimple_Command(Command):
    def doCommand(self, RSClientIn=None):
        """
    Returns simple pilots efficiency

    :attr:`args`:
        - args[0]: string - should be a ValidRes

        - args[1]: string - should be the name of the ValidRes

    returns:
      {
        'Result': 'Good'|'Fair'|'Poor'|'Idle'|'Bad'
      }
    """
        super(PilotsEffSimple_Command, self).doCommand()

        if self.args[0] in ('Service', 'Services'):
            if RSClientIn is not None:
                rsc = RSClientIn
            else:
                from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient
                rsc = ResourceStatusClient()

            try:
                name = rsc.getGeneralName(self.args[0], self.args[1],
                                          'Site')['Value'][0]
            except:
                gLogger.error(
                    "PilotsEffSimple_Command: can't get a general name for %s %s"
                    % (self.args[0], self.args[1]))
                return {'Result': 'Unknown'}
            granularity = 'Site'

        elif self.args[0] in ('Site', 'Sites', 'Resource', 'Resources'):
            name = self.args[1]
            granularity = self.args[0]
        else:
            raise InvalidRes, where(self, self.doCommand)

        if self.client is None:
            from DIRAC.ResourceStatusSystem.Client.PilotsClient import PilotsClient
            self.client = PilotsClient()

        try:
            res = self.client.getPilotsSimpleEff(granularity,
                                                 name,
                                                 timeout=self.timeout)
            if res is None:
                return {'Result': 'Idle'}
            if res[name] is None:
                return {'Result': 'Idle'}
        except:
            gLogger.exception("Exception when calling PilotsClient for %s %s" %
                              (granularity, name))
            return {'Result': 'Unknown'}

        return {'Result': res[name]}

    doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
예제 #2
0
class PilotsEffSimple_Command(Command):
  
  def doCommand(self, RSClientIn = None):
    """ 
    Returns simple pilots efficiency
    
    :attr:`args`:
        - args[0]: string - should be a ValidRes
        
        - args[1]: string - should be the name of the ValidRes

    returns:
      {
        'Result': 'Good'|'Fair'|'Poor'|'Idle'|'Bad'
      }
    """
    super(PilotsEffSimple_Command, self).doCommand()

    if self.args[0] in ('Service', 'Services'):
      if RSClientIn is not None:
        rsc = RSClientIn
      else:
        from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient   
        rsc = ResourceStatusClient()

      try:
        name = rsc.getGeneralName(self.args[0], self.args[1], 'Site')[0]
      except:
        gLogger.error("PilotsEffSimple_Command: can't get a general name for %s %s" %(self.args[0], self.args[1]))
        return {'Result':'Unknown'}      
      granularity = 'Site'
    
    elif self.args[0] in ('Site', 'Sites', 'Resource', 'Resources'):
      name = self.args[1]
      granularity = self.args[0]
    else:
      raise InvalidRes, where(self, self.doCommand)
    
    if self.client is None:
      from DIRAC.ResourceStatusSystem.Client.PilotsClient import PilotsClient   
      self.client = PilotsClient()
      
    try:
      res = self.client.getPilotsSimpleEff(granularity, name, timeout = self.timeout)
      if res is None:
        return {'Result':'Idle'}
      if res[name] is None:
        return {'Result':'Idle'}
    except:
      gLogger.exception("Exception when calling PilotsClient for %s %s" %(granularity, name))
      return {'Result':'Unknown'}
    
    return {'Result':res[name]} 

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
예제 #3
0
class PilotsEffSimpleEverySites_Command( Command ):

  def doCommand( self, sites = None ):
    """ 
    Returns simple pilots efficiency for all the sites and resources in input.
        
    :params:
      :attr:`sites`: list of site names (when not given, take every site)
    
    :returns:
      {'SiteName':  {'PE_S': 'Good'|'Fair'|'Poor'|'Idle'|'Bad'} ...}
    """

    if self.client is None:
      from DIRAC.ResourceStatusSystem.Client.PilotsClient import PilotsClient
      self.client = PilotsClient()

    if sites is None:
#      from DIRAC.Core.DISET.RPCClient import RPCClient
      RPC = RPCClient( "ResourceStatus/ResourceStatus" )
      sites = RPC.getSitesList()
      if not sites['OK']:
        raise RSSException, where( self, self.doCommand ) + " " + sites['Message']
      else:
        sites = sites['Value']

    if self.RPC is None:
#      from DIRAC.Core.DISET.RPCClient import RPCClient
      self.RPC = RPCClient( "WorkloadManagement/WMSAdministrator" )

    try:
      res = self.client.getPilotsSimpleEff( 'Site', sites, None, self.RPC )
      if res is None:
        res = []
    except:
      gLogger.exception( "Exception when calling PilotsClient." )
      return {}

    resToReturn = {}

    for site in res:
      resToReturn[site] = {'PE_S': res[site]}

    return resToReturn


  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
예제 #4
0
class PilotsEffSimpleEverySites_Command(Command):
    def doCommand(self, sites=None):
        """ 
    Returns simple pilots efficiency for all the sites and resources in input.
        
    :params:
      :attr:`sites`: list of site names (when not given, take every site)
    
    :returns:
      {'SiteName':  {'PE_S': 'Good'|'Fair'|'Poor'|'Idle'|'Bad'} ...}
    """

        if self.client is None:
            from DIRAC.ResourceStatusSystem.Client.PilotsClient import PilotsClient
            self.client = PilotsClient()

        if sites is None:
            #      from DIRAC.Core.DISET.RPCClient import RPCClient
            RPC = RPCClient("ResourceStatus/ResourceStatus")
            sites = RPC.getSitesList()
            if not sites['OK']:
                raise RSSException, where(
                    self, self.doCommand) + " " + sites['Message']
            else:
                sites = sites['Value']

        if self.RPC is None:
            #      from DIRAC.Core.DISET.RPCClient import RPCClient
            self.RPC = RPCClient("WorkloadManagement/WMSAdministrator")

        try:
            res = self.client.getPilotsSimpleEff('Site', sites, None, self.RPC)
            if res is None:
                res = []
        except:
            gLogger.exception("Exception when calling PilotsClient.")
            return {}

        resToReturn = {}

        for site in res:
            resToReturn[site] = {'PE_S': res[site]}

        return resToReturn

    doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__