grpc 1.59.5-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +40 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +208 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +875 -0
- data/src/ruby/ext/grpc/rb_channel.h +35 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +172 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +496 -0
- data/src/ruby/ext/grpc/rb_grpc.h +83 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +603 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +910 -0
- data/src/ruby/ext/grpc/rb_loader.c +61 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +405 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +44 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +66 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +180 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +207 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +676 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +692 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +160 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +405 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require_relative 'client_stub'
|
16
|
+
require_relative 'rpc_desc'
|
17
|
+
|
18
|
+
# GRPC contains the General RPC module.
|
19
|
+
module GRPC
|
20
|
+
# Provides behaviour used to implement schema-derived service classes.
|
21
|
+
#
|
22
|
+
# Is intended to be used to support both client and server
|
23
|
+
# IDL-schema-derived servers.
|
24
|
+
module GenericService
|
25
|
+
# creates a new string that is the underscore separate version of s.
|
26
|
+
#
|
27
|
+
# E.g,
|
28
|
+
# PrintHTML -> print_html
|
29
|
+
# AMethod -> a_method
|
30
|
+
# AnRpc -> an_rpc
|
31
|
+
#
|
32
|
+
# @param s [String] the string to be converted.
|
33
|
+
def self.underscore(s)
|
34
|
+
s = +s # Avoid mutating the argument, as it might be frozen.
|
35
|
+
s.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
36
|
+
s.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
37
|
+
s.tr!('-', '_')
|
38
|
+
s.downcase!
|
39
|
+
s
|
40
|
+
end
|
41
|
+
|
42
|
+
# Used to indicate that a name has already been specified
|
43
|
+
class DuplicateRpcName < StandardError
|
44
|
+
def initialize(name)
|
45
|
+
super("rpc (#{name}) is already defined")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Provides a simple DSL to describe RPC services.
|
50
|
+
#
|
51
|
+
# E.g, a Maths service that uses the serializable messages DivArgs,
|
52
|
+
# DivReply and Num might define its endpoint uses the following way:
|
53
|
+
#
|
54
|
+
# rpc :div DivArgs, DivReply # single request, single response
|
55
|
+
# rpc :sum stream(Num), Num # streamed input, single response
|
56
|
+
# rpc :fib FibArgs, stream(Num) # single request, streamed response
|
57
|
+
# rpc :div_many stream(DivArgs), stream(DivReply)
|
58
|
+
# # streamed req and resp
|
59
|
+
#
|
60
|
+
# Each 'rpc' adds an RpcDesc to classes including this module, and
|
61
|
+
# #assert_rpc_descs_have_methods is used to ensure the including class
|
62
|
+
# provides methods with signatures that support all the descriptors.
|
63
|
+
module Dsl
|
64
|
+
# This configures the method names that the serializable message
|
65
|
+
# implementation uses to marshal and unmarshal messages.
|
66
|
+
#
|
67
|
+
# - unmarshal_class method must be a class method on the serializable
|
68
|
+
# message type that takes a string (byte stream) and produces and object
|
69
|
+
#
|
70
|
+
# - marshal_class_method is called on a serializable message instance
|
71
|
+
# and produces a serialized string.
|
72
|
+
#
|
73
|
+
# The Dsl verifies that the types in the descriptor have both the
|
74
|
+
# unmarshal and marshal methods.
|
75
|
+
attr_writer(:marshal_class_method, :unmarshal_class_method)
|
76
|
+
|
77
|
+
# This allows configuration of the service name.
|
78
|
+
attr_accessor(:service_name)
|
79
|
+
|
80
|
+
# Adds an RPC spec.
|
81
|
+
#
|
82
|
+
# Takes the RPC name and the classes representing the types to be
|
83
|
+
# serialized, and adds them to the including classes rpc_desc hash.
|
84
|
+
#
|
85
|
+
# input and output should both have the methods #marshal and #unmarshal
|
86
|
+
# that are responsible for writing and reading an object instance from a
|
87
|
+
# byte buffer respectively.
|
88
|
+
#
|
89
|
+
# @param name [String] the name of the rpc
|
90
|
+
# @param input [Object] the input parameter's class
|
91
|
+
# @param output [Object] the output parameter's class
|
92
|
+
def rpc(name, input, output)
|
93
|
+
fail(DuplicateRpcName, name) if rpc_descs.key? name
|
94
|
+
assert_can_marshal(input)
|
95
|
+
assert_can_marshal(output)
|
96
|
+
rpc_descs[name] = RpcDesc.new(name, input, output,
|
97
|
+
marshal_class_method,
|
98
|
+
unmarshal_class_method)
|
99
|
+
define_method(GenericService.underscore(name.to_s).to_sym) do |*|
|
100
|
+
fail GRPC::BadStatus.new_status_exception(
|
101
|
+
GRPC::Core::StatusCodes::UNIMPLEMENTED)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def inherited(subclass)
|
106
|
+
# Each subclass should have a distinct class variable with its own
|
107
|
+
# rpc_descs
|
108
|
+
subclass.rpc_descs.merge!(rpc_descs)
|
109
|
+
subclass.service_name = service_name
|
110
|
+
end
|
111
|
+
|
112
|
+
# the name of the instance method used to marshal events to a byte
|
113
|
+
# stream.
|
114
|
+
def marshal_class_method
|
115
|
+
@marshal_class_method ||= :marshal
|
116
|
+
end
|
117
|
+
|
118
|
+
# the name of the class method used to unmarshal from a byte stream.
|
119
|
+
def unmarshal_class_method
|
120
|
+
@unmarshal_class_method ||= :unmarshal
|
121
|
+
end
|
122
|
+
|
123
|
+
def assert_can_marshal(cls)
|
124
|
+
cls = cls.type if cls.is_a? RpcDesc::Stream
|
125
|
+
mth = unmarshal_class_method
|
126
|
+
unless cls.methods.include? mth
|
127
|
+
fail(ArgumentError, "#{cls} needs #{cls}.#{mth}")
|
128
|
+
end
|
129
|
+
mth = marshal_class_method
|
130
|
+
return if cls.methods.include? mth
|
131
|
+
fail(ArgumentError, "#{cls} needs #{cls}.#{mth}")
|
132
|
+
end
|
133
|
+
|
134
|
+
# @param cls [Class] the class of a serializable type
|
135
|
+
# @return cls wrapped in a RpcDesc::Stream
|
136
|
+
def stream(cls)
|
137
|
+
assert_can_marshal(cls)
|
138
|
+
RpcDesc::Stream.new(cls)
|
139
|
+
end
|
140
|
+
|
141
|
+
# the RpcDescs defined for this GenericService, keyed by name.
|
142
|
+
def rpc_descs
|
143
|
+
@rpc_descs ||= {}
|
144
|
+
end
|
145
|
+
|
146
|
+
# Creates a rpc client class with methods for accessing the methods
|
147
|
+
# currently in rpc_descs.
|
148
|
+
def rpc_stub_class
|
149
|
+
descs = rpc_descs
|
150
|
+
route_prefix = service_name
|
151
|
+
Class.new(ClientStub) do
|
152
|
+
# @param host [String] the host the stub connects to
|
153
|
+
# @param creds [Core::ChannelCredentials|Symbol] The channel
|
154
|
+
# credentials to use, or :this_channel_is_insecure otherwise
|
155
|
+
# @param kw [KeywordArgs] the channel arguments, plus any optional
|
156
|
+
# args for configuring the client's channel
|
157
|
+
def initialize(host, creds, **kw)
|
158
|
+
super(host, creds, **kw)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Used define_method to add a method for each rpc_desc. Each method
|
162
|
+
# calls the base class method for the given descriptor.
|
163
|
+
descs.each_pair do |name, desc|
|
164
|
+
mth_name = GenericService.underscore(name.to_s).to_sym
|
165
|
+
marshal = desc.marshal_proc
|
166
|
+
unmarshal = desc.unmarshal_proc(:output)
|
167
|
+
route = "/#{route_prefix}/#{name}"
|
168
|
+
if desc.request_response?
|
169
|
+
define_method(mth_name) do |req, metadata = {}|
|
170
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
171
|
+
request_response(route, req, marshal, unmarshal, **metadata)
|
172
|
+
end
|
173
|
+
elsif desc.client_streamer?
|
174
|
+
define_method(mth_name) do |reqs, metadata = {}|
|
175
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
176
|
+
client_streamer(route, reqs, marshal, unmarshal, **metadata)
|
177
|
+
end
|
178
|
+
elsif desc.server_streamer?
|
179
|
+
define_method(mth_name) do |req, metadata = {}, &blk|
|
180
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
181
|
+
server_streamer(route, req, marshal, unmarshal, **metadata, &blk)
|
182
|
+
end
|
183
|
+
else # is a bidi_stream
|
184
|
+
define_method(mth_name) do |reqs, metadata = {}, &blk|
|
185
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
186
|
+
bidi_streamer(route, reqs, marshal, unmarshal, **metadata, &blk)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.included(o)
|
195
|
+
o.extend(Dsl)
|
196
|
+
# Update to the use the service name including module. Provide a default
|
197
|
+
# that can be nil e.g. when modules are declared dynamically.
|
198
|
+
return unless o.service_name.nil?
|
199
|
+
if o.name.nil?
|
200
|
+
o.service_name = 'GenericService'
|
201
|
+
else
|
202
|
+
modules = o.name.split('::')
|
203
|
+
if modules.length > 2
|
204
|
+
o.service_name = modules[modules.length - 2]
|
205
|
+
else
|
206
|
+
o.service_name = modules.first
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright 2017 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require_relative './structs'
|
16
|
+
|
17
|
+
# GRPC contains the General RPC module.
|
18
|
+
module GRPC
|
19
|
+
# GoogleRpcStatusUtils provides utilities to convert between a
|
20
|
+
# GRPC::Core::Status and a deserialized Google::Rpc::Status proto
|
21
|
+
# Returns nil if the grpc-status-details-bin trailer could not be
|
22
|
+
# converted to a GoogleRpcStatus due to the server not providing
|
23
|
+
# the necessary trailers.
|
24
|
+
# Raises an error if the server did provide the necessary trailers
|
25
|
+
# but they fail to deseriliaze into a GoogleRpcStatus protobuf.
|
26
|
+
class GoogleRpcStatusUtils
|
27
|
+
def self.extract_google_rpc_status(status)
|
28
|
+
fail ArgumentError, 'bad type' unless status.is_a? Struct::Status
|
29
|
+
grpc_status_details_bin_trailer = 'grpc-status-details-bin'
|
30
|
+
binstatus = status.metadata[grpc_status_details_bin_trailer]
|
31
|
+
return nil if binstatus.nil?
|
32
|
+
|
33
|
+
# Lazily load grpc_c and protobuf_c.so for users of this method.
|
34
|
+
require_relative './grpc'
|
35
|
+
require 'google/rpc/status_pb'
|
36
|
+
|
37
|
+
Google::Rpc::Status.decode(binstatus)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
begin
|
16
|
+
ruby_version_dirname = /(\d+\.\d+)/.match(RUBY_VERSION).to_s
|
17
|
+
distrib_lib_dir = File.expand_path(ruby_version_dirname,
|
18
|
+
File.dirname(__FILE__))
|
19
|
+
if !Dir.glob("#{distrib_lib_dir}/grpc_c*").empty?
|
20
|
+
require "#{distrib_lib_dir}/grpc_c"
|
21
|
+
else
|
22
|
+
require 'grpc/grpc_c'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# GRPC contains the General RPC module.
|
16
|
+
module GRPC
|
17
|
+
# DefaultLogger is a module included in GRPC if no other logging is set up for
|
18
|
+
# it. See ../spec/spec_helpers an example of where other logging is added.
|
19
|
+
module DefaultLogger
|
20
|
+
def logger
|
21
|
+
LOGGER
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# NoopLogger implements the methods of Ruby's conventional logging interface
|
27
|
+
# that are actually used internally within gRPC with a noop implementation.
|
28
|
+
class NoopLogger
|
29
|
+
def info(_ignored)
|
30
|
+
end
|
31
|
+
|
32
|
+
def debug(_ignored)
|
33
|
+
end
|
34
|
+
|
35
|
+
def warn(_ignored)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
LOGGER = NoopLogger.new
|
40
|
+
end
|
41
|
+
|
42
|
+
# Inject the noop #logger if no module-level logger method has been injected.
|
43
|
+
extend DefaultLogger unless methods.include?(:logger)
|
44
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# GRPC contains the General RPC module.
|
16
|
+
module GRPC
|
17
|
+
# Notifier is useful high-level synchronization primitive.
|
18
|
+
class Notifier
|
19
|
+
attr_reader :payload, :notified
|
20
|
+
alias_method :notified?, :notified
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@mutex = Mutex.new
|
24
|
+
@cvar = ConditionVariable.new
|
25
|
+
@notified = false
|
26
|
+
@payload = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def wait
|
30
|
+
@mutex.synchronize do
|
31
|
+
@cvar.wait(@mutex) until notified?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def notify(payload)
|
36
|
+
@mutex.synchronize do
|
37
|
+
return Error.new('already notified') if notified?
|
38
|
+
@payload = payload
|
39
|
+
@notified = true
|
40
|
+
@cvar.signal
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
Struct.new('Status', :code, :details, :metadata, :debug_error_string)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# GRPC contains the General RPC module.
|
16
|
+
module GRPC
|
17
|
+
VERSION = '1.59.5'
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
ssl_roots_path = File.expand_path('../../../../etc/roots.pem', __FILE__)
|
16
|
+
|
17
|
+
require_relative 'grpc/errors'
|
18
|
+
require_relative 'grpc/structs'
|
19
|
+
require_relative 'grpc/grpc'
|
20
|
+
require_relative 'grpc/logconfig'
|
21
|
+
require_relative 'grpc/notifier'
|
22
|
+
require_relative 'grpc/version'
|
23
|
+
require_relative 'grpc/core/status_codes'
|
24
|
+
require_relative 'grpc/core/time_consts'
|
25
|
+
require_relative 'grpc/generic/active_call'
|
26
|
+
require_relative 'grpc/generic/client_stub'
|
27
|
+
require_relative 'grpc/generic/service'
|
28
|
+
require_relative 'grpc/generic/rpc_server'
|
29
|
+
require_relative 'grpc/generic/interceptors'
|
30
|
+
|
31
|
+
begin
|
32
|
+
file = File.open(ssl_roots_path)
|
33
|
+
roots = file.read
|
34
|
+
GRPC::Core::ChannelCredentials.set_default_roots_pem roots
|
35
|
+
ensure
|
36
|
+
file.close
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Protocol Buffers
|
2
|
+
================
|
3
|
+
|
4
|
+
This folder contains protocol buffers provided with gRPC ruby, and the generated
|
5
|
+
code to them.
|
6
|
+
|
7
|
+
PREREQUISITES
|
8
|
+
-------------
|
9
|
+
|
10
|
+
The code is generated using the protoc (> 3.0.0.alpha.1) and the
|
11
|
+
grpc_ruby_plugin. These must be installed to regenerate the IDL defined
|
12
|
+
classes, but that's not necessary just to use them.
|
13
|
+
|
14
|
+
health_check/v1
|
15
|
+
--------------------
|
16
|
+
|
17
|
+
This package defines the surface of a simple health check service that gRPC
|
18
|
+
servers may choose to implement, and provides an implementation for it. To
|
19
|
+
re-generate the surface.
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ # (from this directory)
|
23
|
+
$ protoc -I ../../proto ../../proto/grpc/health/v1/health.proto \
|
24
|
+
--grpc_out=. \
|
25
|
+
--ruby_out=. \
|
26
|
+
--plugin=protoc-gen-grpc=`which grpc_ruby_plugin`
|
27
|
+
```
|
28
|
+
|
29
|
+
test
|
30
|
+
----
|
31
|
+
|
32
|
+
This package defines the surface of the gRPC interop test service and client
|
33
|
+
To re-generate the surface, it's necessary to have checked-out versions of
|
34
|
+
the grpc interop test proto, e.g, by having the full gRPC repository. E.g,
|
35
|
+
|
36
|
+
```bash
|
37
|
+
$ # (from this directory within the grpc repo)
|
38
|
+
$ protoc -I../../.. ../../../test/proto/{messages,test,empty}.proto \
|
39
|
+
--grpc_out=. \
|
40
|
+
--ruby_out=. \
|
41
|
+
--plugin=protoc-gen-grpc=`which grpc_ruby_plugin`
|
42
|
+
```
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
# Copyright 2015 gRPC authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# Regenerates gRPC service stubs from proto files.
|
17
|
+
set -e
|
18
|
+
cd $(dirname $0)/../../..
|
19
|
+
|
20
|
+
# protoc and grpc_*_plugin binaries can be obtained by running
|
21
|
+
# $ bazel build @com_google_protobuf//:protoc //src/compiler:all
|
22
|
+
PROTOC=bazel-bin/external/com_google_protobuf/protoc
|
23
|
+
PLUGIN=protoc-gen-grpc=bazel-bin/src/compiler/grpc_ruby_plugin
|
24
|
+
|
25
|
+
$PROTOC -I src/proto src/proto/grpc/health/v1/health.proto \
|
26
|
+
--grpc_out=src/ruby/pb \
|
27
|
+
--ruby_out=src/ruby/pb \
|
28
|
+
--plugin=$PLUGIN
|
29
|
+
|
30
|
+
$PROTOC -I . \
|
31
|
+
src/proto/grpc/testing/{messages,test,empty}.proto \
|
32
|
+
--grpc_out=src/ruby/pb \
|
33
|
+
--ruby_out=src/ruby/pb \
|
34
|
+
--plugin=$PLUGIN
|
35
|
+
|
36
|
+
$PROTOC -I . \
|
37
|
+
-I third_party/protobuf/src \
|
38
|
+
src/proto/grpc/testing/{messages,payloads,stats,benchmark_service,report_qps_scenario_service,worker_service,control}.proto \
|
39
|
+
--grpc_out=src/ruby/qps \
|
40
|
+
--ruby_out=src/ruby/qps \
|
41
|
+
--plugin=$PLUGIN
|
42
|
+
|
43
|
+
$PROTOC -I src/proto/math src/proto/math/math.proto \
|
44
|
+
--grpc_out=src/ruby/bin \
|
45
|
+
--ruby_out=src/ruby/bin \
|
46
|
+
--plugin=$PLUGIN
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'grpc'
|
16
|
+
require 'grpc/health/v1/health_services_pb'
|
17
|
+
|
18
|
+
module Grpc
|
19
|
+
# Health contains classes and modules that support providing a health check
|
20
|
+
# service.
|
21
|
+
module Health
|
22
|
+
# Checker is implementation of the schema-specified health checking service.
|
23
|
+
class Checker < V1::Health::Service
|
24
|
+
StatusCodes = GRPC::Core::StatusCodes
|
25
|
+
HealthCheckResponse = V1::HealthCheckResponse
|
26
|
+
|
27
|
+
# Initializes the statuses of participating services
|
28
|
+
def initialize
|
29
|
+
@statuses = {}
|
30
|
+
@status_mutex = Mutex.new # guards access to @statuses
|
31
|
+
end
|
32
|
+
|
33
|
+
# Implements the rpc IDL API method
|
34
|
+
def check(req, _call)
|
35
|
+
status = nil
|
36
|
+
@status_mutex.synchronize do
|
37
|
+
status = @statuses["#{req.service}"]
|
38
|
+
end
|
39
|
+
if status.nil?
|
40
|
+
fail GRPC::BadStatus.new_status_exception(StatusCodes::NOT_FOUND)
|
41
|
+
end
|
42
|
+
HealthCheckResponse.new(status: status)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Adds the health status for a given service.
|
46
|
+
def add_status(service, status)
|
47
|
+
@status_mutex.synchronize { @statuses["#{service}"] = status }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Adds given health status for all given services
|
51
|
+
def set_status_for_services(status, *services)
|
52
|
+
@status_mutex.synchronize do
|
53
|
+
services.each { |service| @statuses["#{service}"] = status }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Adds health status for each service given within hash
|
58
|
+
def add_statuses(service_statuses = {})
|
59
|
+
@status_mutex.synchronize do
|
60
|
+
service_statuses.each_pair { |service, status| @statuses["#{service}"] = status }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Clears the status for the given service.
|
65
|
+
def clear_status(service)
|
66
|
+
@status_mutex.synchronize { @statuses.delete("#{service}") }
|
67
|
+
end
|
68
|
+
|
69
|
+
# Clears alls the statuses.
|
70
|
+
def clear_all
|
71
|
+
@status_mutex.synchronize { @statuses = {} }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: grpc/health/v1/health.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n\x1bgrpc/health/v1/health.proto\x12\x0egrpc.health.v1\"%\n\x12HealthCheckRequest\x12\x0f\n\x07service\x18\x01 \x01(\t\"\xa9\x01\n\x13HealthCheckResponse\x12\x41\n\x06status\x18\x01 \x01(\x0e\x32\x31.grpc.health.v1.HealthCheckResponse.ServingStatus\"O\n\rServingStatus\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x0b\n\x07SERVING\x10\x01\x12\x0f\n\x0bNOT_SERVING\x10\x02\x12\x13\n\x0fSERVICE_UNKNOWN\x10\x03\x32\xae\x01\n\x06Health\x12P\n\x05\x43heck\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponse\x12R\n\x05Watch\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponse0\x01\x42\x61\n\x11io.grpc.health.v1B\x0bHealthProtoP\x01Z,google.golang.org/grpc/health/grpc_health_v1\xaa\x02\x0eGrpc.Health.V1b\x06proto3"
|
9
|
+
|
10
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
|
12
|
+
begin
|
13
|
+
pool.add_serialized_file(descriptor_data)
|
14
|
+
rescue TypeError => e
|
15
|
+
# Compatibility code: will be removed in the next major version.
|
16
|
+
require 'google/protobuf/descriptor_pb'
|
17
|
+
parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
|
18
|
+
parsed.clear_dependency
|
19
|
+
serialized = parsed.class.encode(parsed)
|
20
|
+
file = pool.add_serialized_file(serialized)
|
21
|
+
warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}"
|
22
|
+
imports = [
|
23
|
+
]
|
24
|
+
imports.each do |type_name, expected_filename|
|
25
|
+
import_file = pool.lookup(type_name).file_descriptor
|
26
|
+
if import_file.name != expected_filename
|
27
|
+
warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
warn "Each proto file must use a consistent fully-qualified name."
|
31
|
+
warn "This will become an error in the next major version."
|
32
|
+
end
|
33
|
+
|
34
|
+
module Grpc
|
35
|
+
module Health
|
36
|
+
module V1
|
37
|
+
HealthCheckRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckRequest").msgclass
|
38
|
+
HealthCheckResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse").msgclass
|
39
|
+
HealthCheckResponse::ServingStatus = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse.ServingStatus").enummodule
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|