Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
834 changes: 193 additions & 641 deletions xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancerProvider;
import io.grpc.LoadBalancerRegistry;
import io.grpc.NameResolver.ConfigOrError;
import io.grpc.Status;
import io.grpc.xds.EnvoyServerProtoData.OutlierDetection;
Expand All @@ -41,6 +42,15 @@
*/
@Internal
public final class ClusterResolverLoadBalancerProvider extends LoadBalancerProvider {
private final LoadBalancerRegistry lbRegistry;

public ClusterResolverLoadBalancerProvider() {
this.lbRegistry = null;
}

ClusterResolverLoadBalancerProvider(LoadBalancerRegistry lbRegistry) {
this.lbRegistry = checkNotNull(lbRegistry, "lbRegistry");
}

@Override
public boolean isAvailable() {
Expand All @@ -65,7 +75,11 @@ public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalanc

@Override
public LoadBalancer newLoadBalancer(Helper helper) {
return new ClusterResolverLoadBalancer(helper);
LoadBalancerRegistry lbRegistry = this.lbRegistry;
if (lbRegistry == null) {
lbRegistry = LoadBalancerRegistry.getDefaultRegistry();
}
return new ClusterResolverLoadBalancer(helper, lbRegistry);
}

static final class ClusterResolverConfig {
Expand Down
2 changes: 1 addition & 1 deletion xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static OutlierDetection fromEnvoyOutlierDetection(
Integer minimumHosts = envoyOutlierDetection.hasSuccessRateMinimumHosts()
? envoyOutlierDetection.getSuccessRateMinimumHosts().getValue() : null;
Integer requestVolume = envoyOutlierDetection.hasSuccessRateRequestVolume()
? envoyOutlierDetection.getSuccessRateMinimumHosts().getValue() : null;
? envoyOutlierDetection.getSuccessRateRequestVolume().getValue() : null;

successRateEjection = SuccessRateEjection.create(stdevFactor, enforcementPercentage,
minimumHosts, requestVolume);
Expand Down
10 changes: 7 additions & 3 deletions xds/src/main/java/io/grpc/xds/XdsDependencyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.grpc.xds.client.XdsClient;
import io.grpc.xds.client.XdsClient.ResourceWatcher;
import io.grpc.xds.client.XdsResourceType;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand Down Expand Up @@ -83,7 +84,7 @@ private enum TrackedWatcherTypeEnum {

private static final int MAX_CLUSTER_RECURSION_DEPTH = 16; // Specified by gRFC A37

static boolean enableLogicalDns = false;
static boolean enableLogicalDns = true;

private final String listenerName;
private final XdsClient xdsClient;
Expand Down Expand Up @@ -394,10 +395,13 @@ private static StatusOr<XdsEndpointResource.EdsUpdate> dnsToEdsUpdate(
return StatusOr.fromStatus(dnsData.getStatus());
}

List<Endpoints.LbEndpoint> endpoints = new ArrayList<>();
List<SocketAddress> addresses = new ArrayList<>();
for (EquivalentAddressGroup eag : dnsData.getValue()) {
endpoints.add(Endpoints.LbEndpoint.create(eag, 1, true, dnsHostName, ImmutableMap.of()));
addresses.addAll(eag.getAddresses());
}
EquivalentAddressGroup eag = new EquivalentAddressGroup(addresses);
List<Endpoints.LbEndpoint> endpoints = ImmutableList.of(
Endpoints.LbEndpoint.create(eag, 1, true, dnsHostName, ImmutableMap.of()));
LocalityLbEndpoints lbEndpoints =
LocalityLbEndpoints.create(endpoints, 1, 0, ImmutableMap.of());
return StatusOr.fromValue(new XdsEndpointResource.EdsUpdate(
Expand Down
16 changes: 15 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ public void start(Listener2 listener) {
resolveState.start();
}

@Override
public void refresh() {
if (resolveState != null) {
resolveState.refresh();
}
}

private static String expandPercentS(String template, String replacement) {
return template.replace("%s", replacement);
}
Expand Down Expand Up @@ -323,7 +330,10 @@ private void updateResolutionResult(XdsConfig xdsConfig) {
.setAttributes(attrs)
.setServiceConfig(parsedServiceConfig)
.build();
listener.onResult2(result);
if (!listener.onResult2(result).isOk()) {
// TODO: check if this is right
resolveState.xdsDependencyManager.requestReresolution();
}
}

/**
Expand Down Expand Up @@ -662,6 +672,10 @@ void start() {
xdsDependencyManager.start(this);
}

void refresh() {
xdsDependencyManager.requestReresolution();
}

private void shutdown() {
if (stopped) {
return;
Expand Down
Loading