From d2cd39d0d80f577cba6947790b33990467b1c94c Mon Sep 17 00:00:00 2001 From: BlueWall Date: Wed, 4 Apr 2012 14:15:52 -0400 Subject: [PATCH] Adding configuration management to plugins --- .../LoadRegions/LoadRegionsPlugin.cs | 3 +- .../IntegrationServiceBase.cs | 68 ++++++++++++++++--- .../IntegrationService/IntegrationUtils.cs | 29 ++++++++ .../IntegrationService/PluginManager.cs | 36 ++++++++++ prebuild.xml | 2 + 5 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 OpenSim/Services/IntegrationService/PluginManager.cs diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs index cefaf2ff15..a41a27349e 100644 --- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs +++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs @@ -135,7 +135,8 @@ namespace OpenSim.ApplicationPlugins.LoadRegions } } } - // Temporary fix for an issue after the mono-addis upgrade + + //[TODO]: Temporary fix for an issue after the mono-addis upgrade // PostInilise can fire before the region is loaded, so need to // track down the cause of that Thread.Sleep(300); diff --git a/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs b/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs index d1ffc3ec76..fa27a62a7c 100644 --- a/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs +++ b/OpenSim/Services/IntegrationService/IntegrationServiceBase.cs @@ -37,6 +37,7 @@ using GridRegion = OpenSim.Services.Interfaces.GridRegion; using Mono.Addins; using log4net; +using Ux = OpenSim.Services.IntegrationService.IUtils; [assembly:AddinRoot ("IntegrationService", "1.0")] @@ -47,9 +48,9 @@ namespace OpenSim.Services.IntegrationService { void Init(IConfigSource config); string Name{ get; } + string ConfigName { get; } } - public class IntegrationServiceBase : ServiceBase { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -59,7 +60,9 @@ namespace OpenSim.Services.IntegrationService protected IPresenceService m_PresenceService; protected IGridService m_GridService; protected IHttpServer m_Server; + protected string m_IntegrationConfig; IConfig m_IntegrationServerConfig; + string m_IntegrationConfigLoc; public IntegrationServiceBase(IConfigSource config, IHttpServer server) : base(config) @@ -73,11 +76,34 @@ namespace OpenSim.Services.IntegrationService string RegistryLocation = serverConfig.GetString("PluginRegistryLocation", "."); + // Deal with files only for now - will add url/environment later + m_IntegrationConfigLoc = serverConfig.GetString("IntegrationConfig", String.Empty); + if(String.IsNullOrEmpty(m_IntegrationConfigLoc)) + m_log.Error("[INTEGRATION SERVICE]: No IntegrationConfig defined in the Robust.ini"); + AddinManager.AddinLoaded += on_addinloaded_; AddinManager.AddinLoadError += on_addinloaderror_; m_Server = server; + m_IntegrationServerConfig = config.Configs["IntegrationService"]; + if (m_IntegrationServerConfig == null) + { + throw new Exception("[INTEGRATION SERVICE]: Missing configuration"); + return; + } + + // Add a command to the console + if (MainConsole.Instance != null) + { + MainConsole.Instance.Commands.AddCommand("Integration", true, + "show repos", + "show repos", + "Show list of registered plugin repositories", + String.Empty, + HandleShowRepos); + } + suppress_console_output_(true); AddinManager.Initialize (RegistryLocation); AddinManager.Registry.Update (); @@ -85,18 +111,16 @@ namespace OpenSim.Services.IntegrationService foreach (IntegrationPlugin cmd in AddinManager.GetExtensionObjects("/OpenSim/IntegrationService")) { - cmd.Init (config); + IConfigSource ConfigSource = Ux.GetConfigSource(m_IntegrationConfigLoc, cmd.ConfigName); + + // We maintain a configuration per-plugin to enhance modularity + // If ConfigSource is null, we will get the default from the repo + // and write it to our directory + cmd.Init (ConfigSource); server.AddStreamHandler((IRequestHandler)cmd); m_log.InfoFormat("[INTEGRATION SERVICE]: Loading IntegrationService plugin {0}", cmd.Name); } - m_IntegrationServerConfig = config.Configs["IntegrationService"]; - if (m_IntegrationServerConfig == null) - { - throw new Exception("[INTEGRATION SERVICE]: Missing configuration"); - return; - } - string gridService = m_IntegrationServerConfig.GetString("GridService", String.Empty); string presenceService = m_IntegrationServerConfig.GetString("PresenceService", String.Empty); @@ -110,6 +134,11 @@ namespace OpenSim.Services.IntegrationService } + private IConfigSource GetConfig(string configName) + { + return new IniConfigSource(); + } + private void on_addinloaderror_(object sender, AddinErrorEventArgs args) { if (args.Exception == null) @@ -140,5 +169,26 @@ namespace OpenSim.Services.IntegrationService System.Console.SetOut(prev_console_); } } + + + + + #region console handlers + private void HandleShowRepos(string module, string[] cmd) + { + if ( cmd.Length < 2 ) + { + MainConsole.Instance.Output("Syntax: show repos"); + return; + } + +// List list = m_Database.ListNames(); +// +// foreach (UserData name in list) +// { +// MainConsole.Instance.Output(String.Format("{0} {1}",name.FirstName, name.LastName)); +// } + } + #endregion } } diff --git a/OpenSim/Services/IntegrationService/IntegrationUtils.cs b/OpenSim/Services/IntegrationService/IntegrationUtils.cs index e4a78579e9..a934b2a6bc 100644 --- a/OpenSim/Services/IntegrationService/IntegrationUtils.cs +++ b/OpenSim/Services/IntegrationService/IntegrationUtils.cs @@ -27,9 +27,11 @@ using System; +using System.IO; using System.Reflection; using System.Text; using log4net; +using Nini.Config; using OpenMetaverse.StructuredData; @@ -39,6 +41,7 @@ namespace OpenSim.Services.IntegrationService { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + #region web utils public static bool ParseStringToOSDMap(string input, out OSDMap json) { try @@ -97,5 +100,31 @@ namespace OpenSim.Services.IntegrationService { return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(doc)); } + #endregion web utils + + #region config utils + public static IConfigSource GetConfigSource(string IniPath, string IniName) + { + string configFilePath = Path.GetFullPath( + Path.Combine(IniPath, IniName)); + + if (File.Exists(configFilePath)) + { + IConfigSource config = new IniConfigSource(configFilePath); + return config; + } + else + { + return new IniConfigSource(); + } + } + #endregion config utils + + public static T LoadPlugin(string dllName, Object[] args) where T:class + { + return OpenSim.Server.Base.ServerUtils.LoadPlugin(dllName, args); + + } + } } \ No newline at end of file diff --git a/OpenSim/Services/IntegrationService/PluginManager.cs b/OpenSim/Services/IntegrationService/PluginManager.cs new file mode 100644 index 0000000000..f5dfa8d89b --- /dev/null +++ b/OpenSim/Services/IntegrationService/PluginManager.cs @@ -0,0 +1,36 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * 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 OpenSimulator Project 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 DEVELOPERS ``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 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 Mono.Addins; +using Mono.Addins.Setup; + +namespace OpenSim.Services.IntegrationService +{ + + +} \ No newline at end of file diff --git a/prebuild.xml b/prebuild.xml index 7efe17ae40..2cf807ab00 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1181,6 +1181,8 @@ + +