From 89c164fbc18e082bf2d036bd2167b824e90aebc1 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 28 May 2008 17:59:46 +0000 Subject: let Grid Servers specify a connect string in their configuration. --- OpenSim/Data/GridDataBase.cs | 2 +- OpenSim/Data/IGridData.cs | 2 +- OpenSim/Data/ILogData.cs | 2 +- OpenSim/Data/MSSQL/MSSQLGridData.cs | 3 ++- OpenSim/Data/MSSQL/MSSQLLogData.cs | 3 ++- OpenSim/Data/MySQL/MySQLGridData.cs | 29 +++++++++++++++----------- OpenSim/Data/MySQL/MySQLLogData.cs | 34 ++++++++++++++++++++----------- OpenSim/Data/SQLite/SQLiteGridData.cs | 4 ++-- OpenSim/Data/SQLite/SQLiteManager.cs | 14 +++++++++++-- OpenSim/Framework/GridConfig.cs | 6 ++++++ OpenSim/Grid/GridServer/GridManager.cs | 6 +++--- OpenSim/Grid/GridServer/GridServerBase.cs | 2 +- 12 files changed, 70 insertions(+), 37 deletions(-) diff --git a/OpenSim/Data/GridDataBase.cs b/OpenSim/Data/GridDataBase.cs index 036e2eb..0c9d24a 100644 --- a/OpenSim/Data/GridDataBase.cs +++ b/OpenSim/Data/GridDataBase.cs @@ -36,7 +36,7 @@ namespace OpenSim.Data public abstract RegionProfileData GetProfileByString(string regionName); public abstract RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax); public abstract bool AuthenticateSim(LLUUID UUID, ulong regionHandle, string simrecvkey); - public abstract void Initialise(); + public abstract void Initialise(string connect); public abstract void Close(); public abstract string getName(); public abstract string getVersion(); diff --git a/OpenSim/Data/IGridData.cs b/OpenSim/Data/IGridData.cs index b2a8d26..e242312 100644 --- a/OpenSim/Data/IGridData.cs +++ b/OpenSim/Data/IGridData.cs @@ -86,7 +86,7 @@ namespace OpenSim.Data /// /// Initialises the interface /// - void Initialise(); + void Initialise(string connect); /// /// Closes the interface diff --git a/OpenSim/Data/ILogData.cs b/OpenSim/Data/ILogData.cs index a533c87..7275637 100644 --- a/OpenSim/Data/ILogData.cs +++ b/OpenSim/Data/ILogData.cs @@ -69,7 +69,7 @@ namespace OpenSim.Data /// /// Initialises the interface /// - void Initialise(); + void Initialise(string connect); /// /// Closes the interface diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs index 0bdd460..d7adb84 100644 --- a/OpenSim/Data/MSSQL/MSSQLGridData.cs +++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs @@ -53,8 +53,9 @@ namespace OpenSim.Data.MSSQL /// /// Initialises the Grid Interface /// - override public void Initialise() + override public void Initialise(string connect) { + // TODO: make the connect string actually do something IniFile iniFile = new IniFile("mssql_connection.ini"); string settingDataSource = iniFile.ParseFileReadValue("data_source"); diff --git a/OpenSim/Data/MSSQL/MSSQLLogData.cs b/OpenSim/Data/MSSQL/MSSQLLogData.cs index 2bb5839..c75290e 100644 --- a/OpenSim/Data/MSSQL/MSSQLLogData.cs +++ b/OpenSim/Data/MSSQL/MSSQLLogData.cs @@ -43,8 +43,9 @@ namespace OpenSim.Data.MSSQL /// /// Artificial constructor called when the plugin is loaded /// - public void Initialise() + public void Initialise(string connect) { + // TODO: do something with the connect string IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); diff --git a/OpenSim/Data/MySQL/MySQLGridData.cs b/OpenSim/Data/MySQL/MySQLGridData.cs index e830133..421c283 100644 --- a/OpenSim/Data/MySQL/MySQLGridData.cs +++ b/OpenSim/Data/MySQL/MySQLGridData.cs @@ -51,19 +51,24 @@ namespace OpenSim.Data.MySQL /// /// Initialises the Grid Interface /// - override public void Initialise() + override public void Initialise(string connect) { - IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); - string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); - string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); - string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); - string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); - string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); - - database = - new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, - settingPort); + if (connect != String.Empty) { + database = new MySQLManager(connect); + } else { + m_log.Warn("Using deprecated mysql_connection.ini. Please update database_connect in GridServer_Config.xml and we'll use that instead"); + IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); + string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); + string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); + string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); + string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); + string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); + string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); + + database = + new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, + settingPort); + } TestTables(); } diff --git a/OpenSim/Data/MySQL/MySQLLogData.cs b/OpenSim/Data/MySQL/MySQLLogData.cs index bb34d34..0873066 100644 --- a/OpenSim/Data/MySQL/MySQLLogData.cs +++ b/OpenSim/Data/MySQL/MySQLLogData.cs @@ -24,6 +24,9 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; +using System.Reflection; +using log4net; namespace OpenSim.Data.MySQL { @@ -31,7 +34,8 @@ namespace OpenSim.Data.MySQL /// An interface to the log database for MySQL /// internal class MySQLLogData : ILogData - { + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); /// /// The database manager /// @@ -40,19 +44,25 @@ namespace OpenSim.Data.MySQL /// /// Artificial constructor called when the plugin is loaded /// - public void Initialise() + public void Initialise(string connect) { - IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); - string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); - string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); - string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); - string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); - string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); + if (connect != String.Empty) { + database = new MySQLManager(connect); + } else { + m_log.Warn("Using deprecated mysql_connection.ini. Please update database_connect in GridServer_Config.xml and we'll use that instead"); - database = - new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, - settingPort); + IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); + string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); + string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); + string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); + string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); + string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); + string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); + + database = + new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, + settingPort); + } } /// diff --git a/OpenSim/Data/SQLite/SQLiteGridData.cs b/OpenSim/Data/SQLite/SQLiteGridData.cs index 989ec77..7c5bb0c 100644 --- a/OpenSim/Data/SQLite/SQLiteGridData.cs +++ b/OpenSim/Data/SQLite/SQLiteGridData.cs @@ -48,9 +48,9 @@ namespace OpenSim.Data.SQLite /// /// Initialises the Grid Interface /// - override public void Initialise() + override public void Initialise(string connect) { - database = new SQLiteManager("localhost", "db", "user", "password", "false"); + database = new SQLiteManager(connect); } /// diff --git a/OpenSim/Data/SQLite/SQLiteManager.cs b/OpenSim/Data/SQLite/SQLiteManager.cs index e1d2cdf..4d39527 100644 --- a/OpenSim/Data/SQLite/SQLiteManager.cs +++ b/OpenSim/Data/SQLite/SQLiteManager.cs @@ -49,11 +49,21 @@ namespace OpenSim.Data.SQLite /// The username logging into the database /// The password for the user logging in /// Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'. - public SQLiteManager(string hostname, string database, string username, string password, string cpooling) + public SQLiteManager(string connect) { try { - string connectionString = "URI=file:GridServerSqlite.db;"; + string connectionString = String.Empty; + if (connect != String.Empty) + { + connectionString = connect; + } + else + { + m_log.Warn("[SQLITE] grid db not specified, using default"); + connectionString = "URI=file:GridServerSqlite.db;"; + } + dbcon = new SQLiteConnection(connectionString); dbcon.Open(); diff --git a/OpenSim/Framework/GridConfig.cs b/OpenSim/Framework/GridConfig.cs index f0cf91f..e405b26 100644 --- a/OpenSim/Framework/GridConfig.cs +++ b/OpenSim/Framework/GridConfig.cs @@ -39,6 +39,7 @@ namespace OpenSim.Framework private ConfigurationMember configMember; public string DatabaseProvider = String.Empty; + public string DatabaseConnect = String.Empty; public string DefaultAssetServer = String.Empty; public string DefaultUserServer = String.Empty; public string GridOwner = String.Empty; @@ -85,6 +86,8 @@ namespace OpenSim.Framework "Key to expect from a simulator", "null", false); configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING, "DLL for database provider", "OpenSim.Data.MySQL.dll", false); + configMember.addConfigurationOption("database_connect", ConfigurationOption.ConfigurationTypes.TYPE_STRING, + "Database connect string", "", false); configMember.addConfigurationOption("http_port", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Http Listener port", DefaultHttpPort.ToString(), false); @@ -128,6 +131,9 @@ namespace OpenSim.Framework case "database_provider": DatabaseProvider = (string) configuration_result; break; + case "database_connect": + DatabaseConnect = (string) configuration_result; + break; case "http_port": HttpPort = (uint) configuration_result; break; diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs index d0eec32..2933f04 100644 --- a/OpenSim/Grid/GridServer/GridManager.cs +++ b/OpenSim/Grid/GridServer/GridManager.cs @@ -58,7 +58,7 @@ namespace OpenSim.Grid.GridServer /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. /// /// The filename to the grid server plugin DLL - public void AddPlugin(string FileName) + public void AddPlugin(string FileName, string Connect) { m_log.Info("[DATA]: Attempting to load " + FileName); Assembly pluginAssembly = Assembly.LoadFrom(FileName); @@ -75,7 +75,7 @@ namespace OpenSim.Grid.GridServer { IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(); + plug.Initialise(Connect); _plugins.Add(plug.getName(), plug); m_log.Info("[DATA]: Added IGridData Interface"); } @@ -87,7 +87,7 @@ namespace OpenSim.Grid.GridServer { ILogData plug = (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(); + plug.Initialise(Connect); _logplugins.Add(plug.getName(), plug); m_log.Info("[DATA]: Added ILogData Interface"); } diff --git a/OpenSim/Grid/GridServer/GridServerBase.cs b/OpenSim/Grid/GridServer/GridServerBase.cs index 4e29cbf..263866a 100644 --- a/OpenSim/Grid/GridServer/GridServerBase.cs +++ b/OpenSim/Grid/GridServer/GridServerBase.cs @@ -135,7 +135,7 @@ namespace OpenSim.Grid.GridServer { m_log.Info("[DATA]: Connecting to Storage Server"); m_gridManager = new GridManager(); - m_gridManager.AddPlugin(m_config.DatabaseProvider); + m_gridManager.AddPlugin(m_config.DatabaseProvider, m_config.DatabaseConnect); m_gridManager.Config = m_config; } -- cgit v1.1