Skip to content

Commit 2631fa8

Browse files
committed
revert parser impl
1 parent 37b1b1c commit 2631fa8

17 files changed

+436
-426
lines changed

xds/src/main/java/com/linecorp/armeria/xds/ClusterResourceFactory.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://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, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.armeria.xds;
18+
19+
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
20+
21+
final class ClusterResourceParser extends ResourceParser<Cluster, ClusterXdsResource> {
22+
23+
static final ClusterResourceParser INSTANCE = new ClusterResourceParser();
24+
25+
private ClusterResourceParser() {}
26+
27+
@Override
28+
ClusterXdsResource parse(Cluster cluster, XdsExtensionRegistry registry,
29+
String version, long revision) {
30+
return new ClusterXdsResource(cluster, version);
31+
}
32+
33+
@Override
34+
String name(Cluster cluster) {
35+
return cluster.getName();
36+
}
37+
38+
@Override
39+
Class<Cluster> clazz() {
40+
return Cluster.class;
41+
}
42+
43+
@Override
44+
boolean isFullStateOfTheWorld() {
45+
return true;
46+
}
47+
48+
@Override
49+
XdsType type() {
50+
return XdsType.CLUSTER;
51+
}
52+
}

xds/src/main/java/com/linecorp/armeria/xds/DeltaActualStream.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ public void onNext(DeltaDiscoveryResponse value) {
218218
}
219219
lifecycleObserver.responseReceived(value);
220220

221-
final XdsResourceFactory factory =
222-
extensionRegistry.queryByTypeUrl(value.getTypeUrl(), XdsResourceFactory.class);
223-
if (factory == null) {
221+
final ResourceParser<?, ?> parser = XdsResourceParserUtil.fromTypeUrl(value.getTypeUrl());
222+
if (parser == null) {
224223
logger.warn("Delta XDS stream received unexpected type: {}", value.getTypeUrl());
225224
return;
226225
}
227-
handleResponse(factory, value);
226+
handleResponse(parser, value);
228227
}
229228

230229
@Override
@@ -249,11 +248,11 @@ public void onCompleted() {
249248
owner.retryOrClose(false);
250249
}
251250

252-
private void handleResponse(XdsResourceFactory factory, DeltaDiscoveryResponse response) {
253-
final XdsType type = factory.type();
251+
private void handleResponse(ResourceParser<?, ?> parser, DeltaDiscoveryResponse response) {
252+
final XdsType type = parser.type();
254253
final List<Resource> deltaResources = response.getResourcesList();
255254
final ParsedResourcesHolder holder =
256-
XdsResourceParseUtil.parseDeltaResources(factory, extensionRegistry, deltaResources);
255+
parser.parseDeltaResources(deltaResources, extensionRegistry);
257256

258257
if (!holder.errors().isEmpty()) {
259258
holder.invalidResources().forEach((name, error) ->

xds/src/main/java/com/linecorp/armeria/xds/EndpointResourceFactory.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://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, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.armeria.xds;
18+
19+
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment;
20+
21+
final class EndpointResourceParser extends ResourceParser<ClusterLoadAssignment, EndpointXdsResource> {
22+
23+
static final EndpointResourceParser INSTANCE = new EndpointResourceParser();
24+
25+
private EndpointResourceParser() {}
26+
27+
@Override
28+
EndpointXdsResource parse(ClusterLoadAssignment message, XdsExtensionRegistry registry,
29+
String version, long revision) {
30+
return new EndpointXdsResource(message, version);
31+
}
32+
33+
@Override
34+
String name(ClusterLoadAssignment message) {
35+
return message.getClusterName();
36+
}
37+
38+
@Override
39+
Class<ClusterLoadAssignment> clazz() {
40+
return ClusterLoadAssignment.class;
41+
}
42+
43+
@Override
44+
boolean isFullStateOfTheWorld() {
45+
return false;
46+
}
47+
48+
@Override
49+
XdsType type() {
50+
return XdsType.ENDPOINT;
51+
}
52+
}

xds/src/main/java/com/linecorp/armeria/xds/ListenerResourceFactory.java

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2023 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://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, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.armeria.xds;
18+
19+
import java.util.List;
20+
21+
import com.linecorp.armeria.xds.filter.XdsHttpFilter;
22+
23+
import io.envoyproxy.envoy.config.listener.v3.Listener;
24+
import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager;
25+
26+
final class ListenerResourceParser extends ResourceParser<Listener, ListenerXdsResource> {
27+
28+
static final ListenerResourceParser INSTANCE = new ListenerResourceParser();
29+
30+
private ListenerResourceParser() {}
31+
32+
@Override
33+
ListenerXdsResource parse(Listener message, XdsExtensionRegistry registry,
34+
String version, long revision) {
35+
final HttpConnectionManager connectionManager =
36+
XdsUnpackUtil.unpackConnectionManager(message, registry);
37+
final List<XdsHttpFilter> downstreamFilters =
38+
XdsUnpackUtil.resolveDownstreamFilters(connectionManager, registry);
39+
return new ListenerXdsResource(message, connectionManager, downstreamFilters,
40+
version, revision);
41+
}
42+
43+
@Override
44+
String name(Listener message) {
45+
return message.getName();
46+
}
47+
48+
@Override
49+
Class<Listener> clazz() {
50+
return Listener.class;
51+
}
52+
53+
@Override
54+
boolean isFullStateOfTheWorld() {
55+
return true;
56+
}
57+
58+
@Override
59+
XdsType type() {
60+
return XdsType.LISTENER;
61+
}
62+
}

0 commit comments

Comments
 (0)