From 7c1b2a5dde3b61dae4cca6bff7d2fe560be96fae Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 13 Aug 2016 05:22:29 +0100 Subject: add some wiring to have GetUserAccounts for multiple IDs on a single request to grid services. Unfinished, untested --- .../LocalUserAccountServiceConnector.cs | 6 ++ .../RemoteUserAccountServiceConnector.cs | 35 +++++++++++ .../SimianUserAccountServiceConnector.cs | 6 ++ .../UserAccounts/UserAccountServicesConnector.cs | 72 ++++++++++++++++++++++ .../Services/HypergridService/UserAccountCache.cs | 6 ++ OpenSim/Services/Interfaces/IUserAccountService.cs | 1 + .../UserAccountService/UserAccountService.cs | 13 ++++ 7 files changed, 139 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs index cf9a7b4..1002b85 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs @@ -182,6 +182,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts return UserAccountService.GetUserAccount(scopeID, Email); } + public List GetUserAccounts(UUID scopeID, List IDs, out bool suported) + { + return UserAccountService.GetUserAccounts(scopeID, IDs, out suported); + } + + public List GetUserAccountsWhere(UUID scopeID, string query) { return null; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs index afbba30..fb5fae1 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs @@ -26,6 +26,8 @@ */ using System; +using System.Collections; +using System.Collections.Generic; using Nini.Config; using log4net; using Mono.Addins; @@ -158,6 +160,39 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts return account; } + public override List GetUserAccounts(UUID scopeID, List IDs, out bool suported) + { + suported = true; + List accs = new List(); + List missing = new List(); + + UUID uuid = UUID.Zero;; + UserAccount account; + bool inCache = false; + + foreach(string id in IDs) + { + if(UUID.TryParse(id, out uuid)) + { + account = m_Cache.Get(uuid, out inCache); + if (inCache) + accs.Add(account); + else + missing.Add(id); + } + } + + if(missing.Count > 0) + { + List ext = base.GetUserAccounts(scopeID, missing, out suported); + if(suported && ext != null) + accs.AddRange(ext); + } + + return accs; + } + + public override bool StoreUserAccount(UserAccount data) { // This remote connector refuses to serve this method diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs index 563a1e7..1ef5ad2 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs @@ -201,6 +201,12 @@ namespace OpenSim.Services.Connectors.SimianGrid return null; } + public List GetUserAccounts(UUID scopeID, List IDs, out bool suported) + { + suported = false; + return null; + } + public bool StoreUserAccount(UserAccount data) { // m_log.InfoFormat("[SIMIAN ACCOUNT CONNECTOR]: Storing user account for " + data.Name); diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs index 3de0a20..e625143 100644 --- a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs +++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs @@ -191,6 +191,78 @@ namespace OpenSim.Services.Connectors return accounts; } + public virtual List GetUserAccounts(UUID scopeID, List IDs, out bool suported) + { + suported = true; + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getmultiaccounts"; + + sendData["ScopeID"] = scopeID.ToString(); + sendData["IDS"] = new List(IDs); + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/accounts"; + // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString, + m_Auth); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetMultiUserAccounts received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); + } + + List accounts = new List(); + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + if (replyData.ContainsKey("result")) + { + if(replyData["result"].ToString() == "null") + return accounts; + + if(replyData["result"].ToString() == "Failure") + { + suported = false; + return accounts; + } + } + + Dictionary.ValueCollection accountList = replyData.Values; + //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); + foreach (object acc in accountList) + { + if (acc is Dictionary) + { + UserAccount pinfo = new UserAccount((Dictionary)acc); + accounts.Add(pinfo); + } + else + m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetMultiUserAccounts received invalid response type {0}", + acc.GetType()); + } + } + else + m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetMultiUserAccounts received null response"); + + return accounts; + } + + public void InvalidateCache(UUID userID) { } diff --git a/OpenSim/Services/HypergridService/UserAccountCache.cs b/OpenSim/Services/HypergridService/UserAccountCache.cs index 6c3c655..618bd97 100644 --- a/OpenSim/Services/HypergridService/UserAccountCache.cs +++ b/OpenSim/Services/HypergridService/UserAccountCache.cs @@ -100,6 +100,12 @@ namespace OpenSim.Services.HypergridService return null; } + public List GetUserAccounts(UUID scopeID, List IDs, out bool suported) + { + suported = false; + return null; + } + public void InvalidateCache(UUID userID) { m_UUIDCache.Remove(userID); diff --git a/OpenSim/Services/Interfaces/IUserAccountService.cs b/OpenSim/Services/Interfaces/IUserAccountService.cs index 1814699..1914040 100644 --- a/OpenSim/Services/Interfaces/IUserAccountService.cs +++ b/OpenSim/Services/Interfaces/IUserAccountService.cs @@ -187,6 +187,7 @@ namespace OpenSim.Services.Interfaces /// List GetUserAccounts(UUID scopeID, string query); List GetUserAccountsWhere(UUID scopeID, string where); + List GetUserAccounts(UUID scopeID, List IDs, out bool suported); /// /// Store the data given, wich replaces the stored data, therefore must be complete. diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 6010f0c..fbe5e3b 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -265,6 +265,19 @@ namespace OpenSim.Services.UserAccountService return MakeUserAccount(d[0]); } + public List GetUserAccounts(UUID scopeID, List IDs, out bool suported) + { + suported = true; + List accs = new List(); + UUID uuid = UUID.Zero; + foreach(string id in IDs) + { + if (UUID.TryParse(id, out uuid) && uuid != UUID.Zero) + accs.Add(GetUserAccount(scopeID, uuid)); + } + return accs; + } + public void InvalidateCache(UUID userID) { } -- cgit v1.1