Пример #1
0
  def __addUserDataToConfiguration( self ):
    if not self.isParsed:
      self.__parseCommandLine()

    errorsList = self.__loadCFGFiles()

    if gConfigurationData.getServers():
      retVal = self.syncRemoteConfiguration()
      if not retVal[ 'OK' ]:
        return retVal
    else:
      gLogger.warn( "Running without remote configuration" )

    try:
      if self.componentType == "service":
        self.__setDefaultSection( getServiceSection( self.componentName ) )
      elif self.componentType == "agent":
        self.__setDefaultSection( getAgentSection( self.componentName ) )
      elif self.componentType == "executor":
        self.__setDefaultSection( getExecutorSection( self.componentName ) )
      elif self.componentType == "web":
        self.__setDefaultSection( "/%s" % self.componentName )
      elif self.componentType == "script":
        if self.componentName and self.componentName[0] == "/":
          self.__setDefaultSection( self.componentName )
          self.componentName = self.componentName[1:]
        else:
          self.__setDefaultSection( "/Scripts/%s" % self.componentName )
      else:
        self.__setDefaultSection( "/" )
    except Exception, e:
      errorsList.append( str( e ) )
Пример #2
0
    def __addUserDataToConfiguration(self):
        if not self.isParsed:
            self.__parseCommandLine()

        errorsList = self.__loadCFGFiles()

        if gConfigurationData.getServers():
            retVal = self.syncRemoteConfiguration()
            if not retVal['OK']:
                return retVal
        else:
            gLogger.warn("Running without remote configuration")

        try:
            if self.componentType == "service":
                self.__setDefaultSection(getServiceSection(self.componentName))
            elif self.componentType == "agent":
                self.__setDefaultSection(getAgentSection(self.componentName))
            elif self.componentType == "executor":
                self.__setDefaultSection(getExecutorSection(
                    self.componentName))
            elif self.componentType == "web":
                self.__setDefaultSection("/%s" % self.componentName)
            elif self.componentType == "script":
                if self.componentName and self.componentName[0] == "/":
                    self.__setDefaultSection(self.componentName)
                    self.componentName = self.componentName[1:]
                else:
                    self.__setDefaultSection("/Scripts/%s" %
                                             self.componentName)
            else:
                self.__setDefaultSection("/")
        except Exception, e:
            errorsList.append(str(e))
Пример #3
0
    def __init__(self, database=False):
        super(PolicyBasedSecurityManager, self).__init__(database)

        from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceSection
        from DIRAC import gConfig
        from DIRAC.ConfigurationSystem.Client.Helpers.Path import cfgPath

        serviceSection = getServiceSection('DataManagement/FileCatalog')

        pluginPath = gConfig.getValue(cfgPath(serviceSection,
                                              'SecurityPolicy'))

        if not pluginPath:
            raise Exception("SecurityPolicy not defined in service options")

        pluginCls = self.__loadPlugin(pluginPath)
        self.policyObj = pluginCls(database=database)

        # For the old clients to work with the new policy (since getPathPermissions is meant to disappear...)
        # we fetch the old SecurityManager, and we call it if needed in the plugin.
        oldSecurityManagerName = gConfig.getValue(
            cfgPath(serviceSection, 'OldSecurityManager'), '')
        self.policyObj.oldSecurityManager = None
        if oldSecurityManagerName:
            self.policyObj.oldSecurityManager = eval("%s(self.db)" %
                                                     oldSecurityManagerName)
