aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins
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/AssetInventoryServer/Plugins
parent- IAssetProviderPlugin was changed to IAssetDataPlugin (diff)
downloadopensim-SC_OLD-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.zip
opensim-SC_OLD-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.tar.gz
opensim-SC_OLD-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.tar.bz2
opensim-SC_OLD-dbee7fcb21a65b8ff7e6143ac7c7bf6a65520540.tar.xz
- implement and load NullMetrics module in AssetInventoryServer
- update AssetBase de/serialization in AssetInventoryServer
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs150
-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
4 files changed, 203 insertions, 132 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs
new file mode 100644
index 0000000..86ae5cd
--- /dev/null
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetrics.cs
@@ -0,0 +1,150 @@
1/*
2 * Copyright (c) 2008 Intel Corporation
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * -- Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * -- Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * -- Neither the name of the Intel Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30using System;
31using OpenMetaverse;
32
33namespace OpenSim.Grid.AssetInventoryServer.Plugins
34{
35 public class NullMetrics : IMetricsProvider
36 {
37 AssetInventoryServer server;
38
39 public NullMetrics()
40 {
41 }
42
43 #region IMetricsProvider implementation
44
45 public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time)
46 {
47 Logger.Log.DebugFormat("[{0}] AssetMetadataFetch(): AssetID: {1}, Response: {2}", extension, assetID, response);
48 }
49
50 public void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
51 {
52 Logger.Log.DebugFormat("[{0}] AssetDataFetch(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
53 dataSize, response);
54 }
55
56 public void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
57 {
58 Logger.Log.DebugFormat("[{0}] AssetCreate(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
59 dataSize, response);
60 }
61
62 public void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
63 {
64 Logger.Log.DebugFormat("[{0}] InventoryFetch(): ObjID: {1}, Folder: {2}, OwnerID: {3}, Response: {4}", extension,
65 objID, folder, owner, response);
66 }
67
68 public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
69 {
70 Logger.Log.DebugFormat("[{0}] InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension,
71 folderID, owner, response);
72 }
73
74 public void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time)
75 {
76 Logger.Log.DebugFormat("[{0}] InventoryFetchFolderList(): OwnerID: {1}, Response: {2}", extension,
77 owner, response);
78 }
79
80 public void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time)
81 {
82 Logger.Log.DebugFormat("[{0}] InventoryFetchInventory(): OwnerID: {1}, Response: {2}", extension,
83 owner, response);
84 }
85
86 public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time)
87 {
88 Logger.Log.DebugFormat("[{0}] InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension,
89 owner, response);
90 }
91
92 public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time)
93 {
94 Logger.Log.DebugFormat("[{0}] InventoryCreate(): OwnerID: {1}, Response: {2}", extension,
95 owner, response);
96 }
97
98 public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time)
99 {
100 Logger.Log.DebugFormat("[{0}] InventoryCreateInventory(): Response: {1}", extension,
101 response);
102 }
103
104 public void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
105 {
106 Logger.Log.DebugFormat("[{0}] InventoryDelete(): OwnerID: {1}, Folder: {2}, Response: {3}", extension,
107 owner, folder, response);
108 }
109
110 public void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
111 {
112 Logger.Log.DebugFormat("[{0}] InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension,
113 owner, response);
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
149 }
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>