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