aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins/Simple
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:28:34 +0000
committerMike Mazur2009-02-16 02:28:34 +0000
commitab5e3328323a66028bfd47562d9d515dbec433be (patch)
treed81184cd1f8788c20b4600649195be66e03f48c3 /OpenSim/Grid/AssetInventoryServer/Plugins/Simple
parentWe need to return a zero-length byte array from the Handle() routine. (diff)
downloadopensim-SC-ab5e3328323a66028bfd47562d9d515dbec433be.zip
opensim-SC-ab5e3328323a66028bfd47562d9d515dbec433be.tar.gz
opensim-SC-ab5e3328323a66028bfd47562d9d515dbec433be.tar.bz2
opensim-SC-ab5e3328323a66028bfd47562d9d515dbec433be.tar.xz
- removed OpenSim.Grid.AssetInventoryServer.Metadata class in favor of
OpenSim.Framework.AssetMetadata and related updates in AssetInventory server - removed dependency on MySql.Data.MySqlClient - commented out the bulk of OpenSimInventoryStorage due to missing MySql.Data dependency - refactor asset creation in OpenSimAssetFrontend - commented out ForEach implementation, which also depended on MySql.Data, until it's supported by OpenSim backends - commented out some handlers in BrowseFrontend and ReferenceFrontend as they relied on either ForEach or the removed Metadata class
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins/Simple')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs79
1 files changed, 37 insertions, 42 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs
index cd0a454..384f5f0 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs
@@ -45,7 +45,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
45 45
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 AssetInventoryServer server; 47 AssetInventoryServer server;
48 Dictionary<UUID, Metadata> metadataStorage; 48 Dictionary<UUID, AssetMetadata> metadataStorage;
49 Dictionary<UUID, string> filenames; 49 Dictionary<UUID, string> filenames;
50 50
51 public SimpleAssetStoragePlugin() 51 public SimpleAssetStoragePlugin()
@@ -54,7 +54,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
54 54
55 #region Required Interfaces 55 #region Required Interfaces
56 56
57 public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) 57 public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata)
58 { 58 {
59 metadata = null; 59 metadata = null;
60 BackendResponse ret; 60 BackendResponse ret;
@@ -98,8 +98,9 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
98 98
99 public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) 99 public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset)
100 { 100 {
101 Metadata metadata = null; 101 asset = new AssetBase();
102 byte[] assetData = null; 102 AssetMetadata metadata = asset.Metadata;
103
103 string filename; 104 string filename;
104 BackendResponse ret; 105 BackendResponse ret;
105 106
@@ -108,7 +109,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
108 { 109 {
109 try 110 try
110 { 111 {
111 assetData = File.ReadAllBytes(filename); 112 asset.Data = File.ReadAllBytes(filename);
112 ret = BackendResponse.Success; 113 ret = BackendResponse.Success;
113 } 114 }
114 catch (Exception ex) 115 catch (Exception ex)
@@ -116,80 +117,74 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
116 m_log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); 117 m_log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message);
117 ret = BackendResponse.Failure; 118 ret = BackendResponse.Failure;
118 } 119 }
120
121 asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(asset.Metadata.ContentType);
122 asset.Metadata.Local = false;
119 } 123 }
120 else 124 else
121 { 125 {
126 asset = null;
122 ret = BackendResponse.NotFound; 127 ret = BackendResponse.NotFound;
123 } 128 }
124 129
125 asset = new AssetBase();
126 asset.Data = assetData;
127 asset.Metadata.FullID = metadata.ID;
128 asset.Metadata.Name = metadata.Name;
129 asset.Metadata.Description = metadata.Description;
130 asset.Metadata.CreationDate = metadata.CreationDate;
131 asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
132 asset.Metadata.Local = false;
133 asset.Metadata.Temporary = metadata.Temporary;
134
135 server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); 130 server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
136 server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); 131 server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (asset != null && asset.Data != null ? asset.Data.Length : 0), DateTime.Now);
137 return ret; 132 return ret;
138 } 133 }
139 134
140 public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) 135 public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID)
141 { 136 {
142 assetID = metadata.ID = UUID.Random(); 137 assetID = asset.FullID = UUID.Random();
143 return TryCreateAsset(metadata, assetData); 138 return TryCreateAsset(asset);
144 } 139 }
145 140
146 public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) 141 public BackendResponse TryCreateAsset(AssetBase asset)
147 { 142 {
148 BackendResponse ret; 143 BackendResponse ret;
149 144
150 string path; 145 string path;
151 string filename = String.Format("{0}.{1}", metadata.ID, Utils.ContentTypeToExtension(metadata.ContentType)); 146 string filename = String.Format("{0}.{1}", asset.FullID, Utils.ContentTypeToExtension(asset.Metadata.ContentType));
152 147
153 if (metadata.Temporary) 148 if (asset.Metadata.Temporary)
154 path = Path.Combine(TEMP_DATA_DIR, filename); 149 path = Path.Combine(TEMP_DATA_DIR, filename);
155 else 150 else
156 path = Path.Combine(DEFAULT_DATA_DIR, filename); 151 path = Path.Combine(DEFAULT_DATA_DIR, filename);
157 152
158 try 153 try
159 { 154 {
160 File.WriteAllBytes(path, assetData); 155 File.WriteAllBytes(path, asset.Data);
161 lock (filenames) filenames[metadata.ID] = path; 156 lock (filenames) filenames[asset.FullID] = path;
162 157
163 // Set the creation date to right now 158 // Set the creation date to right now
164 metadata.CreationDate = DateTime.Now; 159 asset.Metadata.CreationDate = DateTime.Now;
165 160
166 lock (metadataStorage) 161 lock (metadataStorage)
167 metadataStorage[metadata.ID] = metadata; 162 metadataStorage[asset.FullID] = asset.Metadata;
168 163
169 ret = BackendResponse.Success; 164 ret = BackendResponse.Success;
170 } 165 }
171 catch (Exception ex) 166 catch (Exception ex)
172 { 167 {
173 m_log.ErrorFormat("Failed writing data for asset {0} to {1}: {2}", metadata.ID, filename, ex.Message); 168 m_log.ErrorFormat("Failed writing data for asset {0} to {1}: {2}", asset.FullID, filename, ex.Message);
174 ret = BackendResponse.Failure; 169 ret = BackendResponse.Failure;
175 } 170 }
176 171
177 server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); 172 server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now);
178 return ret; 173 return ret;
179 } 174 }
180 175
181 public int ForEach(Action<Metadata> action, int start, int count) 176 public int ForEach(Action<AssetMetadata> action, int start, int count)
182 { 177 {
183 int rowCount = 0; 178 int rowCount = 0;
184 179
185 lock (metadataStorage) 180 //lock (metadataStorage)
186 { 181 //{
187 foreach (Metadata metadata in metadataStorage.Values) 182 // foreach (Metadata metadata in metadataStorage.Values)
188 { 183 // {
189 action(metadata); 184 // action(metadata);
190 ++rowCount; 185 // ++rowCount;
191 } 186 // }
192 } 187 //}
193 188
194 return rowCount; 189 return rowCount;
195 } 190 }
@@ -202,7 +197,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
202 { 197 {
203 this.server = server; 198 this.server = server;
204 199
205 metadataStorage = new Dictionary<UUID, Metadata>(); 200 metadataStorage = new Dictionary<UUID, AssetMetadata>();
206 filenames = new Dictionary<UUID, string>(); 201 filenames = new Dictionary<UUID, string>();
207 202
208 LoadFiles(DEFAULT_DATA_DIR, false); 203 LoadFiles(DEFAULT_DATA_DIR, false);
@@ -272,18 +267,18 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
272 string filename = assets[i]; 267 string filename = assets[i];
273 byte[] data = File.ReadAllBytes(filename); 268 byte[] data = File.ReadAllBytes(filename);
274 269
275 Metadata metadata = new Metadata(); 270 AssetMetadata metadata = new AssetMetadata();
276 metadata.CreationDate = File.GetCreationTime(filename); 271 metadata.CreationDate = File.GetCreationTime(filename);
277 metadata.Description = String.Empty; 272 metadata.Description = String.Empty;
278 metadata.ID = SimpleUtils.ParseUUIDFromFilename(filename); 273 metadata.FullID = SimpleUtils.ParseUUIDFromFilename(filename);
279 metadata.Name = SimpleUtils.ParseNameFromFilename(filename); 274 metadata.Name = SimpleUtils.ParseNameFromFilename(filename);
280 metadata.SHA1 = OpenMetaverse.Utils.SHA1(data); 275 metadata.SHA1 = OpenMetaverse.Utils.SHA1(data);
281 metadata.Temporary = false; 276 metadata.Temporary = false;
282 metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.')); 277 metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.'));
283 278
284 // Store the loaded data 279 // Store the loaded data
285 metadataStorage[metadata.ID] = metadata; 280 metadataStorage[metadata.FullID] = metadata;
286 filenames[metadata.ID] = filename; 281 filenames[metadata.FullID] = filename;
287 } 282 }
288 } 283 }
289 catch (Exception ex) 284 catch (Exception ex)