Ejemplo n.º 1
0
Archivo: KV.cs Proyecto: stulzq/NConsul
        /// <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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
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));
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Info is used to query for information about an ACL token
        /// </summary>
        /// <param name="id">The ACL ID to request information about</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 ACL entry matching the provided ID, or a query result with a null response if no token matched the provided ID</returns>
        public async Task <QueryResult <ACLEntry> > Info(string id, QueryOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Get <ACLEntry[]>(string.Format("/v1/acl/info/{0}", id), q).Execute(ct).ConfigureAwait(false);

            return(new QueryResult <ACLEntry>(res, res.Response != null && res.Response.Length > 0 ? res.Response[0] : null));
        }
Ejemplo n.º 6
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));
 }
Ejemplo n.º 7
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));
 }
Ejemplo n.º 8
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));
 }
Ejemplo n.º 9
0
 public Task <QueryResult <Stream> > Save(QueryOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Get <Stream>("/v1/snapshot", q).ExecuteStreaming(ct));
 }
Ejemplo n.º 10
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));
 }
Ejemplo n.º 11
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));
 }