Пример #1
0
class StorageElementsStats_Command( Command ):
  """
  The StorageElementsStats_Command class is a command class to know about
  present storageElementss stats
  """

  def doCommand( self ):
    """
    Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getStorageElementsStats`

    :params:
      :attr:`args`: a tuple
        - `args[0]` should be in ['Site', 'Resource']

        - `args[1]` should be the name of the Site or Resource

    :returns:

    """
    super( StorageElementsStats_Command, self ).doCommand()

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

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

    try:
      resR = self.client.getStorageElementsStats( granularity, name, 'Read' )['Value']
      resW = self.client.getStorageElementsStats( granularity, name, 'Write' )['Value']
    except:
      gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( granularity, name ) )
      return {'Result':'Unknown'}

    res = {}
    for key in ValidStatus:
      res[ key ] = resR[ key ] + resW[ key ]

    return {'Result':res}

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
Пример #2
0
class StorageElementsStats_Command(Command):
    """
  The StorageElementsStats_Command class is a command class to know about
  present storageElementss stats
  """

    def doCommand(self):
        """
    Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getStorageElementsStats`

    :params:
      :attr:`args`: a tuple
        - `args[0]` should be in ['Site', 'Resource']

        - `args[1]` should be the name of the Site or Resource

    :returns:

    """
        super(StorageElementsStats_Command, self).doCommand()

        if self.args[0] in ("Service", "Services"):
            granularity = "Site"
            name = self.args[1].split("@")[1]
        elif self.args[0] in ("Site", "Sites", "Resource", "Resources"):
            granularity = self.args[0]
            name = self.args[1]
        else:
            raise InvalidRes, where(self, self.doCommand)

        if self.client is None:
            from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient

            self.client = ResourceStatusClient(timeout=self.timeout)

        try:
            res = self.client.getStorageElementsStats(granularity, name)
        except:
            gLogger.exception("Exception when calling ResourceStatusClient for %s %s" % (granularity, name))
            return {"Result": "Unknown"}

        return {"Result": res}

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