Skip to content

Commit 9fcbe4c

Browse files
committed
Framework definition to support A74
1 parent 4222f77 commit 9fcbe4c

File tree

9 files changed

+1343
-22
lines changed

9 files changed

+1343
-22
lines changed

xds/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies {
4646
thirdpartyImplementation project(':grpc-protobuf'),
4747
project(':grpc-stub')
4848
compileOnly sourceSets.thirdparty.output
49+
testCompileOnly sourceSets.thirdparty.output
4950
implementation project(':grpc-stub'),
5051
project(':grpc-core'),
5152
project(':grpc-util'),
@@ -59,6 +60,7 @@ dependencies {
5960
libraries.protobuf.java.util
6061
def nettyDependency = implementation project(':grpc-netty')
6162

63+
testImplementation project(':grpc-api')
6264
testImplementation project(':grpc-rls')
6365
testImplementation project(':grpc-inprocess')
6466
testImplementation testFixtures(project(':grpc-core')),
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright 2024 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.xds;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import io.grpc.StatusOr;
22+
import io.grpc.xds.XdsClusterResource.CdsUpdate;
23+
import io.grpc.xds.XdsEndpointResource.EdsUpdate;
24+
import io.grpc.xds.XdsListenerResource.LdsUpdate;
25+
import io.grpc.xds.XdsRouteConfigureResource.RdsUpdate;
26+
import java.io.Closeable;
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
import java.util.Objects;
30+
31+
/**
32+
* Represents the xDS configuration tree for a specified Listener.
33+
*/
34+
public class XdsConfig {
35+
final LdsUpdate listener;
36+
final RdsUpdate route;
37+
final Map<String, StatusOr<XdsClusterConfig>> clusters;
38+
private final int hashCode;
39+
40+
XdsConfig(LdsUpdate listener, RdsUpdate route, Map<String, StatusOr<XdsClusterConfig>> clusters) {
41+
this.listener = listener;
42+
this.route = route;
43+
this.clusters = clusters;
44+
45+
hashCode = Objects.hash(listener, route, clusters);
46+
}
47+
48+
@Override
49+
public boolean equals(Object obj) {
50+
if (!(obj instanceof XdsConfig)) {
51+
return false;
52+
}
53+
54+
XdsConfig o = (XdsConfig) obj;
55+
56+
return Objects.equals(listener, o.listener) && Objects.equals(route, o.route)
57+
&& Objects.equals(clusters, o.clusters);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return hashCode;
63+
}
64+
65+
@Override
66+
public String toString() {
67+
StringBuilder builder = new StringBuilder();
68+
builder.append("XdsConfig{listener=").append(listener)
69+
.append(", route=").append(route)
70+
.append(", clusters={").append(clusters).append("}}");
71+
return builder.toString();
72+
}
73+
74+
public static class XdsClusterConfig {
75+
final String clusterName;
76+
final CdsUpdate clusterResource;
77+
final StatusOr<EdsUpdate> endpoint;
78+
79+
XdsClusterConfig(String clusterName, CdsUpdate clusterResource,
80+
StatusOr<EdsUpdate> endpoint) {
81+
this.clusterName = clusterName;
82+
this.clusterResource = clusterResource;
83+
this.endpoint = endpoint;
84+
}
85+
86+
@Override
87+
public int hashCode() {
88+
return clusterName.hashCode() + clusterResource.hashCode() + endpoint.hashCode();
89+
}
90+
91+
@Override
92+
public boolean equals(Object obj) {
93+
if (!(obj instanceof XdsClusterConfig)) {
94+
return false;
95+
}
96+
XdsClusterConfig o = (XdsClusterConfig) obj;
97+
return Objects.equals(clusterName, o.clusterName)
98+
&& Objects.equals(clusterResource, o.clusterResource)
99+
&& Objects.equals(endpoint, o.endpoint);
100+
}
101+
102+
@Override
103+
public String toString() {
104+
StringBuilder builder = new StringBuilder();
105+
builder.append("XdsClusterConfig{clusterName=").append(clusterName)
106+
.append(", clusterResource=").append(clusterResource)
107+
.append(", endpoint=").append(endpoint).append("}");
108+
return builder.toString();
109+
}
110+
}
111+
112+
static class XdsConfigBuilder {
113+
private LdsUpdate listener;
114+
private RdsUpdate route;
115+
private Map<String, StatusOr<XdsClusterConfig>> clusters = new HashMap<>();
116+
117+
XdsConfigBuilder setListener(LdsUpdate listener) {
118+
this.listener = listener;
119+
return this;
120+
}
121+
122+
XdsConfigBuilder setRoute(RdsUpdate route) {
123+
this.route = route;
124+
return this;
125+
}
126+
127+
XdsConfigBuilder addCluster(String name, StatusOr<XdsClusterConfig> clusterConfig) {
128+
clusters.put(name, clusterConfig);
129+
return this;
130+
}
131+
132+
XdsConfig build() {
133+
checkNotNull(listener, "listener");
134+
checkNotNull(route, "route");
135+
return new XdsConfig(listener, route, clusters);
136+
}
137+
}
138+
139+
public interface XdsClusterSubscriptionRegistry {
140+
Closeable subscribeToCluster(String clusterName);
141+
}
142+
}

0 commit comments

Comments
 (0)