diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Grid/GridServiceConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | 346 |
1 files changed, 346 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs new file mode 100644 index 0000000..ae7db7e --- /dev/null +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | |||
@@ -0,0 +1,346 @@ | |||
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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class GridServicesConnector : IGridService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | |||
51 | public GridServicesConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public GridServicesConnector(string serverURI) | ||
56 | { | ||
57 | m_ServerURI = serverURI.TrimEnd('/'); | ||
58 | } | ||
59 | |||
60 | public GridServicesConnector(IConfigSource source) | ||
61 | { | ||
62 | Initialise(source); | ||
63 | } | ||
64 | |||
65 | public virtual void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig gridConfig = source.Configs["GridService"]; | ||
68 | if (gridConfig == null) | ||
69 | { | ||
70 | m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
71 | throw new Exception("Grid connector init error"); | ||
72 | } | ||
73 | |||
74 | string serviceURI = gridConfig.GetString("GridServerURI", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceURI == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); | ||
80 | throw new Exception("Grid connector init error"); | ||
81 | } | ||
82 | m_ServerURI = serviceURI; | ||
83 | } | ||
84 | |||
85 | |||
86 | #region IGridService | ||
87 | |||
88 | public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) | ||
89 | { | ||
90 | Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); | ||
91 | Dictionary<string, string> sendData = new Dictionary<string,string>(); | ||
92 | foreach (KeyValuePair<string, object> kvp in rinfo) | ||
93 | sendData[kvp.Key] = (string)kvp.Value; | ||
94 | |||
95 | sendData["SCOPEID"] = scopeID.ToString(); | ||
96 | |||
97 | sendData["METHOD"] = "register"; | ||
98 | |||
99 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
100 | m_ServerURI + "/grid", | ||
101 | ServerUtils.BuildQueryString(sendData)); | ||
102 | |||
103 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
104 | |||
105 | if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) | ||
106 | return true; | ||
107 | |||
108 | return false; | ||
109 | } | ||
110 | |||
111 | public bool DeregisterRegion(UUID regionID) | ||
112 | { | ||
113 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
114 | |||
115 | sendData["REGIONID"] = regionID.ToString(); | ||
116 | |||
117 | sendData["METHOD"] = "deregister"; | ||
118 | |||
119 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
120 | m_ServerURI + "/grid", | ||
121 | ServerUtils.BuildQueryString(sendData)); | ||
122 | |||
123 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
124 | |||
125 | if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) | ||
126 | return true; | ||
127 | |||
128 | return false; | ||
129 | } | ||
130 | |||
131 | public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID) | ||
132 | { | ||
133 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
134 | |||
135 | sendData["SCOPEID"] = scopeID.ToString(); | ||
136 | sendData["REGIONID"] = regionID.ToString(); | ||
137 | |||
138 | sendData["METHOD"] = "get_neighbours"; | ||
139 | |||
140 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
141 | m_ServerURI + "/grid", | ||
142 | ServerUtils.BuildQueryString(sendData)); | ||
143 | |||
144 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
145 | |||
146 | List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); | ||
147 | if (replyData != null) | ||
148 | { | ||
149 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
150 | foreach (object r in rinfosList) | ||
151 | { | ||
152 | if (r is Dictionary<string, object>) | ||
153 | { | ||
154 | SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); | ||
155 | rinfos.Add(rinfo); | ||
156 | } | ||
157 | else | ||
158 | m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response", | ||
159 | scopeID, regionID); | ||
160 | } | ||
161 | } | ||
162 | else | ||
163 | m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response", | ||
164 | scopeID, regionID); | ||
165 | |||
166 | return rinfos; | ||
167 | } | ||
168 | |||
169 | public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) | ||
170 | { | ||
171 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
172 | |||
173 | sendData["SCOPEID"] = scopeID.ToString(); | ||
174 | sendData["REGIONID"] = regionID.ToString(); | ||
175 | |||
176 | sendData["METHOD"] = "get_region_by_uuid"; | ||
177 | |||
178 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
179 | m_ServerURI + "/grid", | ||
180 | ServerUtils.BuildQueryString(sendData)); | ||
181 | |||
182 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
183 | |||
184 | SimpleRegionInfo rinfo = null; | ||
185 | if ((replyData != null) && (replyData["result"] != null)) | ||
186 | { | ||
187 | if (replyData["result"] is Dictionary<string, object>) | ||
188 | rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); | ||
189 | else | ||
190 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response", | ||
191 | scopeID, regionID); | ||
192 | } | ||
193 | else | ||
194 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", | ||
195 | scopeID, regionID); | ||
196 | |||
197 | return rinfo; | ||
198 | } | ||
199 | |||
200 | public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) | ||
201 | { | ||
202 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
203 | |||
204 | sendData["SCOPEID"] = scopeID.ToString(); | ||
205 | sendData["X"] = x.ToString(); | ||
206 | sendData["Y"] = y.ToString(); | ||
207 | |||
208 | sendData["METHOD"] = "get_region_by_position"; | ||
209 | |||
210 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
211 | m_ServerURI + "/grid", | ||
212 | ServerUtils.BuildQueryString(sendData)); | ||
213 | |||
214 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
215 | |||
216 | SimpleRegionInfo rinfo = null; | ||
217 | if ((replyData != null) && (replyData["result"] != null)) | ||
218 | { | ||
219 | if (replyData["result"] is Dictionary<string, object>) | ||
220 | rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); | ||
221 | else | ||
222 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response", | ||
223 | scopeID, x, y); | ||
224 | } | ||
225 | else | ||
226 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", | ||
227 | scopeID, x, y); | ||
228 | |||
229 | return rinfo; | ||
230 | } | ||
231 | |||
232 | public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) | ||
233 | { | ||
234 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
235 | |||
236 | sendData["SCOPEID"] = scopeID.ToString(); | ||
237 | sendData["NAME"] = regionName; | ||
238 | |||
239 | sendData["METHOD"] = "get_region_by_name"; | ||
240 | |||
241 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
242 | m_ServerURI + "/grid", | ||
243 | ServerUtils.BuildQueryString(sendData)); | ||
244 | |||
245 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
246 | |||
247 | SimpleRegionInfo rinfo = null; | ||
248 | if ((replyData != null) && (replyData["result"] != null)) | ||
249 | { | ||
250 | if (replyData["result"] is Dictionary<string, object>) | ||
251 | rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); | ||
252 | else | ||
253 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response", | ||
254 | scopeID, regionName); | ||
255 | } | ||
256 | else | ||
257 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", | ||
258 | scopeID, regionName); | ||
259 | |||
260 | return rinfo; | ||
261 | } | ||
262 | |||
263 | public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) | ||
264 | { | ||
265 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
266 | |||
267 | sendData["SCOPEID"] = scopeID.ToString(); | ||
268 | sendData["NAME"] = name; | ||
269 | sendData["MAX"] = maxNumber.ToString(); | ||
270 | |||
271 | sendData["METHOD"] = "get_regions_by_name"; | ||
272 | |||
273 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
274 | m_ServerURI + "/grid", | ||
275 | ServerUtils.BuildQueryString(sendData)); | ||
276 | |||
277 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
278 | |||
279 | List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); | ||
280 | if (replyData != null) | ||
281 | { | ||
282 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
283 | foreach (object r in rinfosList) | ||
284 | { | ||
285 | if (r is Dictionary<string, object>) | ||
286 | { | ||
287 | SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); | ||
288 | rinfos.Add(rinfo); | ||
289 | } | ||
290 | else | ||
291 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received invalid response", | ||
292 | scopeID, name, maxNumber); | ||
293 | } | ||
294 | } | ||
295 | else | ||
296 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", | ||
297 | scopeID, name, maxNumber); | ||
298 | |||
299 | return rinfos; | ||
300 | } | ||
301 | |||
302 | public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) | ||
303 | { | ||
304 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | ||
305 | |||
306 | sendData["SCOPEID"] = scopeID.ToString(); | ||
307 | sendData["XMIN"] = xmin.ToString(); | ||
308 | sendData["XMAX"] = xmax.ToString(); | ||
309 | sendData["YMIN"] = ymin.ToString(); | ||
310 | sendData["YMAX"] = ymax.ToString(); | ||
311 | |||
312 | sendData["METHOD"] = "get_region_range"; | ||
313 | |||
314 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
315 | m_ServerURI + "/grid", | ||
316 | ServerUtils.BuildQueryString(sendData)); | ||
317 | |||
318 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
319 | |||
320 | List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); | ||
321 | if (replyData != null) | ||
322 | { | ||
323 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
324 | foreach (object r in rinfosList) | ||
325 | { | ||
326 | if (r is Dictionary<string, object>) | ||
327 | { | ||
328 | SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); | ||
329 | rinfos.Add(rinfo); | ||
330 | } | ||
331 | else | ||
332 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received invalid response", | ||
333 | scopeID, xmin, xmax, ymin, ymax); | ||
334 | } | ||
335 | } | ||
336 | else | ||
337 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", | ||
338 | scopeID, xmin, xmax, ymin, ymax); | ||
339 | |||
340 | return rinfos; | ||
341 | } | ||
342 | |||
343 | #endregion | ||
344 | |||
345 | } | ||
346 | } | ||