public ConsulItem(KVPair kvPair)
 {
     CreateIndex = kvPair.CreateIndex;
     Flags = kvPair.Flags;
     Key = kvPair.Key;
     Value = kvPair.Value;
 }
示例#2
0
 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);
 }
示例#3
0
 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"; }
 }
示例#4
0
 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"; }
 }
示例#5
0
 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"; }
 }
示例#6
0
 /// <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);
 }
示例#7
0
 /// <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);
 }
示例#8
0
 /// <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);
 }
示例#9
0
 /// <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);
 }
示例#10
0
 /// <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));
 }
示例#11
0
 /// <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));
 }
示例#12
0
 /// <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();
 }
示例#13
0
 /// <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);
 }
示例#14
0
 /// <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);
 }
示例#15
0
 /// <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);
 }
示例#16
0
 /// <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();
 }
示例#17
0
 /// <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);
 }
示例#18
0
 /// <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);
 }
示例#19
0
 /// <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();
 }
示例#20
0
 /// <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);
 }
示例#21
0
 /// <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));
 }
示例#22
0
 private void WriteValue(string key, string value)
 {
     var pair = new KVPair(key)
         {
             Value = Encoding.UTF8.GetBytes(value),
         };
     _client.KV.Put(pair);
 }
示例#23
0
 /// <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));
 }
示例#24
0
 /// <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);
 }
示例#25
0
 /// <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);
 }
示例#26
0
 /// <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 };
 }
示例#27
0
 /// <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;
 }
示例#29
0
        /// <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));
        }
示例#30
0
 /// <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;
        }
示例#32
0
 /// <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;
 }
示例#34
0
 /// <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());
 }
示例#35
0
 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"; }
 }
示例#36
0
 /// <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));
 }
示例#37
0
 /// <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));
 }
示例#38
0
文件: KV.cs 项目: Pliner/consuldotnet
 /// <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();
 }