Skip to content

Commit 85495b0

Browse files
committed
Removing separate CallCredentials from ServerInfo
1 parent 8788f6e commit 85495b0

10 files changed

+61
-123
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,20 @@ public GrpcXdsTransport(ManagedChannel channel) {
7070

7171
public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo, CallCredentials callCredentials) {
7272
String target = serverInfo.target();
73-
ChannelCredentials channelCredentials =
74-
(ChannelCredentials) serverInfo.implSpecificChannelCredConfig();
75-
Object callCredConfig = serverInfo.implSpecificCallCredConfig();
76-
if (callCredConfig != null) {
77-
channelCredentials = CompositeChannelCredentials.create(
78-
channelCredentials, (CallCredentials) callCredConfig);
79-
}
73+
Object implSpecificConfig = serverInfo.implSpecificConfig();
8074

81-
this.channel = Grpc.newChannelBuilder(target, channelCredentials)
75+
this.channel = Grpc.newChannelBuilder(target, (ChannelCredentials) implSpecificConfig)
8276
.keepAliveTime(5, TimeUnit.MINUTES)
8377
.build();
8478

85-
if (callCredentials != null && callCredConfig != null) {
79+
if (callCredentials != null && implSpecificConfig instanceof CompositeChannelCredentials) {
80+
this.callCredentials =
81+
new CompositeCallCredentials(
82+
callCredentials,
83+
((CompositeChannelCredentials) implSpecificConfig).getCallCredentials());
84+
} else if (implSpecificConfig instanceof CompositeChannelCredentials) {
8685
this.callCredentials =
87-
new CompositeCallCredentials(callCredentials, (CallCredentials) callCredConfig);
88-
} else if (callCredConfig != null) {
89-
this.callCredentials = (CallCredentials) callCredConfig;
86+
((CompositeChannelCredentials) implSpecificConfig).getCallCredentials();
9087
} else {
9188
this.callCredentials = callCredentials;
9289
}

xds/src/main/java/io/grpc/xds/client/Bootstrapper.java

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public BootstrapInfo bootstrap(Map<String, ?> rawData) throws XdsInitializationE
5757
public abstract static class ServerInfo {
5858
public abstract String target();
5959

60-
public abstract Object implSpecificChannelCredConfig();
61-
62-
@Nullable public abstract Object implSpecificCallCredConfig();
60+
public abstract Object implSpecificConfig();
6361

6462
public abstract boolean ignoreResourceDeletion();
6563

@@ -68,47 +66,18 @@ public abstract static class ServerInfo {
6866
public abstract boolean resourceTimerIsTransientError();
6967

7068
@VisibleForTesting
71-
public static ServerInfo create(
72-
String target,
73-
@Nullable Object implSpecificChannelCredConfig) {
74-
return new AutoValue_Bootstrapper_ServerInfo(
75-
target,
76-
implSpecificChannelCredConfig,
77-
null,
78-
false,
79-
false,
80-
false);
81-
}
82-
83-
@VisibleForTesting
84-
public static ServerInfo create(
85-
String target,
86-
@Nullable Object implSpecificChannelCredConfig,
87-
@Nullable Object implSpecificCallCredConfig) {
88-
return new AutoValue_Bootstrapper_ServerInfo(
89-
target,
90-
implSpecificChannelCredConfig,
91-
implSpecificCallCredConfig,
92-
false,
93-
false,
94-
false);
69+
public static ServerInfo create(String target, @Nullable Object implSpecificConfig) {
70+
return new AutoValue_Bootstrapper_ServerInfo(target, implSpecificConfig,
71+
false, false, false);
9572
}
9673

9774
@VisibleForTesting
9875
public static ServerInfo create(
99-
String target,
100-
Object implSpecificChannelCredConfig,
101-
@Nullable Object implSpecificCallCredConfig,
102-
boolean ignoreResourceDeletion,
103-
boolean isTrustedXdsServer,
104-
boolean resourceTimerIsTransientError) {
76+
String target, Object implSpecificConfig, boolean ignoreResourceDeletion,
77+
boolean isTrustedXdsServer, boolean resourceTimerIsTransientError) {
10578
return new AutoValue_Bootstrapper_ServerInfo(
106-
target,
107-
implSpecificChannelCredConfig,
108-
implSpecificCallCredConfig,
109-
ignoreResourceDeletion,
110-
isTrustedXdsServer,
111-
resourceTimerIsTransientError);
79+
target, implSpecificConfig,
80+
ignoreResourceDeletion, isTrustedXdsServer, resourceTimerIsTransientError);
11281
}
11382
}
11483

xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import com.google.common.annotations.VisibleForTesting;
2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableMap;
22+
import io.grpc.CallCredentials;
23+
import io.grpc.ChannelCredentials;
24+
import io.grpc.CompositeChannelCredentials;
2225
import io.grpc.Internal;
2326
import io.grpc.InternalLogId;
2427
import io.grpc.internal.GrpcUtil;
@@ -275,8 +278,11 @@ private List<ServerInfo> parseServerInfos(List<?> rawServerConfigs, XdsLogger lo
275278
servers.add(
276279
ServerInfo.create(
277280
serverUri,
278-
implSpecificChannelCredConfig,
279-
implSpecificCallCredConfig,
281+
(implSpecificCallCredConfig != null)
282+
? CompositeChannelCredentials.create(
283+
(ChannelCredentials) implSpecificChannelCredConfig,
284+
(CallCredentials) implSpecificCallCredConfig)
285+
: implSpecificChannelCredConfig,
280286
ignoreResourceDeletion,
281287
serverFeatures != null
282288
&& serverFeatures.contains(SERVER_FEATURE_TRUSTED_XDS_SERVER),

xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNull;
22-
import static org.junit.Assert.assertSame;
2321
import static org.junit.Assert.assertThrows;
2422
import static org.junit.Assert.fail;
2523
import static org.mockito.Mockito.mock;
2624
import static org.mockito.Mockito.verifyNoInteractions;
2725

2826
import com.google.common.collect.ImmutableMap;
2927
import com.google.common.collect.Iterables;
28+
import io.grpc.CallCredentials;
3029
import io.grpc.CompositeCallCredentials;
30+
import io.grpc.CompositeChannelCredentials;
3131
import io.grpc.InsecureChannelCredentials;
3232
import io.grpc.TlsChannelCredentials;
3333
import io.grpc.internal.GrpcUtil;
@@ -131,9 +131,8 @@ public void parseBootstrap_singleXdsServer() throws XdsInitializationException {
131131
assertThat(info.servers()).hasSize(1);
132132
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
133133
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
134-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
134+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
135135
InsecureChannelCredentials.class);
136-
assertNull(serverInfo.implSpecificCallCredConfig());
137136
assertThat(info.node()).isEqualTo(
138137
getNodeBuilder()
139138
.setId("ENVOY_NODE_ID")
@@ -186,14 +185,12 @@ public void parseBootstrap_multipleXdsServers() throws XdsInitializationExceptio
186185
List<ServerInfo> serverInfoList = info.servers();
187186
assertThat(serverInfoList.get(0).target())
188187
.isEqualTo("trafficdirector-foo.googleapis.com:443");
189-
assertThat(serverInfoList.get(0).implSpecificChannelCredConfig())
188+
assertThat(serverInfoList.get(0).implSpecificConfig())
190189
.isInstanceOf(TlsChannelCredentials.class);
191-
assertNull(serverInfoList.get(0).implSpecificCallCredConfig());
192190
assertThat(serverInfoList.get(1).target())
193191
.isEqualTo("trafficdirector-bar.googleapis.com:443");
194-
assertThat(serverInfoList.get(1).implSpecificChannelCredConfig())
192+
assertThat(serverInfoList.get(1).implSpecificConfig())
195193
.isInstanceOf(InsecureChannelCredentials.class);
196-
assertNull(serverInfoList.get(0).implSpecificCallCredConfig());
197194
assertThat(info.node()).isEqualTo(
198195
getNodeBuilder()
199196
.setId("ENVOY_NODE_ID")
@@ -237,9 +234,8 @@ public void parseBootstrap_IgnoreIrrelevantFields() throws XdsInitializationExce
237234
assertThat(info.servers()).hasSize(1);
238235
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
239236
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
240-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
237+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
241238
InsecureChannelCredentials.class);
242-
assertNull(serverInfo.implSpecificCallCredConfig());
243239
assertThat(info.node()).isEqualTo(
244240
getNodeBuilder()
245241
.setId("ENVOY_NODE_ID")
@@ -310,9 +306,8 @@ public void parseBootstrap_useFirstSupportedChannelCredentials()
310306
assertThat(info.servers()).hasSize(1);
311307
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
312308
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
313-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
309+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
314310
InsecureChannelCredentials.class);
315-
assertNull(serverInfo.implSpecificCallCredConfig());
316311
assertThat(info.node()).isEqualTo(getNodeBuilder().build());
317312
}
318313

@@ -607,9 +602,8 @@ public void useV2ProtocolByDefault() throws XdsInitializationException {
607602
BootstrapInfo info = bootstrapper.bootstrap();
608603
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
609604
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
610-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
605+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
611606
InsecureChannelCredentials.class);
612-
assertNull(serverInfo.implSpecificCallCredConfig());
613607
assertThat(serverInfo.ignoreResourceDeletion()).isFalse();
614608
}
615609

@@ -631,9 +625,8 @@ public void useV3ProtocolIfV3FeaturePresent() throws XdsInitializationException
631625
BootstrapInfo info = bootstrapper.bootstrap();
632626
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
633627
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
634-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
628+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
635629
InsecureChannelCredentials.class);
636-
assertNull(serverInfo.implSpecificCallCredConfig());
637630
assertThat(serverInfo.ignoreResourceDeletion()).isFalse();
638631
}
639632

@@ -655,9 +648,8 @@ public void serverFeatureIgnoreResourceDeletion() throws XdsInitializationExcept
655648
BootstrapInfo info = bootstrapper.bootstrap();
656649
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
657650
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
658-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
651+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
659652
InsecureChannelCredentials.class);
660-
assertNull(serverInfo.implSpecificCallCredConfig());
661653
// Only ignore_resource_deletion feature enabled: confirm it's on, and xds_v3 is off.
662654
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
663655
}
@@ -680,9 +672,8 @@ public void serverFeatureTrustedXdsServer() throws XdsInitializationException {
680672
BootstrapInfo info = bootstrapper.bootstrap();
681673
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
682674
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
683-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
675+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
684676
InsecureChannelCredentials.class);
685-
assertNull(serverInfo.implSpecificCallCredConfig());
686677
assertThat(serverInfo.isTrustedXdsServer()).isTrue();
687678
}
688679

@@ -704,9 +695,8 @@ public void serverFeatureIgnoreResourceDeletion_xdsV3() throws XdsInitialization
704695
BootstrapInfo info = bootstrapper.bootstrap();
705696
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
706697
assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
707-
assertThat(serverInfo.implSpecificChannelCredConfig()).isInstanceOf(
698+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
708699
InsecureChannelCredentials.class);
709-
assertNull(serverInfo.implSpecificCallCredConfig());
710700
// ignore_resource_deletion features enabled: confirm both are on.
711701
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
712702
}
@@ -951,7 +941,8 @@ public void parseNotSupportedCallCredentials() throws Exception {
951941
BootstrapInfo info = bootstrapper.bootstrap();
952942
assertThat(info.servers()).hasSize(1);
953943
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
954-
assertNull(serverInfo.implSpecificCallCredConfig());
944+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(
945+
InsecureChannelCredentials.class);
955946
}
956947

957948
@Test
@@ -1050,8 +1041,10 @@ public void parseTwoSupportedCallCredentialsWithValidConfig() throws Exception {
10501041
BootstrapInfo info = bootstrapper.bootstrap();
10511042
assertThat(info.servers()).hasSize(1);
10521043
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
1053-
assertSame(CompositeCallCredentials.class,
1054-
serverInfo.implSpecificCallCredConfig().getClass());
1044+
assertThat(serverInfo.implSpecificConfig()).isInstanceOf(CompositeChannelCredentials.class);
1045+
CallCredentials callCredentials =
1046+
((CompositeChannelCredentials) serverInfo.implSpecificConfig()).getCallCredentials();
1047+
assertThat(callCredentials).isInstanceOf(CompositeCallCredentials.class);
10551048

10561049
jwtToken_1.delete();
10571050
jwtToken_2.delete();

xds/src/test/java/io/grpc/xds/GrpcXdsClientImplDataTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,11 +3549,7 @@ private static Filter buildHttpConnectionManagerFilter(HttpFilter... httpFilters
35493549

35503550
private XdsResourceType.Args getXdsResourceTypeArgs(boolean isTrustedServer) {
35513551
return new XdsResourceType.Args(
3552-
ServerInfo.create("http://td", "", "", false, isTrustedServer, false),
3553-
"1.0",
3554-
null,
3555-
null,
3556-
null,
3557-
null);
3552+
ServerInfo.create("http://td", "", false, isTrustedServer, false), "1.0", null, null, null, null
3553+
);
35583554
}
35593555
}

xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,8 @@ public void setUp() throws IOException {
347347
.start());
348348
channel =
349349
cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
350-
xdsServerInfo = ServerInfo.create(
351-
SERVER_URI,
352-
CHANNEL_CREDENTIALS,
353-
null,
354-
ignoreResourceDeletion(),
355-
true,
356-
false);
350+
xdsServerInfo = ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, ignoreResourceDeletion(),
351+
true, false);
357352
BootstrapInfo bootstrapInfo =
358353
Bootstrapper.BootstrapInfo.builder()
359354
.servers(Collections.singletonList(xdsServerInfo))
@@ -3164,13 +3159,8 @@ public void flowControlAbsent() throws Exception {
31643159
@Test
31653160
public void resourceTimerIsTransientError_schedulesExtendedTimeout() {
31663161
BootstrapperImpl.xdsDataErrorHandlingEnabled = true;
3167-
ServerInfo serverInfo = ServerInfo.create(
3168-
SERVER_URI,
3169-
CHANNEL_CREDENTIALS,
3170-
null,
3171-
false,
3172-
true,
3173-
true);
3162+
ServerInfo serverInfo = ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS,
3163+
false, true, true);
31743164
BootstrapInfo bootstrapInfo =
31753165
Bootstrapper.BootstrapInfo.builder()
31763166
.servers(Collections.singletonList(serverInfo))
@@ -3214,13 +3204,8 @@ public void resourceTimerIsTransientError_schedulesExtendedTimeout() {
32143204
@Test
32153205
public void resourceTimerIsTransientError_callsOnErrorUnavailable() {
32163206
BootstrapperImpl.xdsDataErrorHandlingEnabled = true;
3217-
xdsServerInfo = ServerInfo.create(
3218-
SERVER_URI,
3219-
CHANNEL_CREDENTIALS,
3220-
null,
3221-
ignoreResourceDeletion(),
3222-
true,
3223-
true);
3207+
xdsServerInfo = ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, ignoreResourceDeletion(),
3208+
true, true);
32243209
BootstrapInfo bootstrapInfo =
32253210
Bootstrapper.BootstrapInfo.builder()
32263211
.servers(Collections.singletonList(xdsServerInfo))
@@ -4337,13 +4322,8 @@ private XdsClientImpl createXdsClient(String serverUri) {
43374322

43384323
private BootstrapInfo buildBootStrap(String serverUri) {
43394324

4340-
ServerInfo xdsServerInfo = ServerInfo.create(
4341-
serverUri,
4342-
CHANNEL_CREDENTIALS,
4343-
null,
4344-
ignoreResourceDeletion(),
4345-
true,
4346-
false);
4325+
ServerInfo xdsServerInfo = ServerInfo.create(serverUri, CHANNEL_CREDENTIALS,
4326+
ignoreResourceDeletion(), true, false);
43474327

43484328
return Bootstrapper.BootstrapInfo.builder()
43494329
.servers(Collections.singletonList(xdsServerInfo))

xds/src/test/java/io/grpc/xds/SharedXdsClientPoolProviderTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.auth.oauth2.OAuth2Credentials;
2929
import com.google.common.util.concurrent.SettableFuture;
3030
import io.grpc.CallCredentials;
31+
import io.grpc.CompositeChannelCredentials;
3132
import io.grpc.Grpc;
3233
import io.grpc.InsecureChannelCredentials;
3334
import io.grpc.InsecureServerCredentials;
@@ -242,8 +243,9 @@ public void xdsClient_usesJwtTokenFileCallCredentials() throws Exception {
242243
// Set up bootstrap & xDS client pool provider
243244
ServerInfo server = ServerInfo.create(
244245
xdsServerUri,
245-
InsecureChannelCredentials.create(),
246-
JwtTokenFileCallCredentials.create(jwtToken.toString()));
246+
CompositeChannelCredentials.create(
247+
InsecureChannelCredentials.create(),
248+
JwtTokenFileCallCredentials.create(jwtToken.toString())));
247249
BootstrapInfo bootstrapInfo =
248250
BootstrapInfo.builder().servers(Collections.singletonList(server)).node(node).build();
249251
when(bootstrapper.bootstrap()).thenReturn(bootstrapInfo);

xds/src/test/java/io/grpc/xds/XdsClientFallbackTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public void connect_then_mainServerDown_fallbackServerUp() throws Exception {
347347
@Override
348348
public XdsTransport create(Bootstrapper.ServerInfo serverInfo) {
349349
ChannelCredentials channelCredentials =
350-
(ChannelCredentials) serverInfo.implSpecificChannelCredConfig();
350+
(ChannelCredentials) serverInfo.implSpecificConfig();
351351
return new GrpcXdsTransportFactory.GrpcXdsTransport(
352352
Grpc.newChannelBuilder(serverInfo.target(), channelCredentials)
353353
.executor(executor)

xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,13 @@ public void resolving_targetAuthorityInAuthoritiesMap() {
368368
String serviceAuthority = "[::FFFF:129.144.52.38]:80";
369369
bootstrapInfo = BootstrapInfo.builder()
370370
.servers(ImmutableList.of(ServerInfo.create(
371-
"td.googleapis.com", InsecureChannelCredentials.create(), null, true, true, false)))
371+
"td.googleapis.com", InsecureChannelCredentials.create(), true, true, false)))
372372
.node(Node.newBuilder().build())
373373
.authorities(
374374
ImmutableMap.of(targetAuthority, AuthorityInfo.create(
375375
"xdstp://" + targetAuthority + "/envoy.config.listener.v3.Listener/%s?foo=1&bar=2",
376376
ImmutableList.of(ServerInfo.create(
377-
"td.googleapis.com",
378-
InsecureChannelCredentials.create(),
379-
null,
380-
true,
381-
true,
382-
false)))))
377+
"td.googleapis.com", InsecureChannelCredentials.create(), true, true, false)))))
383378
.build();
384379
expectedLdsResourceName = "xdstp://xds.authority.com/envoy.config.listener.v3.Listener/"
385380
+ "%5B::FFFF:129.144.52.38%5D:80?bar=2&foo=1"; // query param canonified

0 commit comments

Comments
 (0)