Exemplo n.º 1
0
        public EtcdResult SetValue(string key, string value, long?ttl = null, string prevValue = null, long?prevIndex = null, bool?prevExist = null)
        {
            List <string> query = new List <string>();

            if (prevValue != null)
            {
                query.Add("prevValue=" + Uri.EscapeUriString(prevValue));
            }
            if (prevIndex != null)
            {
                query.Add("prevIndex=" + prevIndex.ToString());
            }
            if (prevExist != null && prevExist == true)
            {
                query.Add("prevExist=true");
            }
            foreach (EtcdServer srv in serverList)
            {
                string uri = BuildRequestUri(srv.host, srv.port, "keys", key, query.ToArray());
                NameValueCollection data       = BuildRequestData(null, value, ttl);
                string             responseStr = null;
                WebExceptionStatus status      = DoWebRequest(uri, "PUT", data, out responseStr);
                if (status == WebExceptionStatus.Success || status == WebExceptionStatus.ProtocolError)
                {
                    return(EtcdResult.Parse(responseStr));
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public EtcdResult Get(string key, bool recursive, bool?sorted = null)
        {
            List <string> query = new List <string>();

            if (recursive)
            {
                query.Add("recursive=true");
            }
            if (sorted != null && sorted == true)
            {
                query.Add("sorted=true");
            }

            foreach (EtcdServer srv in serverList)
            {
                string             uri         = BuildRequestUri(srv.host, srv.port, "keys", key, query.ToArray());
                string             responseStr = null;
                WebExceptionStatus status      = DoWebRequest(uri, "GET", out responseStr);
                if (status == WebExceptionStatus.Success || status == WebExceptionStatus.ProtocolError)
                {
                    return(EtcdResult.Parse(responseStr));
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        public static EtcdResult Parse(string jsonStr)
        {
            Object obj;

            if (!SimpleJson.SimpleJson.TryDeserializeObject(jsonStr, out obj))
            {
                return(null);
            }
            SimpleJson.JsonObject jsonObj = (SimpleJson.JsonObject)obj;
            EtcdResult            result  = new EtcdResult();

            if (jsonObj.ContainsKey("errorCode"))
            {
                result.action = "unknown";
                result.error  = EtcdError.Parse(jsonObj);
            }
            else
            {
                if (jsonObj.ContainsKey("action"))
                {
                    result.action = (string)jsonObj["action"];
                }
                if (jsonObj.ContainsKey("node"))
                {
                    result.node = EtcdResultNode.Parse((SimpleJson.JsonObject)jsonObj["node"]);
                }
                if (jsonObj.ContainsKey("prevNode"))
                {
                    result.prevNode = EtcdResultNode.Parse((SimpleJson.JsonObject)jsonObj["prevNode"]);
                }
            }
            return(result);
        }
Exemplo n.º 4
0
 public EtcdResult Enqueue(string key, string value, long?ttl = null)
 {
     foreach (EtcdServer srv in serverList)
     {
         string uri = BuildRequestUri(srv.host, srv.port, "keys", key);
         NameValueCollection data       = BuildRequestData(null, value, ttl);
         string             responseStr = null;
         WebExceptionStatus status      = DoWebRequest(uri, "POST", data, out responseStr);
         if (status == WebExceptionStatus.Success || status == WebExceptionStatus.ProtocolError)
         {
             return(EtcdResult.Parse(responseStr));
         }
     }
     return(null);
 }
Exemplo n.º 5
0
 public EtcdResult DeleteDir(string key, bool recursive)
 {
     foreach (EtcdServer srv in serverList)
     {
         string uri = null;
         if (recursive)
         {
             uri = BuildRequestUri(srv.host, srv.port, "keys", key, "recursive=true");
         }
         else
         {
             uri = BuildRequestUri(srv.host, srv.port, "keys", key);
         }
         string             responseStr = null;
         WebExceptionStatus status      = DoWebRequest(uri, "DELETE", out responseStr);
         if (status == WebExceptionStatus.Success || status == WebExceptionStatus.ProtocolError)
         {
             return(EtcdResult.Parse(responseStr));
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        public EtcdResult DeleteValue(string key, string prevValue = null, long?prevIndex = null)
        {
            List <string> query = new List <string>();

            if (prevValue != null)
            {
                query.Add("prevValue=" + Uri.EscapeUriString(prevValue));
            }
            if (prevIndex != null)
            {
                query.Add("prevIndex=" + prevIndex.ToString());
            }
            foreach (EtcdServer srv in serverList)
            {
                string             uri         = BuildRequestUri(srv.host, srv.port, "keys", key, query.ToArray());
                string             responseStr = null;
                WebExceptionStatus status      = DoWebRequest(uri, "DELETE", out responseStr);
                if (status == WebExceptionStatus.Success || status == WebExceptionStatus.ProtocolError)
                {
                    return(EtcdResult.Parse(responseStr));
                }
            }
            return(null);
        }
Exemplo n.º 7
0
 public EtcdResult Watch(string key, int waitIndex, out EtcdResult result)
 {
     throw new NotImplementedException();
 }