Пример #1
0
  def initialize(self):
    # Build the URLs
    self._url = self._cfg.getURL()
    if not self._url:
      return S_ERROR("Could not build service URL for %s" % self._name)
    gLogger.verbose("Service URL is %s" % self._url)
    # Load handler
    result = self._loadHandlerInit()
    if not result['OK']:
      return result
    self._handler = result['Value']
    # Initialize lock manager
    self._lockManager = LockManager(self._cfg.getMaxWaitingPetitions())
    self._initMonitoring()
    self._threadPool = ThreadPool(max(1, self._cfg.getMinThreads()),
                                  max(0, self._cfg.getMaxThreads()),
                                  self._cfg.getMaxWaitingPetitions())
    self._threadPool.daemonize()
    self._msgBroker = MessageBroker("%sMSB" % self._name, threadPool=self._threadPool)
    # Create static dict
    self._serviceInfoDict = {'serviceName': self._name,
                             'serviceSectionPath': PathFinder.getServiceSection(self._name),
                             'URL': self._cfg.getURL(),
                             'messageSender': MessageSender(self._name, self._msgBroker),
                             'validNames': self._validNames,
                             'csPaths': [PathFinder.getServiceSection(svcName) for svcName in self._validNames]
                             }
    # Call static initialization function
    try:
      self._handler['class']._rh__initializeClass(dict(self._serviceInfoDict),
                                                  self._lockManager,
                                                  self._msgBroker,
                                                  self._monitor)
      if self._handler['init']:
        for initFunc in self._handler['init']:
          gLogger.verbose("Executing initialization function")
          try:
            result = initFunc(dict(self._serviceInfoDict))
          except Exception as excp:
            gLogger.exception("Exception while calling initialization function", lException=excp)
            return S_ERROR("Exception while calling initialization function: %s" % str(excp))
          if not isReturnStructure(result):
            return S_ERROR("Service initialization function %s must return S_OK/S_ERROR" % initFunc)
          if not result['OK']:
            return S_ERROR("Error while initializing %s: %s" % (self._name, result['Message']))
    except Exception as e:
      errMsg = "Exception while initializing %s" % self._name
      gLogger.exception(e)
      gLogger.exception(errMsg)
      return S_ERROR(errMsg)

    # Load actions after the handler has initialized itself
    result = self._loadActions()
    if not result['OK']:
      return result
    self._actions = result['Value']

    gThreadScheduler.addPeriodicTask(30, self.__reportThreadPoolContents)

    return S_OK()
Пример #2
0
 def initialize( self ):
   #Build the URLs
   self._url = self._cfg.getURL()
   if not self._url:
     return S_ERROR( "Could not build service URL for %s" % self._name )
   gLogger.verbose( "Service URL is %s" % self._url )
   #Discover Handler
   self._handlerLocation = self._discoverHandlerLocation()
   if not self._handlerLocation:
     return S_ERROR( "Could not find handler location for %s" % self._name )
   gLogger.verbose( "Handler found at %s" % self._handlerLocation )
   #Load handler
   result = self._loadHandler()
   if not result[ 'OK' ]:
     return result
   self._handler = result[ 'Value' ]
   #Initialize lock manager
   self._lockManager = LockManager( self._cfg.getMaxWaitingPetitions() )
   #Load actions
   result = self._loadActions()
   if not result[ 'OK' ]:
     return result
   self._actions = result[ 'Value' ]
   self._initMonitoring()
   self._threadPool = ThreadPool( 1,
                                   max( 0, self._cfg.getMaxThreads() ),
                                   self._cfg.getMaxWaitingPetitions() )
   self._threadPool.daemonize()
   self._msgBroker = MessageBroker( "%sMSB" % self._name, threadPool = self._threadPool )
   #Create static dict
   self._serviceInfoDict = { 'serviceName' : self._name,
                              'URL' : self._cfg.getURL(),
                              'systemSectionPath' : self._cfg.getSystemPath(),
                              'serviceSectionPath' : self._cfg.getServicePath(),
                              'messageSender' : MessageSender( self._msgBroker )
                            }
   #Call static initialization function
   try:
     if self._handler[ 'init' ]:
       result = self._handler[ 'init' ]( dict( self._serviceInfoDict ) )
       if not isReturnStructure( result ):
         return S_ERROR( "Service initialization function must return S_OK/S_ERROR" )
       if not result[ 'OK' ]:
         return S_ERROR( "Error while initializing %s: %s" % ( self._name, result[ 'Message' ] ) )
   except Exception, e:
     errMsg = "Exception while intializing %s" % self._name
     gLogger.exception( errMsg )
     return S_ERROR( errMsg )