Пример #4
0
    def __addUserDataToConfiguration(self):
        if not self.isParsed:
            self.__parseCommandLine()

        errorsList = self.__loadCFGFiles()

        if gConfigurationData.getServers():
            retVal = self.syncRemoteConfiguration()
            if not retVal['OK']:
                return retVal
        else:
            gLogger.warn("Running without remote configuration")

        try:
            if self.componentType == "service":
                self.__setDefaultSection(getServiceSection(self.componentName))
            elif self.componentType == "agent":
                self.__setDefaultSection(getAgentSection(self.componentName))
            elif self.componentType == "executor":
                self.__setDefaultSection(getExecutorSection(
                    self.componentName))
            elif self.componentType == "web":
                self.__setDefaultSection("/%s" % self.componentName)
            elif self.componentType == "script":
                if self.componentName and self.componentName[0] == "/":
                    self.__setDefaultSection(self.componentName)
                    self.componentName = self.componentName[1:]
                else:
                    self.__setDefaultSection("/Scripts/%s" %
                                             self.componentName)
            else:
                self.__setDefaultSection("/")
        except Exception as e:
            errorsList.append(str(e))

        self.unprocessedSwitches = []

        for optionName, optionValue in self.parsedOptionList:
            optionName = optionName.lstrip("-")
            for definedOptionTuple in self.commandOptionList:
                if optionName == definedOptionTuple[0].replace(":", "") or \
                        optionName == definedOptionTuple[1].replace("=", ""):
                    if definedOptionTuple[3]:
                        retVal = definedOptionTuple[3](optionValue)
                        if not isinstance(retVal, dict):
                            errorsList.append(
                                "Callback for switch '%s' does not return S_OK or S_ERROR"
                                % optionName)
                        elif not retVal['OK']:
                            errorsList.append(retVal['Message'])
                    else:
                        self.unprocessedSwitches.append(
                            (optionName, optionValue))

        if len(errorsList) > 0:
            return S_ERROR("\n%s" % "\n".join(errorsList))
        return S_OK()
Пример #5
0
 def __init__( self, db, setup ):
   """ c'tor
   :param self: self reference
   :param object the database module
   :param str setup DIRAC setup
   """
   self.__db = db
   self.__setup = setup
   self.__csSection = getServiceSection( "Monitoring/Monitoring", setup = setup )
   self.__plotterList = PlottersList()
Пример #6
0
 def __init__( self, rrdLocation, graphLocation ):
   """
   Initialize RRDManager
   """
   self.rrdLocation = rrdLocation
   self.graphLocation = graphLocation
   self.log = gLogger.getSubLogger( "RRDManager" )
   self.rrdExec = gConfig.getValue( "%s/RRDExec" % getServiceSection( "Framework/Monitoring" ), "rrdtool" )
   for path in ( self.rrdLocation, self.graphLocation ):
     mkDir( path )
Пример #7
0
  def getFtsStrategy( self ):
    """ fts strategy getter """
    csPath = getServiceSection( "DataManagement/FTSManager" )
    csPath = "%s/%s" % ( csPath, "FTSStrategy" )

    ftsHistory = self.ftsDB.getFTSHistory()
    if not ftsHistory['OK']:
      gLogger.warn( "unable to get FTSHistory for FTSStrategy: %s" % ftsHistory['Message'] )
      ftsHistory['Value'] = []
    ftsHistory = ftsHistory['Value']

    return FTSStrategy( csPath, None, ftsHistory )
Пример #8
0
 def __init__(self, rrdLocation, graphLocation):
     """
 Initialize RRDManager
 """
     self.rrdLocation = rrdLocation
     self.graphLocation = graphLocation
     self.log = gLogger.getSubLogger("RRDManager")
     self.rrdExec = gConfig.getValue(
         "%s/RRDExec" % getServiceSection("Framework/Monitoring"),
         "rrdtool")
     for path in (self.rrdLocation, self.graphLocation):
         mkDir(path)
