diff options
author | Melanie | 2011-10-06 15:39:21 +0200 |
---|---|---|
committer | Melanie | 2011-10-06 15:39:21 +0200 |
commit | 363a99593d69c55f084f3438c335d38262beddf8 (patch) | |
tree | b23b76f159af1acb9c019db9c98e180f24a468ac /OpenSim/Services/Connectors | |
parent | Guard another nullref (diff) | |
download | opensim-SC_OLD-363a99593d69c55f084f3438c335d38262beddf8.zip opensim-SC_OLD-363a99593d69c55f084f3438c335d38262beddf8.tar.gz opensim-SC_OLD-363a99593d69c55f084f3438c335d38262beddf8.tar.bz2 opensim-SC_OLD-363a99593d69c55f084f3438c335d38262beddf8.tar.xz |
Change the asset connector to allow connection to different asset servers
depending on the first two digits of the asset id.
Diffstat (limited to 'OpenSim/Services/Connectors')
-rw-r--r-- | OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs index 565e4f2..7db2a81 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs | |||
@@ -51,6 +51,7 @@ namespace OpenSim.Services.Connectors | |||
51 | private int m_retryCounter; | 51 | private int m_retryCounter; |
52 | private Dictionary<int, List<AssetBase>> m_retryQueue = new Dictionary<int, List<AssetBase>>(); | 52 | private Dictionary<int, List<AssetBase>> m_retryQueue = new Dictionary<int, List<AssetBase>>(); |
53 | private Timer m_retryTimer; | 53 | private Timer m_retryTimer; |
54 | private Dictionary<string, string> m_UriMap = new Dictionary<string, string>(); | ||
54 | public AssetServicesConnector() | 55 | public AssetServicesConnector() |
55 | { | 56 | { |
56 | } | 57 | } |
@@ -91,6 +92,34 @@ namespace OpenSim.Services.Connectors | |||
91 | m_retryTimer = new Timer(); | 92 | m_retryTimer = new Timer(); |
92 | m_retryTimer.Elapsed += new ElapsedEventHandler(retryCheck); | 93 | m_retryTimer.Elapsed += new ElapsedEventHandler(retryCheck); |
93 | m_retryTimer.Interval = 60000; | 94 | m_retryTimer.Interval = 60000; |
95 | |||
96 | Uri serverUri = new Uri(m_ServerURI); | ||
97 | |||
98 | string groupHost = serverUri.Host; | ||
99 | |||
100 | for (int i = 0 ; i < 256 ; i++) | ||
101 | { | ||
102 | string prefix = i.ToString("x2"); | ||
103 | groupHost = assetConfig.GetString("AssetServerHost_"+prefix, groupHost); | ||
104 | |||
105 | m_UriMap[prefix] = groupHost; | ||
106 | //m_log.DebugFormat("[ASSET]: Using {0} for prefix {1}", groupHost, prefix); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | private string MapServer(string id) | ||
111 | { | ||
112 | UriBuilder serverUri = new UriBuilder(m_ServerURI); | ||
113 | |||
114 | string prefix = id.Substring(0, 2).ToLower(); | ||
115 | |||
116 | string host = m_UriMap[prefix]; | ||
117 | |||
118 | serverUri.Host = host; | ||
119 | |||
120 | // m_log.DebugFormat("[ASSET]: Using {0} for host name for prefix {1}", host, prefix); | ||
121 | |||
122 | return serverUri.Uri.AbsoluteUri; | ||
94 | } | 123 | } |
95 | 124 | ||
96 | protected void retryCheck(object source, ElapsedEventArgs e) | 125 | protected void retryCheck(object source, ElapsedEventArgs e) |
@@ -145,7 +174,7 @@ namespace OpenSim.Services.Connectors | |||
145 | 174 | ||
146 | public AssetBase Get(string id) | 175 | public AssetBase Get(string id) |
147 | { | 176 | { |
148 | string uri = m_ServerURI + "/assets/" + id; | 177 | string uri = MapServer(id) + "/assets/" + id; |
149 | 178 | ||
150 | AssetBase asset = null; | 179 | AssetBase asset = null; |
151 | if (m_Cache != null) | 180 | if (m_Cache != null) |
@@ -180,7 +209,7 @@ namespace OpenSim.Services.Connectors | |||
180 | return fullAsset.Metadata; | 209 | return fullAsset.Metadata; |
181 | } | 210 | } |
182 | 211 | ||
183 | string uri = m_ServerURI + "/assets/" + id + "/metadata"; | 212 | string uri = MapServer(id) + "/assets/" + id + "/metadata"; |
184 | 213 | ||
185 | AssetMetadata asset = SynchronousRestObjectRequester. | 214 | AssetMetadata asset = SynchronousRestObjectRequester. |
186 | MakeRequest<int, AssetMetadata>("GET", uri, 0); | 215 | MakeRequest<int, AssetMetadata>("GET", uri, 0); |
@@ -197,7 +226,7 @@ namespace OpenSim.Services.Connectors | |||
197 | return fullAsset.Data; | 226 | return fullAsset.Data; |
198 | } | 227 | } |
199 | 228 | ||
200 | RestClient rc = new RestClient(m_ServerURI); | 229 | RestClient rc = new RestClient(MapServer(id)); |
201 | rc.AddResourcePath("assets"); | 230 | rc.AddResourcePath("assets"); |
202 | rc.AddResourcePath(id); | 231 | rc.AddResourcePath(id); |
203 | rc.AddResourcePath("data"); | 232 | rc.AddResourcePath("data"); |
@@ -222,7 +251,7 @@ namespace OpenSim.Services.Connectors | |||
222 | 251 | ||
223 | public bool Get(string id, Object sender, AssetRetrieved handler) | 252 | public bool Get(string id, Object sender, AssetRetrieved handler) |
224 | { | 253 | { |
225 | string uri = m_ServerURI + "/assets/" + id; | 254 | string uri = MapServer(id) + "/assets/" + id; |
226 | 255 | ||
227 | AssetBase asset = null; | 256 | AssetBase asset = null; |
228 | if (m_Cache != null) | 257 | if (m_Cache != null) |
@@ -255,6 +284,31 @@ namespace OpenSim.Services.Connectors | |||
255 | 284 | ||
256 | public string Store(AssetBase asset) | 285 | public string Store(AssetBase asset) |
257 | { | 286 | { |
287 | // Have to assign the asset ID here. This isn't likely to | ||
288 | // trigger since current callers don't pass emtpy IDs | ||
289 | // We need the asset ID to route the request to the proper | ||
290 | // cluster member, so we can't have the server assign one. | ||
291 | if (asset.ID == string.Empty) | ||
292 | { | ||
293 | if (asset.FullID == UUID.Zero) | ||
294 | { | ||
295 | asset.FullID = UUID.Random(); | ||
296 | } | ||
297 | asset.ID = asset.FullID.ToString(); | ||
298 | } | ||
299 | else if (asset.FullID == UUID.Zero) | ||
300 | { | ||
301 | UUID uuid = UUID.Zero; | ||
302 | if (UUID.TryParse(asset.ID, out uuid)) | ||
303 | { | ||
304 | asset.FullID = uuid; | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | asset.FullID = UUID.Random(); | ||
309 | } | ||
310 | } | ||
311 | |||
258 | if (m_Cache != null) | 312 | if (m_Cache != null) |
259 | m_Cache.Cache(asset); | 313 | m_Cache.Cache(asset); |
260 | if (asset.Temporary || asset.Local) | 314 | if (asset.Temporary || asset.Local) |
@@ -262,7 +316,7 @@ namespace OpenSim.Services.Connectors | |||
262 | return asset.ID; | 316 | return asset.ID; |
263 | } | 317 | } |
264 | 318 | ||
265 | string uri = m_ServerURI + "/assets/"; | 319 | string uri = MapServer(asset.FullID.ToString()) + "/assets/"; |
266 | 320 | ||
267 | string newID = string.Empty; | 321 | string newID = string.Empty; |
268 | try | 322 | try |
@@ -339,7 +393,7 @@ namespace OpenSim.Services.Connectors | |||
339 | } | 393 | } |
340 | asset.Data = data; | 394 | asset.Data = data; |
341 | 395 | ||
342 | string uri = m_ServerURI + "/assets/" + id; | 396 | string uri = MapServer(id) + "/assets/" + id; |
343 | 397 | ||
344 | if (SynchronousRestObjectRequester. | 398 | if (SynchronousRestObjectRequester. |
345 | MakeRequest<AssetBase, bool>("POST", uri, asset)) | 399 | MakeRequest<AssetBase, bool>("POST", uri, asset)) |
@@ -354,7 +408,7 @@ namespace OpenSim.Services.Connectors | |||
354 | 408 | ||
355 | public bool Delete(string id) | 409 | public bool Delete(string id) |
356 | { | 410 | { |
357 | string uri = m_ServerURI + "/assets/" + id; | 411 | string uri = MapServer(id) + "/assets/" + id; |
358 | 412 | ||
359 | if (SynchronousRestObjectRequester. | 413 | if (SynchronousRestObjectRequester. |
360 | MakeRequest<int, bool>("DELETE", uri, 0)) | 414 | MakeRequest<int, bool>("DELETE", uri, 0)) |