diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Grid/GridServicesConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/Grid/GridServicesConnector.cs | 671 |
1 files changed, 671 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs new file mode 100644 index 0000000..34ed0d7 --- /dev/null +++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs | |||
@@ -0,0 +1,671 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class GridServicesConnector : IGridService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | |||
51 | public GridServicesConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public GridServicesConnector(string serverURI) | ||
56 | { | ||
57 | m_ServerURI = serverURI.TrimEnd('/'); | ||
58 | } | ||
59 | |||
60 | public GridServicesConnector(IConfigSource source) | ||
61 | { | ||
62 | Initialise(source); | ||
63 | } | ||
64 | |||
65 | public virtual void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig gridConfig = source.Configs["GridService"]; | ||
68 | if (gridConfig == null) | ||
69 | { | ||
70 | m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
71 | throw new Exception("Grid connector init error"); | ||
72 | } | ||
73 | |||
74 | string serviceURI = gridConfig.GetString("GridServerURI", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceURI == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); | ||
80 | throw new Exception("Grid connector init error"); | ||
81 | } | ||
82 | m_ServerURI = serviceURI; | ||
83 | } | ||
84 | |||
85 | |||
86 | #region IGridService | ||
87 | |||
88 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) | ||
89 | { | ||
90 | Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); | ||
91 | Dictionary<string, object> sendData = new Dictionary<string,object>(); | ||
92 | foreach (KeyValuePair<string, object> kvp in rinfo) | ||
93 | sendData[kvp.Key] = (string)kvp.Value; | ||
94 | |||
95 | sendData["SCOPEID"] = scopeID.ToString(); | ||
96 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
97 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
98 | sendData["METHOD"] = "register"; | ||
99 | |||
100 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
101 | string uri = m_ServerURI + "/grid"; | ||
102 | // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); | ||
106 | if (reply != string.Empty) | ||
107 | { | ||
108 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
109 | |||
110 | if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "success")) | ||
111 | { | ||
112 | return String.Empty; | ||
113 | } | ||
114 | else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure")) | ||
115 | { | ||
116 | m_log.ErrorFormat( | ||
117 | "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri); | ||
118 | |||
119 | return replyData["Message"].ToString(); | ||
120 | } | ||
121 | else if (!replyData.ContainsKey("Result")) | ||
122 | { | ||
123 | m_log.ErrorFormat( | ||
124 | "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri); | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | m_log.ErrorFormat( | ||
129 | "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri); | ||
130 | |||
131 | return "Unexpected result " + replyData["Result"].ToString(); | ||
132 | } | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | m_log.ErrorFormat( | ||
137 | "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri); | ||
138 | } | ||
139 | } | ||
140 | catch (Exception e) | ||
141 | { | ||
142 | m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
143 | } | ||
144 | |||
145 | return string.Format("Error communicating with the grid service at {0}", uri); | ||
146 | } | ||
147 | |||
148 | public bool DeregisterRegion(UUID regionID) | ||
149 | { | ||
150 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
151 | |||
152 | sendData["REGIONID"] = regionID.ToString(); | ||
153 | |||
154 | sendData["METHOD"] = "deregister"; | ||
155 | |||
156 | string uri = m_ServerURI + "/grid"; | ||
157 | |||
158 | try | ||
159 | { | ||
160 | string reply | ||
161 | = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); | ||
162 | |||
163 | if (reply != string.Empty) | ||
164 | { | ||
165 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
166 | |||
167 | if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) | ||
168 | return true; | ||
169 | } | ||
170 | else | ||
171 | m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply"); | ||
172 | } | ||
173 | catch (Exception e) | ||
174 | { | ||
175 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
176 | } | ||
177 | |||
178 | return false; | ||
179 | } | ||
180 | |||
181 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | ||
182 | { | ||
183 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
184 | |||
185 | sendData["SCOPEID"] = scopeID.ToString(); | ||
186 | sendData["REGIONID"] = regionID.ToString(); | ||
187 | |||
188 | sendData["METHOD"] = "get_neighbours"; | ||
189 | |||
190 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
191 | |||
192 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
193 | string reply = string.Empty; | ||
194 | string uri = m_ServerURI + "/grid"; | ||
195 | |||
196 | try | ||
197 | { | ||
198 | reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); | ||
199 | } | ||
200 | catch (Exception e) | ||
201 | { | ||
202 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
203 | return rinfos; | ||
204 | } | ||
205 | |||
206 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
207 | |||
208 | if (replyData != null) | ||
209 | { | ||
210 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
211 | //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); | ||
212 | foreach (object r in rinfosList) | ||
213 | { | ||
214 | if (r is Dictionary<string, object>) | ||
215 | { | ||
216 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
217 | rinfos.Add(rinfo); | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | else | ||
222 | m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response", | ||
223 | scopeID, regionID); | ||
224 | |||
225 | return rinfos; | ||
226 | } | ||
227 | |||
228 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | ||
229 | { | ||
230 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
231 | |||
232 | sendData["SCOPEID"] = scopeID.ToString(); | ||
233 | sendData["REGIONID"] = regionID.ToString(); | ||
234 | |||
235 | sendData["METHOD"] = "get_region_by_uuid"; | ||
236 | |||
237 | string reply = string.Empty; | ||
238 | string uri = m_ServerURI + "/grid"; | ||
239 | try | ||
240 | { | ||
241 | reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); | ||
242 | } | ||
243 | catch (Exception e) | ||
244 | { | ||
245 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
246 | return null; | ||
247 | } | ||
248 | |||
249 | GridRegion rinfo = null; | ||
250 | |||
251 | if (reply != string.Empty) | ||
252 | { | ||
253 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
254 | |||
255 | if ((replyData != null) && (replyData["result"] != null)) | ||
256 | { | ||
257 | if (replyData["result"] is Dictionary<string, object>) | ||
258 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); | ||
259 | //else | ||
260 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", | ||
261 | // scopeID, regionID); | ||
262 | } | ||
263 | else | ||
264 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", | ||
265 | scopeID, regionID); | ||
266 | } | ||
267 | else | ||
268 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply"); | ||
269 | |||
270 | return rinfo; | ||
271 | } | ||
272 | |||
273 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | ||
274 | { | ||
275 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
276 | |||
277 | sendData["SCOPEID"] = scopeID.ToString(); | ||
278 | sendData["X"] = x.ToString(); | ||
279 | sendData["Y"] = y.ToString(); | ||
280 | |||
281 | sendData["METHOD"] = "get_region_by_position"; | ||
282 | string reply = string.Empty; | ||
283 | string uri = m_ServerURI + "/grid"; | ||
284 | try | ||
285 | { | ||
286 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
287 | uri, | ||
288 | ServerUtils.BuildQueryString(sendData)); | ||
289 | } | ||
290 | catch (Exception e) | ||
291 | { | ||
292 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
293 | return null; | ||
294 | } | ||
295 | |||
296 | GridRegion rinfo = null; | ||
297 | if (reply != string.Empty) | ||
298 | { | ||
299 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
300 | |||
301 | if ((replyData != null) && (replyData["result"] != null)) | ||
302 | { | ||
303 | if (replyData["result"] is Dictionary<string, object>) | ||
304 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); | ||
305 | //else | ||
306 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region", | ||
307 | // scopeID, x, y); | ||
308 | } | ||
309 | else | ||
310 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", | ||
311 | scopeID, x, y); | ||
312 | } | ||
313 | else | ||
314 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); | ||
315 | |||
316 | return rinfo; | ||
317 | } | ||
318 | |||
319 | public GridRegion GetRegionByName(UUID scopeID, string regionName) | ||
320 | { | ||
321 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
322 | |||
323 | sendData["SCOPEID"] = scopeID.ToString(); | ||
324 | sendData["NAME"] = regionName; | ||
325 | |||
326 | sendData["METHOD"] = "get_region_by_name"; | ||
327 | string reply = string.Empty; | ||
328 | string uri = m_ServerURI + "/grid"; | ||
329 | try | ||
330 | { | ||
331 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
332 | uri, | ||
333 | ServerUtils.BuildQueryString(sendData)); | ||
334 | } | ||
335 | catch (Exception e) | ||
336 | { | ||
337 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
338 | return null; | ||
339 | } | ||
340 | |||
341 | GridRegion rinfo = null; | ||
342 | if (reply != string.Empty) | ||
343 | { | ||
344 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
345 | |||
346 | if ((replyData != null) && (replyData["result"] != null)) | ||
347 | { | ||
348 | if (replyData["result"] is Dictionary<string, object>) | ||
349 | rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]); | ||
350 | } | ||
351 | else | ||
352 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", | ||
353 | scopeID, regionName); | ||
354 | } | ||
355 | else | ||
356 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply"); | ||
357 | |||
358 | return rinfo; | ||
359 | } | ||
360 | |||
361 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) | ||
362 | { | ||
363 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
364 | |||
365 | sendData["SCOPEID"] = scopeID.ToString(); | ||
366 | sendData["NAME"] = name; | ||
367 | sendData["MAX"] = maxNumber.ToString(); | ||
368 | |||
369 | sendData["METHOD"] = "get_regions_by_name"; | ||
370 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
371 | string reply = string.Empty; | ||
372 | string uri = m_ServerURI + "/grid"; | ||
373 | try | ||
374 | { | ||
375 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
376 | uri, | ||
377 | ServerUtils.BuildQueryString(sendData)); | ||
378 | } | ||
379 | catch (Exception e) | ||
380 | { | ||
381 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
382 | return rinfos; | ||
383 | } | ||
384 | |||
385 | if (reply != string.Empty) | ||
386 | { | ||
387 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
388 | |||
389 | if (replyData != null) | ||
390 | { | ||
391 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
392 | foreach (object r in rinfosList) | ||
393 | { | ||
394 | if (r is Dictionary<string, object>) | ||
395 | { | ||
396 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
397 | rinfos.Add(rinfo); | ||
398 | } | ||
399 | } | ||
400 | } | ||
401 | else | ||
402 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", | ||
403 | scopeID, name, maxNumber); | ||
404 | } | ||
405 | else | ||
406 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply"); | ||
407 | |||
408 | return rinfos; | ||
409 | } | ||
410 | |||
411 | public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) | ||
412 | { | ||
413 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
414 | |||
415 | sendData["SCOPEID"] = scopeID.ToString(); | ||
416 | sendData["XMIN"] = xmin.ToString(); | ||
417 | sendData["XMAX"] = xmax.ToString(); | ||
418 | sendData["YMIN"] = ymin.ToString(); | ||
419 | sendData["YMAX"] = ymax.ToString(); | ||
420 | |||
421 | sendData["METHOD"] = "get_region_range"; | ||
422 | |||
423 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
424 | string reply = string.Empty; | ||
425 | string uri = m_ServerURI + "/grid"; | ||
426 | |||
427 | try | ||
428 | { | ||
429 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
430 | uri, | ||
431 | ServerUtils.BuildQueryString(sendData)); | ||
432 | |||
433 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
434 | } | ||
435 | catch (Exception e) | ||
436 | { | ||
437 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
438 | return rinfos; | ||
439 | } | ||
440 | |||
441 | if (reply != string.Empty) | ||
442 | { | ||
443 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
444 | |||
445 | if (replyData != null) | ||
446 | { | ||
447 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
448 | foreach (object r in rinfosList) | ||
449 | { | ||
450 | if (r is Dictionary<string, object>) | ||
451 | { | ||
452 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
453 | rinfos.Add(rinfo); | ||
454 | } | ||
455 | } | ||
456 | } | ||
457 | else | ||
458 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", | ||
459 | scopeID, xmin, xmax, ymin, ymax); | ||
460 | } | ||
461 | else | ||
462 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply"); | ||
463 | |||
464 | return rinfos; | ||
465 | } | ||
466 | |||
467 | public List<GridRegion> GetDefaultRegions(UUID scopeID) | ||
468 | { | ||
469 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
470 | |||
471 | sendData["SCOPEID"] = scopeID.ToString(); | ||
472 | |||
473 | sendData["METHOD"] = "get_default_regions"; | ||
474 | |||
475 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
476 | string reply = string.Empty; | ||
477 | string uri = m_ServerURI + "/grid"; | ||
478 | try | ||
479 | { | ||
480 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
481 | uri, | ||
482 | ServerUtils.BuildQueryString(sendData)); | ||
483 | |||
484 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
485 | } | ||
486 | catch (Exception e) | ||
487 | { | ||
488 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
489 | return rinfos; | ||
490 | } | ||
491 | |||
492 | if (reply != string.Empty) | ||
493 | { | ||
494 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
495 | |||
496 | if (replyData != null) | ||
497 | { | ||
498 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
499 | foreach (object r in rinfosList) | ||
500 | { | ||
501 | if (r is Dictionary<string, object>) | ||
502 | { | ||
503 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
504 | rinfos.Add(rinfo); | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | else | ||
509 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", | ||
510 | scopeID); | ||
511 | } | ||
512 | else | ||
513 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); | ||
514 | |||
515 | return rinfos; | ||
516 | } | ||
517 | |||
518 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) | ||
519 | { | ||
520 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
521 | |||
522 | sendData["SCOPEID"] = scopeID.ToString(); | ||
523 | sendData["X"] = x.ToString(); | ||
524 | sendData["Y"] = y.ToString(); | ||
525 | |||
526 | sendData["METHOD"] = "get_fallback_regions"; | ||
527 | |||
528 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
529 | string reply = string.Empty; | ||
530 | string uri = m_ServerURI + "/grid"; | ||
531 | try | ||
532 | { | ||
533 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
534 | uri, | ||
535 | ServerUtils.BuildQueryString(sendData)); | ||
536 | |||
537 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
538 | } | ||
539 | catch (Exception e) | ||
540 | { | ||
541 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
542 | return rinfos; | ||
543 | } | ||
544 | |||
545 | if (reply != string.Empty) | ||
546 | { | ||
547 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
548 | |||
549 | if (replyData != null) | ||
550 | { | ||
551 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
552 | foreach (object r in rinfosList) | ||
553 | { | ||
554 | if (r is Dictionary<string, object>) | ||
555 | { | ||
556 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
557 | rinfos.Add(rinfo); | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | else | ||
562 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", | ||
563 | scopeID, x, y); | ||
564 | } | ||
565 | else | ||
566 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); | ||
567 | |||
568 | return rinfos; | ||
569 | } | ||
570 | |||
571 | public List<GridRegion> GetHyperlinks(UUID scopeID) | ||
572 | { | ||
573 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
574 | |||
575 | sendData["SCOPEID"] = scopeID.ToString(); | ||
576 | |||
577 | sendData["METHOD"] = "get_hyperlinks"; | ||
578 | |||
579 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
580 | string reply = string.Empty; | ||
581 | string uri = m_ServerURI + "/grid"; | ||
582 | try | ||
583 | { | ||
584 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
585 | uri, | ||
586 | ServerUtils.BuildQueryString(sendData)); | ||
587 | |||
588 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
589 | } | ||
590 | catch (Exception e) | ||
591 | { | ||
592 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
593 | return rinfos; | ||
594 | } | ||
595 | |||
596 | if (reply != string.Empty) | ||
597 | { | ||
598 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
599 | |||
600 | if (replyData != null) | ||
601 | { | ||
602 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
603 | foreach (object r in rinfosList) | ||
604 | { | ||
605 | if (r is Dictionary<string, object>) | ||
606 | { | ||
607 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
608 | rinfos.Add(rinfo); | ||
609 | } | ||
610 | } | ||
611 | } | ||
612 | else | ||
613 | m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response", | ||
614 | scopeID); | ||
615 | } | ||
616 | else | ||
617 | m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); | ||
618 | |||
619 | return rinfos; | ||
620 | } | ||
621 | |||
622 | public int GetRegionFlags(UUID scopeID, UUID regionID) | ||
623 | { | ||
624 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
625 | |||
626 | sendData["SCOPEID"] = scopeID.ToString(); | ||
627 | sendData["REGIONID"] = regionID.ToString(); | ||
628 | |||
629 | sendData["METHOD"] = "get_region_flags"; | ||
630 | |||
631 | string reply = string.Empty; | ||
632 | string uri = m_ServerURI + "/grid"; | ||
633 | try | ||
634 | { | ||
635 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
636 | uri, | ||
637 | ServerUtils.BuildQueryString(sendData)); | ||
638 | } | ||
639 | catch (Exception e) | ||
640 | { | ||
641 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); | ||
642 | return -1; | ||
643 | } | ||
644 | |||
645 | int flags = -1; | ||
646 | |||
647 | if (reply != string.Empty) | ||
648 | { | ||
649 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
650 | |||
651 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
652 | { | ||
653 | Int32.TryParse((string)replyData["result"], out flags); | ||
654 | //else | ||
655 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", | ||
656 | // scopeID, regionID, replyData["result"].GetType()); | ||
657 | } | ||
658 | else | ||
659 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", | ||
660 | scopeID, regionID); | ||
661 | } | ||
662 | else | ||
663 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); | ||
664 | |||
665 | return flags; | ||
666 | } | ||
667 | |||
668 | #endregion | ||
669 | |||
670 | } | ||
671 | } | ||