Let xDS load balancer bootstrap from a bootstrap file. Currently not use configurations from bootstrap in xDS communication as the xDS load balancer implementation is undergoing changes. We will integrate it later.

This commit is contained in:
Chengyuan Zhang 2019-09-09 15:31:54 -07:00
parent 3ae88de5fe
commit 37200cdd3c
4 changed files with 27 additions and 8 deletions

View File

@ -71,6 +71,12 @@ final class XdsLoadBalancer extends LoadBalancer {
private LoadReportClient lrsClient;
@Nullable
private XdsLbState xdsLbState;
// TODO(chengyuanzhang): use information populated by bootstrapper in xDS communication after
// xDS load balancer restructure is done. For now, don't integrate it.
@SuppressWarnings("unused")
@Nullable
private Bootstrapper bootstrapper;
private final AdsStreamCallback adsStreamCallback = new AdsStreamCallback() {
@Override
@ -112,24 +118,27 @@ final class XdsLoadBalancer extends LoadBalancer {
private LbConfig fallbackPolicy;
XdsLoadBalancer(Helper helper, LoadBalancerRegistry lbRegistry,
BackoffPolicy.Provider backoffPolicyProvider) {
this(helper, lbRegistry, backoffPolicyProvider, LoadReportClientFactory.getInstance(),
new FallbackManager(helper, lbRegistry));
BackoffPolicy.Provider backoffPolicyProvider, boolean usingBootstrap) {
this(helper, lbRegistry, backoffPolicyProvider, usingBootstrap,
LoadReportClientFactory.getInstance(), new FallbackManager(helper, lbRegistry));
}
private XdsLoadBalancer(Helper helper,
LoadBalancerRegistry lbRegistry,
BackoffPolicy.Provider backoffPolicyProvider,
boolean usingBootstrap,
LoadReportClientFactory lrsClientFactory,
FallbackManager fallbackManager) {
this(helper, lbRegistry, backoffPolicyProvider, lrsClientFactory, fallbackManager,
new LocalityStoreImpl(new LocalityStoreHelper(helper, fallbackManager), lbRegistry));
this(helper, lbRegistry, backoffPolicyProvider, usingBootstrap, lrsClientFactory,
fallbackManager, new LocalityStoreImpl(new LocalityStoreHelper(helper, fallbackManager),
lbRegistry));
}
@VisibleForTesting
XdsLoadBalancer(Helper helper,
LoadBalancerRegistry lbRegistry,
BackoffPolicy.Provider backoffPolicyProvider,
boolean usingBootstrap,
LoadReportClientFactory lrsClientFactory,
FallbackManager fallbackManager,
LocalityStore localityStore) {
@ -139,6 +148,16 @@ final class XdsLoadBalancer extends LoadBalancer {
this.lrsClientFactory = checkNotNull(lrsClientFactory, "lrsClientFactory");
this.fallbackManager = checkNotNull(fallbackManager, "fallbackManager");
this.localityStore = checkNotNull(localityStore, "localityStore");
if (usingBootstrap) {
// TODO(chengyuanzhang): figure out error handling when bootstrap fails. Currently bootstrap
// has not been integrated, but we do need a clear way of handling this case.
try {
bootstrapper = Bootstrapper.getInstance();
} catch (Exception e) {
helper.getChannelLogger()
.log(ChannelLogLevel.ERROR, "Unable to bootstrap from local bootstrap file.");
}
}
}
private static final class LocalityStoreHelper extends ForwardingLoadBalancerHelper {

View File

@ -67,7 +67,7 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
return new XdsLoadBalancer(helper, LoadBalancerRegistry.getDefaultRegistry(),
new ExponentialBackoffPolicy.Provider());
new ExponentialBackoffPolicy.Provider(), false);
}
@Override

View File

@ -227,7 +227,7 @@ public class XdsLoadBalancerTest {
lbRegistry.register(lbProvider1);
lbRegistry.register(lbProvider2);
lbRegistry.register(roundRobin);
lb = new XdsLoadBalancer(helper, lbRegistry, backoffPolicyProvider);
lb = new XdsLoadBalancer(helper, lbRegistry, backoffPolicyProvider, false);
doReturn(syncContext).when(helper).getSynchronizationContext();
doReturn(fakeClock.getScheduledExecutorService()).when(helper).getScheduledExecutorService();
doReturn(mock(ChannelLogger.class)).when(helper).getChannelLogger();

View File

@ -224,7 +224,7 @@ public class XdsLoadBalancerWithLrsTest {
any(BackoffPolicy.Provider.class), any(LoadStatsStore.class))).thenReturn(lrsClient);
xdsLoadBalancer =
new XdsLoadBalancer(helper, lbRegistry, backoffPolicyProvider, lrsClientFactory,
new XdsLoadBalancer(helper, lbRegistry, backoffPolicyProvider, false, lrsClientFactory,
new FallbackManager(helper, lbRegistry), localityStore);
}