def __init__(self): """Standard Constructor""" try: section = getDatabaseSection("WorkloadManagement/ElasticJobParametersDB") indexPrefix = gConfig.getValue("%s/IndexPrefix" % section, CSGlobals.getSetup()).lower() # Connecting to the ES cluster super(ElasticJobParametersDB, self).__init__(name, "WorkloadManagement/ElasticJobParametersDB", indexPrefix) except Exception as ex: self.log.error("Can't connect to ElasticJobParametersDB", repr(ex)) raise RuntimeError("Can't connect to ElasticJobParametersDB") self.indexName = "%s_%s" % (self.getIndexPrefix(), name.lower()) # Verifying if the index is there, and if not create it res = self.existingIndex(self.indexName) if not res["OK"] or not res["Value"]: result = self.createIndex(self.indexName, mapping, period=None) if not result["OK"]: self.log.error(result["Message"]) raise RuntimeError(result["Message"]) self.log.always("Index created:", self.indexName) self.dslSearch = self._Search(self.indexName) self.dslSearch.extra(track_total_hits=True)
def __init__(self, name='Monitoring/MonitoringDB', readOnly=False): section = getDatabaseSection("Monitoring/MonitoringDB") indexPrefix = gConfig.getValue("%s/IndexPrefix" % section, CSGlobals.getSetup()).lower() super(MonitoringDB, self).__init__('MonitoringDB', name, indexPrefix) self.__readonly = readOnly self.__documents = {} self.__loadIndexes()
def getElasticDBParameters(fullname): """ Retrieve Database parameters from CS fullname should be of the form <System>/<DBname> """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + '/Host') if not result['OK']: # No host name found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Host') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: Host') dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = 'localhost' parameters['Host'] = dbHost # Elasticsearch standard port dbPort = 9200 result = gConfig.getOption(cs_path + '/Port') if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Port') if result['OK']: dbPort = int(result['Value']) else: dbPort = int(result['Value']) parameters['Port'] = dbPort result = gConfig.getOption(cs_path + '/User') if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/User') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: User') dbUser = result['Value'] parameters['User'] = dbUser result = gConfig.getOption(cs_path + '/Password') if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Password') if not result['OK']: return S_ERROR( 'Failed to get the configuration parameter: Password') dbPass = result['Value'] parameters['Password'] = dbPass return S_OK(parameters)
def __init__(self, name='Monitoring/MonitoringDB', readOnly=False): section = getDatabaseSection("Monitoring/MonitoringDB") indexPrefix = gConfig.getValue("%s/IndexPrefix" % section, CSGlobals.getSetup()).lower() super(MonitoringDB, self).__init__('MonitoringDB', name, indexPrefix) self.__readonly = readOnly self.documentTypes = {} # loads all monitoring indexes and types. objectsLoaded = TypeLoader('Monitoring').getTypes() # Load the files for pythonClassName in sorted(objectsLoaded): typeClass = objectsLoaded[pythonClassName] indexName = "%s_%s" % (self.getIndexPrefix(), typeClass()._getIndex()) monitoringType = typeClass().__class__.__name__ mapping = typeClass().mapping monfields = typeClass().monitoringFields period = typeClass().period self.documentTypes[monitoringType] = { 'indexName': indexName, 'mapping': mapping, 'monitoringFields': monfields, 'period': period } if self.__readonly: self.log.info("Read only mode is okay") else: if self.exists("%s-*" % indexName): indexes = self.getIndexes() if indexes: actualIndexName = self.generateFullIndexName( indexName, period) if self.exists(actualIndexName): self.log.info("The index exists:", actualIndexName) else: result = self.createIndex( indexName, self.documentTypes[monitoringType]['mapping'], period) if not result['OK']: self.log.error(result['Message']) raise RuntimeError(result['Message']) self.log.info("The index is created", actualIndexName) else: # in case the index does not exist result = self.createIndex( indexName, self.documentTypes[monitoringType]['mapping'], period) if not result['OK']: self.log.error(result['Message']) raise RuntimeError(result['Message']) self.log.info("The index is created", indexName)
def __init__(self): """ Standard Constructor """ section = getDatabaseSection( "WorkloadManagement/ElasticJobParametersDB") indexPrefix = gConfig.getValue("%s/IndexPrefix" % section, CSGlobals.getSetup()).lower() # Connecting to the ES cluster super(ElasticJobParametersDB, self).__init__(name, 'WorkloadManagement/ElasticJobParametersDB', indexPrefix) self.indexName = "%s_%s" % (self.getIndexPrefix(), name.lower()) # Verifying if the index is there, and if not create it if not self.exists(self.indexName): result = self.createIndex(self.indexName, mapping, period=None) if not result['OK']: self.log.error(result['Message']) raise RuntimeError(result['Message']) self.log.always("Index created:", self.indexName) self.dslSearch = self._Search(self.indexName)
def getCSOption(self, optionName, defaultValue=None): cs_path = getDatabaseSection(self.fullname) return gConfig.getValue("/%s/%s" % (cs_path, optionName), defaultValue)
def __init__(self, name="Monitoring/MonitoringDB", readOnly=False): """Standard constructor""" try: section = getDatabaseSection("Monitoring/MonitoringDB") indexPrefix = gConfig.getValue("%s/IndexPrefix" % section, CSGlobals.getSetup()).lower() # Connecting to the ES cluster super(MonitoringDB, self).__init__(dbname=name.split("/")[1], fullName=name, indexPrefix=indexPrefix) except RuntimeError as ex: self.log.error("Can't connect to MonitoringDB", repr(ex)) raise ex self.__readonly = readOnly self.documentTypes = {} # loads all monitoring indexes and types. objectsLoaded = TypeLoader("Monitoring").getTypes() # Load the files for pythonClassName in sorted(objectsLoaded): typeClass = objectsLoaded[pythonClassName] indexName = "%s_%s" % (self.getIndexPrefix(), typeClass()._getIndex()) monitoringType = typeClass().__class__.__name__ mapping = typeClass().mapping monfields = typeClass().monitoringFields period = self.getCSOption( "MonitoringTypes/%s/Period" % monitoringType, typeClass().period) self.documentTypes[monitoringType] = { "indexName": indexName, "mapping": mapping, "monitoringFields": monfields, "period": period, } if self.__readonly: self.log.info("Read only mode: no new index will be created") else: # Verifying if the index is there, and if not create it res = self.existingIndex("%s-*" % indexName) # check with a wildcard if res["OK"] and res["Value"]: actualIndexName = self.generateFullIndexName( indexName, period) res = self.existingIndex( actualIndexName) # check actual index if not res["OK"] or not res["Value"]: result = self.createIndex( indexName, self.documentTypes[monitoringType]["mapping"], period) if not result["OK"]: self.log.error(result["Message"]) raise RuntimeError(result["Message"]) self.log.always("Index created", actualIndexName) else: # in case the index pattern does not exist result = self.createIndex( indexName, self.documentTypes[monitoringType]["mapping"], period) if not result["OK"]: self.log.error(result["Message"]) raise RuntimeError(result["Message"]) self.log.always("Index created", indexName)
def getElasticDBParameters(fullname): """ Retrieve Database parameters from CS fullname should be of the form <System>/<DBname> """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + '/Host') if not result['OK']: # No host name found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Host') if not result['OK']: gLogger.warn("Failed to get the configuration parameter: Host. Using localhost") dbHost = 'localhost' else: dbHost = result['Value'] else: dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = 'localhost' parameters['Host'] = dbHost # Elasticsearch standard port result = gConfig.getOption(cs_path + '/Port') if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Port') if not result['OK']: gLogger.warn("Failed to get the configuration parameter: Port. Using 9200") dbPort = 9200 else: dbPort = int(result['Value']) else: dbPort = int(result['Value']) parameters['Port'] = dbPort result = gConfig.getOption(cs_path + '/User') if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/User') if not result['OK']: gLogger.warn("Failed to get the configuration parameter: User. Assuming no user/password is provided/needed") dbUser = None else: dbUser = result['Value'] else: dbUser = result['Value'] parameters['User'] = dbUser result = gConfig.getOption(cs_path + '/Password') if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Password') if not result['OK']: gLogger.warn("Failed to get the configuration parameter: Password. Assuming no user/password is provided/needed") dbPass = None else: dbPass = result['Value'] else: dbPass = result['Value'] parameters['Password'] = dbPass result = gConfig.getOption(cs_path + '/SSL') if not result['OK']: # No SSL option found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/SSL') if not result['OK']: gLogger.warn("Failed to get the configuration parameter: SSL. Assuming SSL is needed") ssl = True else: ssl = False if result['Value'].lower() in ('false', 'no', 'n') else True else: ssl = False if result['Value'].lower() in ('false', 'no', 'n') else True parameters['SSL'] = ssl return S_OK(parameters)
def getDBParameters(fullname): """ Retrieve Database parameters from CS fullname should be of the form <System>/<DBname> defaultHost is the host to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultPort is the port to return if the option is not found in the CS defaultUser is the user to return if the option is not found in the CS. Not usePassword is the password to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultDB is the db to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultQueueSize is the QueueSize to return if the option is not found in the CS Returns a dictionary with the keys: 'host', 'port', 'user', 'password', 'db' and 'queueSize' """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + '/Host') if not result['OK']: # No host name found, try at the common place result = gConfig.getOption('/Systems/Databases/Host') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: Host') dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = 'localhost' parameters['Host'] = dbHost # Mysql standard dbPort = 3306 result = gConfig.getOption(cs_path + '/Port') if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption('/Systems/Databases/Port') if result['OK']: dbPort = int(result['Value']) else: dbPort = int(result['Value']) parameters['Port'] = dbPort result = gConfig.getOption(cs_path + '/User') if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption('/Systems/Databases/User') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: User') dbUser = result['Value'] parameters['User'] = dbUser result = gConfig.getOption(cs_path + '/Password') if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption('/Systems/Databases/Password') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: Password') dbPass = result['Value'] parameters['Password'] = dbPass result = gConfig.getOption(cs_path + '/DBName') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: DBName') dbName = result['Value'] parameters['DBName'] = dbName return S_OK(parameters)
def __init__( self, dbname, fullname, maxQueueSize ): self.database_name = dbname self.fullname = fullname self.cs_path = getDatabaseSection( fullname ) self.log = gLogger.getSubLogger( self.database_name ) self.dbHost = '' result = gConfig.getOption( self.cs_path + '/Host' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Host' ) return self.dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if self.dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == self.dbHost: self.dbHost = 'localhost' self.dbUser = '' result = gConfig.getOption( self.cs_path + '/User' ) if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption( '/Systems/Databases/User' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: User' ) return self.dbUser = result['Value'] self.dbPass = '' result = gConfig.getOption( self.cs_path + '/Password' ) if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption( '/Systems/Databases/Password' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Password' ) return self.dbPass = result['Value'] self.dbName = '' result = gConfig.getOption( self.cs_path + '/DBName' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: DBName' ) return self.dbName = result['Value'] self.maxQueueSize = maxQueueSize result = gConfig.getOption( self.cs_path + '/MaxQueueSize' ) if result['OK']: self.maxQueueSize = int( result['Value'] ) MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, maxQueueSize = maxQueueSize ) if not self._connected: err = 'Can not connect to DB, exiting...' self.log.fatal( err ) sys.exit( err ) self.log.info( "==================================================" ) #self.log.info("SystemInstance: "+self.system) self.log.info( "User: "******"Host: " + self.dbHost ) #self.log.info("Password: "******"DBName: " + self.dbName ) self.log.info( "MaxQueue: " + str(self.maxQueueSize) ) self.log.info( "==================================================" )
def getElasticDBParameters(fullname): """ Retrieve Database parameters from CS fullname should be of the form <System>/<DBname> """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + '/Host') if not result['OK']: # No host name found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Host') if not result['OK']: gLogger.warn( "Failed to get the configuration parameter: Host. Using localhost" ) dbHost = 'localhost' else: dbHost = result['Value'] else: dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = 'localhost' parameters['Host'] = dbHost # Elasticsearch standard port result = gConfig.getOption(cs_path + '/Port') if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Port') if not result['OK']: gLogger.warn( "No configuration parameter set for Port, assuming URL points to right location" ) dbPort = None else: dbPort = int(result['Value']) else: dbPort = int(result['Value']) parameters['Port'] = dbPort result = gConfig.getOption(cs_path + '/User') if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/User') if not result['OK']: gLogger.warn( "Failed to get the configuration parameter: User. Assuming no user/password is provided/needed" ) dbUser = None else: dbUser = result['Value'] else: dbUser = result['Value'] parameters['User'] = dbUser result = gConfig.getOption(cs_path + '/Password') if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/Password') if not result['OK']: gLogger.warn( "Failed to get the configuration parameter: Password. Assuming no user/password is provided/needed" ) dbPass = None else: dbPass = result['Value'] else: dbPass = result['Value'] parameters['Password'] = dbPass result = gConfig.getOption(cs_path + '/SSL') if not result['OK']: # No SSL option found, try at the common place result = gConfig.getOption('/Systems/NoSQLDatabases/SSL') if not result['OK']: gLogger.warn( "Failed to get the configuration parameter: SSL. Assuming SSL is needed" ) ssl = True else: ssl = False if result['Value'].lower() in ('false', 'no', 'n') else True else: ssl = False if result['Value'].lower() in ('false', 'no', 'n') else True parameters['SSL'] = ssl return S_OK(parameters)
def __init__(self, dbname, fullname, maxQueueSize, debug=False): self.database_name = dbname self.fullname = fullname self.cs_path = getDatabaseSection(fullname) self.log = gLogger.getSubLogger(self.database_name) self.dbHost = "" result = gConfig.getOption(self.cs_path + "/Host") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: Host") self.dbHost = result["Value"] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if self.dbHost != "localhost": localHostName = socket.getfqdn() if localHostName == self.dbHost: self.dbHost = "localhost" self.dbPort = 3306 result = gConfig.getOption(self.cs_path + "/Port") if not result["OK"]: # No individual port number found, try at the common place result = gConfig.getOption("/Systems/Databases/Port") if result["OK"]: self.dbPort = int(result["Value"]) else: self.dbPort = int(result["Value"]) self.dbUser = "" result = gConfig.getOption(self.cs_path + "/User") if not result["OK"]: # No individual user name found, try at the common place result = gConfig.getOption("/Systems/Databases/User") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: User") self.dbUser = result["Value"] self.dbPass = "" result = gConfig.getOption(self.cs_path + "/Password") if not result["OK"]: # No individual password found, try at the common place result = gConfig.getOption("/Systems/Databases/Password") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: Password") self.dbPass = result["Value"] self.dbName = "" result = gConfig.getOption(self.cs_path + "/DBName") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: DBName") self.dbName = result["Value"] self.maxQueueSize = maxQueueSize result = gConfig.getOption(self.cs_path + "/MaxQueueSize") if result["OK"]: self.maxQueueSize = int(result["Value"]) MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, self.dbPort, maxQueueSize=maxQueueSize, debug=debug, ) if not self._connected: raise RuntimeError("Can not connect to DB %s, exiting..." % dbname) self.log.info("==================================================") # self.log.info("SystemInstance: "+self.system) self.log.info("User: "******"Host: " + self.dbHost) self.log.info("Port: " + str(self.dbPort)) # self.log.info("Password: "******"DBName: " + self.dbName) self.log.info("MaxQueue: " + str(self.maxQueueSize)) self.log.info("==================================================")
def __init__( self, dbname, fullname, maxQueueSize ): self.database_name = dbname self.fullname = fullname self.cs_path = getDatabaseSection( fullname ) self.log = gLogger.getSubLogger( self.database_name ) self.dbHost = '' result = gConfig.getOption( self.cs_path + '/Host' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Host' ) return self.dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if self.dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == self.dbHost: self.dbHost = 'localhost' self.dbPort = 3306 result = gConfig.getOption( self.cs_path + '/Port' ) if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption( '/Systems/Databases/Port' ) if result['OK']: self.dbPort = int(result['Value']) else: self.dbPort = int(result['Value']) self.dbUser = '' result = gConfig.getOption( self.cs_path + '/User' ) if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption( '/Systems/Databases/User' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: User' ) return self.dbUser = result['Value'] self.dbPass = '' result = gConfig.getOption( self.cs_path + '/Password' ) if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption( '/Systems/Databases/Password' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Password' ) return self.dbPass = result['Value'] self.dbName = '' result = gConfig.getOption( self.cs_path + '/DBName' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: DBName' ) return self.dbName = result['Value'] self.maxQueueSize = maxQueueSize result = gConfig.getOption( self.cs_path + '/MaxQueueSize' ) if result['OK']: self.maxQueueSize = int( result['Value'] ) MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, self.dbPort, maxQueueSize = maxQueueSize ) if not self._connected: err = 'Can not connect to DB, exiting...' self.log.fatal( err ) sys.exit( err ) self.log.info( "==================================================" ) #self.log.info("SystemInstance: "+self.system) self.log.info( "User: "******"Host: " + self.dbHost ) self.log.info( "Port: " + str(self.dbPort) ) #self.log.info("Password: "******"DBName: " + self.dbName ) self.log.info( "MaxQueue: " + str(self.maxQueueSize) ) self.log.info( "==================================================" )
def getFromAddr( self ): """ Get the From address to use in proxy expiry e-mails. """ cs_path = getDatabaseSection( self.fullname ) opt_path = "/%s/%s" % ( cs_path, "FromAddr" ) return gConfig.getValue( opt_path, "*****@*****.**" )
def getDBParameters(fullname): """Retrieve Database parameters from CS :param str fullname: should be of the form <System>/<DBname> defaultHost is the host to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultPort is the port to return if the option is not found in the CS defaultUser is the user to return if the option is not found in the CS. Not usePassword is the password to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultDB is the db to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultQueueSize is the QueueSize to return if the option is not found in the CS :return: S_OK(dict)/S_ERROR() - dictionary with the keys: 'host', 'port', 'user', 'password', 'db' and 'queueSize' """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + "/Host") if not result["OK"]: # No host name found, try at the common place result = gConfig.getOption("/Systems/Databases/Host") if not result["OK"]: return S_ERROR("Failed to get the configuration parameter: Host") dbHost = result["Value"] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != "localhost": localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = "localhost" parameters["Host"] = dbHost # Mysql standard dbPort = 3306 result = gConfig.getOption(cs_path + "/Port") if not result["OK"]: # No individual port number found, try at the common place result = gConfig.getOption("/Systems/Databases/Port") if result["OK"]: dbPort = int(result["Value"]) else: dbPort = int(result["Value"]) parameters["Port"] = dbPort result = gConfig.getOption(cs_path + "/User") if not result["OK"]: # No individual user name found, try at the common place result = gConfig.getOption("/Systems/Databases/User") if not result["OK"]: return S_ERROR("Failed to get the configuration parameter: User") dbUser = result["Value"] parameters["User"] = dbUser result = gConfig.getOption(cs_path + "/Password") if not result["OK"]: # No individual password found, try at the common place result = gConfig.getOption("/Systems/Databases/Password") if not result["OK"]: return S_ERROR( "Failed to get the configuration parameter: Password") dbPass = result["Value"] parameters["Password"] = dbPass result = gConfig.getOption(cs_path + "/DBName") if not result["OK"]: return S_ERROR("Failed to get the configuration parameter: DBName") dbName = result["Value"] parameters["DBName"] = dbName return S_OK(parameters)
def getDBParameters(fullname): """ Retrieve Database parameters from CS fullname should be of the form <System>/<DBname> defaultHost is the host to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultPort is the port to return if the option is not found in the CS defaultUser is the user to return if the option is not found in the CS. Not usePassword is the password to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultDB is the db to return if the option is not found in the CS. Not used as the method will fail if it cannot be found defaultQueueSize is the QueueSize to return if the option is not found in the CS Returns a dictionary with the keys: 'host', 'port', 'user', 'password', 'db' and 'queueSize' """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + '/Host') if not result['OK']: # No host name found, try at the common place result = gConfig.getOption('/Systems/Databases/Host') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: Host') dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = 'localhost' parameters['Host'] = dbHost # Mysql standard dbPort = 3306 result = gConfig.getOption(cs_path + '/Port') if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption('/Systems/Databases/Port') if result['OK']: dbPort = int(result['Value']) else: dbPort = int(result['Value']) parameters['Port'] = dbPort result = gConfig.getOption(cs_path + '/User') if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption('/Systems/Databases/User') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: User') dbUser = result['Value'] parameters['User'] = dbUser result = gConfig.getOption(cs_path + '/Password') if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption('/Systems/Databases/Password') if not result['OK']: return S_ERROR( 'Failed to get the configuration parameter: Password') dbPass = result['Value'] parameters['Password'] = dbPass result = gConfig.getOption(cs_path + '/DBName') if not result['OK']: return S_ERROR('Failed to get the configuration parameter: DBName') dbName = result['Value'] parameters['DBName'] = dbName return S_OK(parameters)
def getElasticDBParameters(fullname): """Retrieve Database parameters from CS :param str fullname: should be of the form <System>/<DBname> :return: S_OK(dict)/S_ERROR() """ cs_path = getDatabaseSection(fullname) parameters = {} result = gConfig.getOption(cs_path + "/Host") if not result["OK"]: # No host name found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/Host") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: Host. Using localhost" ) dbHost = "localhost" else: dbHost = result["Value"] else: dbHost = result["Value"] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != "localhost": localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = "localhost" parameters["Host"] = dbHost # Elasticsearch standard port result = gConfig.getOption(cs_path + "/Port") if not result["OK"]: # No individual port number found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/Port") if not result["OK"]: gLogger.warn( "No configuration parameter set for Port, assuming URL points to right location" ) dbPort = None else: dbPort = int(result["Value"]) else: dbPort = int(result["Value"]) parameters["Port"] = dbPort result = gConfig.getOption(cs_path + "/User") if not result["OK"]: # No individual user name found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/User") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: User. Assuming no user/password is provided/needed" ) dbUser = None else: dbUser = result["Value"] else: dbUser = result["Value"] parameters["User"] = dbUser result = gConfig.getOption(cs_path + "/Password") if not result["OK"]: # No individual password found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/Password") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: Password. Assuming no user/password is provided/needed" ) dbPass = None else: dbPass = result["Value"] else: dbPass = result["Value"] parameters["Password"] = dbPass result = gConfig.getOption(cs_path + "/SSL") if not result["OK"]: # No SSL option found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/SSL") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: SSL. Assuming SSL is needed" ) ssl = True else: ssl = False if result["Value"].lower() in ("false", "no", "n") else True else: ssl = False if result["Value"].lower() in ("false", "no", "n") else True parameters["SSL"] = ssl # Elasticsearch use certs result = gConfig.getOption(cs_path + "/CRT") if not result["OK"]: # No CRT option found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/CRT") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: CRT. Using False") certs = False else: certs = result["Value"] else: certs = result["Value"] parameters["CRT"] = certs # Elasticsearch ca_certs result = gConfig.getOption(cs_path + "/ca_certs") if not result["OK"]: # No CA certificate found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/ca_certs") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: ca_certs. Using None" ) ca_certs = None else: ca_certs = result["Value"] else: ca_certs = result["Value"] parameters["ca_certs"] = ca_certs # Elasticsearch client_key result = gConfig.getOption(cs_path + "/client_key") if not result["OK"]: # No client private key found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/client_key") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: client_key. Using None" ) client_key = None else: client_key = result["Value"] else: client_key = result["Value"] parameters["client_key"] = client_key # Elasticsearch client_cert result = gConfig.getOption(cs_path + "/client_cert") if not result["OK"]: # No cient certificate found, try at the common place result = gConfig.getOption("/Systems/NoSQLDatabases/client_cert") if not result["OK"]: gLogger.warn( "Failed to get the configuration parameter: client_cert. Using None" ) client_cert = None else: client_cert = result["Value"] else: client_cert = result["Value"] parameters["client_cert"] = client_cert return S_OK(parameters)
def getCSOption(self, optionName, defaultValue=None): cs_path = getDatabaseSection(self.fullname) # pylint: disable=no-member return gConfig.getValue("/%s/%s" % (cs_path, optionName), defaultValue)
def getElasticDBParameters( fullname ): """ Retrieve Database parameters from CS fullname should be of the form <System>/<DBname> """ cs_path = getDatabaseSection( fullname ) parameters = {} result = gConfig.getOption( cs_path + '/Host' ) if not result['OK']: # No host name found, try at the common place result = gConfig.getOption( '/Systems/NoSQLDatabases/Host' ) if not result['OK']: return S_ERROR( 'Failed to get the configuration parameter: Host' ) dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == dbHost: dbHost = 'localhost' parameters[ 'Host' ] = dbHost # Elasticsearch standard port dbPort = 9200 result = gConfig.getOption( cs_path + '/Port' ) if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption( '/Systems/NoSQLDatabases/Port' ) if result['OK']: dbPort = int( result['Value'] ) else: dbPort = int( result['Value'] ) parameters[ 'Port' ] = dbPort dbuserName = None result = gConfig.getOption( cs_path + '/User' ) if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption( '/Systems/NoSQLDatabases/User' ) if result['OK']: dbuserName = result['Value'] else: dbuserName = result['Value'] if dbuserName: parameters[ 'User' ] = dbuserName dbPassword = None result = gConfig.getOption( cs_path + '/Password' ) if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption( '/Systems/NoSQLDatabases/Password' ) if result['OK']: dbPassword = result['Value'] else: dbPassword = result['Value'] if dbPassword: parameters[ 'Password' ] = dbPassword return S_OK( parameters )