Пример #9
0
  def __addUserDataToConfiguration( self ):
    if not self.isParsed:
      self.__parseCommandLine()

    errorsList = self.__loadCFGFiles()

    if gConfigurationData.getServers():
      retVal = self.syncRemoteConfiguration()
      if not retVal[ 'OK' ]:
        return retVal
    else:
      gLogger.warn( "Running without remote configuration" )

    try:
      if self.componentType == "service":
        self.__setDefaultSection( getServiceSection( self.componentName ) )
      elif self.componentType == "agent":
        self.__setDefaultSection( getAgentSection( self.componentName ) )
      elif self.componentType == "executor":
        self.__setDefaultSection( getExecutorSection( self.componentName ) )
      elif self.componentType == "web":
        self.__setDefaultSection( "/%s" % self.componentName )
      elif self.componentType == "script":
        if self.componentName and self.componentName[0] == "/":
          self.__setDefaultSection( self.componentName )
          self.componentName = self.componentName[1:]
        else:
          self.__setDefaultSection( "/Scripts/%s" % self.componentName )
      else:
        self.__setDefaultSection( "/" )
    except Exception as e:
      errorsList.append( str( e ) )

    self.unprocessedSwitches = []

    for optionName, optionValue in self.parsedOptionList:
      optionName = optionName.lstrip( "-" )
      for definedOptionTuple in self.commandOptionList:
        if optionName == definedOptionTuple[0].replace( ":", "" ) or \
          optionName == definedOptionTuple[1].replace( "=", "" ):
          if definedOptionTuple[3]:
            retVal = definedOptionTuple[3]( optionValue )
            if type( retVal ) != types.DictType:
              errorsList.append( "Callback for switch '%s' does not return S_OK or S_ERROR" % optionName )
            elif not retVal[ 'OK' ]:
              errorsList.append( retVal[ 'Message' ] )
          else:
            self.unprocessedSwitches.append( ( optionName, optionValue ) )

    if len( errorsList ) > 0:
      return S_ERROR( "\n%s" % "\n".join( errorsList ) )
    return S_OK()
Пример #10
0
  def ftsStrategy( cls ):
    """ fts strategy getter """
    if not cls.__ftsStrategy:
      csPath = getServiceSection( "DataManagement/FTSManager" )
      csPath = "%s/%s" % ( csPath, "FTSStrategy" )

      ftsHistory = cls.__ftsDB.getFTSHistory()
      if not ftsHistory["OK"]:
        gLogger.warn( "unable to get FTSHistory for FTSStrategy: %s" % ftsHistory["Message"] )
        ftsHistory["Value"] = []
      ftsHistory = ftsHistory["Value"]

      cls.__ftsStrategy = FTSStrategy( csPath, None, ftsHistory )

    return cls.__ftsStrategy
Пример #11
0
    def ftsStrategy(cls):
        """ fts strategy getter """
        if not cls.__ftsStrategy:
            csPath = getServiceSection("DataManagement/FTSManager")
            csPath = "%s/%s" % (csPath, "FTSStrategy")

            ftsHistory = cls.__ftsDB.getFTSHistory()
            if not ftsHistory["OK"]:
                gLogger.warn("unable to get FTSHistory for FTSStrategy: %s" %
                             ftsHistory["Message"])
                ftsHistory["Value"] = []
            ftsHistory = ftsHistory["Value"]

            cls.__ftsStrategy = FTSStrategy(csPath, None, ftsHistory)

        return cls.__ftsStrategy
Пример #12
0
def main():

    if os.environ.get("DIRAC_USE_TORNADO_IOLOOP",
                      "false").lower() not in ("yes", "true"):
        raise RuntimeError(
            "DIRAC_USE_TORNADO_IOLOOP is not defined in the environment." +
            "\n" + "It is necessary to run with Tornado." + "\n" +
            "https://dirac.readthedocs.io/en/latest/DeveloperGuide/TornadoServices/index.html"
        )

    from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceSection
    from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData
    from DIRAC.ConfigurationSystem.private.Refresher import gRefresher
    from DIRAC.Core.Utilities.DErrno import includeExtensionErrors
    from DIRAC.Core.Tornado.Server.TornadoServer import TornadoServer
    from DIRAC.FrameworkSystem.Client.Logger import gLogger

    if gConfigurationData.isMaster():
        gRefresher.disable()

    localCfg = Script.localCfg
    localCfg.addMandatoryEntry("/DIRAC/Setup")
    localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
    localCfg.addDefaultEntry("LogLevel", "INFO")
    localCfg.addDefaultEntry("LogColor", True)
    resultDict = localCfg.loadUserData()
    if not resultDict["OK"]:
        gLogger.initialize("Tornado-CS", "/")
        gLogger.error("There were errors when loading configuration",
                      resultDict["Message"])
        sys.exit(1)

    includeExtensionErrors()

    gLogger.initialize("Tornado-CS", "/")

    # get the specific master CS port
    try:
        csPort = int(
            gConfigurationData.extractOptionFromCFG(
                "%s/Port" % getServiceSection("Configuration/Server")))
    except TypeError:
        csPort = None

    serverToLaunch = TornadoServer(services="Configuration/Server",
                                   port=csPort)
    serverToLaunch.startTornado()
