use of io.grpc.xds.Bootstrapper.AuthorityInfo in project grpc-java by grpc.
the class XdsNameResolver method start.
@Override
public void start(Listener2 listener) {
this.listener = checkNotNull(listener, "listener");
try {
xdsClientPool = xdsClientPoolFactory.getOrCreate();
} catch (Exception e) {
listener.onError(Status.UNAVAILABLE.withDescription("Failed to initialize xDS").withCause(e));
return;
}
xdsClient = xdsClientPool.getObject();
BootstrapInfo bootstrapInfo = xdsClient.getBootstrapInfo();
String listenerNameTemplate;
if (targetAuthority == null) {
listenerNameTemplate = bootstrapInfo.clientDefaultListenerResourceNameTemplate();
} else {
AuthorityInfo authorityInfo = bootstrapInfo.authorities().get(targetAuthority);
if (authorityInfo == null) {
listener.onError(Status.INVALID_ARGUMENT.withDescription("invalid target URI: target authority not found in the bootstrap"));
return;
}
listenerNameTemplate = authorityInfo.clientListenerResourceNameTemplate();
}
String replacement = serviceAuthority;
if (listenerNameTemplate.startsWith(XDSTP_SCHEME)) {
replacement = XdsClient.percentEncodePath(replacement);
}
String ldsResourceName = expandPercentS(listenerNameTemplate, replacement);
if (!XdsClient.isResourceNameValid(ldsResourceName, ResourceType.LDS.typeUrl()) && !XdsClient.isResourceNameValid(ldsResourceName, ResourceType.LDS.typeUrlV2())) {
listener.onError(Status.INVALID_ARGUMENT.withDescription("invalid listener resource URI for service authority: " + serviceAuthority));
return;
}
ldsResourceName = XdsClient.canonifyResourceName(ldsResourceName);
callCounterProvider = SharedCallCounterMap.getInstance();
resolveState = new ResolveState(ldsResourceName);
resolveState.start();
}
use of io.grpc.xds.Bootstrapper.AuthorityInfo in project grpc-java by grpc.
the class BootstrapperImplTest method parseAuthorities.
@Test
public void parseAuthorities() throws Exception {
BootstrapperImpl.enableFederation = true;
String rawData = "{\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"" + SERVER_URI + "\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ]\n" + " }\n" + " ]\n" + "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
BootstrapInfo info = bootstrapper.bootstrap();
assertThat(info.authorities()).isEmpty();
rawData = "{\n" + " \"authorities\": {\n" + " \"a.com\": {\n" + " \"client_listener_resource_name_template\": \"xdstp://a.com/v1.Listener/id-%s\"\n" + " }\n" + " },\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"" + SERVER_URI + "\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ]\n" + " }\n" + " ]\n" + "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
info = bootstrapper.bootstrap();
assertThat(info.authorities()).hasSize(1);
AuthorityInfo authorityInfo = info.authorities().get("a.com");
assertThat(authorityInfo.clientListenerResourceNameTemplate()).isEqualTo("xdstp://a.com/v1.Listener/id-%s");
// Defaults to top-level servers.
assertThat(authorityInfo.xdsServers()).hasSize(1);
assertThat(authorityInfo.xdsServers().get(0).target()).isEqualTo(SERVER_URI);
rawData = "{\n" + " \"authorities\": {\n" + " \"a.com\": {\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"td2.googleapis.com:443\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"xds_servers\": [\n" + " {\n" + " \"server_uri\": \"" + SERVER_URI + "\",\n" + " \"channel_creds\": [\n" + " {\"type\": \"insecure\"}\n" + " ]\n" + " }\n" + " ]\n" + "}";
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
info = bootstrapper.bootstrap();
assertThat(info.authorities()).hasSize(1);
authorityInfo = info.authorities().get("a.com");
// Defaults to "xdstp://<authority_name>>/envoy.config.listener.v3.Listener/%s"
assertThat(authorityInfo.clientListenerResourceNameTemplate()).isEqualTo("xdstp://a.com/envoy.config.listener.v3.Listener/%s");
assertThat(authorityInfo.xdsServers()).hasSize(1);
assertThat(authorityInfo.xdsServers().get(0).target()).isEqualTo("td2.googleapis.com:443");
}
Aggregations