Пример #1
0
class MonitoredStatus_Command(Command):
    """
  The MonitoredStatus_Command class is a command class to know about
  monitored status.
  """

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

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

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

        - `args[2]`: optional string - a ValidRes (get status of THIS ValidRes
          for name in args[1], will call getGeneralName)

    :returns:
      {'MonitoredStatus': 'Active'|'Probing'|'Banned'}
    """
        super(MonitoredStatus_Command, self).doCommand()

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

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

        try:
            if len(self.args) == 3:
                if ValidRes.index(self.args[2]) >= ValidRes.index(self.args[0]):
                    raise InvalidRes, where(self, self.doCommand)
                toBeFound = self.client.getGeneralName(self.args[0], self.args[1], self.args[2])[0]
                statuses = self.client.getMonitoredStatus(self.args[2], toBeFound)
            else:
                toBeFound = self.args[1]
                statuses = self.client.getMonitoredStatus(self.args[0], toBeFound)

            if not statuses:
                gLogger.warn("No status found for %s" % toBeFound)
                return {"Result": "Unknown"}

        except:
            gLogger.exception("Exception when calling ResourceStatusClient for %s %s" % (self.args[0], self.args[1]))
            return {"Result": "Unknown"}

        if len(statuses) == 1:
            res = statuses[0]
        else:
            i = 0
            for status in statuses:
                ind = ValidStatus.index(status)
                if ind > i:
                    i = ind
            res = ValidStatus[i]

        return {"Result": res}

    doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
Пример #2
0
class MonitoredStatusCommand( Command ):
  """
  The MonitoredStatus_Command class is a command class to know about
  monitored status.
  """

  def __init__( self, args = None, clients = None ):
    
    super( MonitoredStatusCommand, self ).__init__( args, clients )
    
    if 'ResourceStatusClient' in self.apis:
      self.rsClient = self.apis[ 'ResourceStatusClient' ]
    else:
      self.rsClient = ResourceStatusClient()  

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

    :params:
      :attr:`args`: a tuple
        - `args[0]`: string          - should be a ValidElement
        - `args[1]`: string          - should be the name of the ValidElement
        - `args[2]`: optional string - a ValidElement (get status of THIS ValidElement
          for name in args[1], will call getGeneralName)

    :returns:
      {'MonitoredStatus': 'Active'|'Probing'|'Banned'}
    """

#    try:

    validElements = RssConfiguration.getValidElements()

    if len( self.args ) == 3:
      if validElements.index( self.args[2] ) >= validElements.index( self.args[0] ):
        return self.returnERROR( S_ERROR( 'Error in MonitoredStatus_Command' ) )
      toBeFound = self.rsClient.getGeneralName( self.args[0], self.args[1], self.args[2] )[ 'Value' ]
    else:
      toBeFound = self.args[1]

    res = self.rsClient.getMonitoredStatus( self.args[2], toBeFound )
    if res[ 'OK' ]:
      res = res[ 'Value' ]
      if res:
        res = S_OK( res[ 0 ][ 0 ] )
      else:
        res = S_OK( None )  

    else:
      res = self.returnERROR( res )
#    except Exception, e:
#      _msg = '%s (%s): %s' % ( self.__class__.__name__, self.args, e )
#      gLogger.exception( _msg )
#      return S_ERROR( _msg )

    return res 

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

################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
Пример #3
0
class MonitoredStatusCommand(Command):
    """
  The MonitoredStatus_Command class is a command class to know about
  monitored status.
  """
    def __init__(self, args=None, clients=None):

        super(MonitoredStatusCommand, self).__init__(args, clients)

        if 'ResourceStatusClient' in self.apis:
            self.rsClient = self.apis['ResourceStatusClient']
        else:
            self.rsClient = ResourceStatusClient()

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

    :params:
      :attr:`args`: a tuple
        - `args[0]`: string          - should be a ValidElement
        - `args[1]`: string          - should be the name of the ValidElement
        - `args[2]`: optional string - a ValidElement (get status of THIS ValidElement
          for name in args[1], will call getGeneralName)

    :returns:
      {'MonitoredStatus': 'Active'|'Probing'|'Banned'}
    """

        #    try:

        validElements = RssConfiguration.getValidElements()

        if len(self.args) == 3:
            if validElements.index(self.args[2]) >= validElements.index(
                    self.args[0]):
                return self.returnERROR(
                    S_ERROR('Error in MonitoredStatus_Command'))
            toBeFound = self.rsClient.getGeneralName(self.args[0],
                                                     self.args[1],
                                                     self.args[2])['Value']
        else:
            toBeFound = self.args[1]

        res = self.rsClient.getMonitoredStatus(self.args[2], toBeFound)
        if res['OK']:
            res = res['Value']
            if res:
                res = S_OK(res[0][0])
            else:
                res = S_OK(None)

        else:
            res = self.returnERROR(res)
#    except Exception, e:
#      _msg = '%s (%s): %s' % ( self.__class__.__name__, self.args, e )
#      gLogger.exception( _msg )
#      return S_ERROR( _msg )

        return res


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

################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
Пример #4
0
class MonitoredStatus_Command( Command ):
  """
  The MonitoredStatus_Command class is a command class to know about
  monitored status.
  """

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

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

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

        - `args[2]`: optional string - a ValidRes (get status of THIS ValidRes
          for name in args[1], will call getGeneralName)

    :returns:
      {'MonitoredStatus': 'Active'|'Probing'|'Banned'}
    """
    super( MonitoredStatus_Command, self ).doCommand()

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

    try:
      if len( self.args ) == 3:
        if ValidRes.index( self.args[2] ) >= ValidRes.index( self.args[0] ):
          raise InvalidRes, where( self, self.doCommand )

        toBeFound = self.client.getGeneralName( self.args[0], self.args[1], self.args[2] )
        if not toBeFound[ 'OK' ]:
          return {'Result' : 'Unknown'}
        toBeFound = toBeFound['Value']

        statuses = self.client.getMonitoredStatus( self.args[2], toBeFound )
        if not statuses['OK']:
          return {'Result' : 'Unknown'}
        statuses = statuses['Value']

      else:
        toBeFound = self.args[1]
        statuses = self.client.getMonitoredStatus( self.args[0], toBeFound )

        if not statuses['OK']:
          return {'Result' : 'Unknown'}
        statuses = statuses['Value']

      if not statuses:
        gLogger.warn( "No status found for %s" % toBeFound )
        return {'Result':'Unknown'}

    except:
      gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( self.args[0], self.args[1] ) )
      return {'Result':'Unknown'}

    # statuses is a list of statuses. We take the worst returned
    # status.

    assert(type(statuses) == list)
    statuses.sort(key=value_of_status)

    res = statuses[0]

    if len(statuses) > 1:
      gLogger.info( ValidStatus )
      gLogger.info( statuses )

    return {'Result':res}


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