GridServicesConnector.cs 30 KB

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