xds: clean up verbose getters and builders on XdsClient interface (#7784)

Eliminate getters and builders for xDS resource data. They are (should be effectively) immutable and mostly only used for internal implementations. Cleaning up getters and builders significantly reduces the verbosity.
This commit is contained in:
Chengyuan Zhang 2021-01-07 14:55:05 -08:00 committed by GitHub
parent ff52893c79
commit 2755afeaa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 129 additions and 278 deletions

View File

@ -59,6 +59,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -151,49 +152,46 @@ final class ClientXdsClient extends AbstractXdsClient {
Map<String, LdsUpdate> ldsUpdates = new HashMap<>();
Set<String> rdsNames = new HashSet<>();
String errorMessage = null;
for (Map.Entry<String, HttpConnectionManager> entry : httpConnectionManagers.entrySet()) {
LdsUpdate update;
String listenerName = entry.getKey();
HttpConnectionManager hcm = entry.getValue();
LdsUpdate.Builder updateBuilder = LdsUpdate.newBuilder();
long maxStreamDuration = 0;
if (hcm.hasCommonHttpProtocolOptions()) {
HttpProtocolOptions options = hcm.getCommonHttpProtocolOptions();
if (options.hasMaxStreamDuration()) {
maxStreamDuration = Durations.toNanos(options.getMaxStreamDuration());
}
}
if (hcm.hasRouteConfig()) {
List<EnvoyProtoData.VirtualHost> virtualHosts = new ArrayList<>();
for (VirtualHost virtualHostProto : hcm.getRouteConfig().getVirtualHostsList()) {
StructOrError<EnvoyProtoData.VirtualHost> virtualHost =
EnvoyProtoData.VirtualHost.fromEnvoyProtoVirtualHost(virtualHostProto);
if (virtualHost.getErrorDetail() != null) {
errorMessage = "Listener " + listenerName + " contains invalid virtual host: "
+ virtualHost.getErrorDetail();
break;
} else {
updateBuilder.addVirtualHost(virtualHost.getStruct());
nackResponse(ResourceType.LDS, nonce,
"Listener " + listenerName + " contains invalid virtual host: "
+ virtualHost.getErrorDetail());
return;
}
virtualHosts.add(virtualHost.getStruct());
}
update = new LdsUpdate(maxStreamDuration, virtualHosts);
} else if (hcm.hasRds()) {
Rds rds = hcm.getRds();
if (!rds.getConfigSource().hasAds()) {
errorMessage = "Listener " + listenerName + " with RDS config_source not set to ADS";
} else {
updateBuilder.setRdsName(rds.getRouteConfigName());
rdsNames.add(rds.getRouteConfigName());
nackResponse(ResourceType.LDS, nonce,
"Listener " + listenerName + " with RDS config_source not set to ADS");
return;
}
update = new LdsUpdate(maxStreamDuration, rds.getRouteConfigName());
rdsNames.add(rds.getRouteConfigName());
} else {
errorMessage = "Listener " + listenerName + " without inline RouteConfiguration or RDS";
nackResponse(ResourceType.LDS, nonce,
"Listener " + listenerName + " without inline RouteConfiguration or RDS");
return;
}
if (errorMessage != null) {
break;
}
if (hcm.hasCommonHttpProtocolOptions()) {
HttpProtocolOptions options = hcm.getCommonHttpProtocolOptions();
if (options.hasMaxStreamDuration()) {
updateBuilder.setHttpMaxStreamDurationNano(
Durations.toNanos(options.getMaxStreamDuration()));
}
}
ldsUpdates.put(listenerName, updateBuilder.build());
}
if (errorMessage != null) {
nackResponse(ResourceType.LDS, nonce, errorMessage);
return;
ldsUpdates.put(listenerName, update);
}
ackResponse(ResourceType.LDS, versionInfo, nonce);
@ -235,7 +233,6 @@ final class ClientXdsClient extends AbstractXdsClient {
XdsLogLevel.INFO, "Received RDS response for resources: {0}", routeConfigs.keySet());
Map<String, RdsUpdate> rdsUpdates = new HashMap<>();
String errorMessage = null;
for (Map.Entry<String, RouteConfiguration> entry : routeConfigs.entrySet()) {
String routeConfigName = entry.getKey();
RouteConfiguration routeConfig = entry.getValue();
@ -245,21 +242,13 @@ final class ClientXdsClient extends AbstractXdsClient {
StructOrError<EnvoyProtoData.VirtualHost> virtualHost =
EnvoyProtoData.VirtualHost.fromEnvoyProtoVirtualHost(virtualHostProto);
if (virtualHost.getErrorDetail() != null) {
errorMessage = "RouteConfiguration " + routeConfigName
+ " contains invalid virtual host: " + virtualHost.getErrorDetail();
break;
} else {
virtualHosts.add(virtualHost.getStruct());
nackResponse(ResourceType.RDS, nonce, "RouteConfiguration " + routeConfigName
+ " contains invalid virtual host: " + virtualHost.getErrorDetail());
return;
}
virtualHosts.add(virtualHost.getStruct());
}
if (errorMessage != null) {
break;
}
rdsUpdates.put(routeConfigName, RdsUpdate.fromVirtualHosts(virtualHosts));
}
if (errorMessage != null) {
nackResponse(ResourceType.RDS, nonce, errorMessage);
return;
rdsUpdates.put(routeConfigName, new RdsUpdate(virtualHosts));
}
ackResponse(ResourceType.RDS, versionInfo, nonce);
@ -479,11 +468,7 @@ final class ClientXdsClient extends AbstractXdsClient {
}
getLogger().log(XdsLogLevel.INFO, "Received EDS response for resources: {0}", claNames);
String errorMessage = null;
// Endpoint information updates for requested clusters received in this EDS response.
Map<String, EdsUpdate> edsUpdates = new HashMap<>();
// Walk through each ClusterLoadAssignment message. If any of them for requested clusters
// contain invalid information for gRPC's load balancing usage, the whole response is rejected.
for (ClusterLoadAssignment assignment : clusterLoadAssignments) {
String clusterName = assignment.getClusterName();
// Skip information for clusters not requested.
@ -493,9 +478,9 @@ final class ClientXdsClient extends AbstractXdsClient {
if (!edsResourceSubscribers.containsKey(clusterName)) {
continue;
}
EdsUpdate.Builder updateBuilder = EdsUpdate.newBuilder();
updateBuilder.setClusterName(clusterName);
Set<Integer> priorities = new HashSet<>();
Map<Locality, LocalityLbEndpoints> localityLbEndpointsMap = new LinkedHashMap<>();
List<DropOverload> dropOverloads = new ArrayList<>();
int maxPriority = -1;
for (io.envoyproxy.envoy.config.endpoint.v3.LocalityLbEndpoints localityLbEndpoints
: assignment.getEndpointsList()) {
@ -506,9 +491,9 @@ final class ClientXdsClient extends AbstractXdsClient {
}
int localityPriority = localityLbEndpoints.getPriority();
if (localityPriority < 0) {
errorMessage =
"ClusterLoadAssignment " + clusterName + " : locality with negative priority.";
break;
nackResponse(ResourceType.EDS, nonce,
"ClusterLoadAssignment " + clusterName + " : locality with negative priority.");
return;
}
maxPriority = Math.max(maxPriority, localityPriority);
priorities.add(localityPriority);
@ -516,38 +501,30 @@ final class ClientXdsClient extends AbstractXdsClient {
// Inside of it: the address field must be set.
for (LbEndpoint lbEndpoint : localityLbEndpoints.getLbEndpointsList()) {
if (!lbEndpoint.getEndpoint().hasAddress()) {
errorMessage = "ClusterLoadAssignment " + clusterName + " : endpoint with no address.";
break;
nackResponse(ResourceType.EDS, nonce,
"ClusterLoadAssignment " + clusterName + " : endpoint with no address.");
return;
}
}
if (errorMessage != null) {
break;
}
// Note endpoints with health status other than UNHEALTHY and UNKNOWN are still
// handed over to watching parties. It is watching parties' responsibility to
// filter out unhealthy endpoints. See EnvoyProtoData.LbEndpoint#isHealthy().
updateBuilder.addLocalityLbEndpoints(
localityLbEndpointsMap.put(
Locality.fromEnvoyProtoLocality(localityLbEndpoints.getLocality()),
LocalityLbEndpoints.fromEnvoyProtoLocalityLbEndpoints(localityLbEndpoints));
}
if (errorMessage != null) {
break;
}
if (priorities.size() != maxPriority + 1) {
errorMessage = "ClusterLoadAssignment " + clusterName + " : sparse priorities.";
break;
nackResponse(ResourceType.EDS, nonce,
"ClusterLoadAssignment " + clusterName + " : sparse priorities.");
return;
}
for (ClusterLoadAssignment.Policy.DropOverload dropOverload
: assignment.getPolicy().getDropOverloadsList()) {
updateBuilder.addDropPolicy(DropOverload.fromEnvoyProtoDropOverload(dropOverload));
dropOverloads.add(DropOverload.fromEnvoyProtoDropOverload(dropOverload));
}
EdsUpdate update = updateBuilder.build();
EdsUpdate update = new EdsUpdate(clusterName, localityLbEndpointsMap, dropOverloads);
edsUpdates.put(clusterName, update);
}
if (errorMessage != null) {
nackResponse(ResourceType.EDS, nonce, errorMessage);
return;
}
ackResponse(ResourceType.EDS, versionInfo, nonce);
for (String resource : edsResourceSubscribers.keySet()) {

View File

@ -349,12 +349,12 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
logger.log(XdsLogLevel.DEBUG, "Received endpoint update {0}", update);
if (logger.isLoggable(XdsLogLevel.INFO)) {
logger.log(XdsLogLevel.INFO, "Cluster {0}: {1} localities, {2} drop categories",
update.getClusterName(), update.getLocalityLbEndpointsMap().size(),
update.getDropPolicies().size());
update.clusterName, update.localityLbEndpointsMap.size(),
update.dropPolicies.size());
}
Map<Locality, LocalityLbEndpoints> localityLbEndpoints =
update.getLocalityLbEndpointsMap();
List<DropOverload> dropOverloads = update.getDropPolicies();
update.localityLbEndpointsMap;
List<DropOverload> dropOverloads = update.dropPolicies;
List<EquivalentAddressGroup> addresses = new ArrayList<>();
Map<String, Map<Locality, Integer>> prioritizedLocalityWeights = new HashMap<>();
for (Locality locality : localityLbEndpoints.keySet()) {
@ -386,7 +386,7 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
if (prioritizedLocalityWeights.isEmpty()) {
// Will still update the result, as if the cluster resource is revoked.
logger.log(XdsLogLevel.INFO,
"Cluster {0} has no usable priority/locality/endpoint", update.getClusterName());
"Cluster {0} has no usable priority/locality/endpoint", update.clusterName);
}
List<String> priorities = new ArrayList<>(prioritizedLocalityWeights.keySet());
Collections.sort(priorities);

View File

@ -213,12 +213,12 @@ final class EdsLoadBalancer2 extends LoadBalancer {
"Received endpoint update from xDS client {0}: {1}", xdsClient, update);
if (logger.isLoggable(XdsLogLevel.INFO)) {
logger.log(XdsLogLevel.INFO, "Received endpoint update: cluster_name={0}, "
+ "{1} localities, {2} drop categories", update.getClusterName(),
update.getLocalityLbEndpointsMap().size(), update.getDropPolicies().size());
+ "{1} localities, {2} drop categories", update.clusterName,
update.localityLbEndpointsMap.size(), update.dropPolicies.size());
}
dropOverloads = update.getDropPolicies();
dropOverloads = update.dropPolicies;
Map<Locality, LocalityLbEndpoints> localityLbEndpoints =
update.getLocalityLbEndpointsMap();
update.localityLbEndpointsMap;
endpointAddresses = new ArrayList<>();
prioritizedLocalityWeights = new HashMap<>();
for (Locality locality : localityLbEndpoints.keySet()) {

View File

@ -21,8 +21,6 @@ import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.grpc.Status;
import io.grpc.xds.EnvoyProtoData.DropOverload;
import io.grpc.xds.EnvoyProtoData.Locality;
@ -49,13 +47,21 @@ abstract class XdsClient {
static final class LdsUpdate implements ResourceUpdate {
// Total number of nanoseconds to keep alive an HTTP request/response stream.
private final long httpMaxStreamDurationNano;
final long httpMaxStreamDurationNano;
// The name of the route configuration to be used for RDS resource discovery.
@Nullable
private final String rdsName;
final String rdsName;
// The list virtual hosts that make up the route table.
@Nullable
private final List<VirtualHost> virtualHosts;
final List<VirtualHost> virtualHosts;
LdsUpdate(long httpMaxStreamDurationNano, String rdsName) {
this(httpMaxStreamDurationNano, rdsName, null);
}
LdsUpdate(long httpMaxStreamDurationNano, List<VirtualHost> virtualHosts) {
this(httpMaxStreamDurationNano, null, virtualHosts);
}
private LdsUpdate(long httpMaxStreamDurationNano, @Nullable String rdsName,
@Nullable List<VirtualHost> virtualHosts) {
@ -65,20 +71,6 @@ abstract class XdsClient {
? null : Collections.unmodifiableList(new ArrayList<>(virtualHosts));
}
long getHttpMaxStreamDurationNano() {
return httpMaxStreamDurationNano;
}
@Nullable
String getRdsName() {
return rdsName;
}
@Nullable
List<VirtualHost> getVirtualHosts() {
return virtualHosts;
}
@Override
public int hashCode() {
return Objects.hash(httpMaxStreamDurationNano, rdsName, virtualHosts);
@ -109,63 +101,17 @@ abstract class XdsClient {
}
return toStringHelper.toString();
}
static Builder newBuilder() {
return new Builder();
}
static class Builder {
private long httpMaxStreamDurationNano;
@Nullable
private String rdsName;
@Nullable
private List<VirtualHost> virtualHosts;
private Builder() {
}
Builder setHttpMaxStreamDurationNano(long httpMaxStreamDurationNano) {
this.httpMaxStreamDurationNano = httpMaxStreamDurationNano;
return this;
}
Builder setRdsName(String rdsName) {
this.rdsName = rdsName;
return this;
}
Builder addVirtualHost(VirtualHost virtualHost) {
if (virtualHosts == null) {
virtualHosts = new ArrayList<>();
}
virtualHosts.add(virtualHost);
return this;
}
LdsUpdate build() {
checkState((rdsName == null) != (virtualHosts == null), "one of rdsName and virtualHosts");
return new LdsUpdate(httpMaxStreamDurationNano, rdsName, virtualHosts);
}
}
}
static final class RdsUpdate implements ResourceUpdate {
// The list virtual hosts that make up the route table.
private final List<VirtualHost> virtualHosts;
final List<VirtualHost> virtualHosts;
private RdsUpdate(List<VirtualHost> virtualHosts) {
RdsUpdate(List<VirtualHost> virtualHosts) {
this.virtualHosts = Collections.unmodifiableList(
new ArrayList<>(checkNotNull(virtualHosts, "virtualHosts")));
}
static RdsUpdate fromVirtualHosts(List<VirtualHost> virtualHosts) {
return new RdsUpdate(virtualHosts);
}
List<VirtualHost> getVirtualHosts() {
return virtualHosts;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
@ -386,39 +332,17 @@ abstract class XdsClient {
}
static final class EdsUpdate implements ResourceUpdate {
private final String clusterName;
private final Map<Locality, LocalityLbEndpoints> localityLbEndpointsMap;
private final List<DropOverload> dropPolicies;
final String clusterName;
final Map<Locality, LocalityLbEndpoints> localityLbEndpointsMap;
final List<DropOverload> dropPolicies;
private EdsUpdate(
String clusterName,
Map<Locality, LocalityLbEndpoints> localityLbEndpoints,
EdsUpdate(String clusterName, Map<Locality, LocalityLbEndpoints> localityLbEndpoints,
List<DropOverload> dropPolicies) {
this.clusterName = clusterName;
this.localityLbEndpointsMap = localityLbEndpoints;
this.dropPolicies = dropPolicies;
}
static Builder newBuilder() {
return new Builder();
}
String getClusterName() {
return clusterName;
}
/**
* Returns a map of localities with endpoints load balancing information in each locality.
*/
Map<Locality, LocalityLbEndpoints> getLocalityLbEndpointsMap() {
return Collections.unmodifiableMap(localityLbEndpointsMap);
}
/**
* Returns a list of drop policies to be applied to outgoing requests.
*/
List<DropOverload> getDropPolicies() {
return Collections.unmodifiableList(dropPolicies);
this.clusterName = checkNotNull(clusterName, "clusterName");
this.localityLbEndpointsMap = Collections.unmodifiableMap(
new LinkedHashMap<>(checkNotNull(localityLbEndpoints, "localityLbEndpoints")));
this.dropPolicies = Collections.unmodifiableList(
new ArrayList<>(checkNotNull(dropPolicies, "dropPolicies")));
}
@Override
@ -450,39 +374,6 @@ abstract class XdsClient {
.add("dropPolicies", dropPolicies)
.toString();
}
static final class Builder {
private String clusterName;
private Map<Locality, LocalityLbEndpoints> localityLbEndpointsMap = new LinkedHashMap<>();
private List<DropOverload> dropPolicies = new ArrayList<>();
private Builder() {
}
Builder setClusterName(String clusterName) {
this.clusterName = clusterName;
return this;
}
Builder addLocalityLbEndpoints(Locality locality, LocalityLbEndpoints info) {
localityLbEndpointsMap.put(locality, info);
return this;
}
Builder addDropPolicy(DropOverload policy) {
dropPolicies.add(policy);
return this;
}
EdsUpdate build() {
checkState(clusterName != null, "clusterName is not set");
return
new EdsUpdate(
clusterName,
ImmutableMap.copyOf(localityLbEndpointsMap),
ImmutableList.copyOf(dropPolicies));
}
}
}
/**

View File

@ -467,9 +467,9 @@ final class XdsNameResolver extends NameResolver {
return;
}
logger.log(XdsLogLevel.INFO, "Receive LDS resource update: {0}", update);
httpMaxStreamDurationNano = update.getHttpMaxStreamDurationNano();
List<VirtualHost> virtualHosts = update.getVirtualHosts();
String rdsName = update.getRdsName();
httpMaxStreamDurationNano = update.httpMaxStreamDurationNano;
List<VirtualHost> virtualHosts = update.virtualHosts;
String rdsName = update.rdsName;
if (rdsName != null && rdsName.equals(rdsResource)) {
return;
}
@ -603,7 +603,7 @@ final class XdsNameResolver extends NameResolver {
if (RdsResourceWatcherImpl.this != rdsWatcher) {
return;
}
updateRoutes(update.getVirtualHosts());
updateRoutes(update.virtualHosts);
}
});
}

View File

@ -252,7 +252,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "0", Collections.singletonList(LDS_RESOURCE), ResourceType.LDS,
"0000");
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(2);
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
@ -268,7 +268,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "0", Collections.singletonList(LDS_RESOURCE), ResourceType.LDS,
"0000");
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getRdsName()).isEqualTo(RDS_RESOURCE);
assertThat(ldsUpdateCaptor.getValue().rdsName).isEqualTo(RDS_RESOURCE);
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
@ -286,7 +286,7 @@ public abstract class ClientXdsClientTestBase {
LdsResourceWatcher watcher = mock(LdsResourceWatcher.class);
xdsClient.watchLdsResource(LDS_RESOURCE, watcher);
verify(watcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getRdsName()).isEqualTo(RDS_RESOURCE);
assertThat(ldsUpdateCaptor.getValue().rdsName).isEqualTo(RDS_RESOURCE);
call.verifyNoMoreRequest();
}
@ -315,7 +315,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "0", Collections.singletonList(LDS_RESOURCE), ResourceType.LDS,
"0000");
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(2);
listeners = ImmutableList.of(
Any.pack(mf.buildListenerForRds(LDS_RESOURCE, RDS_RESOURCE)));
@ -325,7 +325,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "1", Collections.singletonList(LDS_RESOURCE), ResourceType.LDS,
"0001");
verify(ldsResourceWatcher, times(2)).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getRdsName()).isEqualTo(RDS_RESOURCE);
assertThat(ldsUpdateCaptor.getValue().rdsName).isEqualTo(RDS_RESOURCE);
}
@Test
@ -341,7 +341,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "0", Collections.singletonList(LDS_RESOURCE), ResourceType.LDS,
"0000");
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(2);
call.sendResponse("1", Collections.<Any>emptyList(), ResourceType.LDS, "0001");
@ -374,11 +374,11 @@ public abstract class ClientXdsClientTestBase {
mf.buildRouteConfiguration("do not care", mf.buildOpaqueVirtualHosts(4)))));
call.sendResponse("0", listeners, ResourceType.LDS, "0000");
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(2);
verify(watcher1).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(4);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(4);
verify(watcher2).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(4);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(4);
}
@Test
@ -412,7 +412,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "0", Collections.singletonList(RDS_RESOURCE), ResourceType.RDS,
"0000");
verify(rdsResourceWatcher).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(2);
assertThat(fakeClock.getPendingTasks(RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
}
@ -431,7 +431,7 @@ public abstract class ClientXdsClientTestBase {
RdsResourceWatcher watcher = mock(RdsResourceWatcher.class);
xdsClient.watchRdsResource(RDS_RESOURCE, watcher);
verify(watcher).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(2);
call.verifyNoMoreRequest();
}
@ -459,7 +459,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "0", Collections.singletonList(RDS_RESOURCE), ResourceType.RDS,
"0000");
verify(rdsResourceWatcher).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(2);
routeConfigs = ImmutableList.of(
Any.pack(mf.buildRouteConfiguration(RDS_RESOURCE, mf.buildOpaqueVirtualHosts(4))));
@ -469,7 +469,7 @@ public abstract class ClientXdsClientTestBase {
call.verifyRequest(NODE, "1", Collections.singletonList(RDS_RESOURCE), ResourceType.RDS,
"0001");
verify(rdsResourceWatcher, times(2)).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(4);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(4);
}
@Test
@ -481,20 +481,20 @@ public abstract class ClientXdsClientTestBase {
Any.pack(mf.buildListenerForRds(LDS_RESOURCE, RDS_RESOURCE)));
call.sendResponse("0", listeners, ResourceType.LDS, "0000");
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getRdsName()).isEqualTo(RDS_RESOURCE);
assertThat(ldsUpdateCaptor.getValue().rdsName).isEqualTo(RDS_RESOURCE);
List<Any> routeConfigs = ImmutableList.of(
Any.pack(mf.buildRouteConfiguration(RDS_RESOURCE, mf.buildOpaqueVirtualHosts(2))));
call.sendResponse("0", routeConfigs, ResourceType.RDS, "0000");
verify(rdsResourceWatcher).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(2);
listeners = ImmutableList.of(
Any.pack(mf.buildListener(LDS_RESOURCE,
mf.buildRouteConfiguration("do not care", mf.buildOpaqueVirtualHosts(5)))));
call.sendResponse("1", listeners, ResourceType.LDS, "0001");
verify(ldsResourceWatcher, times(2)).onChanged(ldsUpdateCaptor.capture());
assertThat(ldsUpdateCaptor.getValue().getVirtualHosts()).hasSize(5);
assertThat(ldsUpdateCaptor.getValue().virtualHosts).hasSize(5);
verify(rdsResourceWatcher).onResourceDoesNotExist(RDS_RESOURCE);
}
@ -519,7 +519,7 @@ public abstract class ClientXdsClientTestBase {
call.sendResponse("0", routeConfigs, ResourceType.RDS, "0000");
verify(rdsResourceWatcher).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(2);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(2);
verifyNoMoreInteractions(watcher1, watcher2);
routeConfigs = ImmutableList.of(Any.pack(
@ -527,9 +527,9 @@ public abstract class ClientXdsClientTestBase {
call.sendResponse("2", routeConfigs, ResourceType.RDS, "0002");
verify(watcher1).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(4);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(4);
verify(watcher2).onChanged(rdsUpdateCaptor.capture());
assertThat(rdsUpdateCaptor.getValue().getVirtualHosts()).hasSize(4);
assertThat(rdsUpdateCaptor.getValue().virtualHosts).hasSize(4);
verifyNoMoreInteractions(rdsResourceWatcher);
}
@ -879,12 +879,12 @@ public abstract class ClientXdsClientTestBase {
"0000");
verify(edsResourceWatcher).onChanged(edsUpdateCaptor.capture());
EdsUpdate edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.getDropPolicies())
assertThat(edsUpdate.clusterName).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.dropPolicies)
.containsExactly(
new DropOverload("lb", 200),
new DropOverload("throttle", 1000));
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region1", "zone1", "subzone1"),
new LocalityLbEndpoints(
@ -928,12 +928,12 @@ public abstract class ClientXdsClientTestBase {
xdsClient.watchEdsResource(EDS_RESOURCE, watcher);
verify(watcher).onChanged(edsUpdateCaptor.capture());
EdsUpdate edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.getDropPolicies())
assertThat(edsUpdate.clusterName).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.dropPolicies)
.containsExactly(
new DropOverload("lb", 200),
new DropOverload("throttle", 1000));
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region1", "zone1", "subzone1"),
new LocalityLbEndpoints(
@ -987,12 +987,12 @@ public abstract class ClientXdsClientTestBase {
"0000");
verify(edsResourceWatcher).onChanged(edsUpdateCaptor.capture());
EdsUpdate edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.getDropPolicies())
assertThat(edsUpdate.clusterName).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.dropPolicies)
.containsExactly(
new DropOverload("lb", 200),
new DropOverload("throttle", 1000));
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region1", "zone1", "subzone1"),
new LocalityLbEndpoints(
@ -1015,9 +1015,9 @@ public abstract class ClientXdsClientTestBase {
verify(edsResourceWatcher, times(2)).onChanged(edsUpdateCaptor.capture());
edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.getDropPolicies()).isEmpty();
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.clusterName).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.dropPolicies).isEmpty();
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region2", "zone2", "subzone2"),
new LocalityLbEndpoints(
@ -1071,9 +1071,9 @@ public abstract class ClientXdsClientTestBase {
mf.buildDropOverload("lb", 100)))));
call.sendResponse("0", clusterLoadAssignments, ResourceType.EDS, "0000");
verify(edsWatcher).onChanged(edsUpdateCaptor.capture());
assertThat(edsUpdateCaptor.getValue().getClusterName()).isEqualTo(resource);
assertThat(edsUpdateCaptor.getValue().clusterName).isEqualTo(resource);
verify(edsResourceWatcher).onChanged(edsUpdateCaptor.capture());
assertThat(edsUpdateCaptor.getValue().getClusterName()).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdateCaptor.getValue().clusterName).isEqualTo(EDS_RESOURCE);
clusters = ImmutableList.of(
Any.pack(mf.buildEdsCluster(resource, null, true, null, null)), // no change
@ -1124,12 +1124,12 @@ public abstract class ClientXdsClientTestBase {
call.sendResponse("0", clusterLoadAssignments, ResourceType.EDS, "0000");
verify(edsResourceWatcher).onChanged(edsUpdateCaptor.capture());
EdsUpdate edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.getDropPolicies())
assertThat(edsUpdate.clusterName).isEqualTo(EDS_RESOURCE);
assertThat(edsUpdate.dropPolicies)
.containsExactly(
new DropOverload("lb", 200),
new DropOverload("throttle", 1000));
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region1", "zone1", "subzone1"),
new LocalityLbEndpoints(
@ -1153,9 +1153,9 @@ public abstract class ClientXdsClientTestBase {
verify(watcher1).onChanged(edsUpdateCaptor.capture());
edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(edsResource);
assertThat(edsUpdate.getDropPolicies()).isEmpty();
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.clusterName).isEqualTo(edsResource);
assertThat(edsUpdate.dropPolicies).isEmpty();
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region2", "zone2", "subzone2"),
new LocalityLbEndpoints(
@ -1163,9 +1163,9 @@ public abstract class ClientXdsClientTestBase {
new LbEndpoint("172.44.2.2", 8000, 3, true)), 2, 0));
verify(watcher2).onChanged(edsUpdateCaptor.capture());
edsUpdate = edsUpdateCaptor.getValue();
assertThat(edsUpdate.getClusterName()).isEqualTo(edsResource);
assertThat(edsUpdate.getDropPolicies()).isEmpty();
assertThat(edsUpdate.getLocalityLbEndpointsMap())
assertThat(edsUpdate.clusterName).isEqualTo(edsResource);
assertThat(edsUpdate.dropPolicies).isEmpty();
assertThat(edsUpdate.localityLbEndpointsMap)
.containsExactly(
new Locality("region2", "zone2", "subzone2"),
new LocalityLbEndpoints(

View File

@ -788,14 +788,8 @@ public class ClusterResolverLoadBalancerTest {
void deliverClusterLoadAssignment(String resource, List<DropOverload> dropOverloads,
Map<Locality, LocalityLbEndpoints> localityLbEndpointsMap) {
if (watchers.containsKey(resource)) {
EdsUpdate.Builder builder = EdsUpdate.newBuilder().setClusterName(resource);
for (DropOverload dropOverload : dropOverloads) {
builder.addDropPolicy(dropOverload);
}
for (Locality locality : localityLbEndpointsMap.keySet()) {
builder.addLocalityLbEndpoints(locality, localityLbEndpointsMap.get(locality));
}
watchers.get(resource).onChanged(builder.build());
watchers.get(resource).onChanged(
new EdsUpdate(resource, localityLbEndpointsMap, dropOverloads));
}
}

View File

@ -713,14 +713,8 @@ public class EdsLoadBalancer2Test {
@Override
public void run() {
if (watchers.containsKey(resource)) {
EdsUpdate.Builder builder = EdsUpdate.newBuilder().setClusterName(resource);
for (DropOverload dropOverload : dropOverloads) {
builder.addDropPolicy(dropOverload);
}
for (Locality locality : localityLbEndpointsMap.keySet()) {
builder.addLocalityLbEndpoints(locality, localityLbEndpointsMap.get(locality));
}
watchers.get(resource).onChanged(builder.build());
watchers.get(resource).onChanged(
new EdsUpdate(resource, localityLbEndpointsMap, dropOverloads));
}
}
});

View File

@ -745,12 +745,7 @@ public class XdsNameResolverTest {
if (!resourceName.equals(ldsResource)) {
return;
}
LdsUpdate.Builder updateBuilder = LdsUpdate.newBuilder();
updateBuilder.setHttpMaxStreamDurationNano(httpMaxStreamDurationNano);
for (VirtualHost virtualHost : virtualHosts) {
updateBuilder.addVirtualHost(virtualHost);
}
ldsWatcher.onChanged(updateBuilder.build());
ldsWatcher.onChanged(new LdsUpdate(httpMaxStreamDurationNano, virtualHosts));
}
});
}
@ -764,7 +759,7 @@ public class XdsNameResolverTest {
}
VirtualHost virtualHost =
new VirtualHost("virtual-host", Collections.singletonList(AUTHORITY), routes);
ldsWatcher.onChanged(LdsUpdate.newBuilder().addVirtualHost(virtualHost).build());
ldsWatcher.onChanged(new LdsUpdate(0, Collections.singletonList(virtualHost)));
}
});
}
@ -776,7 +771,7 @@ public class XdsNameResolverTest {
if (!resourceName.equals(ldsResource)) {
return;
}
ldsWatcher.onChanged(LdsUpdate.newBuilder().setRdsName(rdsName).build());
ldsWatcher.onChanged(new LdsUpdate(0, rdsName));
}
});
}
@ -800,7 +795,7 @@ public class XdsNameResolverTest {
if (!resourceName.equals(rdsResource)) {
return;
}
rdsWatcher.onChanged(RdsUpdate.fromVirtualHosts(virtualHosts));
rdsWatcher.onChanged(new RdsUpdate(virtualHosts));
}
});
}