Skip to content

Commit c4aacb3

Browse files
committed
ai comments
1 parent 7eba999 commit c4aacb3

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

client/java-armeria-xds/src/main/java/com/linecorp/centraldogma/client/armeria/xds/configsource/CentralDogmaSotwConfigSourceSubscriptionFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.linecorp.centraldogma.client.armeria.xds.configsource;
1717

18+
import static com.google.common.base.Preconditions.checkArgument;
19+
1820
import java.util.List;
1921
import java.util.Map;
2022

@@ -72,6 +74,8 @@ public SnapshotStream<DiscoveryResponse> create(
7274
final CentralDogmaConfigSource cdConfig =
7375
factoryContext.validator().unpack(
7476
configSource.getCustomConfigSource(), CentralDogmaConfigSource.class);
77+
checkArgument(!cdConfig.getClusterName().isEmpty(),
78+
"CentralDogmaConfigSource.cluster_name must not be empty");
7579
final SnapshotStream<ClusterSnapshot> clusterStream =
7680
factoryContext.clusterStream(cdConfig.getClusterName());
7781
final EventExecutor eventLoop = factoryContext.eventLoop();

client/java-armeria-xds/src/main/java/com/linecorp/centraldogma/client/armeria/xds/configsource/ResourcePath.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.fasterxml.jackson.databind.JsonNode;
2323

24+
import com.linecorp.armeria.common.QueryParams;
2425
import com.linecorp.centraldogma.common.Query;
2526

2627
/**
@@ -43,8 +44,6 @@
4344
*/
4445
final class ResourcePath {
4546

46-
private static final String PROFILE_PARAM = "profile=";
47-
4847
private final String project;
4948
private final String repo;
5049
private final String path;
@@ -53,18 +52,17 @@ final class ResourcePath {
5352
private final boolean ftl;
5453

5554
static ResourcePath parse(String resourceName) {
56-
// Split off ?profile= if present.
55+
// Split off query string if present.
5756
String name = resourceName;
5857
String profile = null;
5958
final int questionMark = resourceName.indexOf('?');
6059
if (questionMark >= 0) {
6160
final String queryString = resourceName.substring(questionMark + 1);
6261
name = resourceName.substring(0, questionMark);
63-
if (queryString.startsWith(PROFILE_PARAM)) {
64-
profile = queryString.substring(PROFILE_PARAM.length());
65-
checkArgument(!profile.isEmpty(),
66-
"Invalid resource name (empty profile): %s", resourceName);
67-
}
62+
final QueryParams params = QueryParams.fromQueryString(queryString);
63+
profile = params.get("profile");
64+
checkArgument(profile == null || !profile.isEmpty(),
65+
"Invalid resource name (empty profile): %s", resourceName);
6866
}
6967

7068
final int firstSlash = name.indexOf('/');

it/xds-client/src/test/java/com/linecorp/centraldogma/xds/it/CentralDogmaConfigSourceTemplateTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class CentralDogmaConfigSourceTemplateTest {
6464
}
6565
""".formatted(RESOURCE_NAME);
6666

67-
// A listener template using <#list> for routes and ${toJson()} for match rules.
67+
// A listener template — each route object is serialized transparently via ${toJson(r)},
68+
// so any field on config.route.v3.Route is supported without template changes.
6869
private static final String LISTENER_JSON_TEMPLATE = """
6970
{
7071
"name": "%1$s",
@@ -80,10 +81,7 @@ class CentralDogmaConfigSourceTemplateTest {
8081
"domains": ["*"],
8182
"routes": [
8283
<#list vars.routes as r>
83-
{
84-
"match": ${toJson(r.match)},
85-
"route": { "cluster": "${r.cluster}" }
86-
}<#if r?has_next>,</#if>
84+
${toJson(r)}<#if r?has_next>,</#if>
8785
</#list>
8886
]
8987
}]
@@ -129,9 +127,7 @@ class CentralDogmaConfigSourceTemplateTest {
129127
- "*"
130128
routes:
131129
<#list vars.routes as r>
132-
- match: ${toJson(r.match)}
133-
route:
134-
cluster: ${r.cluster}
130+
- ${toJson(r)}
135131
</#list>
136132
httpFilters:
137133
- name: envoy.filters.http.router
@@ -186,17 +182,20 @@ private static String routesYaml(String clusterExt, int routeCount) {
186182
- name: x-api-version
187183
stringMatch:
188184
exact: v2
189-
cluster: %1$s
185+
route:
186+
cluster: %1$s
190187
- match:
191188
prefix: /
192-
cluster: %1$s
189+
route:
190+
cluster: %1$s
193191
""".formatted(cluster);
194192
}
195193
return """
196194
routes:
197195
- match:
198196
prefix: /
199-
cluster: %s
197+
route:
198+
cluster: %s
200199
""".formatted(cluster);
201200
}
202201

0 commit comments

Comments
 (0)