* Rex Merges, Grid/AssetServer
parent
2e30c9cdc0
commit
f55bba8019
|
@ -34,20 +34,21 @@ using OpenSim.Framework;
|
|||
using OpenSim.Framework.AssetLoader.Filesystem;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Framework.Statistics;
|
||||
|
||||
namespace OpenSim.Grid.AssetServer
|
||||
{
|
||||
/// <summary>
|
||||
/// An asset server
|
||||
/// </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 static OpenAsset_Main assetserver;
|
||||
|
||||
private LogBase m_console;
|
||||
|
||||
// Temporarily hardcoded - should be a plugin
|
||||
protected IAssetLoader assetLoader = new AssetLoaderFileSystem();
|
||||
|
||||
|
@ -56,7 +57,9 @@ namespace OpenSim.Grid.AssetServer
|
|||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Starting...\n");
|
||||
log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
m_log.Info("Starting...\n");
|
||||
|
||||
assetserver = new OpenAsset_Main();
|
||||
assetserver.Startup();
|
||||
|
@ -70,34 +73,32 @@ namespace OpenSim.Grid.AssetServer
|
|||
|
||||
while (true)
|
||||
{
|
||||
m_console.MainLogPrompt();
|
||||
m_console.Prompt();
|
||||
}
|
||||
}
|
||||
|
||||
private OpenAsset_Main()
|
||||
{
|
||||
if (!Directory.Exists(Util.logDir()))
|
||||
{
|
||||
Directory.CreateDirectory(Util.logDir());
|
||||
}
|
||||
m_console =
|
||||
new LogBase((Path.Combine(Util.logDir(), "opengrid-AssetServer-console.log")), "OpenAsset", this, true);
|
||||
MainLog.Instance = m_console;
|
||||
m_console = new ConsoleBase("OpenAsset", this);
|
||||
|
||||
MainConsole.Instance = m_console;
|
||||
}
|
||||
|
||||
public void Startup()
|
||||
{
|
||||
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);
|
||||
|
||||
m_console.Verbose("ASSET", "Loading default asset set..");
|
||||
m_log.Info("[ASSET]: Loading default asset set..");
|
||||
LoadDefaultAssets();
|
||||
|
||||
m_console.Verbose("ASSET", "Starting HTTP process");
|
||||
m_log.Info("[ASSET]: Starting HTTP process");
|
||||
BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
|
||||
|
||||
StatsManager.StartCollectingAssetStats();
|
||||
|
||||
httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider));
|
||||
httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider));
|
||||
|
||||
|
@ -111,7 +112,7 @@ namespace OpenSim.Grid.AssetServer
|
|||
|
||||
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);
|
||||
IAssetProvider assetPlugin = null;
|
||||
foreach (Type pluginType in pluginAssembly.GetTypes())
|
||||
|
@ -127,7 +128,7 @@ namespace OpenSim.Grid.AssetServer
|
|||
assetPlugin = plug;
|
||||
assetPlugin.Initialise();
|
||||
|
||||
MainLog.Instance.Verbose("ASSET SERVER", "Added " + assetPlugin.Name + " " + assetPlugin.Version);
|
||||
m_log.Info("[ASSET SERVER]: Added " + assetPlugin.Name + " " + assetPlugin.Version);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -146,14 +147,14 @@ namespace OpenSim.Grid.AssetServer
|
|||
m_assetProvider = LoadDatabasePlugin(config.DatabaseProvider);
|
||||
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);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainLog.Instance.Warn("ASSET", "setupDB() - Exception occured");
|
||||
MainLog.Instance.Warn("ASSET", e.ToString());
|
||||
m_log.Warn("[ASSET]: setupDB() - Exception occured");
|
||||
m_log.Warn("[ASSET]: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,12 +168,21 @@ namespace OpenSim.Grid.AssetServer
|
|||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
case "shutdown":
|
||||
|
@ -181,9 +191,5 @@ namespace OpenSim.Grid.AssetServer
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(string ShowWhat)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly : AssemblyConfiguration("")]
|
||||
[assembly : AssemblyCompany("")]
|
||||
[assembly : AssemblyProduct("OGS-AssetServer")]
|
||||
[assembly : AssemblyCopyright("Copyright © 2007")]
|
||||
[assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")]
|
||||
[assembly : AssemblyTrademark("")]
|
||||
[assembly : AssemblyCulture("")]
|
||||
|
||||
|
|
|
@ -35,17 +35,32 @@ using libsecondlife;
|
|||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Framework.Statistics;
|
||||
|
||||
namespace OpenSim.Grid.AssetServer
|
||||
{
|
||||
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 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)
|
||||
{
|
||||
MainLog.Instance.Verbose("REST", "In Handle");
|
||||
string param = GetParam(path);
|
||||
byte[] result = new byte[] {};
|
||||
try
|
||||
|
@ -54,14 +69,21 @@ namespace OpenSim.Grid.AssetServer
|
|||
|
||||
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);
|
||||
if (asset != null)
|
||||
{
|
||||
MainLog.Instance.Verbose("REST", "GET:/asset found {0}, {1}", assetID, asset.Name);
|
||||
|
||||
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
||||
|
@ -70,36 +92,37 @@ namespace OpenSim.Grid.AssetServer
|
|||
xw.Flush();
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
StreamReader sr = new StreamReader(ms);
|
||||
//StreamReader sr = new StreamReader(ms);
|
||||
|
||||
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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
MainLog.Instance.Error(e.ToString());
|
||||
m_log.Error(e.ToString());
|
||||
}
|
||||
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
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private OpenAsset_Main m_assetManager;
|
||||
private IAssetProvider m_assetProvider;
|
||||
|
||||
|
@ -115,7 +138,7 @@ namespace OpenSim.Grid.AssetServer
|
|||
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||
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.CommitAssets();
|
||||
|
||||
|
|
Loading…
Reference in New Issue