public ConsulItem(KVPair kvPair) { CreateIndex = kvPair.CreateIndex; Flags = kvPair.Flags; Key = kvPair.Key; Value = kvPair.Value; }
public void Add(Feature feature) { var pair = new KVPair(BuildPath(string.Format("{0}/features/{1}", FeaturesKey, feature.Key))) { Value = Encoding.UTF8.GetBytes("1") }; _client.KV.Put(pair); }
private void btnPushClusterConfig_Click(object sender, EventArgs e) { KVPair kvClusters = new KVPair(OrekService.Config.ClustersPrefix) { Value = Encoding.UTF8.GetBytes("")}; bool result = OrekService.ConsulClient.KV.Put(kvClusters).Response; if (result) { toolStripStatusLabel1.Text = "Succesfully saved initial config"; btnPushClusterConfig.Enabled = false; btnReloadClusterConfig.Enabled = true; } else { toolStripStatusLabel1.Text = "Save of initial config failed"; } }
private void btnCreateOrekConsulConfig_Click(object sender, EventArgs e) { KVPair kvHeartBeatTtl = new KVPair(OrekService.Config.ConfigPrefix + "heartbeatttl") { Value = Encoding.UTF8.GetBytes(tbTimeOut.Text) }; bool result = OrekService.ConsulClient.KV.Put(kvHeartBeatTtl).Response; KVPair kvTimeout = new KVPair(OrekService.Config.ConfigPrefix + "timeout") { Value = Encoding.UTF8.GetBytes(tbTimeOut.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvTimeout).Response; if (result) { toolStripStatusLabel1.Text = "Succesfully saved initial config"; btnSaveTimeOut.Enabled = false; btnCancelTimeOut.Enabled = false; btnSveHeartBeatTTL.Enabled = false; btnCancelHeartBeatTTL.Enabled = false; btnCreateOrekConsulConfig.Enabled = false; } else { toolStripStatusLabel1.Text = "Save of initial config failed"; } }
private void btnSaveCluster_Click(object sender, EventArgs e) { var clusterpath = OrekService.Config.ClustersPrefix + tbClusterName.Text + "/"; KVPair kvCluster = new KVPair(clusterpath) { Value = Encoding.UTF8.GetBytes("") }; bool result = OrekService.ConsulClient.KV.Put(kvCluster).Response; KVPair kvName = new KVPair(clusterpath + "name") { Value = Encoding.UTF8.GetBytes(tbClusterName.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvName).Response; KVPair kvWindowsServiceName = new KVPair(clusterpath + "windowsservice") { Value = Encoding.UTF8.GetBytes(tbWindowsServiceName.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvWindowsServiceName).Response; KVPair kvLimit = new KVPair(clusterpath + "limit") { Value = Encoding.UTF8.GetBytes(tbLimit.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvLimit).Response; KVPair kvHeartBeatTtl = new KVPair(clusterpath + "heartbeatttl") { Value = Encoding.UTF8.GetBytes(tbHeartBeatTtl.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvHeartBeatTtl).Response; KVPair kvStartTimeout = new KVPair(clusterpath + "starttimeout") { Value = Encoding.UTF8.GetBytes(tbStartTimeout.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvStartTimeout).Response; KVPair kvStopTimeout = new KVPair(clusterpath + "stoptimeout") { Value = Encoding.UTF8.GetBytes(tbStopTimeout.Text) }; result = result && OrekService.ConsulClient.KV.Put(kvStopTimeout).Response; if (result) { toolStripStatusLabel1.Text = "Succesfully saved initial config"; btnSaveCluster.Enabled = false; btnCancelCluster.Enabled = false; LoadClusters(); } else { toolStripStatusLabel1.Text = "Save of initial config failed"; } }
/// <summary> /// Put is used to write a new value. Only the Key, Flags and Value properties are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the write attempt succeeded</returns> public WriteResult<bool> Put(KVPair p) { return Put(p, WriteOptions.Empty); }
/// <summary> /// Acquire is used for a lock acquisition operation. The Key, Flags, Value and Session are respected. /// </summary>p.Validate(); /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the acquisition attempt succeeded</returns> public async Task<WriteResult<bool>> Acquire(KVPair p) { return await Acquire(p, WriteOptions.Default).ConfigureAwait(false); }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public async Task<WriteResult<bool>> DeleteCAS(KVPair p, WriteOptions q) { p.Validate(); var req = _client.Delete<bool>(string.Format("/v1/kv/{0}", p.Key), q); req.Params.Add("cas", p.ModifyIndex.ToString()); return await req.Execute().ConfigureAwait(false); }
/// <summary> /// CAS is used for a Check-And-Set operation. The Key, ModifyIndex, Flags and Value are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the write attempt succeeded</returns> public async Task<WriteResult<bool>> CAS(KVPair p, WriteOptions q) { p.Validate(); var req = _client.Put<byte[], bool>(string.Format("/v1/kv/{0}", p.Key), p.Value, q); if (p.Flags > 0) { req.Params["flags"] = p.Flags.ToString(); } req.Params["cas"] = p.ModifyIndex.ToString(); return await req.Execute().ConfigureAwait(false); }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public Task <WriteResult <bool> > DeleteCAS(KVPair p, CancellationToken ct = default(CancellationToken)) { return(DeleteCAS(p, WriteOptions.Default, ct)); }
/// <summary> /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the release attempt succeeded</returns> public Task <WriteResult <bool> > Release(KVPair p) { return(Release(p, WriteOptions.Default)); }
/// <summary> /// Put is used to write a new value. Only the Key, Flags and Value is respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the write attempt succeeded</returns> public Task<WriteResult<bool>> Put(KVPair p, WriteOptions q) { p.Validate(); var req = _client.Put<byte[], bool>(string.Format("/v1/kv/{0}", p.Key), p.Value, q); if (p.Flags > 0) { req.Params["flags"] = p.Flags.ToString(); } return req.Execute(); }
/// <summary> /// Put is used to write a new value. Only the Key, Flags and Value properties are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the write attempt succeeded</returns> public Task<WriteResult<bool>> Put(KVPair p) { return Put(p, WriteOptions.Default); }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public Task<WriteResult<bool>> DeleteCAS(KVPair p) { return DeleteCAS(p, WriteOptions.Default); }
/// <summary> /// Acquire is used for a lock acquisiiton operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the acquisition attempt succeeded</returns> public WriteResult<bool> Acquire(KVPair p) { return Acquire(p, WriteOptions.Empty); }
/// <summary> /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the release attempt succeeded</returns> public WriteResult<bool> Release(KVPair p, WriteOptions q) { var req = _client.CreateWriteRequest<object, bool>(string.Format("/v1/kv/{0}", p.Key), q); if (p.Flags > 0) { req.Params["flags"] = p.Flags.ToString(); } req.Params["release"] = p.Session; return req.Execute(); }
/// <summary> /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the release attempt succeeded</returns> public WriteResult<bool> Release(KVPair p) { return Release(p, WriteOptions.Empty); }
/// <summary> /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the release attempt succeeded</returns> public Task<WriteResult<bool>> Release(KVPair p) { return Release(p, WriteOptions.Default); }
/// <summary> /// CAS is used for a Check-And-Set operation. The Key, ModifyIndex, Flags and Value are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the write attempt succeeded</returns> public WriteResult<bool> CAS(KVPair p, WriteOptions q) { var req = _client.CreateWriteRequest<byte[], bool>(string.Format("/v1/kv/{0}", p.Key), p.Value, q); if (p.Flags > 0) { req.Params["flags"] = p.Flags.ToString(); } req.Params["cas"] = p.ModifyIndex.ToString(); return req.Execute(); }
/// <summary> /// Acquire is used for a lock acquisition operation. The Key, Flags, Value and Session are respected. /// </summary>p.Validate(); /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the acquisition attempt succeeded</returns> public Task<WriteResult<bool>> Acquire(KVPair p) { return Acquire(p, WriteOptions.Default); }
/// <summary> /// Delete is used to delete a single key. /// </summary> /// <param name="key">The key name to delete</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public Task <WriteResult <bool> > Delete(string key, WriteOptions q, CancellationToken ct = default(CancellationToken)) { KVPair.ValidatePath(key); return(_client.DeleteReturning <bool>(string.Format("/v1/kv/{0}", key.TrimStart('/')), q).Execute(ct)); }
private void WriteValue(string key, string value) { var pair = new KVPair(key) { Value = Encoding.UTF8.GetBytes(value), }; _client.KV.Put(pair); }
/// <summary> /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the release attempt succeeded</returns> public Task <WriteResult <bool> > Release(KVPair p, CancellationToken ct = default(CancellationToken)) { return(Release(p, WriteOptions.Default, ct)); }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public WriteResult<bool> DeleteCAS(KVPair p) { return DeleteCAS(p, WriteOptions.Empty); }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public async Task<WriteResult<bool>> DeleteCAS(KVPair p) { return await DeleteCAS(p, WriteOptions.Default).ConfigureAwait(false); }
/// <summary> /// findLock is used to find the KV Pair which is used for coordination /// </summary> /// <param name="pairs">A list of KVPairs</param> /// <returns>The semaphore storage KV pair</returns> private KVPair FindLock(KVPair[] pairs) { var key = string.Join("/", Opts.Prefix, DefaultSemaphoreKey); if (pairs != null) { return pairs.FirstOrDefault(p => p.Key == key) ?? new KVPair(key) { Flags = SemaphoreFlagValue }; } return new KVPair(key) { Flags = SemaphoreFlagValue }; }
/// <summary> /// Release is used for a lock release operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the release attempt succeeded</returns> public async Task<WriteResult<bool>> Release(KVPair p, WriteOptions q) { p.Validate(); var req = _client.Put<object, bool>(string.Format("/v1/kv/{0}", p.Key), q); if (p.Flags > 0) { req.Params["flags"] = p.Flags.ToString(); } req.Params["release"] = p.Session; return await req.Execute().ConfigureAwait(false); }
internal static KVPair ToKVPair(ConsulSiloRegistration siloRegistration) { var ret = new KVPair(ConsulSiloRegistrationAssembler.ParseDeploymentSiloKey(siloRegistration.DeploymentId, siloRegistration.Address)); ret.ModifyIndex = siloRegistration.LastIndex; ret.Value = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(siloRegistration)); return ret; }
/// <summary> /// DecodeLock is used to decode a SemaphoreLock from an entry in Consul /// </summary> /// <param name="pair"></param> /// <returns>A decoded lock or a new, blank lock</returns> private SemaphoreLock DecodeLock(KVPair pair) { if (pair == null || pair.Value == null) { return new SemaphoreLock() { Limit = Opts.Limit }; } return JsonConvert.DeserializeObject<SemaphoreLock>(Encoding.UTF8.GetString(pair.Value)); }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public WriteResult<bool> DeleteCAS(KVPair p, WriteOptions q) { var req = _client.CreateWriteRequest<object, bool>(HttpMethod.Delete, string.Format("/v1/kv/{0}", p.Key), q); req.Params.Add("cas", p.ModifyIndex.ToString()); return req.Execute(); }
internal static ConsulSiloRegistration FromKVPairs(String deploymentId, KVPair siloKV, KVPair iAmAliveKV) { var ret = JsonConvert.DeserializeObject<ConsulSiloRegistration>(Encoding.UTF8.GetString(siloKV.Value)); var keyParts = siloKV.Key.Split(KeySeparator); ret.Address = SiloAddress.FromParsableString(keyParts.Last()); ret.DeploymentId = deploymentId; ret.LastIndex = siloKV.ModifyIndex; if (iAmAliveKV == null) ret.IAmAliveTime = ret.StartTime; else ret.IAmAliveTime = JsonConvert.DeserializeObject<DateTime>(Encoding.UTF8.GetString(iAmAliveKV.Value)); return ret; }
/// <summary> /// Acquire is used for a lock acquisition operation. The Key, Flags, Value and Session are respected. /// </summary>p.Validate(); /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the acquisition attempt succeeded</returns> public Task <WriteResult <bool> > Acquire(KVPair p) { return(Acquire(p, WriteOptions.Default)); }
internal static KVPair ToIAmAliveKVPair(String deploymentId, SiloAddress siloAddress, DateTime iAmAliveTime) { var ret = new KVPair(ConsulSiloRegistrationAssembler.ParseSiloIAmAliveKey(deploymentId, siloAddress)); ret.Value = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(iAmAliveTime)); return ret; }
/// <summary> /// Delete is used to delete a single key. /// </summary> /// <param name="key">The key name to delete</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public Task <WriteResult <bool> > Delete(string key, WriteOptions q) { KVPair.ValidatePath(key); return(_client.Delete <bool>(string.Format("/v1/kv/{0}", key), q).Execute()); }
private void btnSaveTimeOut_Click(object sender, EventArgs e) { KVPair kvTimeout = new KVPair(OrekService.Config.ConfigPrefix + "timeout") { Value = Encoding.UTF8.GetBytes(tbTimeOut.Text) }; bool result = OrekService.ConsulClient.KV.Put(kvTimeout).Response; if (result) { toolStripStatusLabel1.Text = "Succesfully saved TimeOut"; btnSaveTimeOut.Enabled = false; btnCancelTimeOut.Enabled = false; } else { toolStripStatusLabel1.Text = "Save of TimeOut failed"; } }
/// <summary> /// DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures. /// </summary> /// <param name="p">The key/value pair to delete</param> /// <returns>A write result indicating if the delete attempt succeeded</returns> public Task <WriteResult <bool> > DeleteCAS(KVPair p) { return(DeleteCAS(p, WriteOptions.Default)); }
/// <summary> /// Put is used to write a new value. Only the Key, Flags and Value properties are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <returns>A write result indicating if the write attempt succeeded</returns> public Task <WriteResult <bool> > Put(KVPair p) { return(Put(p, WriteOptions.Default)); }
/// <summary> /// Acquire is used for a lock acquisiiton operation. The Key, Flags, Value and Session are respected. /// </summary> /// <param name="p">The key/value pair to store in Consul</param> /// <param name="q">Customized write options</param> /// <returns>A write result indicating if the acquisition attempt succeeded</returns> public WriteResult<bool> Acquire(KVPair p, WriteOptions q) { var req = _client.CreateWrite<byte[], bool>(string.Format("/v1/kv/{0}", p.Key), p.Value, q); if (p.Flags > 0) { req.Params["flags"] = p.Flags.ToString(); } req.Params["acquire"] = p.Session; return req.Execute(); }