grpc 1.42.0.pre1-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +34 -0
  7. data/src/ruby/bin/math_server.rb +191 -0
  8. data/src/ruby/bin/math_services_pb.rb +51 -0
  9. data/src/ruby/bin/noproto_client.rb +93 -0
  10. data/src/ruby/bin/noproto_server.rb +97 -0
  11. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  12. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  13. data/src/ruby/ext/grpc/extconf.rb +123 -0
  14. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  15. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  16. data/src/ruby/ext/grpc/rb_call.c +1051 -0
  17. data/src/ruby/ext/grpc/rb_call.h +57 -0
  18. data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
  19. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  20. data/src/ruby/ext/grpc/rb_channel.c +846 -0
  21. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  22. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  23. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  24. data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
  25. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  26. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  27. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  28. data/src/ruby/ext/grpc/rb_compression_options.c +471 -0
  29. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  30. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  31. data/src/ruby/ext/grpc/rb_event_thread.c +145 -0
  32. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  33. data/src/ruby/ext/grpc/rb_grpc.c +333 -0
  34. data/src/ruby/ext/grpc/rb_grpc.h +77 -0
  35. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +605 -0
  36. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +913 -0
  37. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  38. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  39. data/src/ruby/ext/grpc/rb_server.c +385 -0
  40. data/src/ruby/ext/grpc/rb_server.h +32 -0
  41. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  42. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  43. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
  44. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  45. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  46. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  47. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  48. data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
  49. data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
  50. data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
  51. data/src/ruby/lib/grpc/3.0/grpc_c.bundle +0 -0
  52. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  53. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  54. data/src/ruby/lib/grpc/errors.rb +277 -0
  55. data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
  56. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  57. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  58. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  59. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  60. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  61. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  62. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  63. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  64. data/src/ruby/lib/grpc/grpc.rb +24 -0
  65. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  66. data/src/ruby/lib/grpc/notifier.rb +45 -0
  67. data/src/ruby/lib/grpc/structs.rb +15 -0
  68. data/src/ruby/lib/grpc/version.rb +18 -0
  69. data/src/ruby/lib/grpc.rb +37 -0
  70. data/src/ruby/pb/README.md +42 -0
  71. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  72. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  73. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  74. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  75. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  76. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  77. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  78. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  79. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +145 -0
  80. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
  81. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  82. data/src/ruby/pb/test/client.rb +769 -0
  83. data/src/ruby/pb/test/server.rb +252 -0
  84. data/src/ruby/pb/test/xds_client.rb +415 -0
  85. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  86. data/src/ruby/spec/call_spec.rb +180 -0
  87. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  88. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  89. data/src/ruby/spec/channel_spec.rb +245 -0
  90. data/src/ruby/spec/client_auth_spec.rb +152 -0
  91. data/src/ruby/spec/client_server_spec.rb +664 -0
  92. data/src/ruby/spec/compression_options_spec.rb +149 -0
  93. data/src/ruby/spec/debug_message_spec.rb +134 -0
  94. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  95. data/src/ruby/spec/errors_spec.rb +142 -0
  96. data/src/ruby/spec/generic/active_call_spec.rb +683 -0
  97. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  98. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  99. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  100. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  101. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  102. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  103. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  104. data/src/ruby/spec/generic/service_spec.rb +263 -0
  105. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  106. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  107. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  108. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  109. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  112. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  113. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  114. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  115. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  116. data/src/ruby/spec/server_spec.rb +231 -0
  117. data/src/ruby/spec/spec_helper.rb +61 -0
  118. data/src/ruby/spec/support/helpers.rb +107 -0
  119. data/src/ruby/spec/support/services.rb +160 -0
  120. data/src/ruby/spec/testdata/README +1 -0
  121. data/src/ruby/spec/testdata/ca.pem +20 -0
  122. data/src/ruby/spec/testdata/client.key +28 -0
  123. data/src/ruby/spec/testdata/client.pem +20 -0
  124. data/src/ruby/spec/testdata/server1.key +28 -0
  125. data/src/ruby/spec/testdata/server1.pem +22 -0
  126. data/src/ruby/spec/time_consts_spec.rb +74 -0
  127. data/src/ruby/spec/user_agent_spec.rb +74 -0
  128. metadata +404 -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 File.directory?(distrib_lib_dir)
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.42.0.pre1'
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,51 @@
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
+ src/proto/grpc/core/stats.proto \
38
+ --grpc_out=src/ruby/qps \
39
+ --ruby_out=src/ruby/qps \
40
+ --plugin=$PLUGIN
41
+
42
+ $PROTOC -I . \
43
+ src/proto/grpc/testing/{messages,payloads,stats,benchmark_service,report_qps_scenario_service,worker_service,control}.proto \
44
+ --grpc_out=src/ruby/qps \
45
+ --ruby_out=src/ruby/qps \
46
+ --plugin=$PLUGIN
47
+
48
+ $PROTOC -I src/proto/math src/proto/math/math.proto \
49
+ --grpc_out=src/ruby/bin \
50
+ --ruby_out=src/ruby/bin \
51
+ --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,31 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: grpc/health/v1/health.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("grpc/health/v1/health.proto", :syntax => :proto3) do
8
+ add_message "grpc.health.v1.HealthCheckRequest" do
9
+ optional :service, :string, 1
10
+ end
11
+ add_message "grpc.health.v1.HealthCheckResponse" do
12
+ optional :status, :enum, 1, "grpc.health.v1.HealthCheckResponse.ServingStatus"
13
+ end
14
+ add_enum "grpc.health.v1.HealthCheckResponse.ServingStatus" do
15
+ value :UNKNOWN, 0
16
+ value :SERVING, 1
17
+ value :NOT_SERVING, 2
18
+ value :SERVICE_UNKNOWN, 3
19
+ end
20
+ end
21
+ end
22
+
23
+ module Grpc
24
+ module Health
25
+ module V1
26
+ HealthCheckRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckRequest").msgclass
27
+ HealthCheckResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse").msgclass
28
+ HealthCheckResponse::ServingStatus = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse.ServingStatus").enummodule
29
+ end
30
+ end
31
+ end