aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:26:09 +0000
committerMike Mazur2009-02-16 02:26:09 +0000
commitdbee7fcb21a65b8ff7e6143ac7c7bf6a65520540 (patch)
tree61892c065d99a3511c117f3c2466e26c4ee7099d /OpenSim/Grid
parent- IAssetProviderPlugin was changed to IAssetDataPlugin (diff)
downloadopensim-SC-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.zip
opensim-SC-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.tar.gz
opensim-SC-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.tar.bz2
opensim-SC-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.tar.xz
- implement and load NullMetrics module in AssetInventoryServer
- update AssetBase de/serialization in AssetInventoryServer
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs42
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Interfaces.cs6
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs (renamed from OpenSim/Grid/AssetInventoryServer/Extensions/NullMetrics.cs)48
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs114
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs58
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml13
6 files changed, 94 insertions, 187 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
index 8d71f72..d37c63d 100644
--- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
+++ b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
@@ -106,41 +106,8 @@ namespace OpenSim.Grid.AssetInventoryServer
106 return false; 106 return false;
107 } 107 }
108 108
109 //try
110 //{
111 // // Create a reference list for C# extensions compiled at runtime
112 // List<string> references = new List<string>();
113 // references.Add("OpenMetaverseTypes.dll");
114 // references.Add("OpenMetaverse.dll");
115 // references.Add("OpenMetaverse.StructuredData.dll");
116 // references.Add("OpenMetaverse.Http.dll");
117 // references.Add("ExtensionLoader.dll");
118 // references.Add("AssetServer.exe");
119
120 // // Get a list of all of the members of AssetServer that are interfaces
121 // List<FieldInfo> assignables = ExtensionLoader<AssetServer>.GetInterfaces(this);
122
123 // // Load all of the extensions
124 // ExtensionLoader<AssetServer>.LoadAllExtensions(
125 // Assembly.GetExecutingAssembly(),
126 // Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
127 // extensionList,
128 // references,
129 // "AssetServer.*.dll",
130 // "AssetServer.*.cs",
131 // this,
132 // assignables);
133 //}
134 //catch (ExtensionException ex)
135 //{
136 // Logger.Log.Error("Interface loading failed, shutting down: " + ex.Message);
137 // if (ex.InnerException != null)
138 // Logger.Log.Error(ex.InnerException.Message, ex.InnerException);
139 // Stop();
140 // return false;
141 //}
142
143 StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider") as IAssetStorageProvider; 109 StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider") as IAssetStorageProvider;
110 MetricsProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/MetricsProvider") as IMetricsProvider;
144 111
145 try 112 try
146 { 113 {
@@ -155,13 +122,6 @@ namespace OpenSim.Grid.AssetInventoryServer
155 122
156 frontend = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/Frontend"); 123 frontend = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/Frontend");
157 124
158 // Start all of the extensions
159 //foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
160 //{
161 // Logger.Log.Info("Starting extension " + extension.GetType().Name);
162 // extension.Start(this);
163 //}
164
165 return true; 125 return true;
166 } 126 }
167 127
diff --git a/OpenSim/Grid/AssetInventoryServer/Interfaces.cs b/OpenSim/Grid/AssetInventoryServer/Interfaces.cs
index 13b0205..67ffa2f 100644
--- a/OpenSim/Grid/AssetInventoryServer/Interfaces.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Interfaces.cs
@@ -54,12 +54,12 @@ namespace OpenSim.Grid.AssetInventoryServer
54 { 54 {
55 private AssetInventoryServer server; 55 private AssetInventoryServer server;
56 56
57 public AssetInventoryServerPluginInitialiser (AssetInventoryServer server) 57 public AssetInventoryServerPluginInitialiser(AssetInventoryServer server)
58 { 58 {
59 this.server = server; 59 this.server = server;
60 } 60 }
61 61
62 public override void Initialise (IPlugin plugin) 62 public override void Initialise(IPlugin plugin)
63 { 63 {
64 IAssetInventoryServerPlugin p = plugin as IAssetInventoryServerPlugin; 64 IAssetInventoryServerPlugin p = plugin as IAssetInventoryServerPlugin;
65 p.Initialise (server); 65 p.Initialise (server);
@@ -136,7 +136,7 @@ namespace OpenSim.Grid.AssetInventoryServer
136 bool IsInventoryWriteAuthorized(UUID authToken, Uri owner); 136 bool IsInventoryWriteAuthorized(UUID authToken, Uri owner);
137 } 137 }
138 138
139 public interface IMetricsProvider 139 public interface IMetricsProvider : IAssetInventoryServerPlugin
140 { 140 {
141 void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time); 141 void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time);
142 void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time); 142 void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time);
diff --git a/OpenSim/Grid/AssetInventoryServer/Extensions/NullMetrics.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs
index ba190c1..86ae5cd 100644
--- a/OpenSim/Grid/AssetInventoryServer/Extensions/NullMetrics.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs
@@ -28,12 +28,11 @@
28 */ 28 */
29 29
30using System; 30using System;
31using ExtensionLoader;
32using OpenMetaverse; 31using OpenMetaverse;
33 32
34namespace OpenSim.Grid.AssetInventoryServer.Extensions 33namespace OpenSim.Grid.AssetInventoryServer.Plugins
35{ 34{
36 public class NullMetrics : IExtension<AssetInventoryServer>, IMetricsProvider 35 public class NullMetrics : IMetricsProvider
37 { 36 {
38 AssetInventoryServer server; 37 AssetInventoryServer server;
39 38
@@ -41,14 +40,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Extensions
41 { 40 {
42 } 41 }
43 42
44 public void Start(AssetInventoryServer server) 43 #region IMetricsProvider implementation
45 {
46 this.server = server;
47 }
48
49 public void Stop()
50 {
51 }
52 44
53 public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time) 45 public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time)
54 { 46 {
@@ -120,5 +112,39 @@ namespace OpenSim.Grid.AssetInventoryServer.Extensions
120 Logger.Log.DebugFormat("[{0}] InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension, 112 Logger.Log.DebugFormat("[{0}] InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension,
121 owner, response); 113 owner, response);
122 } 114 }
115
116 #endregion IMetricsProvider implementation
117
118 #region IPlugin implementation
119
120 public void Initialise(AssetInventoryServer server)
121 {
122 this.server = server;
123 }
124
125 /// <summary>
126 /// <para>Initialises metrics interface</para>
127 /// </summary>
128 public void Initialise()
129 {
130 this.server = null;
131 }
132
133 public void Dispose()
134 {
135 }
136
137 public string Version
138 {
139 // TODO: this should be something meaningful and not hardcoded?
140 get { return "0.1"; }
141 }
142
143 public string Name
144 {
145 get { return "AssetInventoryServer Null Metrics"; }
146 }
147
148 #endregion IPlugin implementation
123 } 149 }
124} 150}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
index 1abd3f5..0326771 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
@@ -31,7 +31,9 @@ using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Net; 32using System.Net;
33using System.IO; 33using System.IO;
34using System.Text;
34using System.Xml; 35using System.Xml;
36using System.Xml.Serialization;
35using ExtensionLoader; 37using ExtensionLoader;
36using OpenMetaverse; 38using OpenMetaverse;
37using HttpServer; 39using HttpServer;
@@ -100,52 +102,29 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
100 102
101 if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success) 103 if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
102 { 104 {
103 MemoryStream stream = new MemoryStream(); 105 AssetBase asset = new AssetBase();
104 106 asset.Data = assetData;
105 XmlWriterSettings settings = new XmlWriterSettings(); 107 asset.Metadata.FullID = metadata.ID;
106 settings.Indent = true; 108 asset.Metadata.Name = metadata.Name;
107 XmlWriter writer = XmlWriter.Create(stream, settings); 109 asset.Metadata.Description = metadata.Description;
108 110 asset.Metadata.CreationDate = metadata.CreationDate;
109 writer.WriteStartDocument(); 111 asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
110 writer.WriteStartElement("AssetBase"); 112 asset.Metadata.Local = false;
111 writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); 113 asset.Metadata.Temporary = metadata.Temporary;
112 writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); 114
113 writer.WriteStartElement("FullID"); 115 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
114 writer.WriteStartElement("Guid"); 116 MemoryStream ms = new MemoryStream();
115 writer.WriteString(assetID.ToString()); 117 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
116 writer.WriteEndElement(); 118 xs.Serialize(xw, asset);
117 writer.WriteEndElement(); 119 xw.Flush();
118 writer.WriteStartElement("ID"); 120
119 writer.WriteString(assetID.ToString()); 121 ms.Seek(0, SeekOrigin.Begin);
120 writer.WriteEndElement(); 122 byte[] buffer = ms.GetBuffer();
121 writer.WriteStartElement("Data");
122 writer.WriteBase64(assetData, 0, assetData.Length);
123 writer.WriteEndElement();
124 writer.WriteStartElement("Type");
125 writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType));
126 writer.WriteEndElement();
127 writer.WriteStartElement("Name");
128 writer.WriteString(metadata.Name);
129 writer.WriteEndElement();
130 writer.WriteStartElement("Description");
131 writer.WriteString(metadata.Description);
132 writer.WriteEndElement();
133 writer.WriteStartElement("Local");
134 writer.WriteValue(false);
135 writer.WriteEndElement();
136 writer.WriteStartElement("Temporary");
137 writer.WriteValue(metadata.Temporary);
138 writer.WriteEndElement();
139 writer.WriteEndElement();
140 writer.WriteEndDocument();
141
142 writer.Flush();
143 byte[] buffer = stream.GetBuffer();
144 123
145 response.Status = HttpStatusCode.OK; 124 response.Status = HttpStatusCode.OK;
146 response.ContentType = "application/xml"; 125 response.ContentType = "application/xml";
147 response.ContentLength = stream.Length; 126 response.ContentLength = ms.Length;
148 response.Body.Write(buffer, 0, (int)stream.Length); 127 response.Body.Write(buffer, 0, (int) ms.Length);
149 response.Body.Flush(); 128 response.Body.Flush();
150 } 129 }
151 else 130 else
@@ -164,55 +143,26 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
164 143
165 bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 144 bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
166 { 145 {
167 byte[] assetData = null;
168 Metadata metadata = new Metadata(); 146 Metadata metadata = new Metadata();
169 147
170 Logger.Log.Debug("Handling OpenSim asset upload"); 148 Logger.Log.Debug("Handling OpenSim asset upload");
171 149
172 try 150 try
173 { 151 {
174 using (XmlReader reader = XmlReader.Create(request.Body)) 152 AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(request.Body);
175 {
176 reader.MoveToContent();
177 reader.ReadStartElement("AssetBase");
178
179 reader.ReadStartElement("FullID");
180 UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID);
181 reader.ReadEndElement();
182 reader.ReadStartElement("ID");
183 reader.Skip();
184 reader.ReadEndElement();
185
186 // HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229
187 //int readBytes = 0;
188 //byte[] buffer = new byte[1024];
189 //MemoryStream stream = new MemoryStream();
190 //BinaryWriter writer = new BinaryWriter(stream);
191 //while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0)
192 // writer.Write(buffer, 0, readBytes);
193 //writer.Flush();
194 //assetData = stream.GetBuffer();
195 //Array.Resize<byte>(ref assetData, (int)stream.Length);
196
197 assetData = Convert.FromBase64String(reader.ReadElementContentAsString());
198
199 int type;
200 Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type);
201 metadata.ContentType = Utils.SLAssetTypeToContentType(type);
202 metadata.Name = reader.ReadElementContentAsString("Name", String.Empty);
203 metadata.Description = reader.ReadElementContentAsString("Description", String.Empty);
204 Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary);
205 Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary);
206
207 reader.ReadEndElement();
208 }
209 153
210 if (assetData != null && assetData.Length > 0) 154 if (asset.Data != null && asset.Data.Length > 0)
211 { 155 {
212 metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData); 156 metadata.ID = asset.Metadata.FullID;
157 metadata.ContentType = Utils.SLAssetTypeToContentType((int) asset.Metadata.Type);
158 metadata.Name = asset.Metadata.Name;
159 metadata.Description = asset.Metadata.Description;
160 metadata.Temporary = asset.Metadata.Temporary;
161
162 metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data);
213 metadata.CreationDate = DateTime.Now; 163 metadata.CreationDate = DateTime.Now;
214 164
215 BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData); 165 BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, asset.Data);
216 166
217 if (storageResponse == BackendResponse.Success) 167 if (storageResponse == BackendResponse.Success)
218 response.Status = HttpStatusCode.Created; 168 response.Status = HttpStatusCode.Created;
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
index 40959a4..37dd241 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
@@ -145,66 +145,24 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
145 assetData = null; 145 assetData = null;
146 //BackendResponse ret; 146 //BackendResponse ret;
147 147
148 AssetBase asset_base = m_assetProvider.FetchAsset(assetID); 148 AssetBase asset = m_assetProvider.FetchAsset(assetID);
149 149
150 if (asset_base != null) 150 if (asset != null)
151 { 151 {
152 metadata = new Metadata(); 152 metadata = new Metadata();
153 metadata.ID = asset.Metadata.FullID;
153 metadata.CreationDate = OpenMetaverse.Utils.Epoch; 154 metadata.CreationDate = OpenMetaverse.Utils.Epoch;
154 metadata.SHA1 = null; 155 metadata.SHA1 = null;
155 metadata.Name = asset_base.Name; 156 metadata.Name = asset.Metadata.Name;
156 metadata.Description = asset_base.Description; 157 metadata.Description = asset.Metadata.Description;
157 metadata.ContentType = Utils.SLAssetTypeToContentType(asset_base.Type); 158 metadata.ContentType = Utils.SLAssetTypeToContentType(asset.Metadata.Type);
158 metadata.Temporary = asset_base.Temporary; 159 metadata.Temporary = asset.Metadata.Temporary;
159 160
160 assetData = asset_base.Data; 161 assetData = asset.Data;
161 } 162 }
162 else return BackendResponse.NotFound; 163 else return BackendResponse.NotFound;
163 164
164 return BackendResponse.Success; 165 return BackendResponse.Success;
165
166 //using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
167 //{
168 // IDataReader reader;
169
170 // try
171 // {
172 // dbConnection.Open();
173
174 // IDbCommand command = dbConnection.CreateCommand();
175 // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString());
176 // reader = command.ExecuteReader();
177
178 // if (reader.Read())
179 // {
180 // metadata = new Metadata();
181 // metadata.CreationDate = OpenMetaverse.Utils.Epoch;
182 // metadata.SHA1 = null;
183 // metadata.ID = assetID;
184 // metadata.Name = reader.GetString(0);
185 // metadata.Description = reader.GetString(1);
186 // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
187 // metadata.Temporary = reader.GetBoolean(3);
188
189 // assetData = (byte[])reader.GetValue(4);
190
191 // ret = BackendResponse.Success;
192 // }
193 // else
194 // {
195 // ret = BackendResponse.NotFound;
196 // }
197 // }
198 // catch (MySqlException ex)
199 // {
200 // Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
201 // ret = BackendResponse.Failure;
202 // }
203 //}
204
205 //server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
206 //server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
207 //return ret;
208 } 166 }
209 167
210 public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) 168 public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID)
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
new file mode 100644
index 0000000..bca7ee1
--- /dev/null
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
@@ -0,0 +1,13 @@
1<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins" version="0.1">
2 <Runtime>
3 <Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.dll" />
4 </Runtime>
5
6 <Dependencies>
7 <Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" />
8 </Dependencies>
9
10 <Extension path="/OpenSim/AssetInventoryServer/MetricsProvider">
11 <Plugin id="OpenSimMetrics" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.NullMetrics" />
12 </Extension>
13</Addin>