GridServicesConnector.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 GetRegionByHandle(UUID scopeID, ulong regionhandle)
  231. {
  232. //still not on protocol
  233. Util.RegionHandleToWorldLoc(regionhandle, out uint x, out uint y);
  234. return GetRegionByPosition(scopeID, (int)x, (int)y);
  235. }
  236. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
  237. {
  238. GridRegion rinfo = null;
  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. 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. }