GridServicesConnector.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. using log4net;
  28. using System;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using Nini.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.ServiceAuth;
  35. using OpenSim.Services.Interfaces;
  36. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  37. using OpenSim.Server.Base;
  38. using OpenMetaverse;
  39. namespace OpenSim.Services.Connectors
  40. {
  41. public class GridServicesConnector : BaseServiceConnector, IGridService
  42. {
  43. private static readonly ILog m_log =
  44. LogManager.GetLogger(
  45. MethodBase.GetCurrentMethod().DeclaringType);
  46. private string m_ServerURI = String.Empty;
  47. private ExpiringCache<ulong, GridRegion> m_regionCache =
  48. new ExpiringCache<ulong, GridRegion>();
  49. public GridServicesConnector()
  50. {
  51. }
  52. public GridServicesConnector(string serverURI)
  53. {
  54. m_ServerURI = serverURI.TrimEnd('/');
  55. }
  56. public GridServicesConnector(IConfigSource source)
  57. {
  58. Initialise(source);
  59. }
  60. public virtual void Initialise(IConfigSource source)
  61. {
  62. IConfig gridConfig = source.Configs["GridService"];
  63. if (gridConfig == null)
  64. {
  65. m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini");
  66. throw new Exception("Grid connector init error");
  67. }
  68. string serviceURI = gridConfig.GetString("GridServerURI",
  69. String.Empty);
  70. if (serviceURI == String.Empty)
  71. {
  72. m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService");
  73. throw new Exception("Grid connector init error");
  74. }
  75. m_ServerURI = serviceURI;
  76. base.Initialise(source, "GridService");
  77. }
  78. #region IGridService
  79. public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
  80. {
  81. Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
  82. Dictionary<string, object> sendData = new Dictionary<string,object>();
  83. foreach (KeyValuePair<string, object> kvp in rinfo)
  84. sendData[kvp.Key] = (string)kvp.Value;
  85. sendData["SCOPEID"] = scopeID.ToString();
  86. sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  87. sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  88. sendData["METHOD"] = "register";
  89. string reqString = ServerUtils.BuildQueryString(sendData);
  90. string uri = m_ServerURI + "/grid";
  91. // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString);
  92. try
  93. {
  94. string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
  95. if (reply != string.Empty)
  96. {
  97. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  98. if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "success"))
  99. {
  100. return String.Empty;
  101. }
  102. else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure"))
  103. {
  104. m_log.ErrorFormat(
  105. "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri);
  106. return replyData["Message"].ToString();
  107. }
  108. else if (!replyData.ContainsKey("Result"))
  109. {
  110. m_log.ErrorFormat(
  111. "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri);
  112. }
  113. else
  114. {
  115. m_log.ErrorFormat(
  116. "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri);
  117. return "Unexpected result " + replyData["Result"].ToString();
  118. }
  119. }
  120. else
  121. {
  122. m_log.ErrorFormat(
  123. "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri);
  124. }
  125. }
  126. catch (Exception e)
  127. {
  128. m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  129. }
  130. return string.Format("Error communicating with the grid service at {0}", uri);
  131. }
  132. public bool DeregisterRegion(UUID regionID)
  133. {
  134. Dictionary<string, object> sendData = new Dictionary<string, object>();
  135. sendData["REGIONID"] = regionID.ToString();
  136. sendData["METHOD"] = "deregister";
  137. string uri = m_ServerURI + "/grid";
  138. try
  139. {
  140. string reply
  141. = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth);
  142. if (reply != string.Empty)
  143. {
  144. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  145. if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
  146. return true;
  147. }
  148. else
  149. m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply");
  150. }
  151. catch (Exception e)
  152. {
  153. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  154. }
  155. return false;
  156. }
  157. public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
  158. {
  159. Dictionary<string, object> sendData = new Dictionary<string, object>();
  160. sendData["SCOPEID"] = scopeID.ToString();
  161. sendData["REGIONID"] = regionID.ToString();
  162. sendData["METHOD"] = "get_neighbours";
  163. List<GridRegion> rinfos = new List<GridRegion>();
  164. string reqString = ServerUtils.BuildQueryString(sendData);
  165. string reply = string.Empty;
  166. string uri = m_ServerURI + "/grid";
  167. try
  168. {
  169. reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
  170. }
  171. catch (Exception e)
  172. {
  173. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  174. return rinfos;
  175. }
  176. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  177. if (replyData != null)
  178. {
  179. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  180. //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count);
  181. foreach (object r in rinfosList)
  182. {
  183. if (r is Dictionary<string, object>)
  184. {
  185. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  186. rinfos.Add(rinfo);
  187. }
  188. }
  189. }
  190. else
  191. m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response",
  192. scopeID, regionID);
  193. return rinfos;
  194. }
  195. public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
  196. {
  197. Dictionary<string, object> sendData = new Dictionary<string, object>();
  198. sendData["SCOPEID"] = scopeID.ToString();
  199. sendData["REGIONID"] = regionID.ToString();
  200. sendData["METHOD"] = "get_region_by_uuid";
  201. string reply = string.Empty;
  202. string uri = m_ServerURI + "/grid";
  203. try
  204. {
  205. reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth);
  206. }
  207. catch (Exception e)
  208. {
  209. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  210. return null;
  211. }
  212. GridRegion rinfo = null;
  213. if (reply != string.Empty)
  214. {
  215. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  216. if ((replyData != null) && (replyData["result"] != null))
  217. {
  218. if (replyData["result"] is Dictionary<string, object>)
  219. rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
  220. //else
  221. // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
  222. // scopeID, regionID);
  223. }
  224. else
  225. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
  226. scopeID, regionID);
  227. }
  228. else
  229. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply");
  230. return rinfo;
  231. }
  232. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
  233. {
  234. GridRegion rinfo = null;
  235. ulong regionHandle = Util.UIntsToLong((uint)x, (uint)y);
  236. // this cache includes NULL regions
  237. if (m_regionCache.TryGetValue(regionHandle, out rinfo))
  238. return rinfo;
  239. Dictionary<string, object> sendData = new Dictionary<string, object>();
  240. sendData["SCOPEID"] = scopeID.ToString();
  241. sendData["X"] = x.ToString();
  242. sendData["Y"] = y.ToString();
  243. sendData["METHOD"] = "get_region_by_position";
  244. string reply = string.Empty;
  245. string uri = m_ServerURI + "/grid";
  246. try
  247. {
  248. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  249. uri,
  250. ServerUtils.BuildQueryString(sendData), m_Auth);
  251. }
  252. catch (Exception e)
  253. {
  254. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  255. return null;
  256. }
  257. if (reply != string.Empty)
  258. {
  259. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  260. if ((replyData != null) && (replyData["result"] != null))
  261. {
  262. if (replyData["result"] is Dictionary<string, object>)
  263. rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
  264. //else
  265. // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region",
  266. // scopeID, x, y);
  267. }
  268. else
  269. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response",
  270. scopeID, x, y);
  271. }
  272. else
  273. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply");
  274. m_regionCache.Add(regionHandle, rinfo, TimeSpan.FromSeconds(600));
  275. return rinfo;
  276. }
  277. public GridRegion GetRegionByName(UUID scopeID, string regionName)
  278. {
  279. Dictionary<string, object> sendData = new Dictionary<string, object>();
  280. sendData["SCOPEID"] = scopeID.ToString();
  281. sendData["NAME"] = regionName;
  282. sendData["METHOD"] = "get_region_by_name";
  283. string reply = string.Empty;
  284. string uri = m_ServerURI + "/grid";
  285. try
  286. {
  287. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  288. uri,
  289. ServerUtils.BuildQueryString(sendData), m_Auth);
  290. }
  291. catch (Exception e)
  292. {
  293. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  294. return null;
  295. }
  296. GridRegion rinfo = null;
  297. if (reply != string.Empty)
  298. {
  299. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  300. if ((replyData != null) && (replyData["result"] != null))
  301. {
  302. if (replyData["result"] is Dictionary<string, object>)
  303. rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
  304. }
  305. else
  306. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response",
  307. scopeID, regionName);
  308. }
  309. else
  310. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply");
  311. return rinfo;
  312. }
  313. public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
  314. {
  315. Dictionary<string, object> sendData = new Dictionary<string, object>();
  316. sendData["SCOPEID"] = scopeID.ToString();
  317. sendData["NAME"] = name;
  318. sendData["MAX"] = maxNumber.ToString();
  319. sendData["METHOD"] = "get_regions_by_name";
  320. List<GridRegion> rinfos = new List<GridRegion>();
  321. string reply = string.Empty;
  322. string uri = m_ServerURI + "/grid";
  323. try
  324. {
  325. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  326. uri,
  327. ServerUtils.BuildQueryString(sendData), m_Auth);
  328. }
  329. catch (Exception e)
  330. {
  331. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  332. return rinfos;
  333. }
  334. if (reply != string.Empty)
  335. {
  336. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  337. if (replyData != null)
  338. {
  339. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  340. foreach (object r in rinfosList)
  341. {
  342. if (r is Dictionary<string, object>)
  343. {
  344. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  345. rinfos.Add(rinfo);
  346. }
  347. }
  348. }
  349. else
  350. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response",
  351. scopeID, name, maxNumber);
  352. }
  353. else
  354. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply");
  355. return rinfos;
  356. }
  357. public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
  358. {
  359. Dictionary<string, object> sendData = new Dictionary<string, object>();
  360. sendData["SCOPEID"] = scopeID.ToString();
  361. sendData["XMIN"] = xmin.ToString();
  362. sendData["XMAX"] = xmax.ToString();
  363. sendData["YMIN"] = ymin.ToString();
  364. sendData["YMAX"] = ymax.ToString();
  365. sendData["METHOD"] = "get_region_range";
  366. List<GridRegion> rinfos = new List<GridRegion>();
  367. string reply = string.Empty;
  368. string uri = m_ServerURI + "/grid";
  369. try
  370. {
  371. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  372. uri,
  373. ServerUtils.BuildQueryString(sendData), m_Auth);
  374. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  375. }
  376. catch (Exception e)
  377. {
  378. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  379. return rinfos;
  380. }
  381. if (reply != string.Empty)
  382. {
  383. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  384. if (replyData != null)
  385. {
  386. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  387. foreach (object r in rinfosList)
  388. {
  389. if (r is Dictionary<string, object>)
  390. {
  391. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  392. rinfos.Add(rinfo);
  393. }
  394. }
  395. }
  396. else
  397. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response",
  398. scopeID, xmin, xmax, ymin, ymax);
  399. }
  400. else
  401. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply");
  402. return rinfos;
  403. }
  404. public List<GridRegion> GetDefaultRegions(UUID scopeID)
  405. {
  406. Dictionary<string, object> sendData = new Dictionary<string, object>();
  407. sendData["SCOPEID"] = scopeID.ToString();
  408. sendData["METHOD"] = "get_default_regions";
  409. List<GridRegion> rinfos = new List<GridRegion>();
  410. string reply = string.Empty;
  411. string uri = m_ServerURI + "/grid";
  412. try
  413. {
  414. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  415. uri,
  416. ServerUtils.BuildQueryString(sendData), m_Auth);
  417. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  418. }
  419. catch (Exception e)
  420. {
  421. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  422. return rinfos;
  423. }
  424. if (reply != string.Empty)
  425. {
  426. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  427. if (replyData != null)
  428. {
  429. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  430. foreach (object r in rinfosList)
  431. {
  432. if (r is Dictionary<string, object>)
  433. {
  434. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  435. rinfos.Add(rinfo);
  436. }
  437. }
  438. }
  439. else
  440. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response",
  441. scopeID);
  442. }
  443. else
  444. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply");
  445. return rinfos;
  446. }
  447. public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID)
  448. {
  449. Dictionary<string, object> sendData = new Dictionary<string, object>();
  450. sendData["SCOPEID"] = scopeID.ToString();
  451. sendData["METHOD"] = "get_default_hypergrid_regions";
  452. List<GridRegion> rinfos = new List<GridRegion>();
  453. string reply = string.Empty;
  454. string uri = m_ServerURI + "/grid";
  455. try
  456. {
  457. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  458. uri,
  459. ServerUtils.BuildQueryString(sendData), m_Auth);
  460. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  461. }
  462. catch (Exception e)
  463. {
  464. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  465. return rinfos;
  466. }
  467. if (reply != string.Empty)
  468. {
  469. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  470. if (replyData != null)
  471. {
  472. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  473. foreach (object r in rinfosList)
  474. {
  475. if (r is Dictionary<string, object>)
  476. {
  477. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  478. rinfos.Add(rinfo);
  479. }
  480. }
  481. }
  482. else
  483. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions {0} received null response",
  484. scopeID);
  485. }
  486. else
  487. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions received null reply");
  488. return rinfos;
  489. }
  490. public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
  491. {
  492. Dictionary<string, object> sendData = new Dictionary<string, object>();
  493. sendData["SCOPEID"] = scopeID.ToString();
  494. sendData["X"] = x.ToString();
  495. sendData["Y"] = y.ToString();
  496. sendData["METHOD"] = "get_fallback_regions";
  497. List<GridRegion> rinfos = new List<GridRegion>();
  498. string reply = string.Empty;
  499. string uri = m_ServerURI + "/grid";
  500. try
  501. {
  502. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  503. uri,
  504. ServerUtils.BuildQueryString(sendData), m_Auth);
  505. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  506. }
  507. catch (Exception e)
  508. {
  509. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  510. return rinfos;
  511. }
  512. if (reply != string.Empty)
  513. {
  514. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  515. if (replyData != null)
  516. {
  517. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  518. foreach (object r in rinfosList)
  519. {
  520. if (r is Dictionary<string, object>)
  521. {
  522. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  523. rinfos.Add(rinfo);
  524. }
  525. }
  526. }
  527. else
  528. m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response",
  529. scopeID, x, y);
  530. }
  531. else
  532. m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply");
  533. return rinfos;
  534. }
  535. public List<GridRegion> GetHyperlinks(UUID scopeID)
  536. {
  537. Dictionary<string, object> sendData = new Dictionary<string, object>();
  538. sendData["SCOPEID"] = scopeID.ToString();
  539. sendData["METHOD"] = "get_hyperlinks";
  540. List<GridRegion> rinfos = new List<GridRegion>();
  541. string reply = string.Empty;
  542. string uri = m_ServerURI + "/grid";
  543. try
  544. {
  545. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  546. uri,
  547. ServerUtils.BuildQueryString(sendData), m_Auth);
  548. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  549. }
  550. catch (Exception e)
  551. {
  552. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  553. return rinfos;
  554. }
  555. if (reply != string.Empty)
  556. {
  557. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  558. if (replyData != null)
  559. {
  560. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  561. foreach (object r in rinfosList)
  562. {
  563. if (r is Dictionary<string, object>)
  564. {
  565. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  566. rinfos.Add(rinfo);
  567. }
  568. }
  569. }
  570. else
  571. m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response",
  572. scopeID);
  573. }
  574. else
  575. m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply");
  576. return rinfos;
  577. }
  578. public int GetRegionFlags(UUID scopeID, UUID regionID)
  579. {
  580. Dictionary<string, object> sendData = new Dictionary<string, object>();
  581. sendData["SCOPEID"] = scopeID.ToString();
  582. sendData["REGIONID"] = regionID.ToString();
  583. sendData["METHOD"] = "get_region_flags";
  584. string reply = string.Empty;
  585. string uri = m_ServerURI + "/grid";
  586. try
  587. {
  588. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  589. uri,
  590. ServerUtils.BuildQueryString(sendData), m_Auth);
  591. }
  592. catch (Exception e)
  593. {
  594. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  595. return -1;
  596. }
  597. int flags = -1;
  598. if (reply != string.Empty)
  599. {
  600. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  601. if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
  602. {
  603. Int32.TryParse((string)replyData["result"], out flags);
  604. //else
  605. // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}",
  606. // scopeID, regionID, replyData["result"].GetType());
  607. }
  608. else
  609. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response",
  610. scopeID, regionID);
  611. }
  612. else
  613. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply");
  614. return flags;
  615. }
  616. public Dictionary<string, object> GetExtraFeatures()
  617. {
  618. Dictionary<string, object> sendData = new Dictionary<string, object>();
  619. Dictionary<string, object> extraFeatures = new Dictionary<string, object>();
  620. sendData["METHOD"] = "get_grid_extra_features";
  621. string reply = string.Empty;
  622. string uri = m_ServerURI + "/grid";
  623. try
  624. {
  625. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  626. uri,
  627. ServerUtils.BuildQueryString(sendData), m_Auth);
  628. }
  629. catch (Exception e)
  630. {
  631. m_log.DebugFormat("[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {0}: {1}", uri, e.Message);
  632. return extraFeatures;
  633. }
  634. if (reply != string.Empty)
  635. {
  636. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  637. if ((replyData != null) && replyData.Count > 0)
  638. {
  639. foreach (string key in replyData.Keys)
  640. {
  641. extraFeatures[key] = replyData[key].ToString();
  642. }
  643. }
  644. }
  645. else
  646. m_log.DebugFormat("[GRID CONNECTOR]: GetExtraServiceURLs received null reply");
  647. return extraFeatures;
  648. }
  649. #endregion
  650. }
  651. }