class DiscoveryService
Shared implementation for state-of-the-world xDS discovery services.
Definitions
def initialize(interface, service_name, control_plane, resource_type: nil)
Initialize a discovery service.
Signature
-
parameter
interfaceClass The gRPC service interface.
-
parameter
service_nameString The fully qualified gRPC service name.
-
parameter
control_planeControlPlane The control plane that provides resources.
-
parameter
resource_typeString | Nil The fixed resource type, or
nilfor aggregated discovery.
Implementation
def initialize(interface, service_name, control_plane, resource_type: nil)
super(interface, service_name)
@control_plane = control_plane
@resource_type = resource_type
end
def stream_resources(input, output)
- asynchronous
Serve a state-of-the-world discovery stream.
Signature
-
parameter
inputEnumerable The stream of discovery requests.
-
parameter
outputInterface(:write) The discovery response stream.
- asynchronous
Implementation
def stream_resources(input, output)
stream = Stream.new(@control_plane, output, resource_type: @resource_type)
@control_plane.register_stream(stream)
reader = Async::Task.current.async do
input.each do |request|
stream.request(request)
end
end
writer = Async::Task.current.async do
stream.run
end
reader.wait
ensure
stream&.close
reader&.stop
writer&.stop
@control_plane.remove_stream(stream) if stream
end
def delta_resources
Reject a delta discovery stream, which is not supported.
Signature
-
raises
Protocol::GRPC::Error Always raised because delta xDS is not implemented.
Implementation
def delta_resources
raise Protocol::GRPC::Error.new(
Protocol::GRPC::Status::UNIMPLEMENTED,
"Delta xDS is not implemented."
)
end