-
Notifications
You must be signed in to change notification settings - Fork 8.8k
feature: init Namingserver #6537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
50c77dc
add signature
ggbocoder b36f5b2
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder e15537d
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder 85398ec
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder e049125
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder 2939f59
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder 6c96366
init namingserver
ggbocoder d022017
fix ci
ggbocoder de90149
fix ci
ggbocoder 95c935f
remove auth infos
ggbocoder 726f7f8
Update namingserver/pom.xml
ggbocoder eac2ade
Update namingserver/pom.xml
ggbocoder 4941f57
Update namingserver/pom.xml
ggbocoder f553880
Update namingserver/pom.xml
ggbocoder 7aec384
fix
ggbocoder 33ab214
Merge remote-tracking branch 'origin/namingserver' into namingserver
ggbocoder 7caf526
change to jackson
ggbocoder e52747a
fix
ggbocoder 311bb12
replace with constants
ggbocoder 1ef041b
simplify controller
ggbocoder 1359144
reformat code
ggbocoder 572932c
opt
ggbocoder 7807b32
Update namingserver/pom.xml
ggbocoder 8760059
fix
ggbocoder 440a53b
Merge remote-tracking branch 'origin/namingserver' into namingserver
ggbocoder 50f8703
register
ggbocoder 3eb13dc
Merge remote-tracking branch 'upstream/2.x' into namingserver
ggbocoder 8c11f7c
Merge remote-tracking branch 'origin/namingserver' into namingserver
ggbocoder 9b809ef
update
ggbocoder 16b705c
update
ggbocoder efd93d7
Update changes/zh-cn/2.x.md
funky-eyes 577d66f
Update changes/en-us/2.x.md
funky-eyes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
common/src/main/java/org/apache/seata/common/metadata/Cluster.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.seata.common.metadata; | ||
|
||
import org.apache.seata.common.metadata.namingserver.Unit; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Cluster { | ||
private String clusterName; | ||
private String clusterType; | ||
private List<Unit> unitData = new ArrayList<>(); | ||
|
||
public Cluster() { | ||
} | ||
|
||
public String getClusterName() { | ||
return clusterName; | ||
} | ||
|
||
public void setClusterName(String clusterName) { | ||
this.clusterName = clusterName; | ||
} | ||
|
||
public String getClusterType() { | ||
return clusterType; | ||
} | ||
|
||
public void setClusterType(String clusterType) { | ||
this.clusterType = clusterType; | ||
} | ||
|
||
public List<Unit> getUnitData() { | ||
return unitData; | ||
} | ||
|
||
public void setUnitData(List<Unit> unitData) { | ||
this.unitData = unitData; | ||
} | ||
|
||
|
||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
common/src/main/java/org/apache/seata/common/metadata/namingserver/Instance.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.seata.common.metadata.namingserver; | ||
|
||
|
||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.seata.common.metadata.ClusterRole; | ||
import org.apache.seata.common.metadata.Node; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.apache.seata.common.util.CollectionUtils.mapToJsonString; | ||
|
||
|
||
public class Instance { | ||
private String namespace; | ||
private String clusterName; | ||
private String unit; | ||
private Node.Endpoint controlEndpoint = new Node.Endpoint(); | ||
private Node.Endpoint transactionEndpoint = new Node.Endpoint(); | ||
private double weight = 1.0; | ||
private boolean healthy = true; | ||
private long term; | ||
private ClusterRole role = ClusterRole.MEMBER; | ||
private Map<String, Object> metadata = new HashMap<>(); | ||
|
||
|
||
private Instance() { | ||
} | ||
|
||
public static Instance getInstance() { | ||
return SingletonHolder.SERVER_INSTANCE; | ||
} | ||
|
||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public void setNamespace(String namespace) { | ||
this.namespace = namespace; | ||
} | ||
|
||
public String getClusterName() { | ||
return clusterName; | ||
} | ||
|
||
public void setClusterName(String clusterName) { | ||
this.clusterName = clusterName; | ||
} | ||
|
||
public String getUnit() { | ||
return unit; | ||
} | ||
|
||
public void setUnit(String unit) { | ||
this.unit = unit; | ||
} | ||
|
||
public ClusterRole getRole() { | ||
return role; | ||
} | ||
|
||
public void setRole(ClusterRole role) { | ||
this.role = role; | ||
} | ||
|
||
public Node.Endpoint getControlEndpoint() { | ||
return controlEndpoint; | ||
} | ||
|
||
public void setControlEndpoint(Node.Endpoint controlEndpoint) { | ||
this.controlEndpoint = controlEndpoint; | ||
} | ||
|
||
public Node.Endpoint getTransactionEndpoint() { | ||
return transactionEndpoint; | ||
} | ||
|
||
public void setTransactionEndpoint(Node.Endpoint transactionEndpoint) { | ||
this.transactionEndpoint = transactionEndpoint; | ||
} | ||
|
||
public double getWeight() { | ||
return weight; | ||
} | ||
|
||
public void setWeight(double weight) { | ||
this.weight = weight; | ||
} | ||
|
||
public boolean isHealthy() { | ||
return healthy; | ||
} | ||
|
||
public void setHealthy(boolean healthy) { | ||
this.healthy = healthy; | ||
} | ||
|
||
public long getTerm() { | ||
return term; | ||
} | ||
|
||
|
||
public void setTerm(long term) { | ||
this.term = term; | ||
} | ||
|
||
public void addMetadata(String key, Object value) { | ||
this.metadata.put(key, value); | ||
} | ||
|
||
public void setMetadata(Map<String, Object> metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(controlEndpoint, transactionEndpoint); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Instance instance = (Instance) o; | ||
return Objects.equals(controlEndpoint, instance.controlEndpoint) && Objects.equals(transactionEndpoint, instance.transactionEndpoint); | ||
} | ||
|
||
|
||
// Recursively convert metadata to JSON | ||
public String toJsonString() { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
try { | ||
return objectMapper.writeValueAsString(this); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
|
||
public Map<String, String> toMap() { | ||
Map<String, String> resultMap = new HashMap<>(); | ||
|
||
|
||
resultMap.put("namespace", namespace); | ||
resultMap.put("clusterName", clusterName); | ||
resultMap.put("unit", unit); | ||
resultMap.put("controlEndpoint", controlEndpoint.toString()); | ||
resultMap.put("transactionEndpoint", transactionEndpoint.toString()); | ||
resultMap.put("weight", String.valueOf(weight)); | ||
resultMap.put("healthy", String.valueOf(healthy)); | ||
resultMap.put("term", String.valueOf(term)); | ||
resultMap.put("metadata", mapToJsonString(metadata)); | ||
|
||
return resultMap; | ||
} | ||
|
||
private static class SingletonHolder { | ||
private static final Instance SERVER_INSTANCE = new Instance(); | ||
} | ||
|
||
|
||
} | ||
|
50 changes: 50 additions & 0 deletions
50
common/src/main/java/org/apache/seata/common/metadata/namingserver/MetaResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.seata.common.metadata.namingserver; | ||
|
||
import org.apache.seata.common.metadata.Cluster; | ||
|
||
import java.util.List; | ||
|
||
public class MetaResponse { | ||
private List<Cluster> clusterList; | ||
private long term; | ||
|
||
public MetaResponse() { | ||
} | ||
|
||
public MetaResponse(List<Cluster> clusterList, long term) { | ||
this.clusterList = clusterList; | ||
this.term = term; | ||
} | ||
|
||
public List<Cluster> getClusterList() { | ||
return clusterList; | ||
} | ||
|
||
public void setClusterList(List<Cluster> clusterList) { | ||
this.clusterList = clusterList; | ||
} | ||
|
||
public long getTerm() { | ||
return term; | ||
} | ||
|
||
public void setTerm(long term) { | ||
this.term = term; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.