- implement and load NullMetrics module in AssetInventoryServer
- update AssetBase de/serialization in AssetInventoryServer0.6.3-post-fixes
parent
98b5e5062e
commit
dbee7fcb21
|
@ -106,41 +106,8 @@ namespace OpenSim.Grid.AssetInventoryServer
|
|||
return false;
|
||||
}
|
||||
|
||||
//try
|
||||
//{
|
||||
// // Create a reference list for C# extensions compiled at runtime
|
||||
// List<string> references = new List<string>();
|
||||
// references.Add("OpenMetaverseTypes.dll");
|
||||
// references.Add("OpenMetaverse.dll");
|
||||
// references.Add("OpenMetaverse.StructuredData.dll");
|
||||
// references.Add("OpenMetaverse.Http.dll");
|
||||
// references.Add("ExtensionLoader.dll");
|
||||
// references.Add("AssetServer.exe");
|
||||
|
||||
// // Get a list of all of the members of AssetServer that are interfaces
|
||||
// List<FieldInfo> assignables = ExtensionLoader<AssetServer>.GetInterfaces(this);
|
||||
|
||||
// // Load all of the extensions
|
||||
// ExtensionLoader<AssetServer>.LoadAllExtensions(
|
||||
// Assembly.GetExecutingAssembly(),
|
||||
// Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||
// extensionList,
|
||||
// references,
|
||||
// "AssetServer.*.dll",
|
||||
// "AssetServer.*.cs",
|
||||
// this,
|
||||
// assignables);
|
||||
//}
|
||||
//catch (ExtensionException ex)
|
||||
//{
|
||||
// Logger.Log.Error("Interface loading failed, shutting down: " + ex.Message);
|
||||
// if (ex.InnerException != null)
|
||||
// Logger.Log.Error(ex.InnerException.Message, ex.InnerException);
|
||||
// Stop();
|
||||
// return false;
|
||||
//}
|
||||
|
||||
StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider") as IAssetStorageProvider;
|
||||
MetricsProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/MetricsProvider") as IMetricsProvider;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -155,13 +122,6 @@ namespace OpenSim.Grid.AssetInventoryServer
|
|||
|
||||
frontend = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/Frontend");
|
||||
|
||||
// Start all of the extensions
|
||||
//foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
|
||||
//{
|
||||
// Logger.Log.Info("Starting extension " + extension.GetType().Name);
|
||||
// extension.Start(this);
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,12 @@ namespace OpenSim.Grid.AssetInventoryServer
|
|||
{
|
||||
private AssetInventoryServer server;
|
||||
|
||||
public AssetInventoryServerPluginInitialiser (AssetInventoryServer server)
|
||||
public AssetInventoryServerPluginInitialiser(AssetInventoryServer server)
|
||||
{
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public override void Initialise (IPlugin plugin)
|
||||
public override void Initialise(IPlugin plugin)
|
||||
{
|
||||
IAssetInventoryServerPlugin p = plugin as IAssetInventoryServerPlugin;
|
||||
p.Initialise (server);
|
||||
|
@ -136,7 +136,7 @@ namespace OpenSim.Grid.AssetInventoryServer
|
|||
bool IsInventoryWriteAuthorized(UUID authToken, Uri owner);
|
||||
}
|
||||
|
||||
public interface IMetricsProvider
|
||||
public interface IMetricsProvider : IAssetInventoryServerPlugin
|
||||
{
|
||||
void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time);
|
||||
void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time);
|
||||
|
|
|
@ -28,12 +28,11 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using ExtensionLoader;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenSim.Grid.AssetInventoryServer.Extensions
|
||||
namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||
{
|
||||
public class NullMetrics : IExtension<AssetInventoryServer>, IMetricsProvider
|
||||
public class NullMetrics : IMetricsProvider
|
||||
{
|
||||
AssetInventoryServer server;
|
||||
|
||||
|
@ -41,14 +40,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Extensions
|
|||
{
|
||||
}
|
||||
|
||||
public void Start(AssetInventoryServer server)
|
||||
{
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
}
|
||||
#region IMetricsProvider implementation
|
||||
|
||||
public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time)
|
||||
{
|
||||
|
@ -120,5 +112,39 @@ namespace OpenSim.Grid.AssetInventoryServer.Extensions
|
|||
Logger.Log.DebugFormat("[{0}] InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension,
|
||||
owner, response);
|
||||
}
|
||||
|
||||
#endregion IMetricsProvider implementation
|
||||
|
||||
#region IPlugin implementation
|
||||
|
||||
public void Initialise(AssetInventoryServer server)
|
||||
{
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Initialises metrics interface</para>
|
||||
/// </summary>
|
||||
public void Initialise()
|
||||
{
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public string Version
|
||||
{
|
||||
// TODO: this should be something meaningful and not hardcoded?
|
||||
get { return "0.1"; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "AssetInventoryServer Null Metrics"; }
|
||||
}
|
||||
|
||||
#endregion IPlugin implementation
|
||||
}
|
||||
}
|
|
@ -31,7 +31,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using ExtensionLoader;
|
||||
using OpenMetaverse;
|
||||
using HttpServer;
|
||||
|
@ -100,52 +102,29 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
|
||||
if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
|
||||
{
|
||||
MemoryStream stream = new MemoryStream();
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.Data = assetData;
|
||||
asset.Metadata.FullID = metadata.ID;
|
||||
asset.Metadata.Name = metadata.Name;
|
||||
asset.Metadata.Description = metadata.Description;
|
||||
asset.Metadata.CreationDate = metadata.CreationDate;
|
||||
asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
|
||||
asset.Metadata.Local = false;
|
||||
asset.Metadata.Temporary = metadata.Temporary;
|
||||
|
||||
XmlWriterSettings settings = new XmlWriterSettings();
|
||||
settings.Indent = true;
|
||||
XmlWriter writer = XmlWriter.Create(stream, settings);
|
||||
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
||||
xs.Serialize(xw, asset);
|
||||
xw.Flush();
|
||||
|
||||
writer.WriteStartDocument();
|
||||
writer.WriteStartElement("AssetBase");
|
||||
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
|
||||
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
|
||||
writer.WriteStartElement("FullID");
|
||||
writer.WriteStartElement("Guid");
|
||||
writer.WriteString(assetID.ToString());
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("ID");
|
||||
writer.WriteString(assetID.ToString());
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("Data");
|
||||
writer.WriteBase64(assetData, 0, assetData.Length);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("Type");
|
||||
writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType));
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("Name");
|
||||
writer.WriteString(metadata.Name);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("Description");
|
||||
writer.WriteString(metadata.Description);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("Local");
|
||||
writer.WriteValue(false);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("Temporary");
|
||||
writer.WriteValue(metadata.Temporary);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndDocument();
|
||||
|
||||
writer.Flush();
|
||||
byte[] buffer = stream.GetBuffer();
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
byte[] buffer = ms.GetBuffer();
|
||||
|
||||
response.Status = HttpStatusCode.OK;
|
||||
response.ContentType = "application/xml";
|
||||
response.ContentLength = stream.Length;
|
||||
response.Body.Write(buffer, 0, (int)stream.Length);
|
||||
response.ContentLength = ms.Length;
|
||||
response.Body.Write(buffer, 0, (int) ms.Length);
|
||||
response.Body.Flush();
|
||||
}
|
||||
else
|
||||
|
@ -164,55 +143,26 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
|
||||
bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
{
|
||||
byte[] assetData = null;
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
Logger.Log.Debug("Handling OpenSim asset upload");
|
||||
|
||||
try
|
||||
{
|
||||
using (XmlReader reader = XmlReader.Create(request.Body))
|
||||
AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(request.Body);
|
||||
|
||||
if (asset.Data != null && asset.Data.Length > 0)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
reader.ReadStartElement("AssetBase");
|
||||
metadata.ID = asset.Metadata.FullID;
|
||||
metadata.ContentType = Utils.SLAssetTypeToContentType((int) asset.Metadata.Type);
|
||||
metadata.Name = asset.Metadata.Name;
|
||||
metadata.Description = asset.Metadata.Description;
|
||||
metadata.Temporary = asset.Metadata.Temporary;
|
||||
|
||||
reader.ReadStartElement("FullID");
|
||||
UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID);
|
||||
reader.ReadEndElement();
|
||||
reader.ReadStartElement("ID");
|
||||
reader.Skip();
|
||||
reader.ReadEndElement();
|
||||
|
||||
// HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229
|
||||
//int readBytes = 0;
|
||||
//byte[] buffer = new byte[1024];
|
||||
//MemoryStream stream = new MemoryStream();
|
||||
//BinaryWriter writer = new BinaryWriter(stream);
|
||||
//while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0)
|
||||
// writer.Write(buffer, 0, readBytes);
|
||||
//writer.Flush();
|
||||
//assetData = stream.GetBuffer();
|
||||
//Array.Resize<byte>(ref assetData, (int)stream.Length);
|
||||
|
||||
assetData = Convert.FromBase64String(reader.ReadElementContentAsString());
|
||||
|
||||
int type;
|
||||
Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type);
|
||||
metadata.ContentType = Utils.SLAssetTypeToContentType(type);
|
||||
metadata.Name = reader.ReadElementContentAsString("Name", String.Empty);
|
||||
metadata.Description = reader.ReadElementContentAsString("Description", String.Empty);
|
||||
Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary);
|
||||
Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary);
|
||||
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
|
||||
if (assetData != null && assetData.Length > 0)
|
||||
{
|
||||
metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData);
|
||||
metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data);
|
||||
metadata.CreationDate = DateTime.Now;
|
||||
|
||||
BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
|
||||
BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, asset.Data);
|
||||
|
||||
if (storageResponse == BackendResponse.Success)
|
||||
response.Status = HttpStatusCode.Created;
|
||||
|
|
|
@ -145,66 +145,24 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
assetData = null;
|
||||
//BackendResponse ret;
|
||||
|
||||
AssetBase asset_base = m_assetProvider.FetchAsset(assetID);
|
||||
AssetBase asset = m_assetProvider.FetchAsset(assetID);
|
||||
|
||||
if (asset_base != null)
|
||||
if (asset != null)
|
||||
{
|
||||
metadata = new Metadata();
|
||||
metadata.ID = asset.Metadata.FullID;
|
||||
metadata.CreationDate = OpenMetaverse.Utils.Epoch;
|
||||
metadata.SHA1 = null;
|
||||
metadata.Name = asset_base.Name;
|
||||
metadata.Description = asset_base.Description;
|
||||
metadata.ContentType = Utils.SLAssetTypeToContentType(asset_base.Type);
|
||||
metadata.Temporary = asset_base.Temporary;
|
||||
metadata.Name = asset.Metadata.Name;
|
||||
metadata.Description = asset.Metadata.Description;
|
||||
metadata.ContentType = Utils.SLAssetTypeToContentType(asset.Metadata.Type);
|
||||
metadata.Temporary = asset.Metadata.Temporary;
|
||||
|
||||
assetData = asset_base.Data;
|
||||
assetData = asset.Data;
|
||||
}
|
||||
else return BackendResponse.NotFound;
|
||||
|
||||
return BackendResponse.Success;
|
||||
|
||||
//using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
|
||||
//{
|
||||
// IDataReader reader;
|
||||
|
||||
// try
|
||||
// {
|
||||
// dbConnection.Open();
|
||||
|
||||
// IDbCommand command = dbConnection.CreateCommand();
|
||||
// command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString());
|
||||
// reader = command.ExecuteReader();
|
||||
|
||||
// if (reader.Read())
|
||||
// {
|
||||
// metadata = new Metadata();
|
||||
// metadata.CreationDate = OpenMetaverse.Utils.Epoch;
|
||||
// metadata.SHA1 = null;
|
||||
// metadata.ID = assetID;
|
||||
// metadata.Name = reader.GetString(0);
|
||||
// metadata.Description = reader.GetString(1);
|
||||
// metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
|
||||
// metadata.Temporary = reader.GetBoolean(3);
|
||||
|
||||
// assetData = (byte[])reader.GetValue(4);
|
||||
|
||||
// ret = BackendResponse.Success;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ret = BackendResponse.NotFound;
|
||||
// }
|
||||
// }
|
||||
// catch (MySqlException ex)
|
||||
// {
|
||||
// Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
|
||||
// ret = BackendResponse.Failure;
|
||||
// }
|
||||
//}
|
||||
|
||||
//server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
|
||||
//server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
|
||||
//return ret;
|
||||
}
|
||||
|
||||
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins" version="0.1">
|
||||
<Runtime>
|
||||
<Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.dll" />
|
||||
</Runtime>
|
||||
|
||||
<Dependencies>
|
||||
<Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" />
|
||||
</Dependencies>
|
||||
|
||||
<Extension path="/OpenSim/AssetInventoryServer/MetricsProvider">
|
||||
<Plugin id="OpenSimMetrics" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.NullMetrics" />
|
||||
</Extension>
|
||||
</Addin>
|
23
prebuild.xml
23
prebuild.xml
|
@ -783,6 +783,29 @@
|
|||
</Files>
|
||||
</Project>
|
||||
|
||||
<Project name="OpenSim.Grid.AssetInventoryServer.Plugins" path="OpenSim/Grid/AssetInventoryServer/Plugins" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
<ReferencePath>../../../../bin/</ReferencePath>
|
||||
<Reference name="System" />
|
||||
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="false" />
|
||||
<Match path="Resources" pattern="*.addin.xml" buildAction="EmbeddedResource" recurse="true" />
|
||||
</Files>
|
||||
</Project>
|
||||
|
||||
<Project name="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim" path="OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
|
|
Loading…
Reference in New Issue