Allow users to start watching xDS resources (#10864)

This commit is contained in:
Anirudh Ramachandra 2024-02-01 22:51:00 +05:30 committed by GitHub
parent a97f21b61e
commit 3202370684
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 48 additions and 41 deletions

View File

@ -26,6 +26,7 @@ import com.google.common.net.UrlEscapers;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.Any; import com.google.protobuf.Any;
import io.grpc.ExperimentalApi;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.xds.Bootstrapper.ServerInfo; import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.LoadStatsManager2.ClusterDropStats; import io.grpc.xds.LoadStatsManager2.ClusterDropStats;
@ -115,7 +116,8 @@ public abstract class XdsClient {
/** /**
* Watcher interface for a single requested xDS resource. * Watcher interface for a single requested xDS resource.
*/ */
interface ResourceWatcher<T extends ResourceUpdate> { @ExperimentalApi("https://github.com/grpc/grpc-java/issues/10862")
public interface ResourceWatcher<T extends ResourceUpdate> {
/** /**
* Called when the resource discovery RPC encounters some transient error. * Called when the resource discovery RPC encounters some transient error.
@ -123,7 +125,7 @@ public abstract class XdsClient {
* <p>Note that we expect that the implementer to: * <p>Note that we expect that the implementer to:
* - Comply with the guarantee to not generate certain statuses by the library: * - Comply with the guarantee to not generate certain statuses by the library:
* https://grpc.github.io/grpc/core/md_doc_statuscodes.html. If the code needs to be * https://grpc.github.io/grpc/core/md_doc_statuscodes.html. If the code needs to be
* propagated to the channel, override it with {@link Status.Code#UNAVAILABLE}. * propagated to the channel, override it with {@link io.grpc.Status.Code#UNAVAILABLE}.
* - Keep {@link Status} description in one form or another, as it contains valuable debugging * - Keep {@link Status} description in one form or another, as it contains valuable debugging
* information. * information.
*/ */
@ -306,13 +308,15 @@ public abstract class XdsClient {
/** /**
* Registers a data watcher for the given Xds resource. * Registers a data watcher for the given Xds resource.
*/ */
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type, String resourceName, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type,
String resourceName,
ResourceWatcher<T> watcher, ResourceWatcher<T> watcher,
Executor executor) { Executor executor) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type, String resourceName, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type,
String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
watchXdsResource(type, resourceName, watcher, MoreExecutors.directExecutor()); watchXdsResource(type, resourceName, watcher, MoreExecutors.directExecutor());
} }
@ -320,7 +324,7 @@ public abstract class XdsClient {
/** /**
* Unregisters the given resource watcher. * Unregisters the given resource watcher.
*/ */
<T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type,
String resourceName, String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -282,7 +282,8 @@ final class XdsClientImpl extends XdsClient
} }
@Override @Override
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type, String resourceName, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type,
String resourceName,
ResourceWatcher<T> watcher, ResourceWatcher<T> watcher,
Executor watcherExecutor) { Executor watcherExecutor) {
syncContext.execute(new Runnable() { syncContext.execute(new Runnable() {
@ -309,7 +310,7 @@ final class XdsClientImpl extends XdsClient
} }
@Override @Override
<T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type,
String resourceName, String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
syncContext.execute(new Runnable() { syncContext.execute(new Runnable() {

View File

@ -789,7 +789,8 @@ public class CdsLoadBalancer2Test {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type, String resourceName, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type,
String resourceName,
ResourceWatcher<T> watcher, Executor syncContext) { ResourceWatcher<T> watcher, Executor syncContext) {
assertThat(type.typeName()).isEqualTo("CDS"); assertThat(type.typeName()).isEqualTo("CDS");
watchers.computeIfAbsent(resourceName, k -> new ArrayList<>()) watchers.computeIfAbsent(resourceName, k -> new ArrayList<>())
@ -798,7 +799,7 @@ public class CdsLoadBalancer2Test {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
<T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type,
String resourceName, String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
assertThat(type.typeName()).isEqualTo("CDS"); assertThat(type.typeName()).isEqualTo("CDS");

View File

@ -1184,7 +1184,8 @@ public class ClusterResolverLoadBalancerTest {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type, String resourceName, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> type,
String resourceName,
ResourceWatcher<T> watcher, ResourceWatcher<T> watcher,
Executor syncContext) { Executor syncContext) {
assertThat(type.typeName()).isEqualTo("EDS"); assertThat(type.typeName()).isEqualTo("EDS");
@ -1194,7 +1195,7 @@ public class ClusterResolverLoadBalancerTest {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
<T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type,
String resourceName, String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
assertThat(type.typeName()).isEqualTo("EDS"); assertThat(type.typeName()).isEqualTo("EDS");

View File

@ -1915,7 +1915,7 @@ public class XdsNameResolverTest {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> resourceType, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> resourceType,
String resourceName, String resourceName,
ResourceWatcher<T> watcher, ResourceWatcher<T> watcher,
Executor syncContext) { Executor syncContext) {
@ -1939,7 +1939,7 @@ public class XdsNameResolverTest {
} }
@Override @Override
<T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type,
String resourceName, String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
switch (type.typeName()) { switch (type.typeName()) {

View File

@ -181,7 +181,7 @@ public class XdsServerTestHelper {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
<T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> resourceType, public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> resourceType,
String resourceName, String resourceName,
ResourceWatcher<T> watcher, ResourceWatcher<T> watcher,
Executor syncContext) { Executor syncContext) {
@ -201,7 +201,7 @@ public class XdsServerTestHelper {
} }
@Override @Override
<T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type,
String resourceName, String resourceName,
ResourceWatcher<T> watcher) { ResourceWatcher<T> watcher) {
switch (type.typeName()) { switch (type.typeName()) {