Exemple #1
0
        /// <summary>
        /// Get is used to lookup a single key
        /// </summary>
        /// <param name="key">The key name</param>
        /// <param name="q">Customized query options</param>
        /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
        /// <returns>A query result containing the requested key/value pair, or a query result with a null response if the key does not exist</returns>
        public async Task <QueryResult <KVPair> > Get(string key, QueryOptions q, CancellationToken ct = default(CancellationToken))
        {
            var req = _client.Get <KVPair[]>(string.Format("/v1/kv/{0}", key.TrimStart('/')), q);
            var res = await req.Execute(ct).ConfigureAwait(false);

            return(new QueryResult <KVPair>(res, res.Response != null && res.Response.Length > 0 ? res.Response[0] : null));
        }
Exemple #2
0
        /// <summary>
        /// List is used to get the most recent events an agent has received. This list can be optionally filtered by the name. This endpoint supports quasi-blocking queries. The index is not monotonic, nor does it provide provide LastContact or KnownLeader.
        /// </summary>
        /// <param name="name">The name of the event to filter for</param>
        /// <param name="q">Customized query options</param>
        /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
        /// <returns>An array of events</returns>
        public Task <QueryResult <UserEvent[]> > List(string name, QueryOptions q, CancellationToken ct)
        {
            var req = _client.Get <UserEvent[]>("/v1/event/list", q);

            if (!string.IsNullOrEmpty(name))
            {
                req.Params["name"] = name;
            }
            return(req.Execute(ct));
        }
Exemple #3
0
 /// <summary>
 /// Datacenters is used to return the coordinates of all the servers in the WAN pool.
 /// </summary>
 /// <returns>A query result containing a map of datacenters, each with a list of coordinates of all the servers in the WAN pool</returns>
 public Task <QueryResult <CoordinateDatacenterMap[]> > Datacenters(CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <CoordinateDatacenterMap[]>(string.Format("/v1/coordinate/datacenters")).Execute(ct));
 }
Exemple #4
0
 /// <summary>
 /// RaftGetConfiguration is used to query the current Raft peer set.
 /// </summary>
 public Task <QueryResult <RaftConfiguration> > RaftGetConfiguration(QueryOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <RaftConfiguration>("/v1/operator/raft/configuration", q).Execute(ct));
 }
Exemple #5
0
 /// <summary>
 /// Datacenters is used to query for all the known datacenters
 /// </summary>
 /// <returns>A list of datacenter names</returns>
 public Task <QueryResult <string[]> > Datacenters(CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <string[]>("/v1/catalog/datacenters").Execute(ct));
 }
Exemple #6
0
 /// <summary>
 /// Checks is used to return the checks associated with a service
 /// </summary>
 /// <param name="service">The service ID</param>
 /// <param name="q">Customized query options</param>
 /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
 /// <returns>A query result containing the health checks matching the provided service ID, or a query result with a null response if no service matched the provided ID</returns>
 public Task <QueryResult <HealthCheck[]> > Checks(string service, QueryOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <HealthCheck[]>(string.Format("/v1/health/checks/{0}", service), q).Execute(ct));
 }
Exemple #7
0
 /// <summary>
 /// Query is used to do a GET request against an endpoint and deserialize the response into an interface using standard Consul conventions.
 /// </summary>
 /// <param name="endpoint">The URL endpoint to access</param>
 /// <param name="q">Custom query options</param>
 /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
 /// <returns>The data returned by the custom endpoint</returns>
 public Task <QueryResult <dynamic> > Query(string endpoint, QueryOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <dynamic>(endpoint, q).Execute(ct));
 }
Exemple #8
0
        /// <summary>
        /// Leader is used to query for a known leader
        /// </summary>
        /// <returns>A write result containing the leader node name</returns>
        public async Task <string> Leader(CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Get <string>("/v1/status/leader").Execute(ct).ConfigureAwait(false);

            return(res.Response);
        }
Exemple #9
0
        /// <summary>
        /// Info looks up a single session
        /// </summary>
        /// <param name="id">The session ID to look up</param>
        /// <param name="q">Customized query options</param>
        /// <returns>A query result containing the session information, or an empty query result if the session entry does not exist</returns>
        public async Task <QueryResult <SessionEntry> > Info(string id, QueryOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Get <SessionEntry[]>(string.Format("/v1/session/info/{0}", id), q).Execute(ct).ConfigureAwait(false);

            return(new QueryResult <SessionEntry>(res, res.Response != null && res.Response.Length > 0 ? res.Response[0] : null));
        }
Exemple #10
0
 public Task <QueryResult <Stream> > Save(QueryOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <Stream>("/v1/snapshot", q).ExecuteStreaming(ct));
 }
Exemple #11
0
 public Task <QueryResult <PreparedQueryExecuteResponse> > Execute(string queryIDOrName, QueryOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <PreparedQueryExecuteResponse>(string.Format("/v1/query/{0}/execute", queryIDOrName), q).Execute(ct));
 }