diff options
author | Mike Mazur | 2009-03-09 07:29:34 +0000 |
---|---|---|
committer | Mike Mazur | 2009-03-09 07:29:34 +0000 |
commit | a2f07ecd2e248966957a8ea70d772276359b02e8 (patch) | |
tree | 5050ec85024e44e4946bfc29782875b3f50f5d37 /OpenSim/Grid/AssetInventoryServer | |
parent | * Tweak llMoveToTarget per mantis 3265 (diff) | |
download | opensim-SC-a2f07ecd2e248966957a8ea70d772276359b02e8.zip opensim-SC-a2f07ecd2e248966957a8ea70d772276359b02e8.tar.gz opensim-SC-a2f07ecd2e248966957a8ea70d772276359b02e8.tar.bz2 opensim-SC-a2f07ecd2e248966957a8ea70d772276359b02e8.tar.xz |
Implemented FetchAssetMetadataSet in DB backends.
This method fetches metadata for a subset of the entries in the assets
database. This functionality is used in the ForEach calls in the asset
storage providers in AssetInventoryServer. With this implemented,
frontends such as the BrowseFrontend should now work.
- MySQL: implemented, sanity tested
- SQLite: implemented, sanity tested
- MSSQL: implemented, not tested
- NHibernate: not implemented
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer')
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs | 185 | ||||
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 48 |
2 files changed, 97 insertions, 136 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs index 6e7519d..34b0565 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs | |||
@@ -42,7 +42,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins | |||
42 | public class BrowseFrontendPlugin : IAssetInventoryServerPlugin | 42 | public class BrowseFrontendPlugin : IAssetInventoryServerPlugin |
43 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | //private AssetInventoryServer m_server; | 45 | private AssetInventoryServer m_server; |
46 | 46 | ||
47 | public BrowseFrontendPlugin() | 47 | public BrowseFrontendPlugin() |
48 | { | 48 | { |
@@ -52,10 +52,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins | |||
52 | 52 | ||
53 | public void Initialise(AssetInventoryServer server) | 53 | public void Initialise(AssetInventoryServer server) |
54 | { | 54 | { |
55 | //m_server = server; | 55 | m_server = server; |
56 | 56 | ||
57 | // Request for / or /?... | 57 | // Request for / or /?... |
58 | //m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); | 58 | m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); |
59 | 59 | ||
60 | m_log.Info("[BROWSEFRONTEND]: Browser Frontend loaded."); | 60 | m_log.Info("[BROWSEFRONTEND]: Browser Frontend loaded."); |
61 | } | 61 | } |
@@ -86,102 +86,87 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins | |||
86 | 86 | ||
87 | #endregion IPlugin implementation | 87 | #endregion IPlugin implementation |
88 | 88 | ||
89 | //public class BrowseRequestHandler : IStreamedRequestHandler | 89 | public class BrowseRequestHandler : BaseStreamHandler |
90 | //{ | 90 | { |
91 | // AssetInventoryServer m_server; | 91 | AssetInventoryServer m_server; |
92 | // string m_contentType; | 92 | |
93 | // string m_httpMethod; | 93 | //public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "(^/$|(^/\?.*)") |
94 | // string m_path; | 94 | public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "/") |
95 | 95 | { | |
96 | // public BrowseRequestHandler(AssetInventoryServer server) | 96 | m_server = server; |
97 | // { | 97 | } |
98 | // m_server = server; | 98 | |
99 | // m_contentType = null; | 99 | public override string ContentType |
100 | // m_httpMethod = "GET"; | 100 | { |
101 | // m_path = @"(^/$)|(^/\?.*)"; | 101 | get { return "text/html"; } |
102 | // } | 102 | } |
103 | 103 | ||
104 | // #region IStreamedRequestHandler implementation | 104 | #region IStreamedRequestHandler implementation |
105 | 105 | ||
106 | // public string ContentType | 106 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
107 | // { | 107 | { |
108 | // get { return m_contentType; } | 108 | const int ASSETS_PER_PAGE = 25; |
109 | // } | 109 | const string HEADER = "<html><head><title>Asset Server</title></head><body>"; |
110 | 110 | const string TABLE_HEADER = | |
111 | // public string HttpMethod | 111 | "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>"; |
112 | // { | 112 | const string TABLE_FOOTER = "</table>"; |
113 | // get { return m_httpMethod; } | 113 | const string FOOTER = "</body></html>"; |
114 | // } | 114 | |
115 | 115 | UUID authToken = Utils.GetAuthToken(httpRequest); | |
116 | // public string Path | 116 | |
117 | // { | 117 | StringBuilder html = new StringBuilder(); |
118 | // get { return m_path; } | 118 | int start = 0; |
119 | // } | 119 | uint page = 0; |
120 | 120 | ||
121 | // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | 121 | if (!String.IsNullOrEmpty(httpRequest.Url.Query)) |
122 | // { | 122 | { |
123 | // const int ASSETS_PER_PAGE = 25; | 123 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); |
124 | // const string HEADER = "<html><head><title>Asset Server</title></head><body>"; | 124 | if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page)) |
125 | // const string TABLE_HEADER = | 125 | start = (int)page * ASSETS_PER_PAGE; |
126 | // "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>"; | 126 | } |
127 | // const string TABLE_FOOTER = "</table>"; | 127 | |
128 | // const string FOOTER = "</body></html>"; | 128 | html.AppendLine(HEADER); |
129 | 129 | ||
130 | // UUID authToken = Utils.GetAuthToken(httpRequest); | 130 | html.AppendLine("<p>"); |
131 | 131 | if (page > 0) | |
132 | // StringBuilder html = new StringBuilder(); | 132 | html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", httpRequest.RawUrl, page - 1); |
133 | // int start = 0; | 133 | html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", httpRequest.RawUrl, page + 1); |
134 | // uint page = 0; | 134 | html.AppendLine("</p>"); |
135 | 135 | ||
136 | // if (!String.IsNullOrEmpty(httpRequest.Url.Query)) | 136 | html.AppendLine(TABLE_HEADER); |
137 | // { | 137 | |
138 | // NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | 138 | m_server.StorageProvider.ForEach( |
139 | // if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page)) | 139 | delegate(AssetMetadata data) |
140 | // start = (int)page * ASSETS_PER_PAGE; | 140 | { |
141 | // } | 141 | if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.FullID)) |
142 | 142 | { | |
143 | // html.AppendLine(HEADER); | 143 | html.AppendLine(String.Format( |
144 | 144 | "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", | |
145 | // html.AppendLine("<p>"); | 145 | data.Name, data.Description, data.ContentType, data.ID, data.Temporary, |
146 | // if (page > 0) | 146 | BitConverter.ToString(data.SHA1).Replace("-", String.Empty))); |
147 | // html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", httpRequest.RawUrl, page - 1); | 147 | } |
148 | // html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", httpRequest.RawUrl, page + 1); | 148 | else |
149 | // html.AppendLine("</p>"); | 149 | { |
150 | 150 | html.AppendLine(String.Format( | |
151 | // html.AppendLine(TABLE_HEADER); | 151 | "<tr><td>[Protected Asset]</td><td> </td><td> </td><td>{0}</td><td>{1}</td><td> </td></tr>", |
152 | 152 | data.ID, data.Temporary)); | |
153 | // m_server.StorageProvider.ForEach( | 153 | } |
154 | // delegate(Metadata data) | 154 | }, start, ASSETS_PER_PAGE |
155 | // { | 155 | ); |
156 | // if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID)) | 156 | |
157 | // { | 157 | html.AppendLine(TABLE_FOOTER); |
158 | // html.AppendLine(String.Format( | 158 | |
159 | // "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", | 159 | html.AppendLine(FOOTER); |
160 | // data.Name, data.Description, data.ContentType, data.ID, data.Temporary, | 160 | |
161 | // BitConverter.ToString(data.SHA1).Replace("-", String.Empty))); | 161 | byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString()); |
162 | // } | 162 | |
163 | // else | 163 | httpResponse.StatusCode = (int) HttpStatusCode.OK; |
164 | // { | 164 | //httpResponse.Body.Write(responseData, 0, responseData.Length); |
165 | // html.AppendLine(String.Format( | 165 | //httpResponse.Body.Flush(); |
166 | // "<tr><td>[Protected Asset]</td><td> </td><td> </td><td>{0}</td><td>{1}</td><td> </td></tr>", | 166 | return responseData; |
167 | // data.ID, data.Temporary)); | 167 | } |
168 | // } | 168 | |
169 | // }, start, ASSETS_PER_PAGE | 169 | #endregion IStreamedRequestHandler implementation |
170 | // ); | 170 | } |
171 | |||
172 | // html.AppendLine(TABLE_FOOTER); | ||
173 | |||
174 | // html.AppendLine(FOOTER); | ||
175 | |||
176 | // byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString()); | ||
177 | |||
178 | // httpResponse.StatusCode = (int) HttpStatusCode.OK; | ||
179 | // httpResponse.Body.Write(responseData, 0, responseData.Length); | ||
180 | // httpResponse.Body.Flush(); | ||
181 | // return responseData; | ||
182 | // } | ||
183 | |||
184 | // #endregion IStreamedRequestHandler implementation | ||
185 | //} | ||
186 | } | 171 | } |
187 | } | 172 | } |
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs index dcacab2..4b0dd7f 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Collections.Generic; | ||
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
32 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
33 | using OpenSim.Data; | 34 | using OpenSim.Data; |
@@ -117,42 +118,17 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
117 | { | 118 | { |
118 | int rowCount = 0; | 119 | int rowCount = 0; |
119 | 120 | ||
120 | //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) | 121 | foreach (AssetMetadata metadata in m_assetProvider.FetchAssetMetadataSet(start, count)) |
121 | //{ | 122 | { |
122 | // MySqlDataReader reader; | 123 | // We set the ContentType here because Utils is only in |
123 | 124 | // AssetInventoryServer. This should be moved to the DB | |
124 | // try | 125 | // backends when the equivalent of SLAssetTypeToContentType is |
125 | // { | 126 | // in OpenSim.Framework or similar. |
126 | // dbConnection.Open(); | 127 | metadata.ContentType = Utils.SLAssetTypeToContentType(metadata.Type); |
127 | 128 | ||
128 | // MySqlCommand command = dbConnection.CreateCommand(); | 129 | action(metadata); |
129 | // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", | 130 | ++rowCount; |
130 | // start, count); | 131 | } |
131 | // reader = command.ExecuteReader(); | ||
132 | // } | ||
133 | // catch (MySqlException ex) | ||
134 | // { | ||
135 | // m_log.Error("[OPENSIMASSETSTORAGE]: Connection to MySQL backend failed: " + ex.Message); | ||
136 | // return 0; | ||
137 | // } | ||
138 | |||
139 | // while (reader.Read()) | ||
140 | // { | ||
141 | // Metadata metadata = new Metadata(); | ||
142 | // metadata.CreationDate = OpenMetaverse.Utils.Epoch; | ||
143 | // metadata.Description = reader.GetString(1); | ||
144 | // metadata.ID = UUID.Parse(reader.GetString(5)); | ||
145 | // metadata.Name = reader.GetString(0); | ||
146 | // metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); | ||
147 | // metadata.Temporary = reader.GetBoolean(3); | ||
148 | // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); | ||
149 | |||
150 | // action(metadata); | ||
151 | // ++rowCount; | ||
152 | // } | ||
153 | |||
154 | // reader.Close(); | ||
155 | //} | ||
156 | 132 | ||
157 | return rowCount; | 133 | return rowCount; |
158 | } | 134 | } |