Пример #13
0
def main():
    # Must be defined BEFORE any dirac import
    os.environ['DIRAC_USE_TORNADO_IOLOOP'] = "True"

    from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceSection
    from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData
    from DIRAC.ConfigurationSystem.Client.LocalConfiguration import LocalConfiguration
    from DIRAC.ConfigurationSystem.private.Refresher import gRefresher
    from DIRAC.Core.Utilities.DErrno import includeExtensionErrors
    from DIRAC.Core.Tornado.Server.TornadoServer import TornadoServer
    from DIRAC.FrameworkSystem.Client.Logger import gLogger

    if gConfigurationData.isMaster():
        gRefresher.disable()

    localCfg = LocalConfiguration()
    localCfg.addMandatoryEntry("/DIRAC/Setup")
    localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
    localCfg.addDefaultEntry("LogLevel", "INFO")
    localCfg.addDefaultEntry("LogColor", True)
    resultDict = localCfg.loadUserData()
    if not resultDict['OK']:
        gLogger.initialize("Tornado-CS", "/")
        gLogger.error("There were errors when loading configuration",
                      resultDict['Message'])
        sys.exit(1)

    includeExtensionErrors()

    gLogger.initialize('Tornado-CS', "/")

    # get the specific master CS port
    try:
        csPort = int(
            gConfigurationData.extractOptionFromCFG(
                '%s/Port' % getServiceSection('Configuration/Server')))
    except TypeError:
        csPort = None

    serverToLaunch = TornadoServer(services='Configuration/Server',
                                   port=csPort)
    serverToLaunch.startTornado()
Пример #14
0
    def __init__(self, database=False):
        super(PolicyBasedSecurityManager, self).__init__(database)

        from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceSection
        from DIRAC import gConfig
        from DIRAC.ConfigurationSystem.Client.Helpers.Path import cfgPath

        serviceSection = getServiceSection("DataManagement/FileCatalog")

        pluginPath = gConfig.getValue(cfgPath(serviceSection, "SecurityPolicy"))

        if not pluginPath:
            raise Exception("SecurityPolicy not defined in service options")

        pluginCls = self.__loadPlugin(pluginPath)
        self.policyObj = pluginCls(database=database)

        # For the old clients to work with the new policy (since getPathPermissions is meant to disappear...)
        # we fetch the old SecurityManager, and we call it if needed in the plugin.
        oldSecurityManagerName = gConfig.getValue(cfgPath(serviceSection, "OldSecurityManager"), "")
        self.policyObj.oldSecurityManager = None
        if oldSecurityManagerName:
            self.policyObj.oldSecurityManager = eval("%s(self.db)" % oldSecurityManagerName)
Пример #15
0
 def __init__( self, serviceName ):
   self.serviceName = serviceName
   self.serviceURL = False
   self.serviceSectionPath = getServiceSection( serviceName )
   self.systemSectionPath = getSystemSection( serviceName )
Пример #16
0
 def __init__( self, db, setup ):
   self._db = db
   self.setup = setup
   self.csSection = getServiceSection( "Accounting/ReportGenerator", setup = setup )
   self.plotterList = PlottersList()
Пример #17
0
 def __init__( self, db, setup ):
   self._db = db
   self.setup = setup
   self.csSection = getServiceSection( "Accounting/ReportGenerator", setup = setup )
   self.plotterList = PlottersList()