From 529dd66ed01f598696ef8d20b465b911931d6fe8 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 16 Feb 2009 02:27:34 +0000 Subject: - remove dependency on ExtensionLoader.dll (DBConnString.cs can go) - bring config system in line with other servers - add new plugin filter class which filters on ID - update AssetInventoryServer.ini file --- .../AssetInventoryServer/AssetInventoryServer.cs | 155 ++++----------------- .../Extensions/DBConnString.cs | 78 ----------- .../Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 11 +- .../OpenSim/OpenSimInventoryStoragePlugin.cs | 27 ++-- .../AssetInventoryServerPlugins.addin.xml | 2 +- 5 files changed, 44 insertions(+), 229 deletions(-) delete mode 100644 OpenSim/Grid/AssetInventoryServer/Extensions/DBConnString.cs (limited to 'OpenSim/Grid/AssetInventoryServer') diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs index bd05d59..f6d46e8 100644 --- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs +++ b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs @@ -32,11 +32,6 @@ using System.Collections.Generic; using System.IO; using System.Net; using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.ServiceProcess; -using ExtensionLoader; -using ExtensionLoader.Config; -//using HttpServer; using log4net; using OpenSim.Framework; using OpenSim.Framework.Servers; @@ -44,12 +39,11 @@ using OpenSim.Framework.Console; namespace OpenSim.Grid.AssetInventoryServer { - public class AssetInventoryServer : BaseOpenSimServer//ServiceBase + public class AssetInventoryServer : BaseOpenSimServer { public const string CONFIG_FILE = "AssetInventoryServer.ini"; - //public WebServer HttpServer; - public IniConfigSource ConfigFile; + public AssetInventoryConfig ConfigFile; public IAssetStorageProvider StorageProvider; public IInventoryStorageProvider InventoryProvider; @@ -57,72 +51,39 @@ namespace OpenSim.Grid.AssetInventoryServer public IAuthorizationProvider AuthorizationProvider; public IMetricsProvider MetricsProvider; - private List frontends = new List(); - private List backends = new List(); + private List m_frontends = new List(); + private List m_backends = new List(); public AssetInventoryServer() { m_console = new ConsoleBase("Asset"); MainConsole.Instance = m_console; - //this.ServiceName = "OpenSimAssetInventoryServer"; } public bool Start() { Logger.Log.Info("Starting Asset Server"); - List extensionList = null; - int port = 0; - X509Certificate2 serverCert = null; + uint port = 0; - try { ConfigFile = new IniConfigSource(CONFIG_FILE); } + try { ConfigFile = new AssetInventoryConfig("AssetInventory Server", (Path.Combine(Util.configDir(), "AssetInventoryServer.ini"))); } catch (Exception) { Logger.Log.Error("Failed to load the config file " + CONFIG_FILE); return false; } - try - { - IConfig extensionConfig = ConfigFile.Configs["Config"]; - - // Load the port number to listen on - port = extensionConfig.GetInt("ListenPort"); - - // Load the server certificate file - string certFile = extensionConfig.GetString("SSLCertFile"); - if (!String.IsNullOrEmpty(certFile)) - serverCert = new X509Certificate2(certFile); - } - catch (Exception) - { - Logger.Log.Error("Failed to load [Config] section from " + CONFIG_FILE); - return false; - } - - try - { - // Load the extension list (and ordering) from our config file - IConfig extensionConfig = ConfigFile.Configs["Extensions"]; - extensionList = new List(extensionConfig.GetKeys()); - } - catch (Exception) - { - Logger.Log.Error("Failed to load [Extensions] section from " + CONFIG_FILE); - return false; - } - - StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider", "OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll") as IAssetStorageProvider; - backends.Add(StorageProvider); + StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider", ConfigFile.AssetStorageProvider) as IAssetStorageProvider; + m_backends.Add(StorageProvider); - InventoryProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/InventoryProvider", "OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll") as IInventoryStorageProvider; - backends.Add(InventoryProvider); + InventoryProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/InventoryProvider", ConfigFile.InventoryStorageProvider) as IInventoryStorageProvider; + m_backends.Add(InventoryProvider); - MetricsProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/MetricsProvider", String.Empty) as IMetricsProvider; - backends.Add(MetricsProvider); + MetricsProvider = LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/MetricsProvider", ConfigFile.MetricsProvider) as IMetricsProvider; + m_backends.Add(MetricsProvider); try { - InitHttpServer(port, serverCert); + InitHttpServer(ConfigFile.HttpPort); } catch (Exception ex) { @@ -131,13 +92,13 @@ namespace OpenSim.Grid.AssetInventoryServer return false; } - frontends.AddRange(LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/Frontend", String.Empty)); + AuthenticationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthenticationProvider", ConfigFile.AuthenticationProvider) as IAuthenticationProvider; + m_backends.Add(AuthenticationProvider); - AuthenticationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthenticationProvider", String.Empty) as IAuthenticationProvider; - backends.Add(AuthenticationProvider); + AuthorizationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthorizationProvider", ConfigFile.AuthorizationProvider) as IAuthorizationProvider; + m_backends.Add(AuthorizationProvider); - AuthorizationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthorizationProvider", String.Empty) as IAuthorizationProvider; - backends.Add(AuthorizationProvider); + m_frontends.AddRange(LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/Frontend", ConfigFile.Frontends)); return true; } @@ -154,7 +115,7 @@ namespace OpenSim.Grid.AssetInventoryServer public override void ShutdownSpecific() { - foreach (IAssetInventoryServerPlugin plugin in frontends) + foreach (IAssetInventoryServerPlugin plugin in m_frontends) { Logger.Log.Debug("Disposing plugin " + plugin.Name); try { plugin.Dispose(); } @@ -162,7 +123,7 @@ namespace OpenSim.Grid.AssetInventoryServer { Logger.Log.ErrorFormat("Failure shutting down plugin {0}: {1}", plugin.Name, ex.Message); } } - foreach (IAssetInventoryServerPlugin plugin in backends) + foreach (IAssetInventoryServerPlugin plugin in m_backends) { Logger.Log.Debug("Disposing plugin " + plugin.Name); try { plugin.Dispose(); } @@ -174,47 +135,14 @@ namespace OpenSim.Grid.AssetInventoryServer HttpServer.Stop(); } - void InitHttpServer(int port, X509Certificate serverCert) + void InitHttpServer(uint port) { - //if (serverCert != null) - // HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false); - //else - // HttpServer = new WebServer(IPAddress.Any, port); - - //HttpServer.LogWriter = new log4netLogWriter(Logger.Log); - - //HttpServer.Set404Handler( - // delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response) - // { - // Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery); - - // string notFoundString = "Page Not FoundThe requested page or method was not found"; - // byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString); - // response.Body.Write(buffer, 0, buffer.Length); - // response.Status = HttpStatusCode.NotFound; - // return true; - // } - //); - - m_httpServer = new BaseHttpServer(8003); - HttpServer.Start(); + m_httpServer = new BaseHttpServer(port); + m_httpServer.Start(); Logger.Log.Info("Asset server is listening on port " + port); } - #region ServiceBase Overrides - - //protected override void OnStart(string[] args) - //{ - // Start(); - //} - //protected override void OnStop() - //{ - // Shutdown(); - //} - - #endregion - private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath, string provider) { PluginLoader loader = new PluginLoader(new AssetInventoryServerPluginInitialiser(this)); @@ -222,7 +150,7 @@ namespace OpenSim.Grid.AssetInventoryServer if (provider == String.Empty) loader.Add(addinPath); else - loader.Add(addinPath, new PluginProviderFilter(provider)); + loader.Add(addinPath, new PluginIdFilter(provider)); //loader.Add(addinPath, new PluginCountConstraint(1)); loader.Load(); @@ -237,7 +165,7 @@ namespace OpenSim.Grid.AssetInventoryServer if (provider == String.Empty) loader.Add(addinPath); else - loader.Add(addinPath, new PluginProviderFilter(provider)); + loader.Add(addinPath, new PluginIdFilter(provider)); //loader.Add(addinPath, new PluginCountConstraint(1)); loader.Load(); @@ -245,37 +173,4 @@ namespace OpenSim.Grid.AssetInventoryServer return loader.Plugins; } } - - //public class log4netLogWriter : ILogWriter - //{ - // ILog Log; - - // public log4netLogWriter(ILog log) - // { - // Log = log; - // } - - // public void Write(object source, LogPrio prio, string message) - // { - // switch (prio) - // { - // case LogPrio.Trace: - // case LogPrio.Debug: - // Log.DebugFormat("{0}: {1}", source, message); - // break; - // case LogPrio.Info: - // Log.InfoFormat("{0}: {1}", source, message); - // break; - // case LogPrio.Warning: - // Log.WarnFormat("{0}: {1}", source, message); - // break; - // case LogPrio.Error: - // Log.ErrorFormat("{0}: {1}", source, message); - // break; - // case LogPrio.Fatal: - // Log.FatalFormat("{0}: {1}", source, message); - // break; - // } - // } - //} } diff --git a/OpenSim/Grid/AssetInventoryServer/Extensions/DBConnString.cs b/OpenSim/Grid/AssetInventoryServer/Extensions/DBConnString.cs deleted file mode 100644 index 78761be..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Extensions/DBConnString.cs +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2008 Intel Corporation - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * -- Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * -- Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * -- Neither the name of the Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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.Xml; -using ExtensionLoader.Config; -using MySql.Data.MySqlClient; - -namespace OpenSim.Grid.AssetInventoryServer.Extensions -{ - public static class DBConnString - { - private static string connectionString; - - /// - /// Parses the MySQL connection string out of either the asset server - /// .ini or a OpenSim-style .xml file and caches the result for future - /// requests - /// - public static string GetConnectionString(IniConfigSource configFile) - { - if (connectionString == null) - { - // Try parsing from the ini file - try - { - // Load the extension list (and ordering) from our config file - IConfig extensionConfig = configFile.Configs["MySQL"]; - connectionString = extensionConfig.GetString("database_connect", null); - } - catch (Exception) { } - - if (connectionString != null) - { - // Force MySQL's broken connection pooling off - MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(connectionString); - builder.Pooling = false; - if (String.IsNullOrEmpty(builder.Database)) - Logger.Log.Error("No database selected in the connectionString: " + connectionString); - connectionString = builder.ToString(); - } - else - { - Logger.Log.Error("Database connection string is missing, check that the database_connect line is " + - "correct and uncommented in AssetInventoryServer.ini"); - } - } - - return connectionString; - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs index e35092b..b7aef08 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs @@ -35,7 +35,6 @@ using MySql.Data.MySqlClient; using OpenMetaverse; using OpenMetaverse.StructuredData; using OpenSim.Framework; -using OpenSim.Grid.AssetInventoryServer.Extensions; using OpenSim.Data; namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim @@ -58,7 +57,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim metadata = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.AssetDatabaseConnect)) { IDataReader reader; @@ -104,7 +103,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim assetData = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.AssetDatabaseConnect)) { IDataReader reader; @@ -156,7 +155,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim { BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.AssetDatabaseConnect)) { try { @@ -205,7 +204,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim { int rowCount = 0; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.AssetDatabaseConnect)) { MySqlDataReader reader; @@ -255,7 +254,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim try { - m_assetProvider = DataPluginFactory.LoadDataPlugin("OpenSim.Data.MySQL.dll", server.ConfigFile.Configs["MySQL"].GetString("database_connect", null)); + m_assetProvider = DataPluginFactory.LoadDataPlugin("OpenSim.Data.MySQL.dll", server.ConfigFile.AssetDatabaseConnect); if (m_assetProvider == null) { Logger.Log.Error("[ASSET]: Failed to load a database plugin, server halting."); diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs index a7d2f92..0ad6c80 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs @@ -35,7 +35,6 @@ using MySql.Data.MySqlClient; using OpenMetaverse; using OpenMetaverse.StructuredData; using OpenSim.Framework; -using OpenSim.Grid.AssetInventoryServer.Extensions; using OpenSim.Data; namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim @@ -58,7 +57,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim item = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { IDataReader reader; @@ -120,7 +119,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim folder = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { IDataReader reader; @@ -167,7 +166,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim contents = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { IDataReader reader; @@ -267,7 +266,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim if (Utils.TryGetOpenSimUUID(owner, out ownerID)) { - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { IDataReader reader; @@ -333,7 +332,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim // Fetch inventory items if (Utils.TryGetOpenSimUUID(owner, out ownerID)) { - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { IDataReader reader; @@ -405,7 +404,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim if (Utils.TryGetOpenSimUUID(owner, out ownerID)) { - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { IDataReader reader; @@ -470,7 +469,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim { BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { try { @@ -537,7 +536,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim { BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { try { @@ -593,7 +592,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim if (Utils.TryGetOpenSimUUID(owner, out ownerID)) { - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { try { @@ -639,7 +638,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim if (Utils.TryGetOpenSimUUID(owner, out ownerID)) { - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { try { @@ -685,7 +684,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim if (Utils.TryGetOpenSimUUID(owner, out ownerID)) { - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { try { @@ -739,7 +738,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim { int rowCount = 0; - using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) + using (MySqlConnection dbConnection = new MySqlConnection(server.ConfigFile.InventoryDatabaseConnect)) { MySqlDataReader reader; @@ -789,7 +788,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim try { - m_inventoryProvider = DataPluginFactory.LoadDataPlugin("OpenSim.Data.MySQL.dll", server.ConfigFile.Configs["MySQL"].GetString("database_connect", null)); + m_inventoryProvider = DataPluginFactory.LoadDataPlugin("OpenSim.Data.MySQL.dll", server.ConfigFile.InventoryDatabaseConnect); if (m_inventoryProvider == null) { Logger.Log.Error("[INVENTORY]: Failed to load a database plugin, server halting."); diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml index 67c4cd2..c1e5c4d 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml @@ -8,7 +8,7 @@ - + -- cgit v1.1