Skip to content

Commit 0fd4975

Browse files
authored
rls: add proto and converter (#6743)
1 parent 37b2313 commit 0fd4975

File tree

11 files changed

+1597
-2
lines changed

11 files changed

+1597
-2
lines changed

bom/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ publishing {
1212

1313
pom.withXml {
1414
// Generate bom using subprojects
15-
def internalProjects = [project.name, 'grpc-gae-interop-testing-jdk8', 'grpc-compiler']
15+
def internalProjects = [project.name, 'grpc-gae-interop-testing-jdk8', 'grpc-compiler', 'grpc-rls']
1616

1717
def dependencyManagement = asNode().appendNode('dependencyManagement')
1818
def dependencies = dependencyManagement.appendNode('dependencies')

buildscripts/sync-protos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ curl -Ls https://github.com/grpc/grpc-proto/archive/master.tar.gz | tar xz -C "$
88
base="$tmpdir/grpc-proto-master"
99

1010
# Copy protos in 'src/main/proto' from grpc-proto for these projects
11-
for project in alts grpclb services; do
11+
for project in alts grpclb services rls; do
1212
while read -r proto; do
1313
[ -f "$base/$proto" ] && cp "$base/$proto" "$project/src/main/proto/$proto"
1414
echo "$proto"

core/src/main/java/io/grpc/internal/JsonUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ public static Integer getNumberAsInteger(Map<String, ?> obj, String key) {
129129
return i;
130130
}
131131

132+
/**
133+
* Gets a number from an object for the given key, casted to an long. If the key is not
134+
* present, this returns null. If the value is not a Double or loses precision when cast to an
135+
* long, throws an exception.
136+
*/
137+
public static Long getNumberAsLong(Map<String, ?> obj, String key) {
138+
Double d = getNumber(obj, key);
139+
if (d == null) {
140+
return null;
141+
}
142+
long l = d.longValue();
143+
if (l != d) {
144+
throw new ClassCastException("Number expected to be long: " + d);
145+
}
146+
return l;
147+
}
148+
149+
132150
/**
133151
* Gets a string from an object for the given key. If the key is not present, this returns null.
134152
* If the value is not a String, throws an exception.

rls/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id "java"
3+
id "maven-publish"
4+
id "com.google.protobuf"
5+
}
6+
7+
description = "gRPC: RouteLookupService Loadbalancing plugin"
8+
9+
evaluationDependsOn(project(':grpc-core').path)
10+
11+
dependencies {
12+
implementation project(':grpc-core'),
13+
project(':grpc-protobuf'),
14+
project(':grpc-stub')
15+
compileOnly libraries.javax_annotation
16+
testCompile libraries.truth
17+
}
18+
19+
configureProtoCompilation()
20+
21+
// do not publish 'grpc-rls'
22+
[publishMavenPublicationToMavenRepository]*.onlyIf { false }
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
package io.grpc.lookup.v1;
2+
3+
import static io.grpc.MethodDescriptor.generateFullMethodName;
4+
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
5+
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
6+
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
7+
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
8+
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
9+
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
10+
import static io.grpc.stub.ClientCalls.futureUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
14+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
15+
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
16+
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
17+
18+
/**
19+
*/
20+
@javax.annotation.Generated(
21+
value = "by gRPC proto compiler",
22+
comments = "Source: grpc/lookup/v1/rls.proto")
23+
public final class RouteLookupServiceGrpc {
24+
25+
private RouteLookupServiceGrpc() {}
26+
27+
public static final String SERVICE_NAME = "grpc.lookup.v1.RouteLookupService";
28+
29+
// Static method descriptors that strictly reflect the proto.
30+
private static volatile io.grpc.MethodDescriptor<io.grpc.lookup.v1.RouteLookupRequest,
31+
io.grpc.lookup.v1.RouteLookupResponse> getRouteLookupMethod;
32+
33+
@io.grpc.stub.annotations.RpcMethod(
34+
fullMethodName = SERVICE_NAME + '/' + "RouteLookup",
35+
requestType = io.grpc.lookup.v1.RouteLookupRequest.class,
36+
responseType = io.grpc.lookup.v1.RouteLookupResponse.class,
37+
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
38+
public static io.grpc.MethodDescriptor<io.grpc.lookup.v1.RouteLookupRequest,
39+
io.grpc.lookup.v1.RouteLookupResponse> getRouteLookupMethod() {
40+
io.grpc.MethodDescriptor<io.grpc.lookup.v1.RouteLookupRequest, io.grpc.lookup.v1.RouteLookupResponse> getRouteLookupMethod;
41+
if ((getRouteLookupMethod = RouteLookupServiceGrpc.getRouteLookupMethod) == null) {
42+
synchronized (RouteLookupServiceGrpc.class) {
43+
if ((getRouteLookupMethod = RouteLookupServiceGrpc.getRouteLookupMethod) == null) {
44+
RouteLookupServiceGrpc.getRouteLookupMethod = getRouteLookupMethod =
45+
io.grpc.MethodDescriptor.<io.grpc.lookup.v1.RouteLookupRequest, io.grpc.lookup.v1.RouteLookupResponse>newBuilder()
46+
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
47+
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "RouteLookup"))
48+
.setSampledToLocalTracing(true)
49+
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
50+
io.grpc.lookup.v1.RouteLookupRequest.getDefaultInstance()))
51+
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
52+
io.grpc.lookup.v1.RouteLookupResponse.getDefaultInstance()))
53+
.setSchemaDescriptor(new RouteLookupServiceMethodDescriptorSupplier("RouteLookup"))
54+
.build();
55+
}
56+
}
57+
}
58+
return getRouteLookupMethod;
59+
}
60+
61+
/**
62+
* Creates a new async stub that supports all call types for the service
63+
*/
64+
public static RouteLookupServiceStub newStub(io.grpc.Channel channel) {
65+
io.grpc.stub.AbstractStub.StubFactory<RouteLookupServiceStub> factory =
66+
new io.grpc.stub.AbstractStub.StubFactory<RouteLookupServiceStub>() {
67+
@java.lang.Override
68+
public RouteLookupServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
69+
return new RouteLookupServiceStub(channel, callOptions);
70+
}
71+
};
72+
return RouteLookupServiceStub.newStub(factory, channel);
73+
}
74+
75+
/**
76+
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
77+
*/
78+
public static RouteLookupServiceBlockingStub newBlockingStub(
79+
io.grpc.Channel channel) {
80+
io.grpc.stub.AbstractStub.StubFactory<RouteLookupServiceBlockingStub> factory =
81+
new io.grpc.stub.AbstractStub.StubFactory<RouteLookupServiceBlockingStub>() {
82+
@java.lang.Override
83+
public RouteLookupServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
84+
return new RouteLookupServiceBlockingStub(channel, callOptions);
85+
}
86+
};
87+
return RouteLookupServiceBlockingStub.newStub(factory, channel);
88+
}
89+
90+
/**
91+
* Creates a new ListenableFuture-style stub that supports unary calls on the service
92+
*/
93+
public static RouteLookupServiceFutureStub newFutureStub(
94+
io.grpc.Channel channel) {
95+
io.grpc.stub.AbstractStub.StubFactory<RouteLookupServiceFutureStub> factory =
96+
new io.grpc.stub.AbstractStub.StubFactory<RouteLookupServiceFutureStub>() {
97+
@java.lang.Override
98+
public RouteLookupServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
99+
return new RouteLookupServiceFutureStub(channel, callOptions);
100+
}
101+
};
102+
return RouteLookupServiceFutureStub.newStub(factory, channel);
103+
}
104+
105+
/**
106+
*/
107+
public static abstract class RouteLookupServiceImplBase implements io.grpc.BindableService {
108+
109+
/**
110+
* <pre>
111+
* Lookup returns a target for a single key.
112+
* </pre>
113+
*/
114+
public void routeLookup(io.grpc.lookup.v1.RouteLookupRequest request,
115+
io.grpc.stub.StreamObserver<io.grpc.lookup.v1.RouteLookupResponse> responseObserver) {
116+
asyncUnimplementedUnaryCall(getRouteLookupMethod(), responseObserver);
117+
}
118+
119+
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
120+
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
121+
.addMethod(
122+
getRouteLookupMethod(),
123+
asyncUnaryCall(
124+
new MethodHandlers<
125+
io.grpc.lookup.v1.RouteLookupRequest,
126+
io.grpc.lookup.v1.RouteLookupResponse>(
127+
this, METHODID_ROUTE_LOOKUP)))
128+
.build();
129+
}
130+
}
131+
132+
/**
133+
*/
134+
public static final class RouteLookupServiceStub extends io.grpc.stub.AbstractAsyncStub<RouteLookupServiceStub> {
135+
private RouteLookupServiceStub(
136+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
137+
super(channel, callOptions);
138+
}
139+
140+
@java.lang.Override
141+
protected RouteLookupServiceStub build(
142+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
143+
return new RouteLookupServiceStub(channel, callOptions);
144+
}
145+
146+
/**
147+
* <pre>
148+
* Lookup returns a target for a single key.
149+
* </pre>
150+
*/
151+
public void routeLookup(io.grpc.lookup.v1.RouteLookupRequest request,
152+
io.grpc.stub.StreamObserver<io.grpc.lookup.v1.RouteLookupResponse> responseObserver) {
153+
asyncUnaryCall(
154+
getChannel().newCall(getRouteLookupMethod(), getCallOptions()), request, responseObserver);
155+
}
156+
}
157+
158+
/**
159+
*/
160+
public static final class RouteLookupServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub<RouteLookupServiceBlockingStub> {
161+
private RouteLookupServiceBlockingStub(
162+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
163+
super(channel, callOptions);
164+
}
165+
166+
@java.lang.Override
167+
protected RouteLookupServiceBlockingStub build(
168+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
169+
return new RouteLookupServiceBlockingStub(channel, callOptions);
170+
}
171+
172+
/**
173+
* <pre>
174+
* Lookup returns a target for a single key.
175+
* </pre>
176+
*/
177+
public io.grpc.lookup.v1.RouteLookupResponse routeLookup(io.grpc.lookup.v1.RouteLookupRequest request) {
178+
return blockingUnaryCall(
179+
getChannel(), getRouteLookupMethod(), getCallOptions(), request);
180+
}
181+
}
182+
183+
/**
184+
*/
185+
public static final class RouteLookupServiceFutureStub extends io.grpc.stub.AbstractFutureStub<RouteLookupServiceFutureStub> {
186+
private RouteLookupServiceFutureStub(
187+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
188+
super(channel, callOptions);
189+
}
190+
191+
@java.lang.Override
192+
protected RouteLookupServiceFutureStub build(
193+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
194+
return new RouteLookupServiceFutureStub(channel, callOptions);
195+
}
196+
197+
/**
198+
* <pre>
199+
* Lookup returns a target for a single key.
200+
* </pre>
201+
*/
202+
public com.google.common.util.concurrent.ListenableFuture<io.grpc.lookup.v1.RouteLookupResponse> routeLookup(
203+
io.grpc.lookup.v1.RouteLookupRequest request) {
204+
return futureUnaryCall(
205+
getChannel().newCall(getRouteLookupMethod(), getCallOptions()), request);
206+
}
207+
}
208+
209+
private static final int METHODID_ROUTE_LOOKUP = 0;
210+
211+
private static final class MethodHandlers<Req, Resp> implements
212+
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
213+
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
214+
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
215+
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
216+
private final RouteLookupServiceImplBase serviceImpl;
217+
private final int methodId;
218+
219+
MethodHandlers(RouteLookupServiceImplBase serviceImpl, int methodId) {
220+
this.serviceImpl = serviceImpl;
221+
this.methodId = methodId;
222+
}
223+
224+
@java.lang.Override
225+
@java.lang.SuppressWarnings("unchecked")
226+
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
227+
switch (methodId) {
228+
case METHODID_ROUTE_LOOKUP:
229+
serviceImpl.routeLookup((io.grpc.lookup.v1.RouteLookupRequest) request,
230+
(io.grpc.stub.StreamObserver<io.grpc.lookup.v1.RouteLookupResponse>) responseObserver);
231+
break;
232+
default:
233+
throw new AssertionError();
234+
}
235+
}
236+
237+
@java.lang.Override
238+
@java.lang.SuppressWarnings("unchecked")
239+
public io.grpc.stub.StreamObserver<Req> invoke(
240+
io.grpc.stub.StreamObserver<Resp> responseObserver) {
241+
switch (methodId) {
242+
default:
243+
throw new AssertionError();
244+
}
245+
}
246+
}
247+
248+
private static abstract class RouteLookupServiceBaseDescriptorSupplier
249+
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
250+
RouteLookupServiceBaseDescriptorSupplier() {}
251+
252+
@java.lang.Override
253+
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
254+
return io.grpc.lookup.v1.RlsProto.getDescriptor();
255+
}
256+
257+
@java.lang.Override
258+
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
259+
return getFileDescriptor().findServiceByName("RouteLookupService");
260+
}
261+
}
262+
263+
private static final class RouteLookupServiceFileDescriptorSupplier
264+
extends RouteLookupServiceBaseDescriptorSupplier {
265+
RouteLookupServiceFileDescriptorSupplier() {}
266+
}
267+
268+
private static final class RouteLookupServiceMethodDescriptorSupplier
269+
extends RouteLookupServiceBaseDescriptorSupplier
270+
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
271+
private final String methodName;
272+
273+
RouteLookupServiceMethodDescriptorSupplier(String methodName) {
274+
this.methodName = methodName;
275+
}
276+
277+
@java.lang.Override
278+
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
279+
return getServiceDescriptor().findMethodByName(methodName);
280+
}
281+
}
282+
283+
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
284+
285+
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
286+
io.grpc.ServiceDescriptor result = serviceDescriptor;
287+
if (result == null) {
288+
synchronized (RouteLookupServiceGrpc.class) {
289+
result = serviceDescriptor;
290+
if (result == null) {
291+
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
292+
.setSchemaDescriptor(new RouteLookupServiceFileDescriptorSupplier())
293+
.addMethod(getRouteLookupMethod())
294+
.build();
295+
}
296+
}
297+
}
298+
return result;
299+
}
300+
}

0 commit comments

Comments
 (0)