certProviders();
+ /**
+ * A template for the name of the Listener resource to subscribe to for a gRPC server.
+ *
+ * If starts with "xdstp:", will be interpreted as a new-style name, in which case the
+ * authority of the URI will be used to select the relevant configuration in the
+ * "authorities" map. The token "%s", if present in this string, will be replaced with
+ * the IP and port on which the server is listening. If the template starts with "xdstp:",
+ * the replaced string will be %-encoded.
+ *
+ *
There is no default; if unset, xDS-based server creation fails.
+ */
@Nullable
public abstract String serverListenerResourceNameTemplate();
+ /**
+ * A template for the name of the Listener resource to subscribe to for a gRPC client channel.
+ * Used only when the channel is created with an "xds:" URI with no authority.
+ *
+ *
If starts with "xdstp:", will be interpreted as a new-style name, in which case the
+ * authority of the URI will be used to select the relevant configuration in the "authorities"
+ * map.
+ *
+ *
The token "%s", if present in this string, will be replaced with the service authority
+ * (i.e., the path part of the target URI used to create the gRPC channel). If the template
+ * starts with "xdstp:", the replaced string will be %-encoded.
+ *
+ *
Defaults to {@code "%s"}.
+ */
+ abstract String clientDefaultListenerResourceNameTemplate();
+
+ /**
+ * A map of authority name to corresponding configuration.
+ *
+ *
This is used in the following cases:
+ *
+ *
+ * - A gRPC client channel is created using an "xds:" URI that includes an
+ * authority.
+ *
+ * - A gRPC client channel is created using an "xds:" URI with no authority,
+ * but the "client_default_listener_resource_name_template" field above turns it into an
+ * "xdstp:" URI.
+ *
+ * - A gRPC server is created and the "server_listener_resource_name_template" field is an
+ * "xdstp:" URI.
+ *
+ *
+ * In any of those cases, it is an error if the specified authority is not present in this
+ * map.
+ *
+ *
Defaults to an empty map.
+ */
+ abstract ImmutableMap authorities();
+
@VisibleForTesting
static Builder builder() {
- return new AutoValue_Bootstrapper_BootstrapInfo.Builder();
+ return new AutoValue_Bootstrapper_BootstrapInfo.Builder()
+ .clientDefaultListenerResourceNameTemplate("%s")
+ .authorities(ImmutableMap.of());
}
@AutoValue.Builder
@VisibleForTesting
abstract static class Builder {
+
abstract Builder servers(List servers);
abstract Builder node(Node node);
@@ -119,6 +205,11 @@ public abstract class Bootstrapper {
abstract Builder serverListenerResourceNameTemplate(
@Nullable String serverListenerResourceNameTemplate);
+ abstract Builder clientDefaultListenerResourceNameTemplate(
+ String clientDefaultListenerResourceNameTemplate);
+
+ abstract Builder authorities(Map authorities);
+
abstract BootstrapInfo build();
}
}
diff --git a/xds/src/main/java/io/grpc/xds/BootstrapperImpl.java b/xds/src/main/java/io/grpc/xds/BootstrapperImpl.java
index 0a044da529..200ded3c1c 100644
--- a/xds/src/main/java/io/grpc/xds/BootstrapperImpl.java
+++ b/xds/src/main/java/io/grpc/xds/BootstrapperImpl.java
@@ -17,6 +17,8 @@
package io.grpc.xds;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import io.grpc.ChannelCredentials;
import io.grpc.InsecureChannelCredentials;
import io.grpc.Internal;
@@ -33,7 +35,6 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -121,41 +122,14 @@ public class BootstrapperImpl extends Bootstrapper {
@Override
BootstrapInfo bootstrap(Map rawData) throws XdsInitializationException {
- List servers = new ArrayList<>();
+ BootstrapInfo.Builder builder = BootstrapInfo.builder();
+
List> rawServerConfigs = JsonUtil.getList(rawData, "xds_servers");
if (rawServerConfigs == null) {
throw new XdsInitializationException("Invalid bootstrap: 'xds_servers' does not exist.");
}
- logger.log(XdsLogLevel.INFO, "Configured with {0} xDS servers", rawServerConfigs.size());
- // TODO(chengyuanzhang): require at least one server URI.
- List