21
21
import static io .grpc .xds .XdsClient .ResourceUpdate ;
22
22
import static io .grpc .xds .XdsClient .canonifyResourceName ;
23
23
import static io .grpc .xds .XdsClient .isResourceNameValid ;
24
- import static io .grpc .xds .XdsClientImpl .ResourceInvalidException ;
25
24
26
25
import com .google .common .annotations .VisibleForTesting ;
27
26
import com .google .common .base .Strings ;
28
27
import com .google .protobuf .Any ;
29
28
import com .google .protobuf .InvalidProtocolBufferException ;
30
29
import com .google .protobuf .Message ;
31
30
import io .envoyproxy .envoy .service .discovery .v3 .Resource ;
31
+ import io .grpc .ExperimentalApi ;
32
32
import io .grpc .LoadBalancerRegistry ;
33
+ import io .grpc .xds .Bootstrapper .ServerInfo ;
34
+ import io .grpc .xds .XdsClient .ResourceUpdate ;
33
35
import java .util .ArrayList ;
34
36
import java .util .HashMap ;
35
37
import java .util .HashSet ;
38
40
import java .util .Set ;
39
41
import javax .annotation .Nullable ;
40
42
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 > {
42
45
static final String TYPE_URL_RESOURCE =
43
46
"type.googleapis.com/envoy.service.discovery.v3.Resource" ;
44
47
static final String TRANSPORT_SOCKET_NAME_TLS = "envoy.transport_sockets.tls" ;
@@ -68,22 +71,22 @@ abstract class XdsResourceType<T extends ResourceUpdate> {
68
71
"type.googleapis.com/xds.type.v3.TypedStruct" ;
69
72
70
73
@ Nullable
71
- abstract String extractResourceName (Message unpackedResource );
74
+ protected abstract String extractResourceName (Message unpackedResource );
72
75
73
- abstract Class <? extends com .google .protobuf .Message > unpackedClassName ();
76
+ protected abstract Class <? extends com .google .protobuf .Message > unpackedClassName ();
74
77
75
- abstract String typeName ();
78
+ protected abstract String typeName ();
76
79
77
- abstract String typeUrl ();
80
+ protected abstract String typeUrl ();
78
81
79
82
// Do not confuse with the SotW approach: it is the mechanism in which the client must specify all
80
83
// resource names it is interested in with each request. Different resource types may behave
81
84
// differently in this approach. For LDS and CDS resources, the server must return all resources
82
85
// that the client has subscribed to in each request. For RDS and EDS, the server may only return
83
86
// the resources that need an update.
84
- abstract boolean isFullStateOfTheWorld ();
87
+ protected abstract boolean isFullStateOfTheWorld ();
85
88
86
- static class Args {
89
+ public static class Args {
87
90
final ServerInfo serverInfo ;
88
91
final String versionInfo ;
89
92
final String nonce ;
@@ -114,6 +117,18 @@ public Args(ServerInfo serverInfo, String versionInfo, String nonce,
114
117
}
115
118
}
116
119
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
+
117
132
ValidatedResourceUpdate <T > parse (Args args , List <Any > resources ) {
118
133
Map <String , ParsedResource <T >> parsedResources = new HashMap <>(resources .size ());
119
134
Set <String > unpackedResources = new HashSet <>(resources .size ());
@@ -147,7 +162,7 @@ ValidatedResourceUpdate<T> parse(Args args, List<Any> resources) {
147
162
T resourceUpdate ;
148
163
try {
149
164
resourceUpdate = doParse (args , unpackedMessage );
150
- } catch (XdsClientImpl . ResourceInvalidException e ) {
165
+ } catch (ResourceInvalidException e ) {
151
166
errors .add (String .format ("%s response %s '%s' validation error: %s" ,
152
167
typeName (), unpackedClassName ().getSimpleName (), cname , e .getMessage ()));
153
168
invalidResources .add (cname );
@@ -162,7 +177,7 @@ ValidatedResourceUpdate<T> parse(Args args, List<Any> resources) {
162
177
163
178
}
164
179
165
- abstract T doParse (Args args , Message unpackedMessage ) throws ResourceInvalidException ;
180
+ protected abstract T doParse (Args args , Message unpackedMessage ) throws ResourceInvalidException ;
166
181
167
182
/**
168
183
* Helper method to unpack serialized {@link com.google.protobuf.Any} message, while replacing
0 commit comments