Пример #3
0
    def initialize(self):
        # Build the URLs
        self._url = self._cfg.getURL()
        if not self._url:
            return S_ERROR("Could not build service URL for %s" % self._name)
        gLogger.verbose("Service URL is %s" % self._url)
        # Load handler
        result = self._loadHandlerInit()
        if not result["OK"]:
            return result
        self._handler = result["Value"]
        # Initialize lock manager
        self._lockManager = LockManager(self._cfg.getMaxWaitingPetitions())
        self._threadPool = ThreadPoolExecutor(max(0,
                                                  self._cfg.getMaxThreads()))
        self._msgBroker = MessageBroker("%sMSB" % self._name,
                                        threadPool=self._threadPool)
        # Create static dict
        self._serviceInfoDict = {
            "serviceName":
            self._name,
            "serviceSectionPath":
            PathFinder.getServiceSection(self._name),
            "URL":
            self._cfg.getURL(),
            "messageSender":
            MessageSender(self._name, self._msgBroker),
            "validNames":
            self._validNames,
            "csPaths": [
                PathFinder.getServiceSection(svcName)
                for svcName in self._validNames
            ],
        }
        self.securityLogging = Operations().getValue(
            "EnableSecurityLogging", True) and getServiceOption(
                self._serviceInfoDict, "EnableSecurityLogging", True)
        # Initialize Monitoring
        # The import needs to be here because of the CS must be initialized before importing
        # this class (see https://github.com/DIRACGrid/DIRAC/issues/4793)
        from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter

        self.activityMonitoringReporter = MonitoringReporter(
            monitoringType="ServiceMonitoring")

        self._initMonitoring()
        # Call static initialization function
        try:
            self._handler["class"]._rh__initializeClass(
                dict(self._serviceInfoDict), self._lockManager,
                self._msgBroker, self.activityMonitoringReporter)
            if self._handler["init"]:
                for initFunc in self._handler["init"]:
                    gLogger.verbose("Executing initialization function")
                    try:
                        result = initFunc(dict(self._serviceInfoDict))
                    except Exception as excp:
                        gLogger.exception(
                            "Exception while calling initialization function",
                            lException=excp)
                        return S_ERROR(
                            "Exception while calling initialization function: %s"
                            % str(excp))
                    if not isReturnStructure(result):
                        return S_ERROR(
                            "Service initialization function %s must return S_OK/S_ERROR"
                            % initFunc)
                    if not result["OK"]:
                        return S_ERROR("Error while initializing %s: %s" %
                                       (self._name, result["Message"]))
        except Exception as e:
            errMsg = "Exception while initializing %s" % self._name
            gLogger.exception(e)
            gLogger.exception(errMsg)
            return S_ERROR(errMsg)
        if self.activityMonitoring:
            gThreadScheduler.addPeriodicTask(30, self.__reportActivity)
            gThreadScheduler.addPeriodicTask(
                100, self.__activityMonitoringReporting)

        # Load actions after the handler has initialized itself
        result = self._loadActions()
        if not result["OK"]:
            return result
        self._actions = result["Value"]

        return S_OK()
Пример #4
0
    def initialize(self):
        # Build the URLs
        self._url = self._cfg.getURL()
        if not self._url:
            return S_ERROR("Could not build service URL for %s" % self._name)
        gLogger.verbose("Service URL is %s" % self._url)
        # Load handler
        result = self._loadHandlerInit()
        if not result['OK']:
            return result
        self._handler = result['Value']
        # Initialize lock manager
        self._lockManager = LockManager(self._cfg.getMaxWaitingPetitions())
        # TODO: remove ThreadPool
        if useThreadPoolExecutor:
            self._threadPool = ThreadPoolExecutor(
                max(0, self._cfg.getMaxThreads()))
        else:
            self._threadPool = ThreadPool(max(1, self._cfg.getMinThreads()),
                                          max(0, self._cfg.getMaxThreads()),
                                          self._cfg.getMaxWaitingPetitions())
            self._threadPool.daemonize()
        self._msgBroker = MessageBroker("%sMSB" % self._name,
                                        threadPool=self._threadPool)
        # Create static dict
        self._serviceInfoDict = {
            'serviceName':
            self._name,
            'serviceSectionPath':
            PathFinder.getServiceSection(self._name),
            'URL':
            self._cfg.getURL(),
            'messageSender':
            MessageSender(self._name, self._msgBroker),
            'validNames':
            self._validNames,
            'csPaths': [
                PathFinder.getServiceSection(svcName)
                for svcName in self._validNames
            ]
        }
        # Initialize Monitoring
        # This is a flag used to check whether "EnableActivityMonitoring" is enabled or not from the config file.
        self.activityMonitoring = (Operations().getValue(
            "EnableActivityMonitoring", False) or getServiceOption(
                self._serviceInfoDict, "EnableActivityMonitoring", False))
        if self.activityMonitoring:
            # The import needs to be here because of the CS must be initialized before importing
            # this class (see https://github.com/DIRACGrid/DIRAC/issues/4793)
            from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter
            self.activityMonitoringReporter = MonitoringReporter(
                monitoringType="ComponentMonitoring")
            gThreadScheduler.addPeriodicTask(
                100, self.__activityMonitoringReporting)
        elif self._standalone:
            self._monitor = gMonitor
        else:
            self._monitor = MonitoringClient()
        self._initMonitoring()
        # Call static initialization function
        try:
            if self.activityMonitoring:
                self._handler['class']._rh__initializeClass(
                    dict(self._serviceInfoDict), self._lockManager,
                    self._msgBroker, self.activityMonitoringReporter)
            else:
                self._handler['class']._rh__initializeClass(
                    dict(self._serviceInfoDict), self._lockManager,
                    self._msgBroker, self._monitor)
            if self._handler['init']:
                for initFunc in self._handler['init']:
                    gLogger.verbose("Executing initialization function")
                    try:
                        result = initFunc(dict(self._serviceInfoDict))
                    except Exception as excp:
                        gLogger.exception(
                            "Exception while calling initialization function",
                            lException=excp)
                        return S_ERROR(
                            "Exception while calling initialization function: %s"
                            % str(excp))
                    if not isReturnStructure(result):
                        return S_ERROR(
                            "Service initialization function %s must return S_OK/S_ERROR"
                            % initFunc)
                    if not result['OK']:
                        return S_ERROR("Error while initializing %s: %s" %
                                       (self._name, result['Message']))
        except Exception as e:
            errMsg = "Exception while initializing %s" % self._name
            gLogger.exception(e)
            gLogger.exception(errMsg)
            return S_ERROR(errMsg)

        # Load actions after the handler has initialized itself
        result = self._loadActions()
        if not result['OK']:
            return result
        self._actions = result['Value']

        if not self.activityMonitoring:
            gThreadScheduler.addPeriodicTask(30,
                                             self.__reportThreadPoolContents)

        return S_OK()