Esempio n. 1
0
class StElWriteInspectorAgent( AgentModule ):
  """ Class StElWriteInspectorAgent is in charge of going through StorageElements
      table, and pass StorageElement and Status to the PEP
  """

#############################################################################

  def initialize( self ):
    """ Standard constructor
    """

    try:
      self.rsDB = ResourceStatusDB()
      self.rmDB = ResourceManagementDB()

      self.StorageElementToBeChecked = Queue.Queue()
      self.StorageElementInCheck     = []

      self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 )
      self.threadPool         = ThreadPool( self.maxNumberOfThreads,
                                            self.maxNumberOfThreads )

      if not self.threadPool:
        self.log.error( 'Can not create Thread Pool' )
        return S_ERROR( 'Can not create Thread Pool' )

      self.setup                = getSetup()[ 'Value' ]
      self.VOExtension          = getExt()
      self.StorageElsWriteFreqs = CheckingFreqs[ 'StorageElsWriteFreqs' ]
      self.nc                   = NotificationClient()
      self.diracAdmin           = DiracAdmin()
      self.csAPI                = CSAPI()

      for _i in xrange( self.maxNumberOfThreads ):
        self.threadPool.generateJobAndQueueIt( self._executeCheck, args = ( None, ) )

      return S_OK()

    except Exception:
      errorStr = "StElWriteInspectorAgent initialization"
      gLogger.exception( errorStr )
      return S_ERROR( errorStr )

#############################################################################

  def execute( self ):
    """
    The main RSInspectorAgent execution method.
    Calls :meth:`DIRAC.ResourceStatusSystem.DB.ResourceStatusDB.getResourcesToCheck` and
    put result in self.StorageElementToBeChecked (a Queue) and in self.StorageElementInCheck (a list)
    """

    try:

      res = self.rsDB.getStuffToCheck( 'StorageElementsWrite', self.StorageElsWriteFreqs )

      for resourceTuple in res:
        if resourceTuple[ 0 ] in self.StorageElementInCheck:
          break
        resourceL = [ 'StorageElementWrite' ]
        for x in resourceTuple:
          resourceL.append( x )
        self.StorageElementInCheck.insert( 0, resourceL[ 1 ] )
        self.StorageElementToBeChecked.put( resourceL )

      return S_OK()

    except Exception, x:
      errorStr = where( self, self.execute )
      gLogger.exception( errorStr, lException = x )
      return S_ERROR( errorStr )
Esempio n. 2
0
class RSInspectorAgent(AgentModule):
    """ Class RSInspectorAgent is in charge of going through Resources
      table, and pass Resource and Status to the PEP
  """

    #############################################################################

    def initialize(self):
        """ Standard constructor
    """

        try:
            self.rsDB = ResourceStatusDB()
            self.rmDB = ResourceManagementDB()

            self.ResourcesToBeChecked = Queue.Queue()
            self.ResourceNamesInCheck = []

            self.maxNumberOfThreads = self.am_getOption('maxThreadsInPool', 1)
            self.threadPool = ThreadPool(self.maxNumberOfThreads,
                                         self.maxNumberOfThreads)

            if not self.threadPool:
                self.log.error('Can not create Thread Pool')
                return S_ERROR('Can not create Thread Pool')

            self.setup = getSetup()['Value']

            self.VOExtension = getExt()

            configModule = __import__(
                self.VOExtension +
                "DIRAC.ResourceStatusSystem.Policy.Configurations", globals(),
                locals(), ['*'])

            self.Resources_check_freq = copy.deepcopy(
                configModule.Resources_check_freq)

            self.nc = NotificationClient()

            self.diracAdmin = DiracAdmin()

            self.csAPI = CSAPI()

            for i in xrange(self.maxNumberOfThreads):
                self.threadPool.generateJobAndQueueIt(self._executeCheck,
                                                      args=(None, ))

            return S_OK()

        except Exception:
            errorStr = "RSInspectorAgent initialization"
            gLogger.exception(errorStr)
            return S_ERROR(errorStr)

#############################################################################

    def execute(self):
        """ 
    The main RSInspectorAgent execution method.
    Calls :meth:`DIRAC.ResourceStatusSystem.DB.ResourceStatusDB.getResourcesToCheck` and 
    put result in self.ResourcesToBeChecked (a Queue) and in self.ResourceNamesInCheck (a list)
    """

        try:

            res = self.rsDB.getStuffToCheck('Resources',
                                            self.Resources_check_freq)

            for resourceTuple in res:
                if resourceTuple[0] in self.ResourceNamesInCheck:
                    break
                resourceL = ['Resource']
                for x in resourceTuple:
                    resourceL.append(x)
                self.ResourceNamesInCheck.insert(0, resourceL[1])
                self.ResourcesToBeChecked.put(resourceL)

            return S_OK()

        except Exception, x:
            errorStr = where(self, self.execute)
            gLogger.exception(errorStr, lException=x)
            return S_ERROR(errorStr)
Esempio n. 3
0
class SeSInspectorAgent(AgentModule):
  """ Class SeSInspectorAgent is in charge of going through Services
      table, and pass Service and Status to the PEP
  """

#############################################################################

  def initialize(self):
    """ Standard constructor
    """
    
    try:
      self.rsDB = ResourceStatusDB()
      self.rmDB = ResourceManagementDB()
      
      self.ServicesToBeChecked = Queue.Queue()
      self.ServiceNamesInCheck = []
      
      self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 )
      self.threadPool = ThreadPool( self.maxNumberOfThreads,
                                    self.maxNumberOfThreads )

      if not self.threadPool:
        self.log.error('Can not create Thread Pool')
        return S_ERROR('Can not create Thread Pool')
      
      self.setup = getSetup()['Value']

      self.VOExtension = getExt()

      configModule = __import__(self.VOExtension+"DIRAC.ResourceStatusSystem.Policy.Configurations", 
                                globals(), locals(), ['*'])
      
      self.Services_check_freq = copy.deepcopy(configModule.Services_check_freq)
      
      self.nc = NotificationClient()

      self.diracAdmin = DiracAdmin()

      self.csAPI = CSAPI()      
      
      for i in xrange(self.maxNumberOfThreads):
        self.threadPool.generateJobAndQueueIt(self._executeCheck, args = (None, ) )  
        
      return S_OK()

    except Exception:
      errorStr = "SeSInspectorAgent initialization"
      gLogger.exception(errorStr)
      return S_ERROR(errorStr)


#############################################################################

  def execute(self):
    """ 
    The main SSInspectorAgent execution method.
    Calls :meth:`DIRAC.ResourceStatusSystem.DB.ResourceStatusDB.getResourcesToCheck` and 
    put result in self.ServicesToBeChecked (a Queue) and in self.ServiceNamesInCheck (a list)
    """
    
    try:

      res = self.rsDB.getStuffToCheck('Services', self.Services_check_freq) 
   
      for resourceTuple in res:
        if resourceTuple[0] in self.ServiceNamesInCheck:
          break
        resourceL = ['Service']
        for x in resourceTuple:
          resourceL.append(x)
        self.ServiceNamesInCheck.insert(0, resourceL[1])
        self.ServicesToBeChecked.put(resourceL)

      return S_OK()

    except Exception, x:
      errorStr = where(self, self.execute)
      gLogger.exception(errorStr,lException=x)
      return S_ERROR(errorStr)