Adding configuration management to plugins

integration
BlueWall 2012-04-04 14:15:52 -04:00
parent a4cb9639cc
commit d2cd39d0d8
5 changed files with 128 additions and 10 deletions

View File

@ -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);

View File

@ -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<UserData> list = m_Database.ListNames();
//
// foreach (UserData name in list)
// {
// MainConsole.Instance.Output(String.Format("{0} {1}",name.FirstName, name.LastName));
// }
}
#endregion
}
}

View File

@ -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<T>(string dllName, Object[] args) where T:class
{
return OpenSim.Server.Base.ServerUtils.LoadPlugin<T>(dllName, args);
}
}
}

View File

@ -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
{
}

View File

@ -1181,6 +1181,8 @@
<Reference name="Nini" path="../../../bin/"/>
<Reference name="log4net" path="../../../bin/"/>
<Reference name="Mono.Addins" path="../../../bin/"/>
<Reference name="Mono.Addins.Setup" path="../../../bin/"/>
<Reference name="Mono.Addins" path="../../../bin/"/>
<Files>
<Match pattern="*.cs" recurse="true"/>