GridServicesConnector.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. ulong regionHandle = Util.UIntsToLong((uint)x, (uint)y);
  235. if (m_regionCache.Contains(regionHandle))
  236. return (GridRegion)m_regionCache[regionHandle];
  237. Dictionary<string, object> sendData = new Dictionary<string, object>();
  238. sendData["SCOPEID"] = scopeID.ToString();
  239. sendData["X"] = x.ToString();
  240. sendData["Y"] = y.ToString();
  241. sendData["METHOD"] = "get_region_by_position";
  242. string reply = string.Empty;
  243. string uri = m_ServerURI + "/grid";
  244. try
  245. {
  246. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  247. uri,
  248. ServerUtils.BuildQueryString(sendData), m_Auth);
  249. }
  250. catch (Exception e)
  251. {
  252. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  253. return null;
  254. }
  255. GridRegion rinfo = null;
  256. if (reply != string.Empty)
  257. {
  258. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  259. if ((replyData != null) && (replyData["result"] != null))
  260. {
  261. if (replyData["result"] is Dictionary<string, object>)
  262. rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
  263. //else
  264. // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region",
  265. // scopeID, x, y);
  266. }
  267. else
  268. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response",
  269. scopeID, x, y);
  270. }
  271. else
  272. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply");
  273. m_regionCache.Add(regionHandle, rinfo, TimeSpan.FromSeconds(600));
  274. return rinfo;
  275. }
  276. public GridRegion GetRegionByName(UUID scopeID, string regionName)
  277. {
  278. Dictionary<string, object> sendData = new Dictionary<string, object>();
  279. sendData["SCOPEID"] = scopeID.ToString();
  280. sendData["NAME"] = regionName;
  281. sendData["METHOD"] = "get_region_by_name";
  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), m_Auth);
  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. GridRegion rinfo = null;
  296. if (reply != string.Empty)
  297. {
  298. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  299. if ((replyData != null) && (replyData["result"] != null))
  300. {
  301. if (replyData["result"] is Dictionary<string, object>)
  302. rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
  303. }
  304. else
  305. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response",
  306. scopeID, regionName);
  307. }
  308. else
  309. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply");
  310. return rinfo;
  311. }
  312. public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
  313. {
  314. Dictionary<string, object> sendData = new Dictionary<string, object>();
  315. sendData["SCOPEID"] = scopeID.ToString();
  316. sendData["NAME"] = name;
  317. sendData["MAX"] = maxNumber.ToString();
  318. sendData["METHOD"] = "get_regions_by_name";
  319. List<GridRegion> rinfos = new List<GridRegion>();
  320. string reply = string.Empty;
  321. string uri = m_ServerURI + "/grid";
  322. try
  323. {
  324. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  325. uri,
  326. ServerUtils.BuildQueryString(sendData), m_Auth);
  327. }
  328. catch (Exception e)
  329. {
  330. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  331. return rinfos;
  332. }
  333. if (reply != string.Empty)
  334. {
  335. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  336. if (replyData != null)
  337. {
  338. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  339. foreach (object r in rinfosList)
  340. {
  341. if (r is Dictionary<string, object>)
  342. {
  343. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  344. rinfos.Add(rinfo);
  345. }
  346. }
  347. }
  348. else
  349. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response",
  350. scopeID, name, maxNumber);
  351. }
  352. else
  353. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply");
  354. return rinfos;
  355. }
  356. public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
  357. {
  358. Dictionary<string, object> sendData = new Dictionary<string, object>();
  359. sendData["SCOPEID"] = scopeID.ToString();
  360. sendData["XMIN"] = xmin.ToString();
  361. sendData["XMAX"] = xmax.ToString();
  362. sendData["YMIN"] = ymin.ToString();
  363. sendData["YMAX"] = ymax.ToString();
  364. sendData["METHOD"] = "get_region_range";
  365. List<GridRegion> rinfos = new List<GridRegion>();
  366. string reply = string.Empty;
  367. string uri = m_ServerURI + "/grid";
  368. try
  369. {
  370. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  371. uri,
  372. ServerUtils.BuildQueryString(sendData), m_Auth);
  373. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  374. }
  375. catch (Exception e)
  376. {
  377. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  378. return rinfos;
  379. }
  380. if (reply != string.Empty)
  381. {
  382. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  383. if (replyData != null)
  384. {
  385. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  386. foreach (object r in rinfosList)
  387. {
  388. if (r is Dictionary<string, object>)
  389. {
  390. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  391. rinfos.Add(rinfo);
  392. }
  393. }
  394. }
  395. else
  396. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response",
  397. scopeID, xmin, xmax, ymin, ymax);
  398. }
  399. else
  400. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply");
  401. return rinfos;
  402. }
  403. public List<GridRegion> GetDefaultRegions(UUID scopeID)
  404. {
  405. Dictionary<string, object> sendData = new Dictionary<string, object>();
  406. sendData["SCOPEID"] = scopeID.ToString();
  407. sendData["METHOD"] = "get_default_regions";
  408. List<GridRegion> rinfos = new List<GridRegion>();
  409. string reply = string.Empty;
  410. string uri = m_ServerURI + "/grid";
  411. try
  412. {
  413. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  414. uri,
  415. ServerUtils.BuildQueryString(sendData), m_Auth);
  416. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  417. }
  418. catch (Exception e)
  419. {
  420. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  421. return rinfos;
  422. }
  423. if (reply != string.Empty)
  424. {
  425. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  426. if (replyData != null)
  427. {
  428. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  429. foreach (object r in rinfosList)
  430. {
  431. if (r is Dictionary<string, object>)
  432. {
  433. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  434. rinfos.Add(rinfo);
  435. }
  436. }
  437. }
  438. else
  439. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response",
  440. scopeID);
  441. }
  442. else
  443. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply");
  444. return rinfos;
  445. }
  446. public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID)
  447. {
  448. Dictionary<string, object> sendData = new Dictionary<string, object>();
  449. sendData["SCOPEID"] = scopeID.ToString();
  450. sendData["METHOD"] = "get_default_hypergrid_regions";
  451. List<GridRegion> rinfos = new List<GridRegion>();
  452. string reply = string.Empty;
  453. string uri = m_ServerURI + "/grid";
  454. try
  455. {
  456. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  457. uri,
  458. ServerUtils.BuildQueryString(sendData), m_Auth);
  459. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  460. }
  461. catch (Exception e)
  462. {
  463. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  464. return rinfos;
  465. }
  466. if (reply != string.Empty)
  467. {
  468. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  469. if (replyData != null)
  470. {
  471. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  472. foreach (object r in rinfosList)
  473. {
  474. if (r is Dictionary<string, object>)
  475. {
  476. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  477. rinfos.Add(rinfo);
  478. }
  479. }
  480. }
  481. else
  482. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions {0} received null response",
  483. scopeID);
  484. }
  485. else
  486. m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions received null reply");
  487. return rinfos;
  488. }
  489. public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
  490. {
  491. Dictionary<string, object> sendData = new Dictionary<string, object>();
  492. sendData["SCOPEID"] = scopeID.ToString();
  493. sendData["X"] = x.ToString();
  494. sendData["Y"] = y.ToString();
  495. sendData["METHOD"] = "get_fallback_regions";
  496. List<GridRegion> rinfos = new List<GridRegion>();
  497. string reply = string.Empty;
  498. string uri = m_ServerURI + "/grid";
  499. try
  500. {
  501. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  502. uri,
  503. ServerUtils.BuildQueryString(sendData), m_Auth);
  504. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  505. }
  506. catch (Exception e)
  507. {
  508. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  509. return rinfos;
  510. }
  511. if (reply != string.Empty)
  512. {
  513. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  514. if (replyData != null)
  515. {
  516. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  517. foreach (object r in rinfosList)
  518. {
  519. if (r is Dictionary<string, object>)
  520. {
  521. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  522. rinfos.Add(rinfo);
  523. }
  524. }
  525. }
  526. else
  527. m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response",
  528. scopeID, x, y);
  529. }
  530. else
  531. m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply");
  532. return rinfos;
  533. }
  534. public List<GridRegion> GetHyperlinks(UUID scopeID)
  535. {
  536. Dictionary<string, object> sendData = new Dictionary<string, object>();
  537. sendData["SCOPEID"] = scopeID.ToString();
  538. sendData["METHOD"] = "get_hyperlinks";
  539. List<GridRegion> rinfos = new List<GridRegion>();
  540. string reply = string.Empty;
  541. string uri = m_ServerURI + "/grid";
  542. try
  543. {
  544. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  545. uri,
  546. ServerUtils.BuildQueryString(sendData), m_Auth);
  547. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  548. }
  549. catch (Exception e)
  550. {
  551. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  552. return rinfos;
  553. }
  554. if (reply != string.Empty)
  555. {
  556. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  557. if (replyData != null)
  558. {
  559. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  560. foreach (object r in rinfosList)
  561. {
  562. if (r is Dictionary<string, object>)
  563. {
  564. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  565. rinfos.Add(rinfo);
  566. }
  567. }
  568. }
  569. else
  570. m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response",
  571. scopeID);
  572. }
  573. else
  574. m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply");
  575. return rinfos;
  576. }
  577. public int GetRegionFlags(UUID scopeID, UUID regionID)
  578. {
  579. Dictionary<string, object> sendData = new Dictionary<string, object>();
  580. sendData["SCOPEID"] = scopeID.ToString();
  581. sendData["REGIONID"] = regionID.ToString();
  582. sendData["METHOD"] = "get_region_flags";
  583. string reply = string.Empty;
  584. string uri = m_ServerURI + "/grid";
  585. try
  586. {
  587. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  588. uri,
  589. ServerUtils.BuildQueryString(sendData), m_Auth);
  590. }
  591. catch (Exception e)
  592. {
  593. m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
  594. return -1;
  595. }
  596. int flags = -1;
  597. if (reply != string.Empty)
  598. {
  599. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  600. if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
  601. {
  602. Int32.TryParse((string)replyData["result"], out flags);
  603. //else
  604. // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}",
  605. // scopeID, regionID, replyData["result"].GetType());
  606. }
  607. else
  608. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response",
  609. scopeID, regionID);
  610. }
  611. else
  612. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply");
  613. return flags;
  614. }
  615. public Dictionary<string, object> GetExtraFeatures()
  616. {
  617. Dictionary<string, object> sendData = new Dictionary<string, object>();
  618. Dictionary<string, object> extraFeatures = new Dictionary<string, object>();
  619. sendData["METHOD"] = "get_grid_extra_features";
  620. string reply = string.Empty;
  621. string uri = m_ServerURI + "/grid";
  622. try
  623. {
  624. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  625. uri,
  626. ServerUtils.BuildQueryString(sendData), m_Auth);
  627. }
  628. catch (Exception e)
  629. {
  630. m_log.DebugFormat("[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {0}: {1}", uri, e.Message);
  631. return extraFeatures;
  632. }
  633. if (reply != string.Empty)
  634. {
  635. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  636. if ((replyData != null) && replyData.Count > 0)
  637. {
  638. foreach (string key in replyData.Keys)
  639. {
  640. extraFeatures[key] = replyData[key].ToString();
  641. }
  642. }
  643. }
  644. else
  645. m_log.DebugFormat("[GRID CONNECTOR]: GetExtraServiceURLs received null reply");
  646. return extraFeatures;
  647. }
  648. #endregion
  649. }
  650. }