2121import static io .grpc .xds .XdsClient .ResourceUpdate ;
2222import static io .grpc .xds .XdsClient .canonifyResourceName ;
2323import static io .grpc .xds .XdsClient .isResourceNameValid ;
24- import static io .grpc .xds .XdsClientImpl .ResourceInvalidException ;
2524
2625import com .google .common .annotations .VisibleForTesting ;
2726import com .google .common .base .Strings ;
2827import com .google .protobuf .Any ;
2928import com .google .protobuf .InvalidProtocolBufferException ;
3029import com .google .protobuf .Message ;
3130import io .envoyproxy .envoy .service .discovery .v3 .Resource ;
31+ import io .grpc .ExperimentalApi ;
3232import io .grpc .LoadBalancerRegistry ;
33+ import io .grpc .xds .Bootstrapper .ServerInfo ;
34+ import io .grpc .xds .XdsClient .ResourceUpdate ;
3335import java .util .ArrayList ;
3436import java .util .HashMap ;
3537import java .util .HashSet ;
3840import java .util .Set ;
3941import javax .annotation .Nullable ;
4042
41- abstract class XdsResourceType <T extends ResourceUpdate > {
43+ @ ExperimentalApi ("https://github.com/grpc/grpc-java/issues/10847" )
44+ public abstract class XdsResourceType <T extends ResourceUpdate > {
4245 static final String TYPE_URL_RESOURCE =
4346 "type.googleapis.com/envoy.service.discovery.v3.Resource" ;
4447 static final String TRANSPORT_SOCKET_NAME_TLS = "envoy.transport_sockets.tls" ;
@@ -68,22 +71,22 @@ abstract class XdsResourceType<T extends ResourceUpdate> {
6871 "type.googleapis.com/xds.type.v3.TypedStruct" ;
6972
7073 @ Nullable
71- abstract String extractResourceName (Message unpackedResource );
74+ protected abstract String extractResourceName (Message unpackedResource );
7275
73- abstract Class <? extends com .google .protobuf .Message > unpackedClassName ();
76+ protected abstract Class <? extends com .google .protobuf .Message > unpackedClassName ();
7477
75- abstract String typeName ();
78+ protected abstract String typeName ();
7679
77- abstract String typeUrl ();
80+ protected abstract String typeUrl ();
7881
7982 // Do not confuse with the SotW approach: it is the mechanism in which the client must specify all
8083 // resource names it is interested in with each request. Different resource types may behave
8184 // differently in this approach. For LDS and CDS resources, the server must return all resources
8285 // that the client has subscribed to in each request. For RDS and EDS, the server may only return
8386 // the resources that need an update.
84- abstract boolean isFullStateOfTheWorld ();
87+ protected abstract boolean isFullStateOfTheWorld ();
8588
86- static class Args {
89+ public static class Args {
8790 final ServerInfo serverInfo ;
8891 final String versionInfo ;
8992 final String nonce ;
@@ -114,6 +117,18 @@ public Args(ServerInfo serverInfo, String versionInfo, String nonce,
114117 }
115118 }
116119
120+ public static final class ResourceInvalidException extends Exception {
121+ private static final long serialVersionUID = 0L ;
122+
123+ public ResourceInvalidException (String message ) {
124+ super (message , null , false , false );
125+ }
126+
127+ public ResourceInvalidException (String message , Throwable cause ) {
128+ super (cause != null ? message + ": " + cause .getMessage () : message , cause , false , false );
129+ }
130+ }
131+
117132 ValidatedResourceUpdate <T > parse (Args args , List <Any > resources ) {
118133 Map <String , ParsedResource <T >> parsedResources = new HashMap <>(resources .size ());
119134 Set <String > unpackedResources = new HashSet <>(resources .size ());
@@ -147,7 +162,7 @@ ValidatedResourceUpdate<T> parse(Args args, List<Any> resources) {
147162 T resourceUpdate ;
148163 try {
149164 resourceUpdate = doParse (args , unpackedMessage );
150- } catch (XdsClientImpl . ResourceInvalidException e ) {
165+ } catch (ResourceInvalidException e ) {
151166 errors .add (String .format ("%s response %s '%s' validation error: %s" ,
152167 typeName (), unpackedClassName ().getSimpleName (), cname , e .getMessage ()));
153168 invalidResources .add (cname );
@@ -162,7 +177,7 @@ ValidatedResourceUpdate<T> parse(Args args, List<Any> resources) {
162177
163178 }
164179
165- abstract T doParse (Args args , Message unpackedMessage ) throws ResourceInvalidException ;
180+ protected abstract T doParse (Args args , Message unpackedMessage ) throws ResourceInvalidException ;
166181
167182 /**
168183 * Helper method to unpack serialized {@link com.google.protobuf.Any} message, while replacing
0 commit comments