Skip to content

Commit 4d51332

Browse files
authored
feature: support Namingserver (#6537)
1 parent 3e89d3c commit 4d51332

File tree

56 files changed

+2193
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2193
-40
lines changed

changes/en-us/2.x.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Add changes here for all PR submitted to the 2.x branch.
44

55
### feature:
66
- [[#6226](https://github.com/apache/incubator-seata/pull/6226)] multi-version seata protocol support
7+
- [[#6537](https://github.com/apache/incubator-seata/pull/6537)] support Namingserver
78

89
### bugfix:
910
- [[#6592](https://github.com/apache/incubator-seata/pull/6592)] fix @Async annotation not working in ClusterWatcherManager
@@ -12,7 +13,6 @@ Add changes here for all PR submitted to the 2.x branch.
1213
- [[#6626](https://github.com/apache/incubator-seata/pull/6626)] fix hsf ConsumerModel convert error
1314
- [[#6642](https://github.com/apache/incubator-seata/pull/6642)] codecov token not found
1415

15-
1616
### optimize:
1717
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] split the task thread pool for committing and rollbacking statuses
1818
- [[#6208](https://github.com/apache/incubator-seata/pull/6208)] optimize : load SeataSerializer by version
@@ -43,5 +43,6 @@ Thanks to these contributors for their code commits. Please report an unintended
4343
- [funky-eyes](https://github.com/funky-eyes)
4444
- [tanyaofei](https://github.com/tanyaofei)
4545
- [wanghongzhou](https://github.com/wanghongzhou)
46+
- [ggbocoder](https://github.com/ggbocoder)
4647

47-
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
48+
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.

changes/zh-cn/2.x.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### feature:
66
- [[#6226](https://github.com/apache/incubator-seata/pull/6226)] 支持seata私有协议多版本兼容
7+
- [[#6537](https://github.com/apache/incubator-seata/pull/6537)] 支持 Namingserver
78

89
### bugfix:
910
- [[#6592](https://github.com/apache/incubator-seata/pull/6592)] fix @Async注解ClusterWatcherManager中不生效的问题
@@ -13,7 +14,6 @@
1314
- [[#6640](https://github.com/apache/incubator-seata/pull/6640)] 优化codecov相关配置
1415
- [[#6642](https://github.com/apache/incubator-seata/pull/6642)] 修复codecov token找不到导致无法提交单测覆盖度报告
1516

16-
1717
### optimize:
1818
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] 拆分 committing 和 rollbacking 状态的任务线程池
1919
- [[#6208](https://github.com/apache/incubator-seata/pull/6208)] 支持多版本的Seata序列化
@@ -43,6 +43,7 @@
4343
- [funky-eyes](https://github.com/funky-eyes)
4444
- [tanyaofei](https://github.com/tanyaofei)
4545
- [wanghongzhou](https://github.com/wanghongzhou)
46+
- [ggbocoder](https://github.com/ggbocoder)
4647

4748

48-
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
49+
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

common/src/main/java/org/apache/seata/common/Constants.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,29 @@ public interface Constants {
219219
* The constant JACKSON_JSON_TEXT_PREFIX
220220
*/
221221
String JACKSON_JSON_TEXT_PREFIX = "{\"@class\":";
222+
223+
/**
224+
* The constant HTTP_PREFIX
225+
*/
226+
String HTTP_PREFIX = "http://";
227+
228+
/**
229+
* The constant HTTP_ADD_GROUP_SUFFIX
230+
*/
231+
String HTTP_ADD_GROUP_SUFFIX = "/naming/v1/addVGroup?";
232+
233+
/**
234+
* The constant CONSTANT_UNIT
235+
*/
236+
String CONSTANT_UNIT = "unit";
237+
238+
/**
239+
* The constant CONSTANT_GROUP
240+
*/
241+
String CONSTANT_GROUP = "vGroup";
242+
243+
/**
244+
* The constant HTTP_REMOVE_GROUP_SUFFIX
245+
*/
246+
String HTTP_REMOVE_GROUP_SUFFIX = "/naming/v1/removeVGroup?";
222247
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.common.metadata;
18+
19+
import org.apache.seata.common.metadata.namingserver.Unit;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
public class Cluster {
25+
private String clusterName;
26+
private String clusterType;
27+
private List<Unit> unitData = new ArrayList<>();
28+
29+
public Cluster() {
30+
}
31+
32+
public String getClusterName() {
33+
return clusterName;
34+
}
35+
36+
public void setClusterName(String clusterName) {
37+
this.clusterName = clusterName;
38+
}
39+
40+
public String getClusterType() {
41+
return clusterType;
42+
}
43+
44+
public void setClusterType(String clusterType) {
45+
this.clusterType = clusterType;
46+
}
47+
48+
public List<Unit> getUnitData() {
49+
return unitData;
50+
}
51+
52+
public void setUnitData(List<Unit> unitData) {
53+
this.unitData = unitData;
54+
}
55+
56+
57+
}
58+
59+

common/src/main/java/org/apache/seata/common/metadata/Node.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ public Endpoint(String host, int port) {
109109
this.port = port;
110110
}
111111

112+
public Endpoint(String host, int port, String protocol) {
113+
this.host = host;
114+
this.port = port;
115+
this.protocol = protocol;
116+
}
117+
112118
public String getHost() {
113119
return host;
114120
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.common.metadata.namingserver;
18+
19+
20+
21+
import com.fasterxml.jackson.core.JsonProcessingException;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import org.apache.seata.common.metadata.ClusterRole;
24+
import org.apache.seata.common.metadata.Node;
25+
26+
import java.util.HashMap;
27+
import java.util.Map;
28+
import java.util.Objects;
29+
30+
import static org.apache.seata.common.util.CollectionUtils.mapToJsonString;
31+
32+
33+
public class Instance {
34+
private String namespace;
35+
private String clusterName;
36+
private String unit;
37+
private Node.Endpoint controlEndpoint = new Node.Endpoint();
38+
private Node.Endpoint transactionEndpoint = new Node.Endpoint();
39+
private double weight = 1.0;
40+
private boolean healthy = true;
41+
private long term;
42+
private ClusterRole role = ClusterRole.MEMBER;
43+
private Map<String, Object> metadata = new HashMap<>();
44+
45+
46+
private Instance() {
47+
}
48+
49+
public static Instance getInstance() {
50+
return SingletonHolder.SERVER_INSTANCE;
51+
}
52+
53+
54+
public String getNamespace() {
55+
return namespace;
56+
}
57+
58+
public void setNamespace(String namespace) {
59+
this.namespace = namespace;
60+
}
61+
62+
public String getClusterName() {
63+
return clusterName;
64+
}
65+
66+
public void setClusterName(String clusterName) {
67+
this.clusterName = clusterName;
68+
}
69+
70+
public String getUnit() {
71+
return unit;
72+
}
73+
74+
public void setUnit(String unit) {
75+
this.unit = unit;
76+
}
77+
78+
public ClusterRole getRole() {
79+
return role;
80+
}
81+
82+
public void setRole(ClusterRole role) {
83+
this.role = role;
84+
}
85+
86+
public Node.Endpoint getControlEndpoint() {
87+
return controlEndpoint;
88+
}
89+
90+
public void setControlEndpoint(Node.Endpoint controlEndpoint) {
91+
this.controlEndpoint = controlEndpoint;
92+
}
93+
94+
public Node.Endpoint getTransactionEndpoint() {
95+
return transactionEndpoint;
96+
}
97+
98+
public void setTransactionEndpoint(Node.Endpoint transactionEndpoint) {
99+
this.transactionEndpoint = transactionEndpoint;
100+
}
101+
102+
public double getWeight() {
103+
return weight;
104+
}
105+
106+
public void setWeight(double weight) {
107+
this.weight = weight;
108+
}
109+
110+
public boolean isHealthy() {
111+
return healthy;
112+
}
113+
114+
public void setHealthy(boolean healthy) {
115+
this.healthy = healthy;
116+
}
117+
118+
public long getTerm() {
119+
return term;
120+
}
121+
122+
123+
public void setTerm(long term) {
124+
this.term = term;
125+
}
126+
127+
public void addMetadata(String key, Object value) {
128+
this.metadata.put(key, value);
129+
}
130+
131+
public void setMetadata(Map<String, Object> metadata) {
132+
this.metadata = metadata;
133+
}
134+
135+
@Override
136+
public int hashCode() {
137+
return Objects.hash(controlEndpoint, transactionEndpoint);
138+
}
139+
140+
@Override
141+
public boolean equals(Object o) {
142+
if (this == o) {
143+
return true;
144+
}
145+
if (o == null || getClass() != o.getClass()) {
146+
return false;
147+
}
148+
Instance instance = (Instance) o;
149+
return Objects.equals(controlEndpoint, instance.controlEndpoint) && Objects.equals(transactionEndpoint, instance.transactionEndpoint);
150+
}
151+
152+
153+
// Recursively convert metadata to JSON
154+
public String toJsonString() {
155+
ObjectMapper objectMapper = new ObjectMapper();
156+
try {
157+
return objectMapper.writeValueAsString(this);
158+
} catch (JsonProcessingException e) {
159+
throw new RuntimeException(e);
160+
}
161+
}
162+
163+
164+
public Map<String, String> toMap() {
165+
Map<String, String> resultMap = new HashMap<>();
166+
167+
168+
resultMap.put("namespace", namespace);
169+
resultMap.put("clusterName", clusterName);
170+
resultMap.put("unit", unit);
171+
resultMap.put("controlEndpoint", controlEndpoint.toString());
172+
resultMap.put("transactionEndpoint", transactionEndpoint.toString());
173+
resultMap.put("weight", String.valueOf(weight));
174+
resultMap.put("healthy", String.valueOf(healthy));
175+
resultMap.put("term", String.valueOf(term));
176+
resultMap.put("metadata", mapToJsonString(metadata));
177+
178+
return resultMap;
179+
}
180+
181+
private static class SingletonHolder {
182+
private static final Instance SERVER_INSTANCE = new Instance();
183+
}
184+
185+
186+
}
187+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.common.metadata.namingserver;
18+
19+
import org.apache.seata.common.metadata.Cluster;
20+
21+
import java.util.List;
22+
23+
public class MetaResponse {
24+
private List<Cluster> clusterList;
25+
private long term;
26+
27+
public MetaResponse() {
28+
}
29+
30+
public MetaResponse(List<Cluster> clusterList, long term) {
31+
this.clusterList = clusterList;
32+
this.term = term;
33+
}
34+
35+
public List<Cluster> getClusterList() {
36+
return clusterList;
37+
}
38+
39+
public void setClusterList(List<Cluster> clusterList) {
40+
this.clusterList = clusterList;
41+
}
42+
43+
public long getTerm() {
44+
return term;
45+
}
46+
47+
public void setTerm(long term) {
48+
this.term = term;
49+
}
50+
}

0 commit comments

Comments
 (0)