def getResourceDict(ceName=None): """Look into LocalSite for Resource Requirements """ from DIRAC.WorkloadManagementSystem.private.Queues import maxCPUSegments ret = gConfig.getOptionsDict("/LocalSite/ResourceDict") if not ret["OK"]: resourceDict = {} else: # FIXME: es mejor copiar el diccionario? resourceDict = dict(ret["Value"]) # if a CE Name is given, check the corresponding section if ceName: ret = gConfig.getOptionsDict("/LocalSite/%s/ResourceDict" % ceName) if ret["OK"]: resourceDict.update(dict(ret["Value"])) # now add some defaults resourceDict["Setup"] = gConfig.getValue("/DIRAC/Setup", "None") if not "CPUTime" in resourceDict: resourceDict["CPUTime"] = maxCPUSegments[-1] if not "PilotType" in resourceDict: # FIXME: this is a test, we need the list of available types resourceDict["PilotType"] = "private" return resourceDict
def getResourceDict( ceName = None ): """Look into LocalSite for Resource Requirements """ from DIRAC.WorkloadManagementSystem.private.Queues import maxCPUSegments ret = gConfig.getOptionsDict( '/LocalSite/ResourceDict' ) if not ret['OK']: resourceDict = {} else: # FIXME: es mejor copiar el diccionario? resourceDict = dict( ret['Value'] ) # if a CE Name is given, check the corresponding section if ceName: ret = gConfig.getOptionsDict( '/LocalSite/%s/ResourceDict' % ceName ) if ret['OK']: resourceDict.update( dict( ret['Value'] ) ) # now add some defaults resourceDict['Setup'] = gConfig.getValue( '/DIRAC/Setup', 'None' ) if not 'CPUTime' in resourceDict: resourceDict['CPUTime'] = maxCPUSegments[-1] if not 'PilotType' in resourceDict: # FIXME: this is a test, we need the list of available types resourceDict['PilotType'] = 'private' return resourceDict
def initializeParameters(self): """ Initialize the CE parameters after they are collected from various sources """ self.log.debug("Initializing the CE parameters") # Collect global defaults first for section in [ '/Resources/Computing/CEDefaults', '/Resources/Computing/%s' % self.ceName ]: result = gConfig.getOptionsDict(section) self.log.debug(result) if not result['OK']: self.log.warn(result['Message']) else: ceOptions = result['Value'] for key in ceOptions: if key in INTEGER_PARAMETERS: ceOptions[key] = int(ceOptions[key]) if key in FLOAT_PARAMETERS: ceOptions[key] = float(ceOptions[key]) if key in LIST_PARAMETERS: ceOptions[key] = gConfig.getValue( os.path.join(section, key), []) self.ceParameters.update(ceOptions) # Get local CE configuration localConfigDict = getCEConfigDict(self.ceName) self.ceParameters.update(localConfigDict) # Adds site level parameters section = '/LocalSite' result = gConfig.getOptionsDict(section) if result['OK'] and result['Value']: localSiteParameters = result['Value'] self.log.debug('Local site parameters are: %s' % (localSiteParameters)) for option, value in localSiteParameters.iteritems(): if option == 'Architecture': self.ceParameters['Platform'] = value self.ceParameters['Architecture'] = value elif option == 'LocalSE': self.ceParameters['LocalSE'] = value.split(', ') else: self.ceParameters[option] = value self._addCEConfigDefaults()
def setParameters(self, ceOptions): """ Add parameters from the given dictionary overriding the previous values :param dict ceOptions: CE parameters dictionary to update already defined ones """ self.ceParameters.update(ceOptions) # At this point we can know the exact type of CE, # try to get generic parameters for this type ceType = self.ceParameters.get('CEType') if ceType: result = gConfig.getOptionsDict('/Resources/Computing/%s' % ceType) if result['OK']: generalCEDict = result['Value'] generalCEDict.update(self.ceParameters) self.ceParameters = generalCEDict # If NumberOfProcessors is present in the description but is equal to zero # interpret it as needing local evaluation if self.ceParameters.get("NumberOfProcessors", -1) == 0: self.ceParameters["NumberOfProcessors"] = multiprocessing.cpu_count() for key in ceOptions: if key in INTEGER_PARAMETERS: self.ceParameters[key] = int(self.ceParameters[key]) if key in FLOAT_PARAMETERS: self.ceParameters[key] = float(self.ceParameters[key]) self._reset() return S_OK()
def initialize(self, systemName, cfgPath): if self.__initialized: return self.__initialized = True from DIRAC.ConfigurationSystem.Client.Config import gConfig from os import getpid # self.__printDebug( "The configuration path is %s" % cfgPath ) # Get the options for the different output backends retDict = gConfig.getOptionsDict("%s/BackendsOptions" % cfgPath) # self.__printDebug( retDict ) if not retDict['OK']: cfgBackOptsDict = { 'FileName': 'Dirac-log_%s.log' % getpid(), 'Interactive': True, 'SleepTime': 150 } else: cfgBackOptsDict = retDict['Value'] self.__backendOptions.update(cfgBackOptsDict) if 'FileName' not in self.__backendOptions: self.__backendOptions['FileName'] = 'Dirac-log_%s.log' % getpid() sleepTime = 150 try: sleepTime = int(self.__backendOptions['SleepTime']) except: pass self.__backendOptions['SleepTime'] = sleepTime self.__backendOptions['Interactive'] = gConfig.getValue( "%s/BackendsOptions/Interactive" % cfgPath, True) self.__backendOptions['Site'] = DIRAC.siteName() self.__backendOptions['Color'] = gConfig.getValue( "%s/LogColor" % cfgPath, False) # Configure outputs desiredBackends = gConfig.getValue("%s/LogBackends" % cfgPath, 'stdout') self.registerBackends(List.fromChar(desiredBackends)) # Configure verbosity defaultLevel = Logger.defaultLogLevel if "Scripts" in cfgPath: defaultLevel = gConfig.getValue('/Systems/Scripts/LogLevel', Logger.defaultLogLevel) self.setLevel(gConfig.getValue("%s/LogLevel" % cfgPath, defaultLevel)) # Configure framing self._showCallingFrame = gConfig.getValue("%s/LogShowLine" % cfgPath, self._showCallingFrame) # Get system name self._systemName = str(systemName) if not self.__backendOptions['Interactive']: ExitCallback.registerExitCallback(self.flushAllMessages)
def setParameters(self, ceOptions): """ Add parameters from the given dictionary overriding the previous values :param dict ceOptions: CE parameters dictionary to update already defined ones """ self.ceParameters.update(ceOptions) # At this point we can know the exact type of CE, # try to get generic parameters for this type ceType = self.ceParameters.get('CEType') if ceType: result = gConfig.getOptionsDict('/Resources/Computing/%s' % ceType) if result['OK']: generalCEDict = result['Value'] generalCEDict.update(self.ceParameters) self.ceParameters = generalCEDict for key in ceOptions: if key in INTEGER_PARAMETERS: self.ceParameters[key] = int(self.ceParameters[key]) if key in FLOAT_PARAMETERS: self.ceParameters[key] = float(self.ceParameters[key]) self._reset() return S_OK()
def setParameters( self, ceOptions ): """ Add parameters from the given dictionary overriding the previous values :param dict ceOptions: CE parameters dictionary to update already defined ones """ self.ceParameters.update( ceOptions ) # At this point we can know the exact type of CE, # try to get generic parameters for this type ceType = self.ceParameters.get( 'CEType' ) if ceType: result = gConfig.getOptionsDict( '/Resources/Computing/%s' % ceType ) if result['OK']: generalCEDict = result['Value'] generalCEDict.update( self.ceParameters ) self.ceParameters = generalCEDict for key in ceOptions: if key in INTEGER_PARAMETERS: self.ceParameters[key] = int( self.ceParameters[key] ) if key in FLOAT_PARAMETERS: self.ceParameters[key] = float( self.ceParameters[key] ) self._reset() return S_OK()
def __discoverURL(self): """ Calculate the final URL. It is called at initialization and in connect in case of issue It sets: * self.serviceURL: the url (dips) selected as target using __findServiceURL * self.__URLTuple: a split of serviceURL obtained by Network.splitURL * self._serviceName: the last part of URLTuple (typically System/Component) """ # Calculate final URL try: result = self.__findServiceURL() except Exception as e: return S_ERROR(repr(e)) if not result['OK']: return result self.serviceURL = result['Value'] retVal = Network.splitURL(self.serviceURL) if not retVal['OK']: return retVal self.__URLTuple = retVal['Value'] self._serviceName = self.__URLTuple[-1] res = gConfig.getOptionsDict("/DIRAC/ConnConf/%s:%s" % self.__URLTuple[1:3]) if res['OK']: opts = res['Value'] for k in opts: if k not in self.kwargs: self.kwargs[k] = opts[k] return S_OK()
def __discoverURL(self): """Calculate the final URL. It is called at initialization and in connect in case of issue It sets: * self.serviceURL: the url (dips) selected as target using __findServiceURL * self.__URLTuple: a split of serviceURL obtained by Network.splitURL * self._serviceName: the last part of URLTuple (typically System/Component) WARNING: COPY PASTE FROM BaseClient """ # Calculate final URL try: result = self.__findServiceURL() except Exception as e: return S_ERROR(repr(e)) if not result["OK"]: return result self.serviceURL = result["Value"] retVal = Network.splitURL(self.serviceURL) if not retVal["OK"]: return retVal self.__URLTuple = retVal["Value"] self._serviceName = self.__URLTuple[-1] res = gConfig.getOptionsDict("/DIRAC/ConnConf/%s:%s" % self.__URLTuple[1:3]) if res["OK"]: opts = res["Value"] for k in opts: if k not in self.kwargs: self.kwargs[k] = opts[k] return S_OK()
def setParameters(self, ceOptions): """ Add parameters from the given dictionary overriding the previous values :param dict ceOptions: CE parameters dictionary to update already defined ones """ self.ceParameters.update(ceOptions) # At this point we can know the exact type of CE, # try to get generic parameters for this type ceType = self.ceParameters.get('CEType') if ceType: result = gConfig.getOptionsDict('/Resources/Computing/%s' % ceType) if result['OK']: generalCEDict = result['Value'] generalCEDict.update(self.ceParameters) self.ceParameters = generalCEDict # If NumberOfProcessors is present in the description but is equal to zero # interpret it as needing local evaluation if self.ceParameters.get("NumberOfProcessors", -1) == 0: self.ceParameters[ "NumberOfProcessors"] = multiprocessing.cpu_count() for key in ceOptions: if key in INTEGER_PARAMETERS: self.ceParameters[key] = int(self.ceParameters[key]) if key in FLOAT_PARAMETERS: self.ceParameters[key] = float(self.ceParameters[key]) self._reset() return S_OK()
def __getSiteParameters(self): """Adds site specific parameters to the resource ClassAd. """ section = "/LocalSite" options = gConfig.getOptionsDict(section) if not options["OK"]: self.log.warn(options["Message"]) return S_ERROR(options["Message"]) if not options["Value"]: self.log.warn("Could not obtain %s section from CS" % (section)) return S_ERROR("Could not obtain %s section from CS" % (section)) localSite = options["Value"] self.log.debug("Local site parameters are: %s" % (localSite)) for option, value in localSite.items(): if option == "Architecture": self.ceParameters["Platform"] = value self.ceParameters["Architecture"] = value elif option == "LocalSE": self.ceParameters["LocalSE"] = value.split(", ") else: self.ceParameters[option] = value return S_OK()
def __getSiteParameters( self ): """Adds site specific parameters to the resource ClassAd. """ section = '/LocalSite' options = gConfig.getOptionsDict( section ) if not options['OK']: self.log.warn( options['Message'] ) return S_ERROR( options['Message'] ) if not options['Value']: self.log.warn( 'Could not obtain %s section from CS' % ( section ) ) return S_ERROR( 'Could not obtain %s section from CS' % ( section ) ) localSite = options['Value'] self.log.debug( 'Local site parameters are: %s' % ( localSite ) ) for option, value in localSite.items(): if option == 'Architecture': self.ceParameters['Platform'] = value self.ceParameters['Architecture'] = value elif option == 'LocalSE': self.ceParameters['LocalSE'] = value.split( ', ' ) else: self.ceParameters[option] = value return S_OK()
def initializeParameters(self): """Initialize the CE parameters after they are collected from various sources""" self.log.debug("Initializing the CE parameters") # Collect global defaults first for section in [ "/Resources/Computing/CEDefaults", "/Resources/Computing/%s" % self.ceType ]: result = gConfig.getOptionsDict(section) self.log.debug(result) if result["OK"]: ceOptions = result["Value"] for key in ceOptions: if key in INTEGER_PARAMETERS: ceOptions[key] = int(ceOptions[key]) if key in FLOAT_PARAMETERS: ceOptions[key] = float(ceOptions[key]) if key in LIST_PARAMETERS: ceOptions[key] = gConfig.getValue( os.path.join(section, key), []) self.ceParameters.update(ceOptions) # Get local CE configuration localConfigDict = getCEConfigDict(self.ceName) self.ceParameters.update(localConfigDict) # Adds site level parameters section = "/LocalSite" result = gConfig.getOptionsDict(section) if result["OK"] and result["Value"]: localSiteParameters = result["Value"] self.log.debug("Local site parameters are: %s" % (localSiteParameters)) for option, value in localSiteParameters.items(): if option == "Architecture": self.ceParameters["Platform"] = value self.ceParameters["Architecture"] = value elif option == "LocalSE": self.ceParameters["LocalSE"] = value.split(", ") else: self.ceParameters[option] = value self._addCEConfigDefaults()
def getCEConfigDict(ceName): """Look into LocalSite for configuration Parameters for this CE""" ceConfigDict = {} if ceName: result = gConfig.getOptionsDict("/LocalSite/%s" % ceName) if result["OK"]: ceConfigDict = result["Value"] return ceConfigDict
def getCEConfigDict(ceName): """Look into LocalSite for configuration Parameters for this CE """ ceConfigDict = {} if ceName: result = gConfig.getOptionsDict("/LocalSite/%s" % ceName) if result["OK"]: ceConfigDict = result["Value"] return ceConfigDict
def getCEConfigDict( ceName ): """Look into LocalSite for configuration Parameters for this CE """ ceConfigDict = {} if ceName: result = gConfig.getOptionsDict( '/LocalSite/%s' % ceName ) if result['OK']: ceConfigDict = result['Value'] return ceConfigDict
def getCEConfigDict(ceName): """Look into LocalSite for configuration Parameters for this CE """ ceConfigDict = {} if ceName: result = gConfig.getOptionsDict('/LocalSite/%s' % ceName) if result['OK']: ceConfigDict = result['Value'] return ceConfigDict
def __getSiteParameters( self ): """Adds site specific parameters to the resource ClassAd. """ osSection = '/Resources/Computing/OSCompatibility' platforms = {} result = gConfig.getOptionsDict( osSection ) if not result['OK']: self.log.warn( result['Message'] ) # return S_ERROR(result['Message']) else: if not result['Value']: self.log.warn( 'Could not obtain %s section from CS' % ( osSection ) ) # return S_ERROR('Could not obtain %s section from CS' %(osSection)) else: platforms = result['Value'] self.log.debug( 'Platforms are %s' % ( platforms ) ) section = '/LocalSite' options = gConfig.getOptionsDict( section ) if not options['OK']: self.log.warn( options['Message'] ) return S_ERROR( options['Message'] ) if not options['Value']: self.log.warn( 'Could not obtain %s section from CS' % ( section ) ) return S_ERROR( 'Could not obtain %s section from CS' % ( section ) ) localSite = options['Value'] self.log.debug( 'Local site parameters are: %s' % ( localSite ) ) for option, value in localSite.items(): if option == 'Architecture': self.ceParameters['LHCbPlatform'] = value self.ceParameters['Architecture'] = value if value in platforms.keys(): compatiblePlatforms = platforms[value] self.ceParameters['CompatiblePlatforms'] = compatiblePlatforms.split( ', ' ) elif option == 'LocalSE': self.ceParameters['LocalSE'] = value.split( ', ' ) else: self.ceParameters[option] = value return S_OK()
def __getResourceRequirements( self ): """Adds resource requirements to the ClassAd. """ reqtSection = '/AgentJobRequirements' result = gConfig.getOptionsDict( reqtSection ) if not result['OK']: self.log.warn( result['Message'] ) return S_OK( result['Message'] ) reqsDict = result['Value'] self.ceRequirementDict.update( reqsDict ) return S_OK( 'Added requirements' )
def getResourceDict( ceName = None ): """Look into LocalSite for Resource Requirements """ from DIRAC.WorkloadManagementSystem.private.Queues import maxCPUSegments ret = gConfig.getOptionsDict( '/LocalSite/ResourceDict' ) if not ret['OK']: resourceDict = {} else: resourceDict = dict( ret['Value'] ) # if a CE Name is given, check the corresponding section if ceName: ret = gConfig.getOptionsDict( '/LocalSite/%s/ResourceDict' % ceName ) if ret['OK']: resourceDict.update( dict( ret['Value'] ) ) # now add some defaults resourceDict['Setup'] = gConfig.getValue( '/DIRAC/Setup', 'None' ) if not 'CPUTime' in resourceDict: resourceDict['CPUTime'] = maxCPUSegments[-1] return resourceDict
def initialize( self, systemName, cfgPath ): if self.__initialized: return self.__initialized = True from DIRAC.ConfigurationSystem.Client.Config import gConfig from os import getpid # self.__printDebug( "The configuration path is %s" % cfgPath ) # Get the options for the different output backends retDict = gConfig.getOptionsDict( "%s/BackendsOptions" % cfgPath ) # self.__printDebug( retDict ) if not retDict[ 'OK' ]: cfgBackOptsDict = { 'FileName': 'Dirac-log_%s.log' % getpid(), 'Interactive': True, 'SleepTime': 150 } else: cfgBackOptsDict = retDict[ 'Value' ] self.__backendOptions.update( cfgBackOptsDict ) if 'FileName' not in self.__backendOptions: self.__backendOptions[ 'FileName' ] = 'Dirac-log_%s.log' % getpid() sleepTime = 150 try: sleepTime = int ( self.__backendOptions[ 'SleepTime' ] ) except: pass self.__backendOptions[ 'SleepTime' ] = sleepTime self.__backendOptions[ 'Interactive' ] = gConfig.getValue( "%s/BackendsOptions/Interactive" % cfgPath, True ) self.__backendOptions[ 'Site' ] = DIRAC.siteName() self.__backendOptions[ 'Color' ] = gConfig.getValue( "%s/LogColor" % cfgPath, False ) # Configure outputs desiredBackends = gConfig.getValue( "%s/LogBackends" % cfgPath, 'stdout' ) self.registerBackends( List.fromChar( desiredBackends ) ) # Configure verbosity defaultLevel = Logger.defaultLogLevel if "Scripts" in cfgPath: defaultLevel = gConfig.getValue( '/Systems/Scripts/LogLevel', Logger.defaultLogLevel ) self.setLevel( gConfig.getValue( "%s/LogLevel" % cfgPath, defaultLevel ) ) # Configure framing self._showCallingFrame = gConfig.getValue( "%s/LogShowLine" % cfgPath, self._showCallingFrame ) # Get system name self._systemName = str( systemName ) if not self.__backendOptions['Interactive']: ExitCallback.registerExitCallback( self.flushAllMessages )
def initializeParameters( self ): """ Initialize the CE parameters after they are collected from various sources """ # Collect global defaults first for section in [ '/Resources/Computing/CEDefaults', '/Resources/Computing/%s' % self.ceName ]: result = gConfig.getOptionsDict( section ) if result['OK']: ceOptions = result['Value'] for key in ceOptions: if key in INTEGER_PARAMETERS: ceOptions[key] = int( ceOptions[key] ) if key in FLOAT_PARAMETERS: ceOptions[key] = float( ceOptions[key] ) if key in LIST_PARAMETERS: ceOptions[key] = gConfig.getValue( os.path.join( section, key ), [] ) self.ceParameters.update( ceOptions ) # Get local CE configuration localConfigDict = getLocalCEConfigDict( self.ceName ) self.ceParameters.update( localConfigDict ) # Adds site level parameters section = '/LocalSite' result = gConfig.getOptionsDict( section ) if result['OK'] and result['Value']: localSiteParameters = result['Value'] self.log.debug( 'Local site parameters are: %s' % ( localSiteParameters ) ) for option, value in localSiteParameters.items(): if option == 'Architecture': self.ceParameters['Platform'] = value self.ceParameters['Architecture'] = value elif option == 'LocalSE': self.ceParameters['LocalSE'] = value.split( ', ' ) else: self.ceParameters[option] = value self._addCEConfigDefaults()
def getResourceDict( ceName = None ): """Look into LocalSite for Resource Requirements """ # FIXME: this /LocalSite/ResourceDict is probably a relic, no no idea why it's here ret = gConfig.getOptionsDict( '/LocalSite/ResourceDict' ) if not ret['OK']: resourceDict = {} else: resourceDict = dict( ret['Value'] ) # if a CE Name is given, check the corresponding section if ceName: ret = gConfig.getOptionsDict( '/LocalSite/%s/ResourceDict' % ceName ) if ret['OK']: resourceDict.update( dict( ret['Value'] ) ) # now add some defaults resourceDict['Setup'] = gConfig.getValue( '/DIRAC/Setup', 'None' ) if not 'CPUTime' in resourceDict: from DIRAC.WorkloadManagementSystem.private.Queues import maxCPUSegments resourceDict['CPUTime'] = gConfig.getValue( '/LocalSite/CPUTime', maxCPUSegments[-1] ) return resourceDict
def initialize(self, systemName, cfgPath): if self.__initialized: return self.__initialized = True from DIRAC.ConfigurationSystem.Client.Config import gConfig from os import getpid # self.__printDebug( "The configuration path is %s" % cfgPath ) # Get the options for the different output backends retDict = gConfig.getOptionsDict("%s/BackendsOptions" % cfgPath) # self.__printDebug( retDict ) if not retDict["OK"]: cfgBackOptsDict = {"FileName": "Dirac-log_%s.log" % getpid(), "Interactive": True, "SleepTime": 150} else: cfgBackOptsDict = retDict["Value"] self.__backendOptions.update(cfgBackOptsDict) if not self.__backendOptions.has_key("Filename"): self.__backendOptions["FileName"] = "Dirac-log_%s.log" % getpid() sleepTime = 150 try: sleepTime = int(self.__backendOptions["SleepTime"]) except: pass self.__backendOptions["SleepTime"] = sleepTime self.__backendOptions["Interactive"] = gConfig.getValue("%s/BackendsOptions/Interactive" % cfgPath, True) self.__backendOptions["Site"] = DIRAC.siteName() # Configure outputs desiredBackends = gConfig.getValue("%s/LogBackends" % cfgPath, "stdout") self.registerBackends(List.fromChar(desiredBackends)) # Configure verbosity defaultLevel = Logger.defaultLogLevel if "Scripts" in cfgPath: defaultLevel = gConfig.getValue("/Systems/Scripts/LogLevel", Logger.defaultLogLevel) self.setLevel(gConfig.getValue("%s/LogLevel" % cfgPath, defaultLevel)) # Configure framing self._showCallingFrame = gConfig.getValue("%s/LogShowLine" % cfgPath, self._showCallingFrame) # Get system name self._systemName = str(systemName) if not self.__backendOptions["Interactive"]: ExitCallback.registerExitCallback(self.flushAllMessages)
def __getCEParameters(self, cfgName): """Adds CE specific parameters to the resource ClassAd. """ section = cfgName options = gConfig.getOptionsDict(section) if not options["OK"]: self.log.warn(options["Message"]) return S_ERROR("Could not obtain %s section from CS" % (section)) if not options["Value"]: return S_ERROR("Empty CS section %s" % (section)) ceOptions = options["Value"] for key in ceOptions: if key in INTEGER_PARAMETERS: ceOptions[key] = int(ceOptions[key]) if key in FLOAT_PARAMETERS: ceOptions[key] = float(ceOptions[key]) self.ceParameters.update(ceOptions) return S_OK()
def __getCEParameters( self, cfgName ): """Adds CE specific parameters to the resource ClassAd. """ section = cfgName options = gConfig.getOptionsDict( section ) if not options['OK']: self.log.warn( options['Message'] ) return S_ERROR( 'Could not obtain %s section from CS' % ( section ) ) if not options['Value']: return S_ERROR( 'Empty CS section %s' % ( section ) ) ceOptions = options['Value'] for key in ceOptions: if key in INTEGER_PARAMETERS: ceOptions[key] = int( ceOptions[key] ) if key in FLOAT_PARAMETERS: ceOptions[key] = float( ceOptions[key] ) self.ceParameters.update( ceOptions ) return S_OK()
def __discoverURL( self ): #Calculate final URL try: result = self.__findServiceURL() except Exception as e: return S_ERROR( repr( e ) ) if not result[ 'OK' ]: return result self.serviceURL = result[ 'Value' ] retVal = Network.splitURL( self.serviceURL ) if not retVal[ 'OK' ]: return retVal self.__URLTuple = retVal[ 'Value' ] self._serviceName = self.__URLTuple[-1] res = gConfig.getOptionsDict( "/DIRAC/ConnConf/%s:%s" % self.__URLTuple[1:3] ) if res[ 'OK' ]: opts = res[ 'Value' ] for k in opts: if k not in self.kwargs: self.kwargs[k] = opts[k] return S_OK()
def __getCEParameters( self, cfgName ): """Adds CE specific parameters to the resource ClassAd. """ section = cfgName options = gConfig.getOptionsDict( section ) if not options['OK']: self.log.warn( options['Message'] ) return S_ERROR( 'Could not obtain %s section from CS' % ( section ) ) if not options['Value']: return S_ERROR( 'Empty CS section %s' % ( section ) ) ceOptions = options['Value'] for key in ceOptions: if key in INTEGER_PARAMETERS: ceOptions[key] = int( ceOptions[key] ) if key in FLOAT_PARAMETERS: ceOptions[key] = float( ceOptions[key] ) if key in LIST_PARAMETERS: ceOptions[key] = gConfig.getValue( os.path.join( section, key ), [] ) self.ceParameters.update( ceOptions ) return S_OK()
def __discoverURL(self): #Calculate final URL try: result = self.__findServiceURL() except Exception as e: return S_ERROR(repr(e)) if not result['OK']: return result self.serviceURL = result['Value'] retVal = Network.splitURL(self.serviceURL) if not retVal['OK']: return retVal self.__URLTuple = retVal['Value'] self._serviceName = self.__URLTuple[-1] res = gConfig.getOptionsDict("/DIRAC/ConnConf/%s:%s" % self.__URLTuple[1:3]) if res['OK']: opts = res['Value'] for k in opts: if k not in self.kwargs: self.kwargs[k] = opts[k] return S_OK()
class BaseClient: VAL_EXTRA_CREDENTIALS_HOST = "hosts" KW_USE_CERTIFICATES = "useCertificates" KW_EXTRA_CREDENTIALS = "extraCredentials" KW_TIMEOUT = "timeout" KW_SETUP = "setup" KW_VO = "VO" KW_DELEGATED_DN = "delegatedDN" KW_DELEGATED_GROUP = "delegatedGroup" KW_IGNORE_GATEWAYS = "ignoreGateways" KW_PROXY_LOCATION = "proxyLocation" KW_PROXY_STRING = "proxyString" KW_PROXY_CHAIN = "proxyChain" KW_SKIP_CA_CHECK = "skipCACheck" KW_KEEP_ALIVE_LAPSE = "keepAliveLapse" __threadConfig = ThreadConfig() def __init__( self, serviceName, **kwargs ): if type( serviceName ) not in types.StringTypes: raise TypeError( "Service name expected to be a string. Received %s type %s" % ( str( serviceName ), type( serviceName ) ) ) self._destinationSrv = serviceName self._serviceName = serviceName self.kwargs = kwargs self.__initStatus = S_OK() self.__idDict = {} self.__extraCredentials = "" self.__enableThreadCheck = False self.__retry = 0 self.__retryDelay = 0 self.__nbOfUrls = 1 #by default we always have 1 url for example: RPCClient('dips://volhcb38.cern.ch:9162/Framework/SystemAdministrator') self.__nbOfRetry = 3 # by default we try try times self.__bannedUrls = [] for initFunc in ( self.__discoverSetup, self.__discoverVO, self.__discoverTimeout, self.__discoverURL, self.__discoverCredentialsToUse, self.__checkTransportSanity, self.__setKeepAliveLapse ): result = initFunc() if not result[ 'OK' ] and self.__initStatus[ 'OK' ]: self.__initStatus = result self._initialize() #HACK for thread-safety: self.__allowedThreadID = False def _initialize( self ): pass def getDestinationService( self ): return self._destinationSrv def getServiceName( self ): return self._serviceName def __discoverSetup( self ): #Which setup to use? if self.KW_SETUP in self.kwargs and self.kwargs[ self.KW_SETUP ]: self.setup = str( self.kwargs[ self.KW_SETUP ] ) else: self.setup = self.__threadConfig.getSetup() if not self.setup: self.setup = gConfig.getValue( "/DIRAC/Setup", "Test" ) return S_OK() def __discoverVO( self ): #Which setup to use? if self.KW_VO in self.kwargs and self.kwargs[ self.KW_VO ]: self.vo = str( self.kwargs[ self.KW_VO ] ) else: self.vo = gConfig.getValue( "/DIRAC/VirtualOrganization", "unknown" ) return S_OK() def __discoverURL( self ): #Calculate final URL try: result = self.__findServiceURL() except Exception, e: return S_ERROR( str( e ) ) if not result[ 'OK' ]: return result self.serviceURL = result[ 'Value' ] retVal = Network.splitURL( self.serviceURL ) if not retVal[ 'OK' ]: return S_ERROR( "URL is malformed: %s" % retVal[ 'Message' ] ) self.__URLTuple = retVal[ 'Value' ] self._serviceName = self.__URLTuple[-1] res = gConfig.getOptionsDict( "/DIRAC/ConnConf/%s:%s" % self.__URLTuple[1:3] ) if res[ 'OK' ]: opts = res[ 'Value' ] for k in opts: if k not in self.kwargs: self.kwargs[k] = opts[k] return S_OK()
def getHelpSection( self ): helpSection = gConfig.getOptionsDict( "%s/Help" % ( self.webSection ) ) if not helpSection[ 'OK' ]: return False return helpSection[ 'Value' ]
def getDocSection( self ): docList = gConfig.getOptionsDict( "%s/Documentation" % self.webSection ) if not docList[ 'OK' ]: return "'none'" return docList[ 'Value' ]