public static void CallBack(EtcdResponse res) { Console.WriteLine("Reloading Config"); Console.ForegroundColor = ConsoleColor.Yellow; PrintAndWatch(); Console.ResetColor(); }
public CanReadQueueKeys() { Client.Queue(AKey, "wassup1"); Client.Queue(AKey, "wassup2"); _response = Client.Get(AKey, sorted: true); }
public override void Load() { EtcdClientOpitions options = new EtcdClientOpitions() { Urls = source.Options.Urls, Username = source.Options.Username, Password = source.Options.Password, UseProxy = false, IgnoreCertificateError = true }; EtcdClient etcdClient = new EtcdClient(options); try { EtcdResponse resp = etcdClient.GetNodeAsync(source.Options.RootKey, recursive: true, sorted: true).Result; if (resp.Node.Nodes != null) { foreach (var node in resp.Node.Nodes) { // child node Data[node.Key] = node.Value; } } } catch (EtcdCommonException.KeyNotFound) { // key does not Console.WriteLine("key not found exception"); } }
public CanReadQueueKeys() { Client.Queue(AKey, "wassup1"); Client.Queue(AKey, "wassup2"); _response = Client.Get(AKey, sorted:true); }
public CanReadQueueKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _etcdClient.Queue(_id.ToString(), "wassup1"); _etcdClient.Queue(_id.ToString(), "wassup2"); _response = _etcdClient.Get(_id.ToString(), sorted:true); }
public async Task <IEnumerable <string> > LookupServiceAsync(string serviceName) { EtcdResponse response = await _client.GetNodeAsync($"/killrvideo/services/{serviceName}", ignoreKeyNotFoundException : true).ConfigureAwait(false); if (response == null) { throw new ServiceNotFoundException(serviceName); } return(response.Node.Nodes.Select(n => n.Value)); }
public void ActionIsSet() { _wasHit = new ManualResetEvent(false); _response = _etcdClient.Set("bob/"+_key, "wassup"); _etcdClient.Watch("bob", resp => { _wasHit.Set(); }); _etcdClient.Set("bob/"+_key, "nope"); _wasHit.WaitOne(1000).ShouldBeTrue(); }
/// <summary> /// 输出在线状态 /// </summary> /// <returns></returns> private static async Task OutputOnlineState() { try { if (m_client != null) { //var response = await m_client.GetNodeAsync("/Client"); try { EtcdResponse resp1 = await m_client.CreateNodeAsync("/Client", "valye"); EtcdResponse resp = await m_client.SetNodeAsync("/Client", "valye"); Console.WriteLine("Key `{0}` is changed, modifiedIndex={1}", "/Client", resp.Node.ModifiedIndex); var value = await m_client.GetNodeValueAsync("/Client", true); Console.WriteLine("The value of `{0}` is `{1}`", "/Client", value); } catch (EtcdCommonException.KeyNotFound) { Console.WriteLine("Key `{0}` does not exist", "/Client"); } var response = await m_client.GetNodeAsync("/", true); if (response != null && response.Node != null) { if (response.Node.Nodes != null) { foreach (var child in response.Node.Nodes) { var key = child.Key.Replace("/Client/", ""); var value = child.Value; string result = $"{key}状态是{value}"; Console.WriteLine(result); } } } } } catch (Exception e) { Console.WriteLine(e); } }
static async void WatchChanges(EtcdClient etcdClient, string key) { long waitIndex = etcdClient.LastIndex; for (; ;) { try { EtcdResponse resp = await etcdClient.WatchNodeAsync(key, recursive : true, waitIndex : waitIndex); if (resp != null && resp.Node != null) { if (string.Equals(resp.Action, EtcdResponse.ACTION_EXPIRE)) { Console.WriteLine("`{0}` is expired", resp.Node.Key); } waitIndex = resp.Node.ModifiedIndex + 1; } continue; } catch (EtcdException.EventIndexCleared) { waitIndex = etcdClient.LastIndex; } catch (EtcdException.WatcherCleared) { waitIndex = etcdClient.LastIndex; } catch (Exception ex) { int indentation = 0; while (ex != null) { if (!(ex is AggregateException)) { Console.WriteLine("{0} {1} : {2}", string.Empty.PadLeft(indentation), ex.GetType().Name, ex.Message); } indentation += 2; ex = ex.InnerException; } } // if something went wrong, wait for 1 second and try again await Task.Delay(1000); } }
public CanUpdateDirsWithTtl() { Client.CreateDir(AKey); _response = Client.CreateDir(AKey, _ttl, true); _now = DateTime.Now; }
public CanDeleteDirsWithStuff() { Client.Set(AKey +"/bob", "hi"); _deleteResponse = Client.DeleteDir(AKey, true); }
public CanCreateDirs() { _response = Client.CreateDir(AKey); }
public void ActionIsSet() { _response.Action.ShouldEqual("set"); }
public TrimUserSuppliedPath() { _response = Client.Set(AKey, "wassup"); }
public CanGetKeysSorted() { Client.Set(ADirectory + "/" +AKey, "wassup"); Client.Set(ADirectory + "/" +AKey + "-2", "not-much"); _getResponse = Client.Get(ADirectory, sorted:true); }
public CanQueueKeys() { _response = Client.Queue(AKey, "wassup"); }
public CanGetKeys() { Client.Set(AKey, "wassup"); _getResponse = Client.Get(AKey); }
public CanDeleteDirs() { Client.CreateDir(AKey); _deleteResponse = Client.DeleteDir(AKey); }
public CanQueueKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Queue(_id.ToString(), "wassup"); }
public CanSetKeysWithTtl() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set(_key.ToString(), "wassup", _ttl); _now = DateTime.Now; }
public CanDeleteDirsWithStuff() { Client.Set(AKey + "/bob", "hi"); _deleteResponse = Client.DeleteDir(AKey, true); }
public CanSetDirsWithTtl() { _response = Client.CreateDir(AKey, _ttl); _now = DateTime.Now; }
[Fact] public void ActionIsSet() { _getResponse.Action.ShouldEqual("get"); }
public CanGetKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set(_key.ToString(), "wassup"); _getResponse = _etcdClient.Get(_key.ToString()); }
public CanGetKeysSorted() { Client.Set(ADirectory + "/" + AKey, "wassup"); Client.Set(ADirectory + "/" + AKey + "-2", "not-much"); _getResponse = Client.Get(ADirectory, sorted: true); }
public CanSetKeys() { _response = Client.Set(AKey, "wassup"); }
public CanDeleteKeys() { Client.Set(AKey, "wassup"); _deleteResponse = Client.Delete(AKey); }
public KeysWithSlashes() { _response = Client.Set("/folder1/bill", "wassup"); }
public CanDeleteKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set(_key.ToString(), "wassup"); _deleteResponse = _etcdClient.Delete(_key.ToString()); }
public CanSetKeysWithTtl() { _response = Client.Set(AKey, "wassup", _ttl); _now = DateTime.Now; }
public KeysWithSlashes() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set("/folder1/bill", "wassup"); }
public CanDeleteDirsWithStuff() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set(_key+"/bob", "hi"); _deleteResponse = _etcdClient.DeleteDir(_key.ToString(), true); }
public CanGetKeysRecursively() { Client.Set(ADirectory + "/" +AKey, "wassup"); Client.Set(ADirectory + "/" +AKey + "-2", "not-much"); _getResponse = Client.Get(ADirectory, recursive:true); }
public static void CallBack(EtcdResponse res) { Console.WriteLine("Reloading Config \n"); PrintAndWatchApiKey(); }
public CanSetKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set("dru", "wassup"); }
public CanGetKeysRecursively() { Client.Set(ADirectory + "/" + AKey, "wassup"); Client.Set(ADirectory + "/" + AKey + "-2", "not-much"); _getResponse = Client.Get(ADirectory, recursive: true); }
public ProvidesHeaders() { Client.Set(AKey, "wassup"); Client.Set(AKey, "wassup2"); _getResponse = Client.Get(AKey); }
public TrimUserSuppliedPath() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/v2/keys")); _response = _etcdClient.Set("dru", "wassup"); }
static async Task DoSample() { EtcdClientOpitions options = new EtcdClientOpitions() { #if NET45 // TODO: This is optional, having HTTPS setup could make this work in .NET Core as well, but it's not tested for now Urls = new string[] { "https://etcd0.em", "https://etcd1.em", "https://etcd2.em" }, #else Urls = new string[] { "http://*****:*****@"client.p12"), // client cerificate JsonDeserializer = new NewtonsoftJsonDeserializer(), }; EtcdClient etcdClient = new EtcdClient(options); string key = "/my/key"; string value; // query the value of the node using GetNodeValueAsync try { value = await etcdClient.GetNodeValueAsync(key); Console.WriteLine("The value of `{0}` is `{1}`", key, value); } catch (EtcdCommonException.KeyNotFound) { Console.WriteLine("Key `{0}` does not exist", key); } // update the value using SetNodeAsync EtcdResponse resp = await etcdClient.SetNodeAsync(key, "some value"); Console.WriteLine("Key `{0}` is changed, modifiedIndex={1}", key, resp.Node.ModifiedIndex); // query the node using GetNodeAsync resp = await etcdClient.GetNodeAsync(key, ignoreKeyNotFoundException : true); if (resp == null || resp.Node == null) { Console.WriteLine("Key `{0}` does not exist", key); } else { Console.WriteLine("The value of `{0}` is `{1}`", key, resp.Node.Value); } ////////////////////////////////////////////////////////// List <Task <EtcdResponse> > tasks = new List <Task <EtcdResponse> >(); key = "/in-order-queue"; // start monitoring the expire event WatchChanges(etcdClient, key); // create 5 in-order nodes, TTL = 3 second for (int i = 0; i < 5; i++) { tasks.Add(etcdClient.CreateInOrderNodeAsync(key, i.ToString(), ttl: 3)); } await Task.WhenAll(tasks); // list the in-order nodes resp = await etcdClient.GetNodeAsync(key, false, recursive : true, sorted : true); if (resp.Node.Nodes != null) { foreach (var node in resp.Node.Nodes) { Console.WriteLine("`{0}` = {1}", node.Key, node.Value); } } ///////////////////////////////////////////////////////////// key = "/my/cas-test"; value = Guid.NewGuid().ToString(); try { resp = await etcdClient.CreateNodeAsync(key, value, null, dir : false); Console.WriteLine("Key `{0}` is created with value {1}", key, value); } catch (EtcdCommonException.NodeExist) { Console.WriteLine("Key `{0}` already exists", key); } long prevIndex = 1; try { resp = await etcdClient.CompareAndSwapNodeAsync(key, value, "new value"); Console.WriteLine("Key `{0}` is updated to `{1}`", key, resp.Node.Value); prevIndex = resp.Node.ModifiedIndex; } catch (EtcdCommonException.KeyNotFound) { Console.WriteLine("Key `{0}` does not exists", key); } catch (EtcdCommonException.TestFailed) { Console.WriteLine("Key `{0}` can not be updated because the supplied previous value is incorrect", key); } try { resp = await etcdClient.CompareAndSwapNodeAsync(key, prevIndex, "new value2"); Console.WriteLine("Key `{0}` is updated to `{1}`", key, resp.Node.Value); } catch (EtcdCommonException.KeyNotFound) { Console.WriteLine("Key `{0}` does not exists", key); } catch (EtcdCommonException.TestFailed) { Console.WriteLine("Key `{0}` can not be updated because the supplied previous index is incorrect", key); } try { resp = await etcdClient.CompareAndDeleteNodeAsync(key, prevIndex + 1); Console.WriteLine("Key `{0}` is deleted", key); } catch (EtcdCommonException.KeyNotFound) { Console.WriteLine("Key `{0}` does not exists", key); } catch (EtcdCommonException.TestFailed) { Console.WriteLine("Key `{0}` can not be deleted because the supplied previous index is incorrect", key); } if (prevIndex == 1) // the previous CAS failed { try { resp = await etcdClient.CompareAndDeleteNodeAsync(key, "new value2"); Console.WriteLine("Key `{0}` is deleted", key); } catch (EtcdCommonException.KeyNotFound) { Console.WriteLine("Key `{0}` does not exists", key); } catch (EtcdCommonException.TestFailed) { Console.WriteLine("Key `{0}` can not be deleted because the supplied previous value is incorrect", key); etcdClient.DeleteNodeAsync(key, ignoreKeyNotFoundException: true).Wait(); } } }
public CanDeleteDirs() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.CreateDir(_key.ToString()); _deleteResponse = _etcdClient.DeleteDir(_key.ToString()); }
public CanSetDirsWithTtl() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.CreateDir(_key.ToString(), _ttl); _now = DateTime.Now; }