aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Grid/GridServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServiceConnector.cs448
1 files changed, 448 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..748892a
--- /dev/null
+++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
@@ -0,0 +1,448 @@
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
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace OpenSim.Services.Connectors
43{
44 public class GridServicesConnector : IGridService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private string m_ServerURI = String.Empty;
51
52 public GridServicesConnector()
53 {
54 }
55
56 public GridServicesConnector(string serverURI)
57 {
58 m_ServerURI = serverURI.TrimEnd('/');
59 }
60
61 public GridServicesConnector(IConfigSource source)
62 {
63 Initialise(source);
64 }
65
66 public virtual void Initialise(IConfigSource source)
67 {
68 IConfig gridConfig = source.Configs["GridService"];
69 if (gridConfig == null)
70 {
71 m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini");
72 throw new Exception("Grid connector init error");
73 }
74
75 string serviceURI = gridConfig.GetString("GridServerURI",
76 String.Empty);
77
78 if (serviceURI == String.Empty)
79 {
80 m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService");
81 throw new Exception("Grid connector init error");
82 }
83 m_ServerURI = serviceURI;
84 }
85
86
87 #region IGridService
88
89 public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo)
90 {
91 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
92 Dictionary<string, string> sendData = new Dictionary<string,string>();
93 foreach (KeyValuePair<string, object> kvp in rinfo)
94 sendData[kvp.Key] = (string)kvp.Value;
95
96 sendData["SCOPEID"] = scopeID.ToString();
97
98 sendData["METHOD"] = "register";
99
100 string reqString = ServerUtils.BuildQueryString(sendData);
101 //m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString);
102 try
103 {
104 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
105 m_ServerURI + "/grid",
106 reqString);
107 if (reply != string.Empty)
108 {
109 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
110
111 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
112 return true;
113 }
114 else
115 m_log.DebugFormat("[GRID CONNECTOR]: RegisterRegion received null reply");
116 }
117 catch (Exception e)
118 {
119 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
120 }
121
122 return false;
123 }
124
125 public virtual bool DeregisterRegion(UUID regionID)
126 {
127 Dictionary<string, string> sendData = new Dictionary<string, string>();
128
129 sendData["REGIONID"] = regionID.ToString();
130
131 sendData["METHOD"] = "deregister";
132
133 try
134 {
135 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
136 m_ServerURI + "/grid",
137 ServerUtils.BuildQueryString(sendData));
138
139 if (reply != string.Empty)
140 {
141 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
142
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: {0}", e.Message);
152 }
153
154 return false;
155 }
156
157 public virtual List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
158 {
159 Dictionary<string, string> sendData = new Dictionary<string, string>();
160
161 sendData["SCOPEID"] = scopeID.ToString();
162 sendData["REGIONID"] = regionID.ToString();
163
164 sendData["METHOD"] = "get_neighbours";
165
166 List<GridRegion> rinfos = new List<GridRegion>();
167
168 string reqString = ServerUtils.BuildQueryString(sendData);
169 string reply = string.Empty;
170 try
171 {
172 reply = SynchronousRestFormsRequester.MakeRequest("POST",
173 m_ServerURI + "/grid",
174 reqString);
175 }
176 catch (Exception e)
177 {
178 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
179 return rinfos;
180 }
181
182 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
183
184 if (replyData != null)
185 {
186 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
187 //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count);
188 foreach (object r in rinfosList)
189 {
190 if (r is Dictionary<string, object>)
191 {
192 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
193 rinfos.Add(rinfo);
194 }
195 else
196 m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response type {2}",
197 scopeID, regionID, r.GetType());
198 }
199 }
200 else
201 m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response",
202 scopeID, regionID);
203
204 return rinfos;
205 }
206
207 public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
208 {
209 Dictionary<string, string> sendData = new Dictionary<string, string>();
210
211 sendData["SCOPEID"] = scopeID.ToString();
212 sendData["REGIONID"] = regionID.ToString();
213
214 sendData["METHOD"] = "get_region_by_uuid";
215
216 string reply = string.Empty;
217 try
218 {
219 reply = SynchronousRestFormsRequester.MakeRequest("POST",
220 m_ServerURI + "/grid",
221 ServerUtils.BuildQueryString(sendData));
222 }
223 catch (Exception e)
224 {
225 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
226 return null;
227 }
228
229 GridRegion rinfo = null;
230
231 if (reply != string.Empty)
232 {
233 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
234
235 if ((replyData != null) && (replyData["result"] != null))
236 {
237 if (replyData["result"] is Dictionary<string, object>)
238 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
239 //else
240 // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
241 // scopeID, regionID);
242 }
243 else
244 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
245 scopeID, regionID);
246 }
247 else
248 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply");
249
250 return rinfo;
251 }
252
253 public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
254 {
255 Dictionary<string, string> sendData = new Dictionary<string, string>();
256
257 sendData["SCOPEID"] = scopeID.ToString();
258 sendData["X"] = x.ToString();
259 sendData["Y"] = y.ToString();
260
261 sendData["METHOD"] = "get_region_by_position";
262 string reply = string.Empty;
263 try
264 {
265 reply = SynchronousRestFormsRequester.MakeRequest("POST",
266 m_ServerURI + "/grid",
267 ServerUtils.BuildQueryString(sendData));
268 }
269 catch (Exception e)
270 {
271 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
272 return null;
273 }
274
275 GridRegion rinfo = null;
276 if (reply != string.Empty)
277 {
278 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
279
280 if ((replyData != null) && (replyData["result"] != null))
281 {
282 if (replyData["result"] is Dictionary<string, object>)
283 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
284 else
285 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response",
286 scopeID, x, y);
287 }
288 else
289 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response",
290 scopeID, x, y);
291 }
292 else
293 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply");
294
295 return rinfo;
296 }
297
298 public virtual GridRegion GetRegionByName(UUID scopeID, string regionName)
299 {
300 Dictionary<string, string> sendData = new Dictionary<string, string>();
301
302 sendData["SCOPEID"] = scopeID.ToString();
303 sendData["NAME"] = regionName;
304
305 sendData["METHOD"] = "get_region_by_name";
306 string reply = string.Empty;
307 try
308 {
309 reply = SynchronousRestFormsRequester.MakeRequest("POST",
310 m_ServerURI + "/grid",
311 ServerUtils.BuildQueryString(sendData));
312 }
313 catch (Exception e)
314 {
315 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
316 return null;
317 }
318
319 GridRegion rinfo = null;
320 if (reply != string.Empty)
321 {
322 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
323
324 if ((replyData != null) && (replyData["result"] != null))
325 {
326 if (replyData["result"] is Dictionary<string, object>)
327 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
328 }
329 else
330 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response",
331 scopeID, regionName);
332 }
333 else
334 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply");
335
336 return rinfo;
337 }
338
339 public virtual List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
340 {
341 Dictionary<string, string> sendData = new Dictionary<string, string>();
342
343 sendData["SCOPEID"] = scopeID.ToString();
344 sendData["NAME"] = name;
345 sendData["MAX"] = maxNumber.ToString();
346
347 sendData["METHOD"] = "get_regions_by_name";
348 List<GridRegion> rinfos = new List<GridRegion>();
349 string reply = string.Empty;
350 try
351 {
352 reply = SynchronousRestFormsRequester.MakeRequest("POST",
353 m_ServerURI + "/grid",
354 ServerUtils.BuildQueryString(sendData));
355 }
356 catch (Exception e)
357 {
358 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
359 return rinfos;
360 }
361
362 if (reply != string.Empty)
363 {
364 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
365
366 if (replyData != null)
367 {
368 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
369 foreach (object r in rinfosList)
370 {
371 if (r is Dictionary<string, object>)
372 {
373 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
374 rinfos.Add(rinfo);
375 }
376 else
377 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received invalid response",
378 scopeID, name, maxNumber);
379 }
380 }
381 else
382 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response",
383 scopeID, name, maxNumber);
384 }
385 else
386 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply");
387
388 return rinfos;
389 }
390
391 public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
392 {
393 Dictionary<string, string> sendData = new Dictionary<string, string>();
394
395 sendData["SCOPEID"] = scopeID.ToString();
396 sendData["XMIN"] = xmin.ToString();
397 sendData["XMAX"] = xmax.ToString();
398 sendData["YMIN"] = ymin.ToString();
399 sendData["YMAX"] = ymax.ToString();
400
401 sendData["METHOD"] = "get_region_range";
402
403 List<GridRegion> rinfos = new List<GridRegion>();
404 string reply = string.Empty;
405 try
406 {
407 reply = SynchronousRestFormsRequester.MakeRequest("POST",
408 m_ServerURI + "/grid",
409 ServerUtils.BuildQueryString(sendData));
410
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: {0}", e.Message);
416 return rinfos;
417 }
418
419 if (reply != string.Empty)
420 {
421 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
422
423 if (replyData != null)
424 {
425 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
426 foreach (object r in rinfosList)
427 {
428 if (r is Dictionary<string, object>)
429 {
430 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
431 rinfos.Add(rinfo);
432 }
433 }
434 }
435 else
436 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response",
437 scopeID, xmin, xmax, ymin, ymax);
438 }
439 else
440 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply");
441
442 return rinfos;
443 }
444
445 #endregion
446
447 }
448}