* Rex Merges, Grid/AssetServer
parent
2e30c9cdc0
commit
f55bba8019
|
@ -34,20 +34,21 @@ using OpenSim.Framework;
|
||||||
using OpenSim.Framework.AssetLoader.Filesystem;
|
using OpenSim.Framework.AssetLoader.Filesystem;
|
||||||
using OpenSim.Framework.Console;
|
using OpenSim.Framework.Console;
|
||||||
using OpenSim.Framework.Servers;
|
using OpenSim.Framework.Servers;
|
||||||
|
using OpenSim.Framework.Statistics;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetServer
|
namespace OpenSim.Grid.AssetServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An asset server
|
/// An asset server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpenAsset_Main : conscmd_callback
|
public class OpenAsset_Main : BaseOpenSimServer, conscmd_callback
|
||||||
{
|
{
|
||||||
|
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
public AssetConfig m_config;
|
public AssetConfig m_config;
|
||||||
|
|
||||||
public static OpenAsset_Main assetserver;
|
public static OpenAsset_Main assetserver;
|
||||||
|
|
||||||
private LogBase m_console;
|
|
||||||
|
|
||||||
// Temporarily hardcoded - should be a plugin
|
// Temporarily hardcoded - should be a plugin
|
||||||
protected IAssetLoader assetLoader = new AssetLoaderFileSystem();
|
protected IAssetLoader assetLoader = new AssetLoaderFileSystem();
|
||||||
|
|
||||||
|
@ -56,7 +57,9 @@ namespace OpenSim.Grid.AssetServer
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Starting...\n");
|
log4net.Config.XmlConfigurator.Configure();
|
||||||
|
|
||||||
|
m_log.Info("Starting...\n");
|
||||||
|
|
||||||
assetserver = new OpenAsset_Main();
|
assetserver = new OpenAsset_Main();
|
||||||
assetserver.Startup();
|
assetserver.Startup();
|
||||||
|
@ -70,34 +73,32 @@ namespace OpenSim.Grid.AssetServer
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
m_console.MainLogPrompt();
|
m_console.Prompt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OpenAsset_Main()
|
private OpenAsset_Main()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(Util.logDir()))
|
m_console = new ConsoleBase("OpenAsset", this);
|
||||||
{
|
|
||||||
Directory.CreateDirectory(Util.logDir());
|
MainConsole.Instance = m_console;
|
||||||
}
|
|
||||||
m_console =
|
|
||||||
new LogBase((Path.Combine(Util.logDir(), "opengrid-AssetServer-console.log")), "OpenAsset", this, true);
|
|
||||||
MainLog.Instance = m_console;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Startup()
|
public void Startup()
|
||||||
{
|
{
|
||||||
m_config = new AssetConfig("ASSET SERVER", (Path.Combine(Util.configDir(), "AssetServer_Config.xml")));
|
m_config = new AssetConfig("ASSET SERVER", (Path.Combine(Util.configDir(), "AssetServer_Config.xml")));
|
||||||
|
|
||||||
m_console.Verbose("ASSET", "Setting up asset DB");
|
m_log.Info("[ASSET]: Setting up asset DB");
|
||||||
setupDB(m_config);
|
setupDB(m_config);
|
||||||
|
|
||||||
m_console.Verbose("ASSET", "Loading default asset set..");
|
m_log.Info("[ASSET]: Loading default asset set..");
|
||||||
LoadDefaultAssets();
|
LoadDefaultAssets();
|
||||||
|
|
||||||
m_console.Verbose("ASSET", "Starting HTTP process");
|
m_log.Info("[ASSET]: Starting HTTP process");
|
||||||
BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
|
BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
|
||||||
|
|
||||||
|
StatsManager.StartCollectingAssetStats();
|
||||||
|
|
||||||
httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider));
|
httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider));
|
||||||
httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider));
|
httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider));
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ namespace OpenSim.Grid.AssetServer
|
||||||
|
|
||||||
public IAssetProvider LoadDatabasePlugin(string FileName)
|
public IAssetProvider LoadDatabasePlugin(string FileName)
|
||||||
{
|
{
|
||||||
MainLog.Instance.Verbose("ASSET SERVER", "LoadDatabasePlugin: Attempting to load " + FileName);
|
m_log.Info("[ASSET SERVER]: LoadDatabasePlugin: Attempting to load " + FileName);
|
||||||
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
|
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
|
||||||
IAssetProvider assetPlugin = null;
|
IAssetProvider assetPlugin = null;
|
||||||
foreach (Type pluginType in pluginAssembly.GetTypes())
|
foreach (Type pluginType in pluginAssembly.GetTypes())
|
||||||
|
@ -127,7 +128,7 @@ namespace OpenSim.Grid.AssetServer
|
||||||
assetPlugin = plug;
|
assetPlugin = plug;
|
||||||
assetPlugin.Initialise();
|
assetPlugin.Initialise();
|
||||||
|
|
||||||
MainLog.Instance.Verbose("ASSET SERVER", "Added " + assetPlugin.Name + " " + assetPlugin.Version);
|
m_log.Info("[ASSET SERVER]: Added " + assetPlugin.Name + " " + assetPlugin.Version);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,14 +147,14 @@ namespace OpenSim.Grid.AssetServer
|
||||||
m_assetProvider = LoadDatabasePlugin(config.DatabaseProvider);
|
m_assetProvider = LoadDatabasePlugin(config.DatabaseProvider);
|
||||||
if (m_assetProvider == null)
|
if (m_assetProvider == null)
|
||||||
{
|
{
|
||||||
MainLog.Instance.Error("ASSET", "Failed to load a database plugin, server halting");
|
m_log.Error("[ASSET]: Failed to load a database plugin, server halting");
|
||||||
Environment.Exit(-1);
|
Environment.Exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MainLog.Instance.Warn("ASSET", "setupDB() - Exception occured");
|
m_log.Warn("[ASSET]: setupDB() - Exception occured");
|
||||||
MainLog.Instance.Warn("ASSET", e.ToString());
|
m_log.Warn("[ASSET]: " + e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,12 +168,21 @@ namespace OpenSim.Grid.AssetServer
|
||||||
m_assetProvider.CreateAsset(asset);
|
m_assetProvider.CreateAsset(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RunCmd(string cmd, string[] cmdparams)
|
public override void RunCmd(string cmd, string[] cmdparams)
|
||||||
{
|
{
|
||||||
|
base.RunCmd(cmd, cmdparams);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case "help":
|
case "help":
|
||||||
m_console.Notice("shutdown - shutdown this asset server (USE CAUTION!)");
|
m_console.Notice(
|
||||||
|
@"shutdown - shutdown this asset server (USE CAUTION!)
|
||||||
|
stats - statistical information for this server");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "stats":
|
||||||
|
m_console.Notice("STATS", Environment.NewLine + StatsManager.AssetStats.Report());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "shutdown":
|
case "shutdown":
|
||||||
|
@ -181,9 +191,5 @@ namespace OpenSim.Grid.AssetServer
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Show(string ShowWhat)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
|
||||||
[assembly : AssemblyConfiguration("")]
|
[assembly : AssemblyConfiguration("")]
|
||||||
[assembly : AssemblyCompany("")]
|
[assembly : AssemblyCompany("")]
|
||||||
[assembly : AssemblyProduct("OGS-AssetServer")]
|
[assembly : AssemblyProduct("OGS-AssetServer")]
|
||||||
[assembly : AssemblyCopyright("Copyright © 2007")]
|
[assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")]
|
||||||
[assembly : AssemblyTrademark("")]
|
[assembly : AssemblyTrademark("")]
|
||||||
[assembly : AssemblyCulture("")]
|
[assembly : AssemblyCulture("")]
|
||||||
|
|
||||||
|
|
|
@ -35,17 +35,32 @@ using libsecondlife;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Framework.Console;
|
using OpenSim.Framework.Console;
|
||||||
using OpenSim.Framework.Servers;
|
using OpenSim.Framework.Servers;
|
||||||
|
using OpenSim.Framework.Statistics;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetServer
|
namespace OpenSim.Grid.AssetServer
|
||||||
{
|
{
|
||||||
public class GetAssetStreamHandler : BaseStreamHandler
|
public class GetAssetStreamHandler : BaseStreamHandler
|
||||||
{
|
{
|
||||||
|
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private OpenAsset_Main m_assetManager;
|
private OpenAsset_Main m_assetManager;
|
||||||
private IAssetProvider m_assetProvider;
|
private IAssetProvider m_assetProvider;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetManager"></param>
|
||||||
|
/// <param name="assetProvider"></param>
|
||||||
|
public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
|
||||||
|
: base("GET", "/assets")
|
||||||
|
{
|
||||||
|
m_log.Info("[REST]: In Get Request");
|
||||||
|
m_assetManager = assetManager;
|
||||||
|
m_assetProvider = assetProvider;
|
||||||
|
}
|
||||||
|
|
||||||
public override byte[] Handle(string path, Stream request)
|
public override byte[] Handle(string path, Stream request)
|
||||||
{
|
{
|
||||||
MainLog.Instance.Verbose("REST", "In Handle");
|
|
||||||
string param = GetParam(path);
|
string param = GetParam(path);
|
||||||
byte[] result = new byte[] {};
|
byte[] result = new byte[] {};
|
||||||
try
|
try
|
||||||
|
@ -54,14 +69,21 @@ namespace OpenSim.Grid.AssetServer
|
||||||
|
|
||||||
if (p.Length > 0)
|
if (p.Length > 0)
|
||||||
{
|
{
|
||||||
LLUUID assetID = LLUUID.Parse(p[0]);
|
LLUUID assetID = null;
|
||||||
|
|
||||||
|
if (!LLUUID.TryParse(p[0], out assetID))
|
||||||
|
{
|
||||||
|
m_log.InfoFormat(
|
||||||
|
"[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StatsManager.AssetStats != null)
|
||||||
|
StatsManager.AssetStats.AddRequest();
|
||||||
|
|
||||||
MainLog.Instance.Verbose("REST", "GET:/asset fetch param={0} UUID={1}", param, assetID);
|
|
||||||
AssetBase asset = m_assetProvider.FetchAsset(assetID);
|
AssetBase asset = m_assetProvider.FetchAsset(assetID);
|
||||||
if (asset != null)
|
if (asset != null)
|
||||||
{
|
{
|
||||||
MainLog.Instance.Verbose("REST", "GET:/asset found {0}, {1}", assetID, asset.Name);
|
|
||||||
|
|
||||||
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
||||||
|
@ -70,36 +92,37 @@ namespace OpenSim.Grid.AssetServer
|
||||||
xw.Flush();
|
xw.Flush();
|
||||||
|
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
StreamReader sr = new StreamReader(ms);
|
//StreamReader sr = new StreamReader(ms);
|
||||||
|
|
||||||
result = ms.GetBuffer();
|
result = ms.GetBuffer();
|
||||||
MainLog.Instance.Verbose("REST", "Buffer: {0}", result);
|
|
||||||
|
m_log.InfoFormat(
|
||||||
|
"[REST]: GET:/asset found {0} with name {1}, size {2} bytes",
|
||||||
|
assetID, asset.Name, result.Length);
|
||||||
|
|
||||||
Array.Resize<byte>(ref result, (int) ms.Length);
|
Array.Resize<byte>(ref result, (int) ms.Length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MainLog.Instance.Verbose("REST", "GET:/asset failed to find {0}", assetID);
|
if (StatsManager.AssetStats != null)
|
||||||
|
StatsManager.AssetStats.AddNotFoundRequest();
|
||||||
|
|
||||||
|
m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MainLog.Instance.Error(e.ToString());
|
m_log.Error(e.ToString());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
|
|
||||||
: base("GET", "/assets")
|
|
||||||
{
|
|
||||||
MainLog.Instance.Verbose("REST", "In Get Request");
|
|
||||||
m_assetManager = assetManager;
|
|
||||||
m_assetProvider = assetProvider;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PostAssetStreamHandler : BaseStreamHandler
|
public class PostAssetStreamHandler : BaseStreamHandler
|
||||||
{
|
{
|
||||||
|
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private OpenAsset_Main m_assetManager;
|
private OpenAsset_Main m_assetManager;
|
||||||
private IAssetProvider m_assetProvider;
|
private IAssetProvider m_assetProvider;
|
||||||
|
|
||||||
|
@ -115,7 +138,7 @@ namespace OpenSim.Grid.AssetServer
|
||||||
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||||
AssetBase asset = (AssetBase) xs.Deserialize(request);
|
AssetBase asset = (AssetBase) xs.Deserialize(request);
|
||||||
|
|
||||||
MainLog.Instance.Verbose("REST", "StoreAndCommitAsset {0}", asset.FullID);
|
m_log.InfoFormat("[REST]: StoreAndCommitAsset {0}", asset.FullID);
|
||||||
m_assetProvider.CreateAsset(asset);
|
m_assetProvider.CreateAsset(asset);
|
||||||
m_assetProvider.CommitAssets();
|
m_assetProvider.CommitAssets();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue