Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/console-trx' into featur…
Browse files Browse the repository at this point in the history
…e/console-trx
  • Loading branch information
xjlgod committed Dec 30, 2024
2 parents 2b905ef + 8c88802 commit e651120
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 20 deletions.
4 changes: 3 additions & 1 deletion changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Add changes here for all PR submitted to the 2.x branch.

### feature:

- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] support XXX
- [[#7069](https://github.com/apache/incubator-seata/pull/7069)] Raft cluster mode supports address translation


### bugfix:

Expand Down Expand Up @@ -35,5 +36,6 @@ Thanks to these contributors for their code commits. Please report an unintended
- [slievrly](https://github.com/slievrly)
- [lyl2008dsg](https://github.com/lyl2008dsg)
- [remind](https://github.com/remind)
- [PeppaO](https://github.com/PeppaO)

Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
3 changes: 2 additions & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### feature:

- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] 支持XXX
- [[#7069](https://github.com/apache/incubator-seata/pull/7069)] Raft集群模式支持地址转换

### bugfix:

Expand Down Expand Up @@ -35,5 +35,6 @@
- [slievrly](https://github.com/slievrly)
- [lyl2008dsg](https://github.com/lyl2008dsg)
- [remind](https://github.com/remind)
- [PeppaO](https://github.com/PeppaO)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
Original file line number Diff line number Diff line change
Expand Up @@ -1110,4 +1110,15 @@ public interface ConfigurationKeys {
* The constant META_PREFIX
*/
String META_PREFIX = SEATA_FILE_ROOT_CONFIG + FILE_CONFIG_SPLIT_CHAR + FILE_ROOT_REGISTRY + FILE_CONFIG_SPLIT_CHAR + "metadata.";

/**
* The constant SERVER_REGISTRY_METADATA_PREFIX
*/
String SERVER_REGISTRY_METADATA_PREFIX = SERVER_PREFIX + FILE_ROOT_REGISTRY + ".metadata";

/**
* The constant SERVER_REGISTRY_METADATA_EXTERNAL
*/
String SERVER_REGISTRY_METADATA_EXTERNAL = SERVER_REGISTRY_METADATA_PREFIX + ".external";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.exception;

public class ParseEndpointException extends RuntimeException {
public ParseEndpointException() {
}

public ParseEndpointException(String message) {
super(message);
}

public ParseEndpointException(String message, Throwable cause) {
super(message, cause);
}

public ParseEndpointException(Throwable cause) {
super(cause);
}

public ParseEndpointException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
86 changes: 84 additions & 2 deletions common/src/main/java/org/apache/seata/common/metadata/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.seata.common.exception.ParseEndpointException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import java.util.List;
import java.util.ArrayList;

public class Node {

Expand Down Expand Up @@ -195,4 +196,85 @@ public String toString() {
}
}

private Node.ExternalEndpoint createExternalEndpoint(String host, int controllerPort, int transactionPort) {
return new Node.ExternalEndpoint(host, controllerPort, transactionPort);
}

public List<ExternalEndpoint> createExternalEndpoints(String external) {
List<Node.ExternalEndpoint> externalEndpoints = new ArrayList<>();
String[] split = external.split(",");

for (String s : split) {
String[] item = s.split(":");
if (item.length == 3) {
try {
String host = item[0];
int controllerPort = Integer.parseInt(item[1]);
int transactionPort = Integer.parseInt(item[2]);
externalEndpoints.add(createExternalEndpoint(host, controllerPort, transactionPort));
} catch (NumberFormatException e) {
throw new ParseEndpointException("Invalid port number in: " + s);
}
} else {
throw new ParseEndpointException("Invalid format for endpoint: " + s);
}
}
return externalEndpoints;
}

public Map<String, Object> updateMetadataWithExternalEndpoints(Map<String, Object> metadata, List<Node.ExternalEndpoint> externalEndpoints) {
Object obj = metadata.get("external");
if (obj == null) {
if (!externalEndpoints.isEmpty()) {
Map<String, Object> metadataMap = new HashMap<>(metadata);
metadataMap.put("external", externalEndpoints);
return metadataMap;
}
return metadata;
}
if (obj instanceof List) {
List<Node.ExternalEndpoint> oldList = (List<Node.ExternalEndpoint>) obj;
oldList.addAll(externalEndpoints);
return metadata;
} else {
throw new ParseEndpointException("Metadata 'external' is not a List.");
}
}

public static class ExternalEndpoint {

private String host;
private int controlPort;
private int transactionPort;

public ExternalEndpoint(String host, int controlPort, int transactionPort) {
this.host = host;
this.controlPort = controlPort;
this.transactionPort = transactionPort;
}

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public int getControlPort() {
return controlPort;
}

public void setControlPort(int controlPort) {
this.controlPort = controlPort;
}

public int getTransactionPort() {
return transactionPort;
}

public void setTransactionPort(int transactionPort) {
this.transactionPort = transactionPort;
}
}
}
16 changes: 16 additions & 0 deletions common/src/main/java/org/apache/seata/common/util/NetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,25 @@ public static String toIpAddress(SocketAddress address) {
* @return the string
*/
public static String toStringAddress(InetSocketAddress address) {
if (address.getAddress() == null) {
return address.getHostString() + ":" + address.getPort();
}
return address.getAddress().getHostAddress() + ":" + address.getPort();
}

/**
* To string host string.
*
* @param address the address
* @return the string
*/
public static String toStringHost(InetSocketAddress address) {
if (address.getAddress() == null) {
return address.getHostString();
}
return address.getAddress().getHostAddress();
}

/**
* To inet socket address inet socket address.
*
Expand Down
Loading

0 comments on commit e651120

Please sign in to comment.