public void Remove(string host) { host = ServerCenter.GetHost(host); for (int i = 0; i < mServers.Count; i++) { if (mServers[i].Agent.Uri.ToString() == host) { ulong id = mServers[i].ID; mServers.RemoveAt(i); if (mServers.Count > 0) { RefreshWeightTable(); } mServerID.Enqueue(id); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route remove server {host} success"); return; } } }
public void NewOrModify(string host, int weight, int maxRps) { host = ServerCenter.GetHost(host); if (weight > 10) { weight = 10; } if (weight < 0) { weight = 0; } var item = mServers.Find(i => i.Agent.Uri.ToString() == host); if (item != null) { item.Weight = weight; item.MaxRPS = maxRps; Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route update server [{host}] weight [{weight}] max rps [{maxRps}] success"); } else { var agent = Gateway.Agents.Get(host); if (agent == null) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway {Url} route add server error {host} server not found!"); return; } else { UrlServerInfo serverItem = new UrlServerInfo(Url, agent); mServerID.TryDequeue(out ulong id); serverItem.ID = id; serverItem.Weight = weight; serverItem.MaxRPS = maxRps; mServers.Add(serverItem); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route add server [{host}] weight [{weight}] max rps [{maxRps}] success"); } } RefreshWeightTable(); }
public void NewOrModify(string host, int weight, int maxRps, bool standby) { host = ServerCenter.GetHost(host); if (weight > 10) { weight = 10; } if (weight < 0) { weight = 0; } var item = mServers.Find(i => i.Agent.Uri.ToString() == host); if (item != null) { item.Weight = weight; item.MaxRPS = maxRps; item.Standby = standby; Gateway.HttpServer.GetLog(LogType.Info)?.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route update server [{host}] weight [{weight}] max rps [{maxRps}] success"); } else { var agent = Gateway.Agents.Get(host); if (agent == null) { Gateway.Agents.SetServer(host, Gateway.AgentMaxConnection); agent = Gateway.Agents.Get(host); } UrlServerInfo serverItem = new UrlServerInfo(Url, agent); mServerID.TryDequeue(out ulong id); serverItem.ID = id; serverItem.Weight = weight; serverItem.MaxRPS = maxRps; serverItem.Standby = standby; mServers.Add(serverItem); Gateway.HttpServer.GetLog(LogType.Info)?.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Url} route add server [{host}] weight [{weight}] max rps [{maxRps}] success"); } RefreshWeightTable(); }