30 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenSim.Framework;
36 using OpenSim.Framework.ServiceAuth;
37 using OpenSim.Services.Interfaces;
39 using OpenSim.Server.Base;
42 namespace OpenSim.Services.Connectors
46 private static readonly ILog m_log =
48 MethodBase.GetCurrentMethod().DeclaringType);
50 private string m_ServerURI = String.Empty;
52 private ExpiringCache<ulong, GridRegion> m_regionCache =
53 new ExpiringCache<ulong, GridRegion>();
61 m_ServerURI = serverURI.TrimEnd(
'/');
71 IConfig gridConfig = source.Configs[
"GridService"];
72 if (gridConfig == null)
74 m_log.Error(
"[GRID CONNECTOR]: GridService missing from OpenSim.ini");
75 throw new Exception(
"Grid connector init error");
78 string serviceURI = gridConfig.GetString(
"GridServerURI",
81 if (serviceURI == String.Empty)
83 m_log.Error(
"[GRID CONNECTOR]: No Server URI named in section GridService");
84 throw new Exception(
"Grid connector init error");
86 m_ServerURI = serviceURI;
88 base.Initialise(source,
"GridService");
96 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
97 Dictionary<string, object> sendData =
new Dictionary<string,object>();
98 foreach (KeyValuePair<string, object> kvp
in rinfo)
99 sendData[kvp.Key] = (string)kvp.Value;
101 sendData[
"SCOPEID"] = scopeID.ToString();
102 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
103 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
104 sendData[
"METHOD"] =
"register";
106 string reqString = ServerUtils.BuildQueryString(sendData);
107 string uri = m_ServerURI +
"/grid";
111 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, reqString, m_Auth);
112 if (reply !=
string.Empty)
114 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
116 if (replyData.ContainsKey(
"Result")&& (replyData[
"Result"].ToString().ToLower() ==
"success"))
120 else if (replyData.ContainsKey(
"Result")&& (replyData[
"Result"].ToString().ToLower() ==
"failure"))
123 "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData[
"Message"], uri);
125 return replyData[
"Message"].ToString();
127 else if (!replyData.ContainsKey(
"Result"))
130 "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri);
135 "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData[
"Result"], uri);
137 return "Unexpected result " + replyData[
"Result"].ToString();
143 "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri);
148 m_log.ErrorFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
151 return string.Format(
"Error communicating with the grid service at {0}", uri);
156 Dictionary<string, object> sendData =
new Dictionary<string, object>();
158 sendData[
"REGIONID"] = regionID.ToString();
160 sendData[
"METHOD"] =
"deregister";
162 string uri = m_ServerURI +
"/grid";
167 = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth);
169 if (reply !=
string.Empty)
171 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
173 if ((replyData[
"Result"] != null) && (replyData[
"Result"].ToString().ToLower() ==
"success"))
177 m_log.DebugFormat(
"[GRID CONNECTOR]: DeregisterRegion received null reply");
181 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
189 Dictionary<string, object> sendData =
new Dictionary<string, object>();
191 sendData[
"SCOPEID"] = scopeID.ToString();
192 sendData[
"REGIONID"] = regionID.ToString();
194 sendData[
"METHOD"] =
"get_neighbours";
196 List<GridRegion> rinfos =
new List<GridRegion>();
198 string reqString = ServerUtils.BuildQueryString(sendData);
199 string reply = string.Empty;
200 string uri = m_ServerURI +
"/grid";
204 reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, reqString, m_Auth);
208 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
212 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
214 if (replyData != null)
216 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
218 foreach (
object r
in rinfosList)
220 if (r is Dictionary<string, object>)
228 m_log.DebugFormat(
"[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response",
236 Dictionary<string, object> sendData =
new Dictionary<string, object>();
238 sendData[
"SCOPEID"] = scopeID.ToString();
239 sendData[
"REGIONID"] = regionID.ToString();
241 sendData[
"METHOD"] =
"get_region_by_uuid";
243 string reply = string.Empty;
244 string uri = m_ServerURI +
"/grid";
247 reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth);
251 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
257 if (reply !=
string.Empty)
259 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
261 if ((replyData != null) && (replyData[
"result"] != null))
263 if (replyData[
"result"] is Dictionary<string, object>)
264 rinfo =
new GridRegion((Dictionary<string, object>)replyData[
"result"]);
270 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
274 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionByUUID received null reply");
281 ulong regionHandle = Util.UIntsToLong((uint)x, (uint)y);
283 if (m_regionCache.Contains(regionHandle))
284 return (
GridRegion)m_regionCache[regionHandle];
286 Dictionary<string, object> sendData =
new Dictionary<string, object>();
288 sendData[
"SCOPEID"] = scopeID.ToString();
289 sendData[
"X"] = x.ToString();
290 sendData[
"Y"] = y.ToString();
292 sendData[
"METHOD"] =
"get_region_by_position";
293 string reply = string.Empty;
294 string uri = m_ServerURI +
"/grid";
297 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
299 ServerUtils.BuildQueryString(sendData), m_Auth);
303 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
308 if (reply !=
string.Empty)
310 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
312 if ((replyData != null) && (replyData[
"result"] != null))
314 if (replyData[
"result"] is Dictionary<string, object>)
315 rinfo =
new GridRegion((Dictionary<string, object>)replyData[
"result"]);
321 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response",
325 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionByPosition received null reply");
327 m_regionCache.Add(regionHandle, rinfo, TimeSpan.FromSeconds(600));
334 Dictionary<string, object> sendData =
new Dictionary<string, object>();
336 sendData[
"SCOPEID"] = scopeID.ToString();
337 sendData[
"NAME"] = regionName;
339 sendData[
"METHOD"] =
"get_region_by_name";
340 string reply = string.Empty;
341 string uri = m_ServerURI +
"/grid";
344 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
346 ServerUtils.BuildQueryString(sendData), m_Auth);
350 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
355 if (reply !=
string.Empty)
357 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
359 if ((replyData != null) && (replyData[
"result"] != null))
361 if (replyData[
"result"] is Dictionary<string, object>)
362 rinfo =
new GridRegion((Dictionary<string, object>)replyData[
"result"]);
365 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response",
366 scopeID, regionName);
369 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionByName received null reply");
376 Dictionary<string, object> sendData =
new Dictionary<string, object>();
378 sendData[
"SCOPEID"] = scopeID.ToString();
379 sendData[
"NAME"] = name;
380 sendData[
"MAX"] = maxNumber.ToString();
382 sendData[
"METHOD"] =
"get_regions_by_name";
383 List<GridRegion> rinfos =
new List<GridRegion>();
384 string reply = string.Empty;
385 string uri = m_ServerURI +
"/grid";
388 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
390 ServerUtils.BuildQueryString(sendData), m_Auth);
394 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
398 if (reply !=
string.Empty)
400 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
402 if (replyData != null)
404 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
405 foreach (
object r
in rinfosList)
407 if (r is Dictionary<string, object>)
415 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response",
416 scopeID, name, maxNumber);
419 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionsByName received null reply");
424 public List<GridRegion>
GetRegionRange(UUID scopeID,
int xmin,
int xmax,
int ymin,
int ymax)
426 Dictionary<string, object> sendData =
new Dictionary<string, object>();
428 sendData[
"SCOPEID"] = scopeID.ToString();
429 sendData[
"XMIN"] = xmin.ToString();
430 sendData[
"XMAX"] = xmax.ToString();
431 sendData[
"YMIN"] = ymin.ToString();
432 sendData[
"YMAX"] = ymax.ToString();
434 sendData[
"METHOD"] =
"get_region_range";
436 List<GridRegion> rinfos =
new List<GridRegion>();
437 string reply = string.Empty;
438 string uri = m_ServerURI +
"/grid";
442 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
444 ServerUtils.BuildQueryString(sendData), m_Auth);
450 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
454 if (reply !=
string.Empty)
456 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
458 if (replyData != null)
460 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
461 foreach (
object r
in rinfosList)
463 if (r is Dictionary<string, object>)
471 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response",
472 scopeID, xmin, xmax, ymin, ymax);
475 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionRange received null reply");
482 Dictionary<string, object> sendData =
new Dictionary<string, object>();
484 sendData[
"SCOPEID"] = scopeID.ToString();
486 sendData[
"METHOD"] =
"get_default_regions";
488 List<GridRegion> rinfos =
new List<GridRegion>();
489 string reply = string.Empty;
490 string uri = m_ServerURI +
"/grid";
493 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
495 ServerUtils.BuildQueryString(sendData), m_Auth);
501 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
505 if (reply !=
string.Empty)
507 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
509 if (replyData != null)
511 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
512 foreach (
object r
in rinfosList)
514 if (r is Dictionary<string, object>)
522 m_log.DebugFormat(
"[GRID CONNECTOR]: GetDefaultRegions {0} received null response",
526 m_log.DebugFormat(
"[GRID CONNECTOR]: GetDefaultRegions received null reply");
533 Dictionary<string, object> sendData =
new Dictionary<string, object>();
535 sendData[
"SCOPEID"] = scopeID.ToString();
537 sendData[
"METHOD"] =
"get_default_hypergrid_regions";
539 List<GridRegion> rinfos =
new List<GridRegion>();
540 string reply = string.Empty;
541 string uri = m_ServerURI +
"/grid";
544 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
546 ServerUtils.BuildQueryString(sendData), m_Auth);
552 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
556 if (reply !=
string.Empty)
558 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
560 if (replyData != null)
562 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
563 foreach (
object r
in rinfosList)
565 if (r is Dictionary<string, object>)
573 m_log.DebugFormat(
"[GRID CONNECTOR]: GetDefaultHypergridRegions {0} received null response",
577 m_log.DebugFormat(
"[GRID CONNECTOR]: GetDefaultHypergridRegions received null reply");
584 Dictionary<string, object> sendData =
new Dictionary<string, object>();
586 sendData[
"SCOPEID"] = scopeID.ToString();
587 sendData[
"X"] = x.ToString();
588 sendData[
"Y"] = y.ToString();
590 sendData[
"METHOD"] =
"get_fallback_regions";
592 List<GridRegion> rinfos =
new List<GridRegion>();
593 string reply = string.Empty;
594 string uri = m_ServerURI +
"/grid";
597 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
599 ServerUtils.BuildQueryString(sendData), m_Auth);
605 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
609 if (reply !=
string.Empty)
611 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
613 if (replyData != null)
615 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
616 foreach (
object r
in rinfosList)
618 if (r is Dictionary<string, object>)
626 m_log.DebugFormat(
"[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response",
630 m_log.DebugFormat(
"[GRID CONNECTOR]: GetFallbackRegions received null reply");
637 Dictionary<string, object> sendData =
new Dictionary<string, object>();
639 sendData[
"SCOPEID"] = scopeID.ToString();
641 sendData[
"METHOD"] =
"get_hyperlinks";
643 List<GridRegion> rinfos =
new List<GridRegion>();
644 string reply = string.Empty;
645 string uri = m_ServerURI +
"/grid";
648 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
650 ServerUtils.BuildQueryString(sendData), m_Auth);
656 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
660 if (reply !=
string.Empty)
662 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
664 if (replyData != null)
666 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
667 foreach (
object r
in rinfosList)
669 if (r is Dictionary<string, object>)
677 m_log.DebugFormat(
"[GRID CONNECTOR]: GetHyperlinks {0} received null response",
681 m_log.DebugFormat(
"[GRID CONNECTOR]: GetHyperlinks received null reply");
688 Dictionary<string, object> sendData =
new Dictionary<string, object>();
690 sendData[
"SCOPEID"] = scopeID.ToString();
691 sendData[
"REGIONID"] = regionID.ToString();
693 sendData[
"METHOD"] =
"get_region_flags";
695 string reply = string.Empty;
696 string uri = m_ServerURI +
"/grid";
699 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
701 ServerUtils.BuildQueryString(sendData), m_Auth);
705 m_log.DebugFormat(
"[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
711 if (reply !=
string.Empty)
713 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
715 if ((replyData != null) && replyData.ContainsKey(
"result") && (replyData[
"result"] != null))
717 Int32.TryParse((string)replyData[
"result"], out flags);
723 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response",
727 m_log.DebugFormat(
"[GRID CONNECTOR]: GetRegionFlags received null reply");
734 Dictionary<string, object> sendData =
new Dictionary<string, object>();
735 Dictionary<string, object> extraFeatures =
new Dictionary<string, object>();
737 sendData[
"METHOD"] =
"get_grid_extra_features";
739 string reply = string.Empty;
740 string uri = m_ServerURI +
"/grid";
744 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
746 ServerUtils.BuildQueryString(sendData), m_Auth);
750 m_log.DebugFormat(
"[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {0}: {1}", uri, e.Message);
751 return extraFeatures;
754 if (reply !=
string.Empty)
756 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
758 if ((replyData != null) && replyData.Count > 0)
760 foreach (
string key in replyData.Keys)
762 extraFeatures[
key] = replyData[
key].ToString();
767 m_log.DebugFormat(
"[GRID CONNECTOR]: GetExtraServiceURLs received null reply");
769 return extraFeatures;
List< GridRegion > GetDefaultHypergridRegions(UUID scopeID)
bool DeregisterRegion(UUID regionID)
Deregister a region with the grid service.
GridServicesConnector(IConfigSource source)
List< GridRegion > GetFallbackRegions(UUID scopeID, int x, int y)
OpenSim.Services.Interfaces.GridRegion GridRegion
GridServicesConnector(string serverURI)
string RegisterRegion(UUID scopeID, GridRegion regionInfo)
Register a region with the grid service.
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
List< GridRegion > GetDefaultRegions(UUID scopeID)
virtual void Initialise(IConfigSource source)
List< GridRegion > GetNeighbours(UUID scopeID, UUID regionID)
Get information about the regions neighbouring the given co-ordinates (in meters).
int GetRegionFlags(UUID scopeID, UUID regionID)
Get internal OpenSimulator region flags.
List< GridRegion > GetHyperlinks(UUID scopeID)
Dictionary< string, object > GetExtraFeatures()
List< GridRegion > GetRegionsByName(UUID scopeID, string name, int maxNumber)
Get information about regions starting with the provided name.
List< GridRegion > GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
Get the region at the given position (in meters)
GridRegion GetRegionByName(UUID scopeID, string regionName)
Get information about a region which exactly matches the name given.
GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)