From 4bae547ecb67fcf74981ad85c02872dedc99f94a Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 14 Jan 2010 06:36:39 -0800 Subject: [PATCH] Added the 2 missing methods in the grid service remote connections. --- .../Handlers/Grid/GridServerPostHandler.cs | 77 +++++++++++++ .../Connectors/Grid/GridServiceConnector.cs | 101 +++++++++++++++++- 2 files changed, 174 insertions(+), 4 deletions(-) diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index d99b791a1b..16015758f6 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs @@ -103,6 +103,12 @@ namespace OpenSim.Server.Handlers.Grid case "get_region_range": return GetRegionRange(request); + case "get_default_regions": + return GetDefaultRegions(request); + + case "get_fallback_regions": + return GetFallbackRegions(request); + } m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method); } @@ -404,6 +410,77 @@ namespace OpenSim.Server.Handlers.Grid return encoding.GetBytes(xmlString); } + byte[] GetDefaultRegions(Dictionary request) + { + //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions"); + UUID scopeID = UUID.Zero; + if (request.ContainsKey("SCOPEID")) + UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); + else + m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range"); + + List rinfos = m_GridService.GetDefaultRegions(scopeID); + + Dictionary result = new Dictionary(); + if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) + result["result"] = "null"; + else + { + int i = 0; + foreach (GridRegion rinfo in rinfos) + { + Dictionary rinfoDict = rinfo.ToKeyValuePairs(); + result["region" + i] = rinfoDict; + i++; + } + } + string xmlString = ServerUtils.BuildXmlResponse(result); + //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); + UTF8Encoding encoding = new UTF8Encoding(); + return encoding.GetBytes(xmlString); + } + + byte[] GetFallbackRegions(Dictionary request) + { + //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange"); + UUID scopeID = UUID.Zero; + if (request.ContainsKey("SCOPEID")) + UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); + else + m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions"); + + int x = 0, y = 0; + if (request.ContainsKey("X")) + Int32.TryParse(request["X"].ToString(), out x); + else + m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions"); + if (request.ContainsKey("Y")) + Int32.TryParse(request["Y"].ToString(), out y); + else + m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions"); + + + List rinfos = m_GridService.GetFallbackRegions(scopeID, x, y); + + Dictionary result = new Dictionary(); + if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) + result["result"] = "null"; + else + { + int i = 0; + foreach (GridRegion rinfo in rinfos) + { + Dictionary rinfoDict = rinfo.ToKeyValuePairs(); + result["region" + i] = rinfoDict; + i++; + } + } + string xmlString = ServerUtils.BuildXmlResponse(result); + //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); + UTF8Encoding encoding = new UTF8Encoding(); + return encoding.GetBytes(xmlString); + } + #endregion #region Misc diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 7f1f2fd481..cf112e119b 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs @@ -448,21 +448,114 @@ namespace OpenSim.Services.Connectors return rinfos; } - #endregion - public List GetDefaultRegions(UUID scopeID) { - return null; + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + + sendData["METHOD"] = "get_default_regions"; + + List rinfos = new List(); + string reply = string.Empty; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/grid", + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", + scopeID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); + + return rinfos; } public List GetFallbackRegions(UUID scopeID, int x, int y) { - return null; + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["X"] = x.ToString(); + sendData["Y"] = y.ToString(); + + sendData["METHOD"] = "get_fallback_regions"; + + List rinfos = new List(); + string reply = string.Empty; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/grid", + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", + scopeID, x, y); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); + + return rinfos; } public int GetRegionFlags(UUID scopeID, UUID regionID) { return 0; } + + #endregion + } }