Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fd069e3
Framework definition to support A74
larry-safran Dec 4, 2024
b2cb05b
Test that update works (with associated fixes)
larry-safran Jan 6, 2025
8e668b5
Cleanup
larry-safran Jan 6, 2025
5b14a3e
Cleanup
larry-safran Jan 6, 2025
5f8d479
Add verification of data changing
larry-safran Jan 7, 2025
ec50490
Support aggregate clusters correctly
larry-safran Jan 7, 2025
5dceeaf
Fix class name referenced in javadoc
larry-safran Jan 7, 2025
fd64f20
Address a number of code review comments and add a test for missing C…
larry-safran Jan 8, 2025
b2e924e
Remove syncContext from watchers. Add checkNotNull, private and fina…
larry-safran Jan 8, 2025
5a75b10
Add a test for corrupt LDS
larry-safran Jan 8, 2025
d3b713f
Change aggregate cluster handling to correctly handle cluster names a…
larry-safran Jan 9, 2025
6089730
Errorprone
larry-safran Jan 9, 2025
d5dea83
Add max recursion limit for clusters to match c++.
larry-safran Jan 14, 2025
28d29fb
Fix handling of route and cluster updates.
larry-safran Jan 15, 2025
4a53fce
Make data private and XdsWatcherBase static
larry-safran Jan 15, 2025
c97118f
In LDS onChanged(), get old activeVirtualHost before possibly doing c…
larry-safran Jan 16, 2025
06466fc
Change comment for clarity
larry-safran Jan 16, 2025
b898e34
Allow EdsWatcher to have multiple CdsWatcher parents
larry-safran Jan 16, 2025
954ced3
Allow EdsWatcher to have multiple CdsWatcher parents
larry-safran Jan 16, 2025
ef13712
Fully support inlined RouteConfig
larry-safran Jan 17, 2025
518cef1
Add lots of `checkNotNull()`
larry-safran Jan 17, 2025
68071e6
Add test case testMultipleParentsInCdsTree, make a couple of cluster …
larry-safran Jan 18, 2025
f99fc56
Add test case testMultipleParentsInCdsTree, make a couple of cluster …
larry-safran Jan 18, 2025
482cd9d
Add virtual host to XdsConfig as per spec
larry-safran Jan 21, 2025
36602b6
Eliminate clusterSubscriptions and use objects directly instead of st…
larry-safran Feb 1, 2025
7042ed9
Add tests. Fix some places that were still using string instead of o…
larry-safran Feb 5, 2025
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
2 changes: 2 additions & 0 deletions xds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
thirdpartyImplementation project(':grpc-protobuf'),
project(':grpc-stub')
compileOnly sourceSets.thirdparty.output
testCompileOnly sourceSets.thirdparty.output
implementation project(':grpc-stub'),
project(':grpc-core'),
project(':grpc-util'),
Expand All @@ -59,6 +60,7 @@ dependencies {
libraries.protobuf.java.util
def nettyDependency = implementation project(':grpc-netty')

testImplementation project(':grpc-api')
testImplementation project(':grpc-rls')
testImplementation project(':grpc-inprocess')
testImplementation testFixtures(project(':grpc-core')),
Expand Down
192 changes: 192 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Copyright 2024 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.grpc.xds;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ImmutableMap;
import io.grpc.StatusOr;
import io.grpc.xds.XdsClusterResource.CdsUpdate;
import io.grpc.xds.XdsEndpointResource.EdsUpdate;
import io.grpc.xds.XdsListenerResource.LdsUpdate;
import io.grpc.xds.XdsRouteConfigureResource.RdsUpdate;
import java.io.Closeable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Represents the xDS configuration tree for a specified Listener.
*/
final class XdsConfig {
private final LdsUpdate listener;
private final RdsUpdate route;
private final VirtualHost virtualHost;
private final ImmutableMap<String, StatusOr<XdsClusterConfig>> clusters;
private final int hashCode;

XdsConfig(LdsUpdate listener, RdsUpdate route, Map<String, StatusOr<XdsClusterConfig>> clusters,
VirtualHost virtualHost) {
this(listener, route, virtualHost, ImmutableMap.copyOf(clusters));
}

public XdsConfig(LdsUpdate listener, RdsUpdate route, VirtualHost virtualHost,
ImmutableMap<String, StatusOr<XdsClusterConfig>> clusters) {
this.listener = listener;
this.route = route;
this.virtualHost = virtualHost;
this.clusters = clusters;

hashCode = Objects.hash(listener, route, virtualHost, clusters);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof XdsConfig)) {
return false;
}

XdsConfig o = (XdsConfig) obj;

return hashCode() == o.hashCode() && Objects.equals(listener, o.listener)
&& Objects.equals(route, o.route) && Objects.equals(virtualHost, o.virtualHost)
&& Objects.equals(clusters, o.clusters);
}

