Skip to content

Commit 46eac47

Browse files
authored
xds: add support for server side Listener watcher in XdsClient (#6801)
1 parent 111e348 commit 46eac47

File tree

5 files changed

+1053
-27
lines changed

5 files changed

+1053
-27
lines changed

xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public String toString() {
159159
* Corresponds to Envoy proto message {@link io.envoyproxy.envoy.api.v2.listener.FilterChain}.
160160
*/
161161
static final class FilterChain {
162+
// TODO(sanjaypujare): flatten structure by moving FilterChainMatch class members here.
162163
private final FilterChainMatch filterChainMatch;
163164
// TODO(sanjaypujare): remove dependency on envoy data type along with rest of the code.
164165
private final io.envoyproxy.envoy.api.v2.auth.DownstreamTlsContext downstreamTlsContext;

xds/src/main/java/io/grpc/xds/XdsClient.java

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,15 @@ abstract class XdsClient {
6262
*/
6363
static final class ConfigUpdate {
6464
private final String clusterName;
65-
private final Listener listener;
6665

67-
private ConfigUpdate(String clusterName, @Nullable Listener listener) {
66+
private ConfigUpdate(String clusterName) {
6867
this.clusterName = clusterName;
69-
this.listener = listener;
7068
}
7169

7270
String getClusterName() {
7371
return clusterName;
7472
}
7573

76-
@Nullable
77-
public Listener getListener() {
78-
return listener;
79-
}
80-
8174
@Override
8275
public String toString() {
8376
return
@@ -93,7 +86,6 @@ static Builder newBuilder() {
9386

9487
static final class Builder {
9588
private String clusterName;
96-
@Nullable private Listener listener;
9789

9890
// Use ConfigUpdate.newBuilder().
9991
private Builder() {
@@ -104,14 +96,9 @@ Builder setClusterName(String clusterName) {
10496
return this;
10597
}
10698

107-
Builder setListener(Listener listener) {
108-
this.listener = listener;
109-
return this;
110-
}
111-
11299
ConfigUpdate build() {
113100
Preconditions.checkState(clusterName != null, "clusterName is not set");
114-
return new ConfigUpdate(clusterName, listener);
101+
return new ConfigUpdate(clusterName);
115102
}
116103
}
117104
}
@@ -352,6 +339,52 @@ EndpointUpdate build() {
352339
}
353340
}
354341

342+
/**
343+
* Updates via resource discovery RPCs using LDS. Includes {@link Listener} object containing
344+
* config for security, RBAC or other server side features such as rate limit.
345+
*/
346+
static final class ListenerUpdate {
347+
// TODO(sanjaypujare): flatten structure by moving Listener class members here.
348+
private final Listener listener;
349+
350+
private ListenerUpdate(Listener listener) {
351+
this.listener = listener;
352+
}
353+
354+
public Listener getListener() {
355+
return listener;
356+
}
357+
358+
@Override
359+
public String toString() {
360+
return MoreObjects.toStringHelper(this)
361+
.add("listener", listener)
362+
.toString();
363+
}
364+
365+
static Builder newBuilder() {
366+
return new Builder();
367+
}
368+
369+
static final class Builder {
370+
private Listener listener;
371+
372+
// Use ListenerUpdate.newBuilder().
373+
private Builder() {
374+
}
375+
376+
Builder setListener(Listener listener) {
377+
this.listener = listener;
378+
return this;
379+
}
380+
381+
ListenerUpdate build() {
382+
Preconditions.checkState(listener != null, "listener is not set");
383+
return new ListenerUpdate(listener);
384+
}
385+
}
386+
}
387+
355388
/**
356389
* Config watcher interface. To be implemented by the xDS resolver.
357390
*/
@@ -385,6 +418,19 @@ interface EndpointWatcher {
385418
void onError(Status error);
386419
}
387420

421+
/**
422+
* Listener watcher interface. To be used by {@link io.grpc.xds.internal.sds.XdsServerBuilder}.
423+
*/
424+
interface ListenerWatcher {
425+
426+
/**
427+
* Called when receiving an update on Listener configuration.
428+
*/
429+
void onListenerChanged(ListenerUpdate update);
430+
431+
void onError(Status error);
432+
}
433+
388434
/**
389435
* Shutdown this {@link XdsClient} and release resources.
390436
*/
@@ -430,6 +476,12 @@ void watchEndpointData(String clusterName, EndpointWatcher watcher) {
430476
void cancelEndpointDataWatch(String clusterName, EndpointWatcher watcher) {
431477
}
432478

479+
/**
480+
* Registers a watcher for a Listener with the given port.
481+
*/
482+
void watchListenerData(int port, ListenerWatcher watcher) {
483+
}
484+
433485
/**
434486
* Report client load stats to a remote server for the given cluster:cluster_service.
435487
*

0 commit comments

Comments
 (0)