From 6019a5ab4b8cf787fd36245b485ccdb6a8ba0766 Mon Sep 17 00:00:00 2001 From: dapengzhang0 Date: Thu, 12 May 2016 14:09:26 -0700 Subject: [PATCH 1/3] health check service --- .../testing/integration/TestServiceImpl.java | 2 +- services/build.gradle | 35 + .../io/grpc/services/health/HealthGrpc.java | 231 ++++ .../services/health/HealthOuterClass.java | 1023 +++++++++++++++++ .../services/health/HealthServiceImpl.java | 88 ++ .../services/health/HealthStatusManager.java | 96 ++ .../io/grpc/services/health/package-info.java | 42 + .../java/io/grpc/services/package-info.java | 35 + services/src/main/proto/health.proto | 51 + .../health/HealthStatusManagerTest.java | 139 +++ settings.gradle | 2 + 11 files changed, 1743 insertions(+), 1 deletion(-) create mode 100644 services/build.gradle create mode 100644 services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java create mode 100644 services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java create mode 100644 services/src/main/java/io/grpc/services/health/HealthServiceImpl.java create mode 100644 services/src/main/java/io/grpc/services/health/HealthStatusManager.java create mode 100644 services/src/main/java/io/grpc/services/health/package-info.java create mode 100644 services/src/main/java/io/grpc/services/package-info.java create mode 100644 services/src/main/proto/health.proto create mode 100644 services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java index d73aee09554..dee585edc47 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java @@ -78,7 +78,7 @@ public TestServiceImpl(ScheduledExecutorService executor) { @Override public void emptyCall(EmptyProtos.Empty empty, - StreamObserver responseObserver) { + StreamObserver responseObserver) { responseObserver.onNext(EmptyProtos.Empty.getDefaultInstance()); responseObserver.onCompleted(); } diff --git a/services/build.gradle b/services/build.gradle new file mode 100644 index 00000000000..46479e7bfca --- /dev/null +++ b/services/build.gradle @@ -0,0 +1,35 @@ +// Add dependency on the protobuf plugin +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath libraries.protobuf_plugin + } +} + +plugins { + id "be.insaneprogramming.gradle.animalsniffer" version "1.4.0" +} + +description = "gRPC: Services" + +dependencies { + compile project(':grpc-protobuf'), + project(':grpc-stub') +} + +configureProtoCompilation() + +// Configure the animal sniffer plugin +animalsniffer { + signature = "org.codehaus.mojo.signature:java16:+@signature" +} + +// Let intellij projects refer to generated code +idea { + module { + sourceDirs += file("${projectDir}/src/generated/main/java"); + sourceDirs += file("${projectDir}/src/generated/main/grpc"); + } +} diff --git a/services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java b/services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java new file mode 100644 index 00000000000..18e191a2037 --- /dev/null +++ b/services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java @@ -0,0 +1,231 @@ +package io.grpc.services.health; + +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.futureUnaryCall; +import static io.grpc.MethodDescriptor.generateFullMethodName; +import static io.grpc.stub.ServerCalls.asyncUnaryCall; +import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; +import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; +import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; +import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; + +/** + */ +@javax.annotation.Generated( + value = "by gRPC proto compiler (version 0.15.0-SNAPSHOT)", + comments = "Source: health.proto") +public class HealthGrpc { + + private HealthGrpc() {} + + public static final String SERVICE_NAME = "grpc.health.v1.Health"; + + // Static method descriptors that strictly reflect the proto. + @io.grpc.ExperimentalApi + public static final io.grpc.MethodDescriptor METHOD_CHECK = + io.grpc.MethodDescriptor.create( + io.grpc.MethodDescriptor.MethodType.UNARY, + generateFullMethodName( + "grpc.health.v1.Health", "Check"), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.services.health.HealthOuterClass.HealthCheckRequest.getDefaultInstance()), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDefaultInstance())); + + /** + * Creates a new async stub that supports all call types for the service + */ + public static HealthStub newStub(io.grpc.Channel channel) { + return new HealthStub(channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static HealthBlockingStub newBlockingStub( + io.grpc.Channel channel) { + return new HealthBlockingStub(channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary and streaming output calls on the service + */ + public static HealthFutureStub newFutureStub( + io.grpc.Channel channel) { + return new HealthFutureStub(channel); + } + + /** + */ + public static interface Health { + + /** + */ + public void check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request, + io.grpc.stub.StreamObserver responseObserver); + } + + @io.grpc.ExperimentalApi + public static abstract class AbstractHealth implements Health, io.grpc.BindableService { + + @java.lang.Override + public void check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnimplementedUnaryCall(METHOD_CHECK, responseObserver); + } + + @java.lang.Override public io.grpc.ServerServiceDefinition bindService() { + return HealthGrpc.bindService(this); + } + } + + /** + */ + public static interface HealthBlockingClient { + + /** + */ + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request); + } + + /** + */ + public static interface HealthFutureClient { + + /** + */ + public com.google.common.util.concurrent.ListenableFuture check( + io.grpc.services.health.HealthOuterClass.HealthCheckRequest request); + } + + public static class HealthStub extends io.grpc.stub.AbstractStub + implements Health { + private HealthStub(io.grpc.Channel channel) { + super(channel); + } + + private HealthStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected HealthStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new HealthStub(channel, callOptions); + } + + @java.lang.Override + public void check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnaryCall( + getChannel().newCall(METHOD_CHECK, getCallOptions()), request, responseObserver); + } + } + + public static class HealthBlockingStub extends io.grpc.stub.AbstractStub + implements HealthBlockingClient { + private HealthBlockingStub(io.grpc.Channel channel) { + super(channel); + } + + private HealthBlockingStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected HealthBlockingStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new HealthBlockingStub(channel, callOptions); + } + + @java.lang.Override + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request) { + return blockingUnaryCall( + getChannel(), METHOD_CHECK, getCallOptions(), request); + } + } + + public static class HealthFutureStub extends io.grpc.stub.AbstractStub + implements HealthFutureClient { + private HealthFutureStub(io.grpc.Channel channel) { + super(channel); + } + + private HealthFutureStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected HealthFutureStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new HealthFutureStub(channel, callOptions); + } + + @java.lang.Override + public com.google.common.util.concurrent.ListenableFuture check( + io.grpc.services.health.HealthOuterClass.HealthCheckRequest request) { + return futureUnaryCall( + getChannel().newCall(METHOD_CHECK, getCallOptions()), request); + } + } + + private static final int METHODID_CHECK = 0; + + private static class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final Health serviceImpl; + private final int methodId; + + public MethodHandlers(Health serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_CHECK: + serviceImpl.check((io.grpc.services.health.HealthOuterClass.HealthCheckRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + public static io.grpc.ServerServiceDefinition bindService( + final Health serviceImpl) { + return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME) + .addMethod( + METHOD_CHECK, + asyncUnaryCall( + new MethodHandlers< + io.grpc.services.health.HealthOuterClass.HealthCheckRequest, + io.grpc.services.health.HealthOuterClass.HealthCheckResponse>( + serviceImpl, METHODID_CHECK))) + .build(); + } +} diff --git a/services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java b/services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java new file mode 100644 index 00000000000..ff2139bb4a2 --- /dev/null +++ b/services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java @@ -0,0 +1,1023 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: health.proto + +package io.grpc.services.health; + +public final class HealthOuterClass { + private HealthOuterClass() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface HealthCheckRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:grpc.health.v1.HealthCheckRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string service = 1; + */ + java.lang.String getService(); + /** + * optional string service = 1; + */ + com.google.protobuf.ByteString + getServiceBytes(); + } + /** + * Protobuf type {@code grpc.health.v1.HealthCheckRequest} + */ + public static final class HealthCheckRequest extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:grpc.health.v1.HealthCheckRequest) + HealthCheckRequestOrBuilder { + // Use HealthCheckRequest.newBuilder() to construct. + private HealthCheckRequest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private HealthCheckRequest() { + service_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private HealthCheckRequest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + service_ = s; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw new RuntimeException(e.setUnfinishedMessage(this)); + } catch (java.io.IOException e) { + throw new RuntimeException( + new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this)); + } finally { + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.services.health.HealthOuterClass.HealthCheckRequest.class, io.grpc.services.health.HealthOuterClass.HealthCheckRequest.Builder.class); + } + + public static final int SERVICE_FIELD_NUMBER = 1; + private volatile java.lang.Object service_; + /** + * optional string service = 1; + */ + public java.lang.String getService() { + java.lang.Object ref = service_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + service_ = s; + return s; + } + } + /** + * optional string service = 1; + */ + public com.google.protobuf.ByteString + getServiceBytes() { + java.lang.Object ref = service_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + service_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getServiceBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, service_); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getServiceBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(1, service_); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(io.grpc.services.health.HealthOuterClass.HealthCheckRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code grpc.health.v1.HealthCheckRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:grpc.health.v1.HealthCheckRequest) + io.grpc.services.health.HealthOuterClass.HealthCheckRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.services.health.HealthOuterClass.HealthCheckRequest.class, io.grpc.services.health.HealthOuterClass.HealthCheckRequest.Builder.class); + } + + // Construct using io.grpc.services.health.HealthOuterClass.HealthCheckRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + service_ = ""; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckRequest getDefaultInstanceForType() { + return io.grpc.services.health.HealthOuterClass.HealthCheckRequest.getDefaultInstance(); + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckRequest build() { + io.grpc.services.health.HealthOuterClass.HealthCheckRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckRequest buildPartial() { + io.grpc.services.health.HealthOuterClass.HealthCheckRequest result = new io.grpc.services.health.HealthOuterClass.HealthCheckRequest(this); + result.service_ = service_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof io.grpc.services.health.HealthOuterClass.HealthCheckRequest) { + return mergeFrom((io.grpc.services.health.HealthOuterClass.HealthCheckRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(io.grpc.services.health.HealthOuterClass.HealthCheckRequest other) { + if (other == io.grpc.services.health.HealthOuterClass.HealthCheckRequest.getDefaultInstance()) return this; + if (!other.getService().isEmpty()) { + service_ = other.service_; + onChanged(); + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + io.grpc.services.health.HealthOuterClass.HealthCheckRequest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (io.grpc.services.health.HealthOuterClass.HealthCheckRequest) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object service_ = ""; + /** + * optional string service = 1; + */ + public java.lang.String getService() { + java.lang.Object ref = service_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + service_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string service = 1; + */ + public com.google.protobuf.ByteString + getServiceBytes() { + java.lang.Object ref = service_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + service_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string service = 1; + */ + public Builder setService( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + service_ = value; + onChanged(); + return this; + } + /** + * optional string service = 1; + */ + public Builder clearService() { + + service_ = getDefaultInstance().getService(); + onChanged(); + return this; + } + /** + * optional string service = 1; + */ + public Builder setServiceBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + service_ = value; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:grpc.health.v1.HealthCheckRequest) + } + + // @@protoc_insertion_point(class_scope:grpc.health.v1.HealthCheckRequest) + private static final io.grpc.services.health.HealthOuterClass.HealthCheckRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new io.grpc.services.health.HealthOuterClass.HealthCheckRequest(); + } + + public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public HealthCheckRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new HealthCheckRequest(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof + com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) + e.getCause(); + } + throw e; + } + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + public interface HealthCheckResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:grpc.health.v1.HealthCheckResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + int getStatusValue(); + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus getStatus(); + } + /** + * Protobuf type {@code grpc.health.v1.HealthCheckResponse} + */ + public static final class HealthCheckResponse extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:grpc.health.v1.HealthCheckResponse) + HealthCheckResponseOrBuilder { + // Use HealthCheckResponse.newBuilder() to construct. + private HealthCheckResponse(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private HealthCheckResponse() { + status_ = 0; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private HealthCheckResponse( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 8: { + int rawValue = input.readEnum(); + + status_ = rawValue; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw new RuntimeException(e.setUnfinishedMessage(this)); + } catch (java.io.IOException e) { + throw new RuntimeException( + new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this)); + } finally { + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.services.health.HealthOuterClass.HealthCheckResponse.class, io.grpc.services.health.HealthOuterClass.HealthCheckResponse.Builder.class); + } + + /** + * Protobuf enum {@code grpc.health.v1.HealthCheckResponse.ServingStatus} + */ + public enum ServingStatus + implements com.google.protobuf.ProtocolMessageEnum { + /** + * UNKNOWN = 0; + */ + UNKNOWN(0, 0), + /** + * SERVING = 1; + */ + SERVING(1, 1), + /** + * NOT_SERVING = 2; + */ + NOT_SERVING(2, 2), + UNRECOGNIZED(-1, -1), + ; + + /** + * UNKNOWN = 0; + */ + public static final int UNKNOWN_VALUE = 0; + /** + * SERVING = 1; + */ + public static final int SERVING_VALUE = 1; + /** + * NOT_SERVING = 2; + */ + public static final int NOT_SERVING_VALUE = 2; + + + public final int getNumber() { + if (index == -1) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + public static ServingStatus valueOf(int value) { + switch (value) { + case 0: return UNKNOWN; + case 1: return SERVING; + case 2: return NOT_SERVING; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + ServingStatus> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public ServingStatus findValueByNumber(int number) { + return ServingStatus.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDescriptor().getEnumTypes().get(0); + } + + private static final ServingStatus[] VALUES = values(); + + public static ServingStatus valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private ServingStatus(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:grpc.health.v1.HealthCheckResponse.ServingStatus) + } + + public static final int STATUS_FIELD_NUMBER = 1; + private int status_; + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public int getStatusValue() { + return status_; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus getStatus() { + io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus result = io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.valueOf(status_); + return result == null ? io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNRECOGNIZED : result; + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (status_ != io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNKNOWN.getNumber()) { + output.writeEnum(1, status_); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (status_ != io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNKNOWN.getNumber()) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(1, status_); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(io.grpc.services.health.HealthOuterClass.HealthCheckResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code grpc.health.v1.HealthCheckResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:grpc.health.v1.HealthCheckResponse) + io.grpc.services.health.HealthOuterClass.HealthCheckResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.services.health.HealthOuterClass.HealthCheckResponse.class, io.grpc.services.health.HealthOuterClass.HealthCheckResponse.Builder.class); + } + + // Construct using io.grpc.services.health.HealthOuterClass.HealthCheckResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + status_ = 0; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse getDefaultInstanceForType() { + return io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDefaultInstance(); + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse build() { + io.grpc.services.health.HealthOuterClass.HealthCheckResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse buildPartial() { + io.grpc.services.health.HealthOuterClass.HealthCheckResponse result = new io.grpc.services.health.HealthOuterClass.HealthCheckResponse(this); + result.status_ = status_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof io.grpc.services.health.HealthOuterClass.HealthCheckResponse) { + return mergeFrom((io.grpc.services.health.HealthOuterClass.HealthCheckResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(io.grpc.services.health.HealthOuterClass.HealthCheckResponse other) { + if (other == io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDefaultInstance()) return this; + if (other.status_ != 0) { + setStatusValue(other.getStatusValue()); + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + io.grpc.services.health.HealthOuterClass.HealthCheckResponse parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (io.grpc.services.health.HealthOuterClass.HealthCheckResponse) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private int status_ = 0; + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public int getStatusValue() { + return status_; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public Builder setStatusValue(int value) { + status_ = value; + onChanged(); + return this; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus getStatus() { + io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus result = io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.valueOf(status_); + return result == null ? io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNRECOGNIZED : result; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public Builder setStatus(io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus value) { + if (value == null) { + throw new NullPointerException(); + } + + status_ = value.getNumber(); + onChanged(); + return this; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public Builder clearStatus() { + + status_ = 0; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:grpc.health.v1.HealthCheckResponse) + } + + // @@protoc_insertion_point(class_scope:grpc.health.v1.HealthCheckResponse) + private static final io.grpc.services.health.HealthOuterClass.HealthCheckResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new io.grpc.services.health.HealthOuterClass.HealthCheckResponse(); + } + + public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public HealthCheckResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new HealthCheckResponse(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof + com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) + e.getCause(); + } + throw e; + } + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public io.grpc.services.health.HealthOuterClass.HealthCheckResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\014health.proto\022\016grpc.health.v1\"%\n\022Health" + + "CheckRequest\022\017\n\007service\030\001 \001(\t\"\224\001\n\023Health" + + "CheckResponse\022A\n\006status\030\001 \001(\01621.grpc.hea" + + "lth.v1.HealthCheckResponse.ServingStatus" + + "\":\n\rServingStatus\022\013\n\007UNKNOWN\020\000\022\013\n\007SERVIN" + + "G\020\001\022\017\n\013NOT_SERVING\020\0022Z\n\006Health\022P\n\005Check\022" + + "\".grpc.health.v1.HealthCheckRequest\032#.gr" + + "pc.health.v1.HealthCheckResponseB*\n\027io.g" + + "rpc.services.health\252\002\016Grpc.Health.V1b\006pr" + + "oto3" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_grpc_health_v1_HealthCheckRequest_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_grpc_health_v1_HealthCheckRequest_descriptor, + new java.lang.String[] { "Service", }); + internal_static_grpc_health_v1_HealthCheckResponse_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_grpc_health_v1_HealthCheckResponse_descriptor, + new java.lang.String[] { "Status", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java b/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java new file mode 100644 index 00000000000..9828d9b16db --- /dev/null +++ b/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.grpc.services.health; + +import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse; +import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus; + +import io.grpc.Status; +import io.grpc.StatusException; +import io.grpc.stub.StreamObserver; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.annotation.Nullable; + + +final class HealthServiceImpl extends HealthGrpc.AbstractHealth { + + /* Due to the latency of rpc calls, synchronization of the map does not help with consistency. + * However, need use ConcurrentHashMap to prevent the possible race condition of currently putting + * two keys with a colliding hashCode into the map. */ + private final Map statusMap + = new ConcurrentHashMap(); + + @Override + public void check(HealthOuterClass.HealthCheckRequest request, + StreamObserver responseObserver) { + ServingStatus status = getStatus(request.getService()); + respond(status, responseObserver); + } + + private void respond(ServingStatus status, StreamObserver responseObserver) { + if (status == null) { + responseObserver.onError(new StatusException(Status.NOT_FOUND)); + } else { + HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build(); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + } + + void setStatus(String service, ServingStatus status) { + statusMap.put(service, status); + } + + @Nullable + ServingStatus getStatus(String service) { + return statusMap.get(service); + } + + void clearStatus(String service) { + statusMap.remove(service); + } + + void clearAll() { + statusMap.clear(); + } +} diff --git a/services/src/main/java/io/grpc/services/health/HealthStatusManager.java b/services/src/main/java/io/grpc/services/health/HealthStatusManager.java new file mode 100644 index 00000000000..4e22416d940 --- /dev/null +++ b/services/src/main/java/io/grpc/services/health/HealthStatusManager.java @@ -0,0 +1,96 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.grpc.services.health; + +import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus; + +import javax.annotation.Nullable; + +/** + * A {@code HealthStatusManager} object manages a health check service. A health check service is + * created in the constructor of {@code HealthStatusManager}, and it can be retrieved by the + * {@link #getHealthService()} method. + * The health status manager can update the health status of gRPC services. + */ +@io.grpc.ExperimentalApi +public final class HealthStatusManager { + + private final HealthServiceImpl healthService; + + /** + * Creates a new health service instance. + */ + public HealthStatusManager() { + healthService = new HealthServiceImpl(); + } + + /** + * Gets the health check service created in the constructor. + */ + public HealthGrpc.AbstractHealth getHealthService() { + return healthService; + } + + /** + * Updates the status of service. + * @param status is one of the values {@link ServingStatus#SERVING}, + * {@link ServingStatus#NOT_SERVING} and {@link ServingStatus#UNKNOWN}. + */ + public void setStatus(String service, ServingStatus status) { + healthService.setStatus(service, status); + } + + /** + * Gets the health status of a service. + * @return {@code null} if there is no record of the status of the service or the service does + * not exist. + */ + @Nullable + public ServingStatus getStatus(String service) { + return healthService.getStatus(service); + } + + /** + * Clears the health status record of a service. + */ + public void clearStatus(String service) { + healthService.clearStatus(service); + } + + /** + * Clears all the health status records. + */ + public void clearAll() { + healthService.clearAll(); + } + +} diff --git a/services/src/main/java/io/grpc/services/health/package-info.java b/services/src/main/java/io/grpc/services/health/package-info.java new file mode 100644 index 00000000000..abdcf9e6089 --- /dev/null +++ b/services/src/main/java/io/grpc/services/health/package-info.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * GRPC Health Checking is a pre-defined proto service that is used to probe whether the server is + * able to handle RPC requests. Please refer to + * + * https://github.com/grpc/grpc/blob/master/doc/health-checking.md + * + * for the service description. + *

+ * {@link io.grpc.services.health.HealthStatusManager} is used for updating health statuses. + */ +package io.grpc.services.health; diff --git a/services/src/main/java/io/grpc/services/package-info.java b/services/src/main/java/io/grpc/services/package-info.java new file mode 100644 index 00000000000..195e6aa2df4 --- /dev/null +++ b/services/src/main/java/io/grpc/services/package-info.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Service definitions and utilities for the pre-defined gRPC services. + */ +package io.grpc.services; diff --git a/services/src/main/proto/health.proto b/services/src/main/proto/health.proto new file mode 100644 index 00000000000..06755527726 --- /dev/null +++ b/services/src/main/proto/health.proto @@ -0,0 +1,51 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package grpc.health.v1; +option csharp_namespace = "Grpc.Health.V1"; +option java_package = "io.grpc.services.health"; + +message HealthCheckRequest { + string service = 1; +} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + } + ServingStatus status = 1; +} + +service Health { + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); +} diff --git a/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java b/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java new file mode 100644 index 00000000000..49df2ce456e --- /dev/null +++ b/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.grpc.services.health; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.grpc.Status; +import io.grpc.StatusException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; + +/** Unit tests for {@link HealthStatusManager}. */ +@RunWith(JUnit4.class) +public class HealthStatusManagerTest { + + private final HealthStatusManager manager = new HealthStatusManager(); + private final HealthGrpc.Health health = manager.getHealthService(); + private final HealthOuterClass.HealthCheckResponse.ServingStatus status + = HealthOuterClass.HealthCheckResponse.ServingStatus.UNKNOWN; + + @Test + public void getHealthService_getterReturnsTheSameHealthRefAfterUpdate() throws Exception { + manager.setStatus("", status); + assertEquals(health, manager.getHealthService()); + } + + @Test + public void setAndGetStatus() throws Exception { + manager.setStatus("", status); + assertEquals(status, manager.getStatus("")); + assertNull(manager.getStatus("invalid")); + } + + + @Test + public void clearStatus() throws Exception { + //setup + manager.setStatus("", status); + //test + manager.clearStatus(""); + //verify + assertNull(manager.getStatus("")); + } + + @Test + public void clearAll() throws Exception { + //setup + manager.setStatus("", status); + manager.setStatus("1", status); + + //test + manager.clearAll(); + + //verify + assertNull(manager.getStatus("")); + assertNull(manager.getStatus("1")); + } + + @Test + public void checkValidStatus() throws Exception { + //setup + manager.setStatus("", status); + HealthOuterClass.HealthCheckRequest request + = HealthOuterClass.HealthCheckRequest.newBuilder().setService("").build(); + @SuppressWarnings("unchecked") + io.grpc.stub.StreamObserver observer + = mock(io.grpc.stub.StreamObserver.class); + + //test + health.check(request, observer); + + //verify + InOrder inOrder = inOrder(observer); + inOrder.verify(observer, times(1)).onNext(any(HealthOuterClass.HealthCheckResponse.class)); + inOrder.verify(observer, times(1)).onCompleted(); + verify(observer, never()).onError(any(Throwable.class)); + } + + @Test + public void checkStatusNotFound() throws Exception { + //setup + manager.setStatus("", status); + HealthOuterClass.HealthCheckRequest request + = HealthOuterClass.HealthCheckRequest.newBuilder().setService("invalid").build(); + @SuppressWarnings("unchecked") + io.grpc.stub.StreamObserver observer + = mock(io.grpc.stub.StreamObserver.class); + + //test + health.check(request, observer); + + //verify + ArgumentCaptor exception = ArgumentCaptor.forClass(StatusException.class); + verify(observer, times(1)).onError(exception.capture()); + assertEquals(Status.NOT_FOUND, exception.getValue().getStatus()); + + verify(observer, never()).onCompleted(); + } +} diff --git a/settings.gradle b/settings.gradle index 9bed7a1075f..8c199acb3b9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,6 +12,7 @@ include ":grpc-testing" include ":grpc-interop-testing" include ":grpc-all" include ":grpc-benchmarks" +include ":grpc-services" include ":grpc-examples" project(':grpc-core').projectDir = "$rootDir/core" as File @@ -27,6 +28,7 @@ project(':grpc-testing').projectDir = "$rootDir/testing" as File project(':grpc-interop-testing').projectDir = "$rootDir/interop-testing" as File project(':grpc-all').projectDir = "$rootDir/all" as File project(':grpc-benchmarks').projectDir = "$rootDir/benchmarks" as File +project(':grpc-services').projectDir = "$rootDir/services" as File project(':grpc-examples').projectDir = "$rootDir/examples" as File if (settings.hasProperty('skipCodegen') && skipCodegen.toBoolean()) { From 22e3b77b0e5e45aa8f78b9e3f0c6d6b2e4d03dd1 Mon Sep 17 00:00:00 2001 From: dapengzhang0 Date: Wed, 18 May 2016 10:00:27 -0700 Subject: [PATCH 2/3] refactored health service and incorporated other review comments --- .../services/health/HealthServiceImpl.java | 4 -- .../services/health/HealthStatusManager.java | 34 +++++------- .../health/HealthStatusManagerTest.java | 52 ++++++++----------- 3 files changed, 34 insertions(+), 56 deletions(-) diff --git a/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java b/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java index 9828d9b16db..bdc7273bf76 100644 --- a/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java +++ b/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java @@ -56,10 +56,6 @@ final class HealthServiceImpl extends HealthGrpc.AbstractHealth { public void check(HealthOuterClass.HealthCheckRequest request, StreamObserver responseObserver) { ServingStatus status = getStatus(request.getService()); - respond(status, responseObserver); - } - - private void respond(ServingStatus status, StreamObserver responseObserver) { if (status == null) { responseObserver.onError(new StatusException(Status.NOT_FOUND)); } else { diff --git a/services/src/main/java/io/grpc/services/health/HealthStatusManager.java b/services/src/main/java/io/grpc/services/health/HealthStatusManager.java index 4e22416d940..7363f8180e2 100644 --- a/services/src/main/java/io/grpc/services/health/HealthStatusManager.java +++ b/services/src/main/java/io/grpc/services/health/HealthStatusManager.java @@ -31,15 +31,16 @@ package io.grpc.services.health; +import static com.google.common.base.Preconditions.checkNotNull; import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus; -import javax.annotation.Nullable; + /** * A {@code HealthStatusManager} object manages a health check service. A health check service is * created in the constructor of {@code HealthStatusManager}, and it can be retrieved by the * {@link #getHealthService()} method. - * The health status manager can update the health status of gRPC services. + * The health status manager can update the health statuses of the server. */ @io.grpc.ExperimentalApi public final class HealthStatusManager { @@ -61,36 +62,27 @@ public HealthGrpc.AbstractHealth getHealthService() { } /** - * Updates the status of service. + * Updates the status of the server. + * @param service the name of some aspect of the server that is associated with a health status. + * This name can have no relation with the gRPC services that the server is running with. + * It can also be an empty String {@code ""} per the gRPC specification. * @param status is one of the values {@link ServingStatus#SERVING}, * {@link ServingStatus#NOT_SERVING} and {@link ServingStatus#UNKNOWN}. */ public void setStatus(String service, ServingStatus status) { + checkNotNull(status, "status"); healthService.setStatus(service, status); } /** - * Gets the health status of a service. - * @return {@code null} if there is no record of the status of the service or the service does - * not exist. - */ - @Nullable - public ServingStatus getStatus(String service) { - return healthService.getStatus(service); - } - - /** - * Clears the health status record of a service. + * Clears the health status record of a service. The health service will respond with NOT_FOUND + * error on checking the status of a cleared service. + * @param service the name of some aspect of the server that is associated with a health status. + * This name can have no relation with the gRPC services that the server is running with. + * It can also be an empty String {@code ""} per the gRPC specification. */ public void clearStatus(String service) { healthService.clearStatus(service); } - /** - * Clears all the health status records. - */ - public void clearAll() { - healthService.clearAll(); - } - } diff --git a/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java b/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java index 49df2ce456e..36e03ba3b64 100644 --- a/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java +++ b/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java @@ -32,7 +32,6 @@ package io.grpc.services.health; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.mockito.Mockito.any; import static org.mockito.Mockito.inOrder; @@ -64,44 +63,33 @@ public void getHealthService_getterReturnsTheSameHealthRefAfterUpdate() throws E assertEquals(health, manager.getHealthService()); } - @Test - public void setAndGetStatus() throws Exception { - manager.setStatus("", status); - assertEquals(status, manager.getStatus("")); - assertNull(manager.getStatus("invalid")); - } - - - @Test - public void clearStatus() throws Exception { - //setup - manager.setStatus("", status); - //test - manager.clearStatus(""); - //verify - assertNull(manager.getStatus("")); - } @Test - public void clearAll() throws Exception { + public void checkValidStatus() throws Exception { //setup manager.setStatus("", status); - manager.setStatus("1", status); + HealthOuterClass.HealthCheckRequest request + = HealthOuterClass.HealthCheckRequest.newBuilder().setService("").build(); + @SuppressWarnings("unchecked") + io.grpc.stub.StreamObserver observer + = mock(io.grpc.stub.StreamObserver.class); //test - manager.clearAll(); + health.check(request, observer); //verify - assertNull(manager.getStatus("")); - assertNull(manager.getStatus("1")); + InOrder inOrder = inOrder(observer); + inOrder.verify(observer, times(1)).onNext(any(HealthOuterClass.HealthCheckResponse.class)); + inOrder.verify(observer, times(1)).onCompleted(); + verify(observer, never()).onError(any(Throwable.class)); } @Test - public void checkValidStatus() throws Exception { + public void checkStatusNotFound() throws Exception { //setup manager.setStatus("", status); HealthOuterClass.HealthCheckRequest request - = HealthOuterClass.HealthCheckRequest.newBuilder().setService("").build(); + = HealthOuterClass.HealthCheckRequest.newBuilder().setService("invalid").build(); @SuppressWarnings("unchecked") io.grpc.stub.StreamObserver observer = mock(io.grpc.stub.StreamObserver.class); @@ -110,18 +98,20 @@ public void checkValidStatus() throws Exception { health.check(request, observer); //verify - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(any(HealthOuterClass.HealthCheckResponse.class)); - inOrder.verify(observer, times(1)).onCompleted(); - verify(observer, never()).onError(any(Throwable.class)); + ArgumentCaptor exception = ArgumentCaptor.forClass(StatusException.class); + verify(observer, times(1)).onError(exception.capture()); + assertEquals(Status.NOT_FOUND, exception.getValue().getStatus()); + + verify(observer, never()).onCompleted(); } @Test - public void checkStatusNotFound() throws Exception { + public void notFoundForClearedStatus() throws Exception { //setup manager.setStatus("", status); + manager.clearStatus(""); HealthOuterClass.HealthCheckRequest request - = HealthOuterClass.HealthCheckRequest.newBuilder().setService("invalid").build(); + = HealthOuterClass.HealthCheckRequest.newBuilder().setService("").build(); @SuppressWarnings("unchecked") io.grpc.stub.StreamObserver observer = mock(io.grpc.stub.StreamObserver.class); From b4251f82070f4aa6ca7d61b4e50259c1776ee66b Mon Sep 17 00:00:00 2001 From: dapengzhang0 Date: Thu, 19 May 2016 16:03:29 -0700 Subject: [PATCH 3/3] refactor health service package --- .../health => health/v1}/HealthGrpc.java | 42 +- .../io/grpc/health/v1/HealthCheckRequest.java | 440 +++++++ .../v1/HealthCheckRequestOrBuilder.java | 19 + .../grpc/health/v1/HealthCheckResponse.java | 498 ++++++++ .../v1/HealthCheckResponseOrBuilder.java | 18 + .../java/io/grpc/health/v1/HealthProto.java | 68 ++ .../services/health/HealthOuterClass.java | 1023 ----------------- .../{health => }/HealthServiceImpl.java | 10 +- .../{health => }/HealthStatusManager.java | 6 +- .../io/grpc/services/health/package-info.java | 42 - services/src/main/proto/health.proto | 5 +- .../{health => }/HealthStatusManagerTest.java | 38 +- 12 files changed, 1098 insertions(+), 1111 deletions(-) rename services/src/generated/main/grpc/io/grpc/{services/health => health/v1}/HealthGrpc.java (75%) create mode 100644 services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequest.java create mode 100644 services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequestOrBuilder.java create mode 100644 services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponse.java create mode 100644 services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponseOrBuilder.java create mode 100644 services/src/generated/main/java/io/grpc/health/v1/HealthProto.java delete mode 100644 services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java rename services/src/main/java/io/grpc/services/{health => }/HealthServiceImpl.java (91%) rename services/src/main/java/io/grpc/services/{health => }/HealthStatusManager.java (96%) delete mode 100644 services/src/main/java/io/grpc/services/health/package-info.java rename services/src/test/java/io/grpc/services/{health => }/HealthStatusManagerTest.java (77%) diff --git a/services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java b/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java similarity index 75% rename from services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java rename to services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java index 18e191a2037..0cb251f236c 100644 --- a/services/src/generated/main/grpc/io/grpc/services/health/HealthGrpc.java +++ b/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java @@ -1,4 +1,4 @@ -package io.grpc.services.health; +package io.grpc.health.v1; import static io.grpc.stub.ClientCalls.asyncUnaryCall; import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; @@ -28,14 +28,14 @@ private HealthGrpc() {} // Static method descriptors that strictly reflect the proto. @io.grpc.ExperimentalApi - public static final io.grpc.MethodDescriptor METHOD_CHECK = + public static final io.grpc.MethodDescriptor METHOD_CHECK = io.grpc.MethodDescriptor.create( io.grpc.MethodDescriptor.MethodType.UNARY, generateFullMethodName( "grpc.health.v1.Health", "Check"), - io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.services.health.HealthOuterClass.HealthCheckRequest.getDefaultInstance()), - io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDefaultInstance())); + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.health.v1.HealthCheckRequest.getDefaultInstance()), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.health.v1.HealthCheckResponse.getDefaultInstance())); /** * Creates a new async stub that supports all call types for the service @@ -66,16 +66,16 @@ public static interface Health { /** */ - public void check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request, - io.grpc.stub.StreamObserver responseObserver); + public void check(io.grpc.health.v1.HealthCheckRequest request, + io.grpc.stub.StreamObserver responseObserver); } @io.grpc.ExperimentalApi public static abstract class AbstractHealth implements Health, io.grpc.BindableService { @java.lang.Override - public void check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void check(io.grpc.health.v1.HealthCheckRequest request, + io.grpc.stub.StreamObserver responseObserver) { asyncUnimplementedUnaryCall(METHOD_CHECK, responseObserver); } @@ -90,7 +90,7 @@ public static interface HealthBlockingClient { /** */ - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request); + public io.grpc.health.v1.HealthCheckResponse check(io.grpc.health.v1.HealthCheckRequest request); } /** @@ -99,8 +99,8 @@ public static interface HealthFutureClient { /** */ - public com.google.common.util.concurrent.ListenableFuture check( - io.grpc.services.health.HealthOuterClass.HealthCheckRequest request); + public com.google.common.util.concurrent.ListenableFuture check( + io.grpc.health.v1.HealthCheckRequest request); } public static class HealthStub extends io.grpc.stub.AbstractStub @@ -121,8 +121,8 @@ protected HealthStub build(io.grpc.Channel channel, } @java.lang.Override - public void check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void check(io.grpc.health.v1.HealthCheckRequest request, + io.grpc.stub.StreamObserver responseObserver) { asyncUnaryCall( getChannel().newCall(METHOD_CHECK, getCallOptions()), request, responseObserver); } @@ -146,7 +146,7 @@ protected HealthBlockingStub build(io.grpc.Channel channel, } @java.lang.Override - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse check(io.grpc.services.health.HealthOuterClass.HealthCheckRequest request) { + public io.grpc.health.v1.HealthCheckResponse check(io.grpc.health.v1.HealthCheckRequest request) { return blockingUnaryCall( getChannel(), METHOD_CHECK, getCallOptions(), request); } @@ -170,8 +170,8 @@ protected HealthFutureStub build(io.grpc.Channel channel, } @java.lang.Override - public com.google.common.util.concurrent.ListenableFuture check( - io.grpc.services.health.HealthOuterClass.HealthCheckRequest request) { + public com.google.common.util.concurrent.ListenableFuture check( + io.grpc.health.v1.HealthCheckRequest request) { return futureUnaryCall( getChannel().newCall(METHOD_CHECK, getCallOptions()), request); } @@ -197,8 +197,8 @@ public MethodHandlers(Health serviceImpl, int methodId) { public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { switch (methodId) { case METHODID_CHECK: - serviceImpl.check((io.grpc.services.health.HealthOuterClass.HealthCheckRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); + serviceImpl.check((io.grpc.health.v1.HealthCheckRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); break; default: throw new AssertionError(); @@ -223,8 +223,8 @@ public static io.grpc.ServerServiceDefinition bindService( METHOD_CHECK, asyncUnaryCall( new MethodHandlers< - io.grpc.services.health.HealthOuterClass.HealthCheckRequest, - io.grpc.services.health.HealthOuterClass.HealthCheckResponse>( + io.grpc.health.v1.HealthCheckRequest, + io.grpc.health.v1.HealthCheckResponse>( serviceImpl, METHODID_CHECK))) .build(); } diff --git a/services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequest.java b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequest.java new file mode 100644 index 00000000000..b06ac1b991f --- /dev/null +++ b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequest.java @@ -0,0 +1,440 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: health.proto + +package io.grpc.health.v1; + +/** + * Protobuf type {@code grpc.health.v1.HealthCheckRequest} + */ +public final class HealthCheckRequest extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:grpc.health.v1.HealthCheckRequest) + HealthCheckRequestOrBuilder { + // Use HealthCheckRequest.newBuilder() to construct. + private HealthCheckRequest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private HealthCheckRequest() { + service_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private HealthCheckRequest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + service_ = s; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw new RuntimeException(e.setUnfinishedMessage(this)); + } catch (java.io.IOException e) { + throw new RuntimeException( + new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this)); + } finally { + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.health.v1.HealthCheckRequest.class, io.grpc.health.v1.HealthCheckRequest.Builder.class); + } + + public static final int SERVICE_FIELD_NUMBER = 1; + private volatile java.lang.Object service_; + /** + * optional string service = 1; + */ + public java.lang.String getService() { + java.lang.Object ref = service_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + service_ = s; + return s; + } + } + /** + * optional string service = 1; + */ + public com.google.protobuf.ByteString + getServiceBytes() { + java.lang.Object ref = service_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + service_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getServiceBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, service_); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getServiceBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(1, service_); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static io.grpc.health.v1.HealthCheckRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static io.grpc.health.v1.HealthCheckRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.health.v1.HealthCheckRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(io.grpc.health.v1.HealthCheckRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code grpc.health.v1.HealthCheckRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:grpc.health.v1.HealthCheckRequest) + io.grpc.health.v1.HealthCheckRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.health.v1.HealthCheckRequest.class, io.grpc.health.v1.HealthCheckRequest.Builder.class); + } + + // Construct using io.grpc.health.v1.HealthCheckRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + service_ = ""; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + } + + public io.grpc.health.v1.HealthCheckRequest getDefaultInstanceForType() { + return io.grpc.health.v1.HealthCheckRequest.getDefaultInstance(); + } + + public io.grpc.health.v1.HealthCheckRequest build() { + io.grpc.health.v1.HealthCheckRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public io.grpc.health.v1.HealthCheckRequest buildPartial() { + io.grpc.health.v1.HealthCheckRequest result = new io.grpc.health.v1.HealthCheckRequest(this); + result.service_ = service_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof io.grpc.health.v1.HealthCheckRequest) { + return mergeFrom((io.grpc.health.v1.HealthCheckRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(io.grpc.health.v1.HealthCheckRequest other) { + if (other == io.grpc.health.v1.HealthCheckRequest.getDefaultInstance()) return this; + if (!other.getService().isEmpty()) { + service_ = other.service_; + onChanged(); + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + io.grpc.health.v1.HealthCheckRequest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (io.grpc.health.v1.HealthCheckRequest) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object service_ = ""; + /** + * optional string service = 1; + */ + public java.lang.String getService() { + java.lang.Object ref = service_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + service_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string service = 1; + */ + public com.google.protobuf.ByteString + getServiceBytes() { + java.lang.Object ref = service_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + service_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string service = 1; + */ + public Builder setService( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + service_ = value; + onChanged(); + return this; + } + /** + * optional string service = 1; + */ + public Builder clearService() { + + service_ = getDefaultInstance().getService(); + onChanged(); + return this; + } + /** + * optional string service = 1; + */ + public Builder setServiceBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + service_ = value; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:grpc.health.v1.HealthCheckRequest) + } + + // @@protoc_insertion_point(class_scope:grpc.health.v1.HealthCheckRequest) + private static final io.grpc.health.v1.HealthCheckRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new io.grpc.health.v1.HealthCheckRequest(); + } + + public static io.grpc.health.v1.HealthCheckRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public HealthCheckRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new HealthCheckRequest(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof + com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) + e.getCause(); + } + throw e; + } + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public io.grpc.health.v1.HealthCheckRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequestOrBuilder.java b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequestOrBuilder.java new file mode 100644 index 00000000000..ba9024bed1f --- /dev/null +++ b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckRequestOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: health.proto + +package io.grpc.health.v1; + +public interface HealthCheckRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:grpc.health.v1.HealthCheckRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string service = 1; + */ + java.lang.String getService(); + /** + * optional string service = 1; + */ + com.google.protobuf.ByteString + getServiceBytes(); +} diff --git a/services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponse.java b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponse.java new file mode 100644 index 00000000000..2f945916aef --- /dev/null +++ b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponse.java @@ -0,0 +1,498 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: health.proto + +package io.grpc.health.v1; + +/** + * Protobuf type {@code grpc.health.v1.HealthCheckResponse} + */ +public final class HealthCheckResponse extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:grpc.health.v1.HealthCheckResponse) + HealthCheckResponseOrBuilder { + // Use HealthCheckResponse.newBuilder() to construct. + private HealthCheckResponse(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private HealthCheckResponse() { + status_ = 0; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private HealthCheckResponse( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 8: { + int rawValue = input.readEnum(); + + status_ = rawValue; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw new RuntimeException(e.setUnfinishedMessage(this)); + } catch (java.io.IOException e) { + throw new RuntimeException( + new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this)); + } finally { + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.health.v1.HealthCheckResponse.class, io.grpc.health.v1.HealthCheckResponse.Builder.class); + } + + /** + * Protobuf enum {@code grpc.health.v1.HealthCheckResponse.ServingStatus} + */ + public enum ServingStatus + implements com.google.protobuf.ProtocolMessageEnum { + /** + * UNKNOWN = 0; + */ + UNKNOWN(0, 0), + /** + * SERVING = 1; + */ + SERVING(1, 1), + /** + * NOT_SERVING = 2; + */ + NOT_SERVING(2, 2), + UNRECOGNIZED(-1, -1), + ; + + /** + * UNKNOWN = 0; + */ + public static final int UNKNOWN_VALUE = 0; + /** + * SERVING = 1; + */ + public static final int SERVING_VALUE = 1; + /** + * NOT_SERVING = 2; + */ + public static final int NOT_SERVING_VALUE = 2; + + + public final int getNumber() { + if (index == -1) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + public static ServingStatus valueOf(int value) { + switch (value) { + case 0: return UNKNOWN; + case 1: return SERVING; + case 2: return NOT_SERVING; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + ServingStatus> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public ServingStatus findValueByNumber(int number) { + return ServingStatus.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return io.grpc.health.v1.HealthCheckResponse.getDescriptor().getEnumTypes().get(0); + } + + private static final ServingStatus[] VALUES = values(); + + public static ServingStatus valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private ServingStatus(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:grpc.health.v1.HealthCheckResponse.ServingStatus) + } + + public static final int STATUS_FIELD_NUMBER = 1; + private int status_; + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public int getStatusValue() { + return status_; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public io.grpc.health.v1.HealthCheckResponse.ServingStatus getStatus() { + io.grpc.health.v1.HealthCheckResponse.ServingStatus result = io.grpc.health.v1.HealthCheckResponse.ServingStatus.valueOf(status_); + return result == null ? io.grpc.health.v1.HealthCheckResponse.ServingStatus.UNRECOGNIZED : result; + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (status_ != io.grpc.health.v1.HealthCheckResponse.ServingStatus.UNKNOWN.getNumber()) { + output.writeEnum(1, status_); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (status_ != io.grpc.health.v1.HealthCheckResponse.ServingStatus.UNKNOWN.getNumber()) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(1, status_); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static io.grpc.health.v1.HealthCheckResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static io.grpc.health.v1.HealthCheckResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.grpc.health.v1.HealthCheckResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(io.grpc.health.v1.HealthCheckResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code grpc.health.v1.HealthCheckResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:grpc.health.v1.HealthCheckResponse) + io.grpc.health.v1.HealthCheckResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.grpc.health.v1.HealthCheckResponse.class, io.grpc.health.v1.HealthCheckResponse.Builder.class); + } + + // Construct using io.grpc.health.v1.HealthCheckResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + status_ = 0; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return io.grpc.health.v1.HealthProto.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + } + + public io.grpc.health.v1.HealthCheckResponse getDefaultInstanceForType() { + return io.grpc.health.v1.HealthCheckResponse.getDefaultInstance(); + } + + public io.grpc.health.v1.HealthCheckResponse build() { + io.grpc.health.v1.HealthCheckResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public io.grpc.health.v1.HealthCheckResponse buildPartial() { + io.grpc.health.v1.HealthCheckResponse result = new io.grpc.health.v1.HealthCheckResponse(this); + result.status_ = status_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof io.grpc.health.v1.HealthCheckResponse) { + return mergeFrom((io.grpc.health.v1.HealthCheckResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(io.grpc.health.v1.HealthCheckResponse other) { + if (other == io.grpc.health.v1.HealthCheckResponse.getDefaultInstance()) return this; + if (other.status_ != 0) { + setStatusValue(other.getStatusValue()); + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + io.grpc.health.v1.HealthCheckResponse parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (io.grpc.health.v1.HealthCheckResponse) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private int status_ = 0; + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public int getStatusValue() { + return status_; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public Builder setStatusValue(int value) { + status_ = value; + onChanged(); + return this; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public io.grpc.health.v1.HealthCheckResponse.ServingStatus getStatus() { + io.grpc.health.v1.HealthCheckResponse.ServingStatus result = io.grpc.health.v1.HealthCheckResponse.ServingStatus.valueOf(status_); + return result == null ? io.grpc.health.v1.HealthCheckResponse.ServingStatus.UNRECOGNIZED : result; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public Builder setStatus(io.grpc.health.v1.HealthCheckResponse.ServingStatus value) { + if (value == null) { + throw new NullPointerException(); + } + + status_ = value.getNumber(); + onChanged(); + return this; + } + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + public Builder clearStatus() { + + status_ = 0; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:grpc.health.v1.HealthCheckResponse) + } + + // @@protoc_insertion_point(class_scope:grpc.health.v1.HealthCheckResponse) + private static final io.grpc.health.v1.HealthCheckResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new io.grpc.health.v1.HealthCheckResponse(); + } + + public static io.grpc.health.v1.HealthCheckResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public HealthCheckResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new HealthCheckResponse(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof + com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) + e.getCause(); + } + throw e; + } + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public io.grpc.health.v1.HealthCheckResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponseOrBuilder.java b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponseOrBuilder.java new file mode 100644 index 00000000000..4d632bcd028 --- /dev/null +++ b/services/src/generated/main/java/io/grpc/health/v1/HealthCheckResponseOrBuilder.java @@ -0,0 +1,18 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: health.proto + +package io.grpc.health.v1; + +public interface HealthCheckResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:grpc.health.v1.HealthCheckResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + int getStatusValue(); + /** + * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; + */ + io.grpc.health.v1.HealthCheckResponse.ServingStatus getStatus(); +} diff --git a/services/src/generated/main/java/io/grpc/health/v1/HealthProto.java b/services/src/generated/main/java/io/grpc/health/v1/HealthProto.java new file mode 100644 index 00000000000..31f1e78f00e --- /dev/null +++ b/services/src/generated/main/java/io/grpc/health/v1/HealthProto.java @@ -0,0 +1,68 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: health.proto + +package io.grpc.health.v1; + +public final class HealthProto { + private HealthProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + static com.google.protobuf.Descriptors.Descriptor + internal_static_grpc_health_v1_HealthCheckRequest_descriptor; + static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable; + static com.google.protobuf.Descriptors.Descriptor + internal_static_grpc_health_v1_HealthCheckResponse_descriptor; + static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\014health.proto\022\016grpc.health.v1\"%\n\022Health" + + "CheckRequest\022\017\n\007service\030\001 \001(\t\"\224\001\n\023Health" + + "CheckResponse\022A\n\006status\030\001 \001(\01621.grpc.hea" + + "lth.v1.HealthCheckResponse.ServingStatus" + + "\":\n\rServingStatus\022\013\n\007UNKNOWN\020\000\022\013\n\007SERVIN" + + "G\020\001\022\017\n\013NOT_SERVING\020\0022Z\n\006Health\022P\n\005Check\022" + + "\".grpc.health.v1.HealthCheckRequest\032#.gr" + + "pc.health.v1.HealthCheckResponseB3\n\021io.g" + + "rpc.health.v1B\013HealthProtoP\001\252\002\016Grpc.Heal" + + "th.V1b\006proto3" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_grpc_health_v1_HealthCheckRequest_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_grpc_health_v1_HealthCheckRequest_descriptor, + new java.lang.String[] { "Service", }); + internal_static_grpc_health_v1_HealthCheckResponse_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_grpc_health_v1_HealthCheckResponse_descriptor, + new java.lang.String[] { "Status", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java b/services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java deleted file mode 100644 index ff2139bb4a2..00000000000 --- a/services/src/generated/main/java/io/grpc/services/health/HealthOuterClass.java +++ /dev/null @@ -1,1023 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: health.proto - -package io.grpc.services.health; - -public final class HealthOuterClass { - private HealthOuterClass() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface HealthCheckRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.health.v1.HealthCheckRequest) - com.google.protobuf.MessageOrBuilder { - - /** - * optional string service = 1; - */ - java.lang.String getService(); - /** - * optional string service = 1; - */ - com.google.protobuf.ByteString - getServiceBytes(); - } - /** - * Protobuf type {@code grpc.health.v1.HealthCheckRequest} - */ - public static final class HealthCheckRequest extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:grpc.health.v1.HealthCheckRequest) - HealthCheckRequestOrBuilder { - // Use HealthCheckRequest.newBuilder() to construct. - private HealthCheckRequest(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private HealthCheckRequest() { - service_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private HealthCheckRequest( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - service_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw new RuntimeException(e.setUnfinishedMessage(this)); - } catch (java.io.IOException e) { - throw new RuntimeException( - new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this)); - } finally { - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.services.health.HealthOuterClass.HealthCheckRequest.class, io.grpc.services.health.HealthOuterClass.HealthCheckRequest.Builder.class); - } - - public static final int SERVICE_FIELD_NUMBER = 1; - private volatile java.lang.Object service_; - /** - * optional string service = 1; - */ - public java.lang.String getService() { - java.lang.Object ref = service_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - service_ = s; - return s; - } - } - /** - * optional string service = 1; - */ - public com.google.protobuf.ByteString - getServiceBytes() { - java.lang.Object ref = service_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - service_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getServiceBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 1, service_); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getServiceBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(1, service_); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.services.health.HealthOuterClass.HealthCheckRequest prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.health.v1.HealthCheckRequest} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.health.v1.HealthCheckRequest) - io.grpc.services.health.HealthOuterClass.HealthCheckRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.services.health.HealthOuterClass.HealthCheckRequest.class, io.grpc.services.health.HealthOuterClass.HealthCheckRequest.Builder.class); - } - - // Construct using io.grpc.services.health.HealthOuterClass.HealthCheckRequest.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - service_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckRequest_descriptor; - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckRequest getDefaultInstanceForType() { - return io.grpc.services.health.HealthOuterClass.HealthCheckRequest.getDefaultInstance(); - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckRequest build() { - io.grpc.services.health.HealthOuterClass.HealthCheckRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckRequest buildPartial() { - io.grpc.services.health.HealthOuterClass.HealthCheckRequest result = new io.grpc.services.health.HealthOuterClass.HealthCheckRequest(this); - result.service_ = service_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.services.health.HealthOuterClass.HealthCheckRequest) { - return mergeFrom((io.grpc.services.health.HealthOuterClass.HealthCheckRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.services.health.HealthOuterClass.HealthCheckRequest other) { - if (other == io.grpc.services.health.HealthOuterClass.HealthCheckRequest.getDefaultInstance()) return this; - if (!other.getService().isEmpty()) { - service_ = other.service_; - onChanged(); - } - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.services.health.HealthOuterClass.HealthCheckRequest parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.services.health.HealthOuterClass.HealthCheckRequest) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object service_ = ""; - /** - * optional string service = 1; - */ - public java.lang.String getService() { - java.lang.Object ref = service_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - service_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string service = 1; - */ - public com.google.protobuf.ByteString - getServiceBytes() { - java.lang.Object ref = service_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - service_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string service = 1; - */ - public Builder setService( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - service_ = value; - onChanged(); - return this; - } - /** - * optional string service = 1; - */ - public Builder clearService() { - - service_ = getDefaultInstance().getService(); - onChanged(); - return this; - } - /** - * optional string service = 1; - */ - public Builder setServiceBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - service_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - - // @@protoc_insertion_point(builder_scope:grpc.health.v1.HealthCheckRequest) - } - - // @@protoc_insertion_point(class_scope:grpc.health.v1.HealthCheckRequest) - private static final io.grpc.services.health.HealthOuterClass.HealthCheckRequest DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.services.health.HealthOuterClass.HealthCheckRequest(); - } - - public static io.grpc.services.health.HealthOuterClass.HealthCheckRequest getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public HealthCheckRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - try { - return new HealthCheckRequest(input, extensionRegistry); - } catch (RuntimeException e) { - if (e.getCause() instanceof - com.google.protobuf.InvalidProtocolBufferException) { - throw (com.google.protobuf.InvalidProtocolBufferException) - e.getCause(); - } - throw e; - } - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckRequest getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface HealthCheckResponseOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.health.v1.HealthCheckResponse) - com.google.protobuf.MessageOrBuilder { - - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - int getStatusValue(); - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus getStatus(); - } - /** - * Protobuf type {@code grpc.health.v1.HealthCheckResponse} - */ - public static final class HealthCheckResponse extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:grpc.health.v1.HealthCheckResponse) - HealthCheckResponseOrBuilder { - // Use HealthCheckResponse.newBuilder() to construct. - private HealthCheckResponse(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private HealthCheckResponse() { - status_ = 0; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private HealthCheckResponse( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 8: { - int rawValue = input.readEnum(); - - status_ = rawValue; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw new RuntimeException(e.setUnfinishedMessage(this)); - } catch (java.io.IOException e) { - throw new RuntimeException( - new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this)); - } finally { - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.services.health.HealthOuterClass.HealthCheckResponse.class, io.grpc.services.health.HealthOuterClass.HealthCheckResponse.Builder.class); - } - - /** - * Protobuf enum {@code grpc.health.v1.HealthCheckResponse.ServingStatus} - */ - public enum ServingStatus - implements com.google.protobuf.ProtocolMessageEnum { - /** - * UNKNOWN = 0; - */ - UNKNOWN(0, 0), - /** - * SERVING = 1; - */ - SERVING(1, 1), - /** - * NOT_SERVING = 2; - */ - NOT_SERVING(2, 2), - UNRECOGNIZED(-1, -1), - ; - - /** - * UNKNOWN = 0; - */ - public static final int UNKNOWN_VALUE = 0; - /** - * SERVING = 1; - */ - public static final int SERVING_VALUE = 1; - /** - * NOT_SERVING = 2; - */ - public static final int NOT_SERVING_VALUE = 2; - - - public final int getNumber() { - if (index == -1) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - public static ServingStatus valueOf(int value) { - switch (value) { - case 0: return UNKNOWN; - case 1: return SERVING; - case 2: return NOT_SERVING; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - ServingStatus> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public ServingStatus findValueByNumber(int number) { - return ServingStatus.valueOf(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(index); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDescriptor().getEnumTypes().get(0); - } - - private static final ServingStatus[] VALUES = values(); - - public static ServingStatus valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int index; - private final int value; - - private ServingStatus(int index, int value) { - this.index = index; - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:grpc.health.v1.HealthCheckResponse.ServingStatus) - } - - public static final int STATUS_FIELD_NUMBER = 1; - private int status_; - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public int getStatusValue() { - return status_; - } - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus getStatus() { - io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus result = io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.valueOf(status_); - return result == null ? io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNRECOGNIZED : result; - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (status_ != io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNKNOWN.getNumber()) { - output.writeEnum(1, status_); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (status_ != io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNKNOWN.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(1, status_); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.services.health.HealthOuterClass.HealthCheckResponse prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.health.v1.HealthCheckResponse} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.health.v1.HealthCheckResponse) - io.grpc.services.health.HealthOuterClass.HealthCheckResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.services.health.HealthOuterClass.HealthCheckResponse.class, io.grpc.services.health.HealthOuterClass.HealthCheckResponse.Builder.class); - } - - // Construct using io.grpc.services.health.HealthOuterClass.HealthCheckResponse.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - status_ = 0; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.services.health.HealthOuterClass.internal_static_grpc_health_v1_HealthCheckResponse_descriptor; - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse getDefaultInstanceForType() { - return io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDefaultInstance(); - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse build() { - io.grpc.services.health.HealthOuterClass.HealthCheckResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse buildPartial() { - io.grpc.services.health.HealthOuterClass.HealthCheckResponse result = new io.grpc.services.health.HealthOuterClass.HealthCheckResponse(this); - result.status_ = status_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.services.health.HealthOuterClass.HealthCheckResponse) { - return mergeFrom((io.grpc.services.health.HealthOuterClass.HealthCheckResponse)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.services.health.HealthOuterClass.HealthCheckResponse other) { - if (other == io.grpc.services.health.HealthOuterClass.HealthCheckResponse.getDefaultInstance()) return this; - if (other.status_ != 0) { - setStatusValue(other.getStatusValue()); - } - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.services.health.HealthOuterClass.HealthCheckResponse parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.services.health.HealthOuterClass.HealthCheckResponse) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int status_ = 0; - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public int getStatusValue() { - return status_; - } - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public Builder setStatusValue(int value) { - status_ = value; - onChanged(); - return this; - } - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus getStatus() { - io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus result = io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.valueOf(status_); - return result == null ? io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus.UNRECOGNIZED : result; - } - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public Builder setStatus(io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus value) { - if (value == null) { - throw new NullPointerException(); - } - - status_ = value.getNumber(); - onChanged(); - return this; - } - /** - * optional .grpc.health.v1.HealthCheckResponse.ServingStatus status = 1; - */ - public Builder clearStatus() { - - status_ = 0; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - - // @@protoc_insertion_point(builder_scope:grpc.health.v1.HealthCheckResponse) - } - - // @@protoc_insertion_point(class_scope:grpc.health.v1.HealthCheckResponse) - private static final io.grpc.services.health.HealthOuterClass.HealthCheckResponse DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.services.health.HealthOuterClass.HealthCheckResponse(); - } - - public static io.grpc.services.health.HealthOuterClass.HealthCheckResponse getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public HealthCheckResponse parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - try { - return new HealthCheckResponse(input, extensionRegistry); - } catch (RuntimeException e) { - if (e.getCause() instanceof - com.google.protobuf.InvalidProtocolBufferException) { - throw (com.google.protobuf.InvalidProtocolBufferException) - e.getCause(); - } - throw e; - } - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.services.health.HealthOuterClass.HealthCheckResponse getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_health_v1_HealthCheckRequest_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable; - private static com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_health_v1_HealthCheckResponse_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\014health.proto\022\016grpc.health.v1\"%\n\022Health" + - "CheckRequest\022\017\n\007service\030\001 \001(\t\"\224\001\n\023Health" + - "CheckResponse\022A\n\006status\030\001 \001(\01621.grpc.hea" + - "lth.v1.HealthCheckResponse.ServingStatus" + - "\":\n\rServingStatus\022\013\n\007UNKNOWN\020\000\022\013\n\007SERVIN" + - "G\020\001\022\017\n\013NOT_SERVING\020\0022Z\n\006Health\022P\n\005Check\022" + - "\".grpc.health.v1.HealthCheckRequest\032#.gr" + - "pc.health.v1.HealthCheckResponseB*\n\027io.g" + - "rpc.services.health\252\002\016Grpc.Health.V1b\006pr" + - "oto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_grpc_health_v1_HealthCheckRequest_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_grpc_health_v1_HealthCheckRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_grpc_health_v1_HealthCheckRequest_descriptor, - new java.lang.String[] { "Service", }); - internal_static_grpc_health_v1_HealthCheckResponse_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_grpc_health_v1_HealthCheckResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_grpc_health_v1_HealthCheckResponse_descriptor, - new java.lang.String[] { "Status", }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java b/services/src/main/java/io/grpc/services/HealthServiceImpl.java similarity index 91% rename from services/src/main/java/io/grpc/services/health/HealthServiceImpl.java rename to services/src/main/java/io/grpc/services/HealthServiceImpl.java index bdc7273bf76..6f6ce886709 100644 --- a/services/src/main/java/io/grpc/services/health/HealthServiceImpl.java +++ b/services/src/main/java/io/grpc/services/HealthServiceImpl.java @@ -29,13 +29,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package io.grpc.services.health; +package io.grpc.services; -import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse; -import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus; +import static io.grpc.health.v1.HealthCheckResponse.ServingStatus; import io.grpc.Status; import io.grpc.StatusException; +import io.grpc.health.v1.HealthCheckRequest; +import io.grpc.health.v1.HealthCheckResponse; +import io.grpc.health.v1.HealthGrpc; import io.grpc.stub.StreamObserver; import java.util.Map; @@ -53,7 +55,7 @@ final class HealthServiceImpl extends HealthGrpc.AbstractHealth { = new ConcurrentHashMap(); @Override - public void check(HealthOuterClass.HealthCheckRequest request, + public void check(HealthCheckRequest request, StreamObserver responseObserver) { ServingStatus status = getStatus(request.getService()); if (status == null) { diff --git a/services/src/main/java/io/grpc/services/health/HealthStatusManager.java b/services/src/main/java/io/grpc/services/HealthStatusManager.java similarity index 96% rename from services/src/main/java/io/grpc/services/health/HealthStatusManager.java rename to services/src/main/java/io/grpc/services/HealthStatusManager.java index 7363f8180e2..620ab36caee 100644 --- a/services/src/main/java/io/grpc/services/health/HealthStatusManager.java +++ b/services/src/main/java/io/grpc/services/HealthStatusManager.java @@ -29,10 +29,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package io.grpc.services.health; +package io.grpc.services; import static com.google.common.base.Preconditions.checkNotNull; -import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus; +import static io.grpc.health.v1.HealthCheckResponse.ServingStatus; + +import io.grpc.health.v1.HealthGrpc; diff --git a/services/src/main/java/io/grpc/services/health/package-info.java b/services/src/main/java/io/grpc/services/health/package-info.java deleted file mode 100644 index abdcf9e6089..00000000000 --- a/services/src/main/java/io/grpc/services/health/package-info.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2016, Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * GRPC Health Checking is a pre-defined proto service that is used to probe whether the server is - * able to handle RPC requests. Please refer to - * - * https://github.com/grpc/grpc/blob/master/doc/health-checking.md - * - * for the service description. - *

- * {@link io.grpc.services.health.HealthStatusManager} is used for updating health statuses. - */ -package io.grpc.services.health; diff --git a/services/src/main/proto/health.proto b/services/src/main/proto/health.proto index 06755527726..bfe6a094d76 100644 --- a/services/src/main/proto/health.proto +++ b/services/src/main/proto/health.proto @@ -31,7 +31,10 @@ syntax = "proto3"; package grpc.health.v1; option csharp_namespace = "Grpc.Health.V1"; -option java_package = "io.grpc.services.health"; + +option java_multiple_files = true; +option java_package = "io.grpc.health.v1"; +option java_outer_classname = "HealthProto"; message HealthCheckRequest { string service = 1; diff --git a/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java b/services/src/test/java/io/grpc/services/HealthStatusManagerTest.java similarity index 77% rename from services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java rename to services/src/test/java/io/grpc/services/HealthStatusManagerTest.java index 36e03ba3b64..6e16eef609f 100644 --- a/services/src/test/java/io/grpc/services/health/HealthStatusManagerTest.java +++ b/services/src/test/java/io/grpc/services/HealthStatusManagerTest.java @@ -29,10 +29,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package io.grpc.services.health; +package io.grpc.services; -import static org.junit.Assert.assertEquals; +import static io.grpc.health.v1.HealthGrpc.Health; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.any; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; @@ -40,8 +41,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; + import io.grpc.Status; import io.grpc.StatusException; +import io.grpc.health.v1.HealthCheckRequest; +import io.grpc.health.v1.HealthCheckResponse; +import io.grpc.stub.StreamObserver; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -53,9 +59,9 @@ public class HealthStatusManagerTest { private final HealthStatusManager manager = new HealthStatusManager(); - private final HealthGrpc.Health health = manager.getHealthService(); - private final HealthOuterClass.HealthCheckResponse.ServingStatus status - = HealthOuterClass.HealthCheckResponse.ServingStatus.UNKNOWN; + private final Health health = manager.getHealthService(); + private final HealthCheckResponse.ServingStatus status + = HealthCheckResponse.ServingStatus.UNKNOWN; @Test public void getHealthService_getterReturnsTheSameHealthRefAfterUpdate() throws Exception { @@ -68,18 +74,16 @@ public void getHealthService_getterReturnsTheSameHealthRefAfterUpdate() throws E public void checkValidStatus() throws Exception { //setup manager.setStatus("", status); - HealthOuterClass.HealthCheckRequest request - = HealthOuterClass.HealthCheckRequest.newBuilder().setService("").build(); + HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("").build(); @SuppressWarnings("unchecked") - io.grpc.stub.StreamObserver observer - = mock(io.grpc.stub.StreamObserver.class); + StreamObserver observer = mock(StreamObserver.class); //test health.check(request, observer); //verify InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(any(HealthOuterClass.HealthCheckResponse.class)); + inOrder.verify(observer, times(1)).onNext(any(HealthCheckResponse.class)); inOrder.verify(observer, times(1)).onCompleted(); verify(observer, never()).onError(any(Throwable.class)); } @@ -88,11 +92,10 @@ public void checkValidStatus() throws Exception { public void checkStatusNotFound() throws Exception { //setup manager.setStatus("", status); - HealthOuterClass.HealthCheckRequest request - = HealthOuterClass.HealthCheckRequest.newBuilder().setService("invalid").build(); + HealthCheckRequest request + = HealthCheckRequest.newBuilder().setService("invalid").build(); @SuppressWarnings("unchecked") - io.grpc.stub.StreamObserver observer - = mock(io.grpc.stub.StreamObserver.class); + StreamObserver observer = mock(StreamObserver.class); //test health.check(request, observer); @@ -110,11 +113,10 @@ public void notFoundForClearedStatus() throws Exception { //setup manager.setStatus("", status); manager.clearStatus(""); - HealthOuterClass.HealthCheckRequest request - = HealthOuterClass.HealthCheckRequest.newBuilder().setService("").build(); + HealthCheckRequest request + = HealthCheckRequest.newBuilder().setService("").build(); @SuppressWarnings("unchecked") - io.grpc.stub.StreamObserver observer - = mock(io.grpc.stub.StreamObserver.class); + StreamObserver observer = mock(StreamObserver.class); //test health.check(request, observer);