@Override
public int hashCode() {
return hashCode;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("XdsConfig{")
.append("\n listener=").append(listener)
.append(",\n route=").append(route)
.append(",\n virtualHost=").append(virtualHost)
.append(",\n clusters=").append(clusters)
.append("\n}");
return builder.toString();
}

public LdsUpdate getListener() {
return listener;

Check warning on line 88 in xds/src/main/java/io/grpc/xds/XdsConfig.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsConfig.java#L88

Added line #L88 was not covered by tests
}

public RdsUpdate getRoute() {
return route;

Check warning on line 92 in xds/src/main/java/io/grpc/xds/XdsConfig.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsConfig.java#L92

Added line #L92 was not covered by tests
}

public VirtualHost getVirtualHost() {
return virtualHost;
}

public ImmutableMap<String, StatusOr<XdsClusterConfig>> getClusters() {
return clusters;
}

static final class XdsClusterConfig {
private final String clusterName;
private final CdsUpdate clusterResource;
private final StatusOr<EdsUpdate> endpoint; //Will be null for non-EDS clusters

XdsClusterConfig(String clusterName, CdsUpdate clusterResource,
StatusOr<EdsUpdate> endpoint) {
this.clusterName = checkNotNull(clusterName, "clusterName");
this.clusterResource = checkNotNull(clusterResource, "clusterResource");
this.endpoint = endpoint;
}

@Override
public int hashCode() {
int endpointHash = (endpoint != null) ? endpoint.hashCode() : 0;
return clusterName.hashCode() + clusterResource.hashCode() + endpointHash;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof XdsClusterConfig)) {
return false;

Check warning on line 124 in xds/src/main/java/io/grpc/xds/XdsConfig.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsConfig.java#L124

Added line #L124 was not covered by tests
}
XdsClusterConfig o = (XdsClusterConfig) obj;
return Objects.equals(clusterName, o.clusterName)
&& Objects.equals(clusterResource, o.clusterResource)
&& Objects.equals(endpoint, o.endpoint);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("XdsClusterConfig{clusterName=").append(clusterName)
.append(", clusterResource=").append(clusterResource)
.append(", endpoint=").append(endpoint).append("}");
return builder.toString();
}

public String getClusterName() {
return clusterName;

Check warning on line 142 in xds/src/main/java/io/grpc/xds/XdsConfig.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsConfig.java#L142

Added line #L142 was not covered by tests
}

public CdsUpdate getClusterResource() {
return clusterResource;
}

public StatusOr<EdsUpdate> getEndpoint() {
return endpoint;
}
}

static final class XdsConfigBuilder {
private LdsUpdate listener;
private RdsUpdate route;
private Map<String, StatusOr<XdsClusterConfig>> clusters = new HashMap<>();
private VirtualHost virtualHost;

XdsConfigBuilder setListener(LdsUpdate listener) {
this.listener = checkNotNull(listener, "listener");
return this;
}

XdsConfigBuilder setRoute(RdsUpdate route) {
this.route = checkNotNull(route, "route");
return this;
}

XdsConfigBuilder addCluster(String name, StatusOr<XdsClusterConfig> clusterConfig) {
checkNotNull(name, "name");
checkNotNull(clusterConfig, "clusterConfig");
clusters.put(name, clusterConfig);
return this;
}

XdsConfigBuilder setVirtualHost(VirtualHost virtualHost) {
this.virtualHost = checkNotNull(virtualHost, "virtualHost");
return this;
}

XdsConfig build() {
checkNotNull(listener, "listener");
checkNotNull(route, "route");
return new XdsConfig(listener, route, clusters, virtualHost);
}
}

public interface XdsClusterSubscriptionRegistry {
Closeable subscribeToCluster(String clusterName);
}
}
Loading