aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
authorDiva Canto2009-09-21 11:05:01 -0700
committerDiva Canto2009-09-21 11:05:01 -0700
commit390137d540b9ae39eba3ba9136bd49d5e992bc5f (patch)
tree2a42679f2da4acff8943ed414a75a7ea0bd13ecb /OpenSim/Services
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.zip
opensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.tar.gz
opensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.tar.bz2
opensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.tar.xz
Added grid handler and grid remote connector.
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServiceConnector.cs346
-rw-r--r--OpenSim/Services/GridService/GridService.cs65
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs2
3 files changed, 358 insertions, 55 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
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 OpenSim.Server.Base;
39using OpenMetaverse;
40
41namespace 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}
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 6aa1c4f..2229421 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -88,13 +88,18 @@ namespace OpenSim.Services.GridService
88 return m_Database.Delete(regionID); 88 return m_Database.Delete(regionID);
89 } 89 }
90 90
91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, int x, int y) 91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
92 { 92 {
93 List<RegionData> rdatas = m_Database.Get(x - 1, y - 1, x + 1, y + 1, scopeID);
94 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 93 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
95 foreach (RegionData rdata in rdatas) 94 RegionData region = m_Database.Get(regionID, scopeID);
96 rinfos.Add(RegionData2RegionInfo(rdata)); 95 if (region != null)
96 {
97 // Not really? Maybe?
98 List<RegionData> rdatas = m_Database.Get(region.posX - 1, region.posY - 1, region.posX + 1, region.posY + 1, scopeID);
99 foreach (RegionData rdata in rdatas)
100 rinfos.Add(RegionData2RegionInfo(rdata));
97 101
102 }
98 return rinfos; 103 return rinfos;
99 } 104 }
100 105
@@ -164,68 +169,20 @@ namespace OpenSim.Services.GridService
164 rdata.posX = (int)rinfo.RegionLocX; 169 rdata.posX = (int)rinfo.RegionLocX;
165 rdata.posY = (int)rinfo.RegionLocY; 170 rdata.posY = (int)rinfo.RegionLocY;
166 rdata.RegionID = rinfo.RegionID; 171 rdata.RegionID = rinfo.RegionID;
172 rdata.Data = rinfo.ToKeyValuePairs();
167 //rdata.RegionName = rinfo.RegionName; 173 //rdata.RegionName = rinfo.RegionName;
168 rdata.Data["external_ip_address"] = rinfo.ExternalEndPoint.Address.ToString();
169 rdata.Data["external_port"] = rinfo.ExternalEndPoint.Port.ToString();
170 rdata.Data["external_host_name"] = rinfo.ExternalHostName;
171 rdata.Data["http_port"] = rinfo.HttpPort.ToString();
172 rdata.Data["internal_ip_address"] = rinfo.InternalEndPoint.Address.ToString();
173 rdata.Data["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
174 rdata.Data["alternate_ports"] = rinfo.m_allow_alternate_ports.ToString();
175 rdata.Data["server_uri"] = rinfo.ServerURI;
176 174
177 return rdata; 175 return rdata;
178 } 176 }
179 177
180 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata) 178 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata)
181 { 179 {
182 SimpleRegionInfo rinfo = new SimpleRegionInfo(); 180 SimpleRegionInfo rinfo = new SimpleRegionInfo(rdata.Data);
183 rinfo.RegionLocX = (uint)rdata.posX; 181 rinfo.RegionLocX = (uint)rdata.posX;
184 rinfo.RegionLocY = (uint)rdata.posY; 182 rinfo.RegionLocY = (uint)rdata.posY;
185 rinfo.RegionID = rdata.RegionID; 183 rinfo.RegionID = rdata.RegionID;
186 //rinfo.RegionName = rdata.RegionName; 184 //rinfo.RegionName = rdata.RegionName;
187 185
188 // Now for the variable data
189 if ((rdata.Data["external_ip_address"] != null) && (rdata.Data["external_port"] != null))
190 {
191 int port = 0;
192 Int32.TryParse((string)rdata.Data["external_port"], out port);
193 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)rdata.Data["external_ip_address"]), port);
194 rinfo.ExternalEndPoint = ep;
195 }
196 else
197 rinfo.ExternalEndPoint = new IPEndPoint(new IPAddress(0), 0);
198
199 if (rdata.Data["external_host_name"] != null)
200 rinfo.ExternalHostName = (string)rdata.Data["external_host_name"] ;
201
202 if (rdata.Data["http_port"] != null)
203 {
204 UInt32 port = 0;
205 UInt32.TryParse((string)rdata.Data["http_port"], out port);
206 rinfo.HttpPort = port;
207 }
208
209 if ((rdata.Data["internal_ip_address"] != null) && (rdata.Data["internal_port"] != null))
210 {
211 int port = 0;
212 Int32.TryParse((string)rdata.Data["internal_port"], out port);
213 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)rdata.Data["internal_ip_address"]), port);
214 rinfo.InternalEndPoint = ep;
215 }
216 else
217 rinfo.InternalEndPoint = new IPEndPoint(new IPAddress(0), 0);
218
219 if (rdata.Data["alternate_ports"] != null)
220 {
221 bool alts = false;
222 Boolean.TryParse((string)rdata.Data["alternate_ports"], out alts);
223 rinfo.m_allow_alternate_ports = alts;
224 }
225
226 if (rdata.Data["server_uri"] != null)
227 rinfo.ServerURI = (string)rdata.Data["server_uri"];
228
229 return rinfo; 186 return rinfo;
230 } 187 }
231 188
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index 83ab9c1..8f6c524 100644
--- a/OpenSim/Services/Interfaces/IGridService.cs
+++ b/OpenSim/Services/Interfaces/IGridService.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Services.Interfaces
55 /// <param name="x"></param> 55 /// <param name="x"></param>
56 /// <param name="y"></param> 56 /// <param name="y"></param>
57 /// <returns></returns> 57 /// <returns></returns>
58 List<SimpleRegionInfo> GetNeighbours(UUID scopeID, int x, int y); 58 List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID);
59 59
60 SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID); 60 SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID);
61 61