aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.HealthCheck
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2016-02-25 13:53:19 -0800
committerGravatar Julien Boeuf <jboeuf@google.com>2016-02-25 13:53:19 -0800
commitad81219aa8e10b4776999965e85b03ab1f2081d6 (patch)
treeaf8a56eda140e0a25a2c1f23adf94c5e743c17bf /src/csharp/Grpc.HealthCheck
parent4f4d37cbde484f7058a03339d85428087490259b (diff)
parent84a74f89668fbf2b6aebbde7ac0e1675cf7f064c (diff)
Merge branch 'master' of github.com:grpc/grpc into server_security_connector
Diffstat (limited to 'src/csharp/Grpc.HealthCheck')
-rw-r--r--src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec2
-rw-r--r--src/csharp/Grpc.HealthCheck/Health.cs72
-rw-r--r--src/csharp/Grpc.HealthCheck/HealthGrpc.cs30
-rw-r--r--src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs46
4 files changed, 51 insertions, 99 deletions
diff --git a/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec b/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
index 66386288df..7b3b391009 100644
--- a/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
+++ b/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
@@ -4,7 +4,7 @@
<id>Grpc.HealthCheck</id>
<title>gRPC C# Healthchecking</title>
<summary>Implementation of gRPC health service</summary>
- <description>Example implementation of grpc.health.v1alpha service that can be used for health-checking.</description>
+ <description>Example implementation of grpc.health.v1 service that can be used for health-checking.</description>
<version>$version$</version>
<authors>Google Inc.</authors>
<owners>grpc-packages</owners>
diff --git a/src/csharp/Grpc.HealthCheck/Health.cs b/src/csharp/Grpc.HealthCheck/Health.cs
index 56673f1adf..d0d0c0b519 100644
--- a/src/csharp/Grpc.HealthCheck/Health.cs
+++ b/src/csharp/Grpc.HealthCheck/Health.cs
@@ -7,7 +7,7 @@ using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
-namespace Grpc.Health.V1Alpha {
+namespace Grpc.Health.V1 {
/// <summary>Holder for reflection information generated from health.proto</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
@@ -23,20 +23,19 @@ namespace Grpc.Health.V1Alpha {
static HealthReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
- "CgxoZWFsdGgucHJvdG8SE2dycGMuaGVhbHRoLnYxYWxwaGEiMwoSSGVhbHRo",
- "Q2hlY2tSZXF1ZXN0EgwKBGhvc3QYASABKAkSDwoHc2VydmljZRgCIAEoCSKZ",
- "AQoTSGVhbHRoQ2hlY2tSZXNwb25zZRJGCgZzdGF0dXMYASABKA4yNi5ncnBj",
- "LmhlYWx0aC52MWFscGhhLkhlYWx0aENoZWNrUmVzcG9uc2UuU2VydmluZ1N0",
- "YXR1cyI6Cg1TZXJ2aW5nU3RhdHVzEgsKB1VOS05PV04QABILCgdTRVJWSU5H",
- "EAESDwoLTk9UX1NFUlZJTkcQAjJkCgZIZWFsdGgSWgoFQ2hlY2sSJy5ncnBj",
- "LmhlYWx0aC52MWFscGhhLkhlYWx0aENoZWNrUmVxdWVzdBooLmdycGMuaGVh",
- "bHRoLnYxYWxwaGEuSGVhbHRoQ2hlY2tSZXNwb25zZUIWqgITR3JwYy5IZWFs",
- "dGguVjFBbHBoYWIGcHJvdG8z"));
+ "CgxoZWFsdGgucHJvdG8SDmdycGMuaGVhbHRoLnYxIiUKEkhlYWx0aENoZWNr",
+ "UmVxdWVzdBIPCgdzZXJ2aWNlGAEgASgJIpQBChNIZWFsdGhDaGVja1Jlc3Bv",
+ "bnNlEkEKBnN0YXR1cxgBIAEoDjIxLmdycGMuaGVhbHRoLnYxLkhlYWx0aENo",
+ "ZWNrUmVzcG9uc2UuU2VydmluZ1N0YXR1cyI6Cg1TZXJ2aW5nU3RhdHVzEgsK",
+ "B1VOS05PV04QABILCgdTRVJWSU5HEAESDwoLTk9UX1NFUlZJTkcQAjJaCgZI",
+ "ZWFsdGgSUAoFQ2hlY2sSIi5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jl",
+ "cXVlc3QaIy5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jlc3BvbnNlQhGq",
+ "Ag5HcnBjLkhlYWx0aC5WMWIGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] {
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1Alpha.HealthCheckRequest), global::Grpc.Health.V1Alpha.HealthCheckRequest.Parser, new[]{ "Host", "Service" }, null, null, null),
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1Alpha.HealthCheckResponse), global::Grpc.Health.V1Alpha.HealthCheckResponse.Parser, new[]{ "Status" }, null, new[]{ typeof(global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus) }, null)
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1.HealthCheckRequest), global::Grpc.Health.V1.HealthCheckRequest.Parser, new[]{ "Service" }, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1.HealthCheckResponse), global::Grpc.Health.V1.HealthCheckResponse.Parser, new[]{ "Status" }, null, new[]{ typeof(global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus) }, null)
}));
}
#endregion
@@ -49,7 +48,7 @@ namespace Grpc.Health.V1Alpha {
public static pb::MessageParser<HealthCheckRequest> Parser { get { return _parser; } }
public static pbr::MessageDescriptor Descriptor {
- get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.MessageTypes[0]; }
+ get { return global::Grpc.Health.V1.HealthReflection.Descriptor.MessageTypes[0]; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor {
@@ -63,7 +62,6 @@ namespace Grpc.Health.V1Alpha {
partial void OnConstruction();
public HealthCheckRequest(HealthCheckRequest other) : this() {
- host_ = other.host_;
service_ = other.service_;
}
@@ -71,18 +69,8 @@ namespace Grpc.Health.V1Alpha {
return new HealthCheckRequest(this);
}
- /// <summary>Field number for the "host" field.</summary>
- public const int HostFieldNumber = 1;
- private string host_ = "";
- public string Host {
- get { return host_; }
- set {
- host_ = pb::Preconditions.CheckNotNull(value, "value");
- }
- }
-
/// <summary>Field number for the "service" field.</summary>
- public const int ServiceFieldNumber = 2;
+ public const int ServiceFieldNumber = 1;
private string service_ = "";
public string Service {
get { return service_; }
@@ -102,14 +90,12 @@ namespace Grpc.Health.V1Alpha {
if (ReferenceEquals(other, this)) {
return true;
}
- if (Host != other.Host) return false;
if (Service != other.Service) return false;
return true;
}
public override int GetHashCode() {
int hash = 1;
- if (Host.Length != 0) hash ^= Host.GetHashCode();
if (Service.Length != 0) hash ^= Service.GetHashCode();
return hash;
}
@@ -119,21 +105,14 @@ namespace Grpc.Health.V1Alpha {
}
public void WriteTo(pb::CodedOutputStream output) {
- if (Host.Length != 0) {
- output.WriteRawTag(10);
- output.WriteString(Host);
- }
if (Service.Length != 0) {
- output.WriteRawTag(18);
+ output.WriteRawTag(10);
output.WriteString(Service);
}
}
public int CalculateSize() {
int size = 0;
- if (Host.Length != 0) {
- size += 1 + pb::CodedOutputStream.ComputeStringSize(Host);
- }
if (Service.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Service);
}
@@ -144,9 +123,6 @@ namespace Grpc.Health.V1Alpha {
if (other == null) {
return;
}
- if (other.Host.Length != 0) {
- Host = other.Host;
- }
if (other.Service.Length != 0) {
Service = other.Service;
}
@@ -160,10 +136,6 @@ namespace Grpc.Health.V1Alpha {
input.SkipLastField();
break;
case 10: {
- Host = input.ReadString();
- break;
- }
- case 18: {
Service = input.ReadString();
break;
}
@@ -179,7 +151,7 @@ namespace Grpc.Health.V1Alpha {
public static pb::MessageParser<HealthCheckResponse> Parser { get { return _parser; } }
public static pbr::MessageDescriptor Descriptor {
- get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.MessageTypes[1]; }
+ get { return global::Grpc.Health.V1.HealthReflection.Descriptor.MessageTypes[1]; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor {
@@ -202,8 +174,8 @@ namespace Grpc.Health.V1Alpha {
/// <summary>Field number for the "status" field.</summary>
public const int StatusFieldNumber = 1;
- private global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus status_ = global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN;
- public global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus Status {
+ private global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus status_ = global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN;
+ public global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus Status {
get { return status_; }
set {
status_ = value;
@@ -227,7 +199,7 @@ namespace Grpc.Health.V1Alpha {
public override int GetHashCode() {
int hash = 1;
- if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) hash ^= Status.GetHashCode();
+ if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) hash ^= Status.GetHashCode();
return hash;
}
@@ -236,7 +208,7 @@ namespace Grpc.Health.V1Alpha {
}
public void WriteTo(pb::CodedOutputStream output) {
- if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
+ if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
output.WriteRawTag(8);
output.WriteEnum((int) Status);
}
@@ -244,7 +216,7 @@ namespace Grpc.Health.V1Alpha {
public int CalculateSize() {
int size = 0;
- if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
+ if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Status);
}
return size;
@@ -254,7 +226,7 @@ namespace Grpc.Health.V1Alpha {
if (other == null) {
return;
}
- if (other.Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
+ if (other.Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
Status = other.Status;
}
}
@@ -267,7 +239,7 @@ namespace Grpc.Health.V1Alpha {
input.SkipLastField();
break;
case 8: {
- status_ = (global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus) input.ReadEnum();
+ status_ = (global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus) input.ReadEnum();
break;
}
}
diff --git a/src/csharp/Grpc.HealthCheck/HealthGrpc.cs b/src/csharp/Grpc.HealthCheck/HealthGrpc.cs
index 882edd5627..68320eb5c2 100644
--- a/src/csharp/Grpc.HealthCheck/HealthGrpc.cs
+++ b/src/csharp/Grpc.HealthCheck/HealthGrpc.cs
@@ -7,15 +7,15 @@ using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
-namespace Grpc.Health.V1Alpha {
+namespace Grpc.Health.V1 {
public static class Health
{
- static readonly string __ServiceName = "grpc.health.v1alpha.Health";
+ static readonly string __ServiceName = "grpc.health.v1.Health";
- static readonly Marshaller<global::Grpc.Health.V1Alpha.HealthCheckRequest> __Marshaller_HealthCheckRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1Alpha.HealthCheckRequest.Parser.ParseFrom);
- static readonly Marshaller<global::Grpc.Health.V1Alpha.HealthCheckResponse> __Marshaller_HealthCheckResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1Alpha.HealthCheckResponse.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Health.V1.HealthCheckRequest> __Marshaller_HealthCheckRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1.HealthCheckRequest.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Health.V1.HealthCheckResponse> __Marshaller_HealthCheckResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1.HealthCheckResponse.Parser.ParseFrom);
- static readonly Method<global::Grpc.Health.V1Alpha.HealthCheckRequest, global::Grpc.Health.V1Alpha.HealthCheckResponse> __Method_Check = new Method<global::Grpc.Health.V1Alpha.HealthCheckRequest, global::Grpc.Health.V1Alpha.HealthCheckResponse>(
+ static readonly Method<global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse> __Method_Check = new Method<global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse>(
MethodType.Unary,
__ServiceName,
"Check",
@@ -25,22 +25,22 @@ namespace Grpc.Health.V1Alpha {
// service descriptor
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
- get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.Services[0]; }
+ get { return global::Grpc.Health.V1.HealthReflection.Descriptor.Services[0]; }
}
// client interface
public interface IHealthClient
{
- global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
- global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options);
- AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
- AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options);
+ global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options);
+ AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options);
}
// server-side interface
public interface IHealth
{
- Task<global::Grpc.Health.V1Alpha.HealthCheckResponse> Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, ServerCallContext context);
+ Task<global::Grpc.Health.V1.HealthCheckResponse> Check(global::Grpc.Health.V1.HealthCheckRequest request, ServerCallContext context);
}
// client stub
@@ -49,22 +49,22 @@ namespace Grpc.Health.V1Alpha {
public HealthClient(Channel channel) : base(channel)
{
}
- public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
var call = CreateCall(__Method_Check, new CallOptions(headers, deadline, cancellationToken));
return Calls.BlockingUnaryCall(call, request);
}
- public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options)
+ public global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options)
{
var call = CreateCall(__Method_Check, options);
return Calls.BlockingUnaryCall(call, request);
}
- public AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
var call = CreateCall(__Method_Check, new CallOptions(headers, deadline, cancellationToken));
return Calls.AsyncUnaryCall(call, request);
}
- public AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options)
+ public AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options)
{
var call = CreateCall(__Method_Check, options);
return Calls.AsyncUnaryCall(call, request);
diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
index e2ad1a834b..21482b302b 100644
--- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
+++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
@@ -37,7 +37,7 @@ using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Utils;
-using Grpc.Health.V1Alpha;
+using Grpc.Health.V1;
namespace Grpc.HealthCheck
{
@@ -48,44 +48,42 @@ namespace Grpc.HealthCheck
/// <code>
/// var serviceImpl = new HealthServiceImpl();
/// server = new Server();
- /// server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl));
+ /// server.AddServiceDefinition(Grpc.Health.V1.Health.BindService(serviceImpl));
/// </code>
/// </summary>
- public class HealthServiceImpl : Grpc.Health.V1Alpha.Health.IHealth
+ public class HealthServiceImpl : Grpc.Health.V1.Health.IHealth
{
private readonly object myLock = new object();
- private readonly Dictionary<Key, HealthCheckResponse.Types.ServingStatus> statusMap =
- new Dictionary<Key, HealthCheckResponse.Types.ServingStatus>();
+ private readonly Dictionary<string, HealthCheckResponse.Types.ServingStatus> statusMap =
+ new Dictionary<string, HealthCheckResponse.Types.ServingStatus>();
/// <summary>
- /// Sets the health status for given host and service.
+ /// Sets the health status for given service.
/// </summary>
- /// <param name="host">The host. Cannot be null.</param>
/// <param name="service">The service. Cannot be null.</param>
/// <param name="status">the health status</param>
- public void SetStatus(string host, string service, HealthCheckResponse.Types.ServingStatus status)
+ public void SetStatus(string service, HealthCheckResponse.Types.ServingStatus status)
{
lock (myLock)
{
- statusMap[CreateKey(host, service)] = status;
+ statusMap[service] = status;
}
}
/// <summary>
- /// Clears health status for given host and service.
+ /// Clears health status for given service.
/// </summary>
- /// <param name="host">The host. Cannot be null.</param>
/// <param name="service">The service. Cannot be null.</param>
- public void ClearStatus(string host, string service)
+ public void ClearStatus(string service)
{
lock (myLock)
{
- statusMap.Remove(CreateKey(host, service));
+ statusMap.Remove(service);
}
}
/// <summary>
- /// Clears statuses for all hosts and services.
+ /// Clears statuses for all services.
/// </summary>
public void ClearAll()
{
@@ -105,11 +103,10 @@ namespace Grpc.HealthCheck
{
lock (myLock)
{
- var host = request.Host;
var service = request.Service;
HealthCheckResponse.Types.ServingStatus status;
- if (!statusMap.TryGetValue(CreateKey(host, service), out status))
+ if (!statusMap.TryGetValue(service, out status))
{
// TODO(jtattermusch): returning specific status from server handler is not supported yet.
throw new RpcException(new Status(StatusCode.NotFound, ""));
@@ -117,22 +114,5 @@ namespace Grpc.HealthCheck
return Task.FromResult(new HealthCheckResponse { Status = status });
}
}
-
- private static Key CreateKey(string host, string service)
- {
- return new Key(host, service);
- }
-
- private struct Key
- {
- public Key(string host, string service)
- {
- this.Host = GrpcPreconditions.CheckNotNull(host);
- this.Service = GrpcPreconditions.CheckNotNull(service);
- }
-
- readonly string Host;
- readonly string Service;
- }
}
}