diff options
Diffstat (limited to '')
-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.cs | 114 | ||||
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 58 | ||||
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml | 13 |
4 files changed, 90 insertions, 143 deletions
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 | ||
30 | using System; | 30 | using System; |
31 | using ExtensionLoader; | ||
32 | using OpenMetaverse; | 31 | using OpenMetaverse; |
33 | 32 | ||
34 | namespace OpenSim.Grid.AssetInventoryServer.Extensions | 33 | namespace 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; | |||
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Net; | 32 | using System.Net; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Text; | ||
34 | using System.Xml; | 35 | using System.Xml; |
36 | using System.Xml.Serialization; | ||
35 | using ExtensionLoader; | 37 | using ExtensionLoader; |
36 | using OpenMetaverse; | 38 | using OpenMetaverse; |
37 | using HttpServer; | 39 | using 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> | ||