GridServicesConnector.cs 29 KB

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