public void DescribeCluster() { var request = new MemberListRequest(); var result = _client.MemberList(request); Assert.NotZero(result.Members.Count); }
private void Start() { Thread th = new Thread(() => { while (true) { try { var rsp = etcdClient.MemberList(new Etcdserverpb.MemberListRequest()); foreach (var p in rsp.Members) { foreach (var client in p.ClientURLs) { dic[client] = null; } } Thread.Sleep(10000); } catch (Exception ex) { GetEtcdClient(); } } }); th.IsBackground = true; th.Name = "MemberList"; th.Start(); }
public MemberListResponse MemberUpdate(MemberListRequest request) { var req = request.ToProto(); var rsp = client.MemberList(req); return(rsp.FromProto()); }
/// <summary> /// 更新集群列表 /// </summary> /// <param name="client"></param> private void UpdateCluster(EtcdClient client) { MemberListRequest request = new MemberListRequest(); var rsp = client.MemberList(request); if (dic.ContainsKey(rsp.Header.ClusterId)) { Health health = dic[rsp.Header.ClusterId]; health.Clients.Add(client); health.Urls.Urls.Clear(); foreach (var kv in rsp.Members) { EtcdClientUrls urls = new EtcdClientUrls(); foreach (var c in kv.ClientURLs) { urls.Urls.Add(c); } health.Urls = urls; } health.Clients.Add(client); } }
public async Task <string> ListAllMembersInCluster() { MemberListRequest request = new MemberListRequest(); etcdClient.MemberList(request); // Sync //MemberListResponse res = etcdClient.MemberList(request); // Async MemberListResponse res = await etcdClient.MemberListAsync(request); JsonMemberList = JsonConvert.SerializeObject(res); // Do something with response //foreach (var member in res.Members) //{ // WriteLine($"member.ID: {member.ID} - member.Name: {member.Name} - member.PeerURLs :{member.PeerURLs} - member.ClientURLs: { member.ClientURLs}"); //} return(JsonMemberList); }
/// <summary> /// 定时刷新节点地址 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Timer_Elapsed(object sender, ElapsedEventArgs e) { MemberListResponse rsp; try { rsp = _client.MemberList(new Etcdserverpb.MemberListRequest()); }catch { GetClient(); return;//下次更新 } lock (Urls) { Urls.Clear(); foreach (var kv in rsp.Members) { EtcdClientUrls etcd = new EtcdClientUrls(); foreach (var c in kv.ClientURLs) { string[] addr = c.Split(new char[] { ':', '/' }, StringSplitOptions.RemoveEmptyEntries); if (addr.Length == 2) { HostAndPort host = new HostAndPort() { Host = addr[0], Port = int.Parse(addr[1]), Flage = addr[0] + addr[1] }; etcd.Urls.Add(host); } else if (addr.Length == 3) { HostAndPort host = new HostAndPort() { Host = addr[1], Port = int.Parse(addr[2]), Flage = addr[1] + addr[2] }; etcd.Urls.Add(host); } } Urls.Add(etcd); // } // if (ClusterUseType == ClusterUse.RoundRobin) { foreach (var c in Urls) { //每个客户端一个连接 foreach (var addr in c.Urls) { ClientMonitor monitor = null; readerWriter.EnterWriteLock(); try { if (dic.TryGetValue(addr.Flage, out monitor)) { try { monitor.Client.Put("Test", "Test"); break; } catch { dic.Remove(addr.Flage); } } else { EtcdClient etcdClient = CreateClient(addr.Host, addr.Port); if (etcdClient != null) { monitor = new ClientMonitor() { Client = etcdClient }; dic[addr.Flage] = monitor; break; } } } finally { readerWriter.ExitWriteLock(); } } } } } }