|
|
@@ -27,10 +27,12 @@ public class PortService {
|
|
|
|
|
|
private final ServiceConfigRepository repository;
|
|
|
|
|
|
- /** 端口类变量名模式(不区分大小写) */
|
|
|
+ /** 端口类变量名模式(不区分大小写)。复数形式的值应为逗号分隔的端口列表 */
|
|
|
private static final Set<String> PORT_VARIABLE_NAMES = Set.of(
|
|
|
"SERVER_PORT", "PORT", "SERVERPORT", "SERVICE_PORT", "HTTP_PORT", "HTTPS_PORT",
|
|
|
- "APP_PORT", "API_PORT", "WEB_PORT", "TOMCAT_PORT", "JETTY_PORT"
|
|
|
+ "APP_PORT", "API_PORT", "WEB_PORT", "TOMCAT_PORT", "JETTY_PORT",
|
|
|
+ "SERVER_PORTS", "PORTS", "SERVERPORTS", "SERVICE_PORTS", "HTTP_PORTS", "HTTPS_PORTS",
|
|
|
+ "APP_PORTS", "API_PORTS", "WEB_PORTS", "TOMCAT_PORTS", "JETTY_PORTS"
|
|
|
);
|
|
|
|
|
|
/** 数字端口号正则 */
|
|
|
@@ -97,13 +99,18 @@ public class PortService {
|
|
|
// 去重
|
|
|
ports = ports.stream().distinct().collect(Collectors.toList());
|
|
|
|
|
|
- // 建立端口 → 变量名的映射
|
|
|
+ // 建立端口 → 变量名的映射(值可能为逗号分隔的多端口)
|
|
|
Map<Integer, List<String>> portToVars = new LinkedHashMap<>();
|
|
|
if (config.getVariables() != null) {
|
|
|
for (CustomVariable v : config.getVariables()) {
|
|
|
- if (isPortVariable(v.getName()) && isValidPort(v.getValue())) {
|
|
|
- int port = Integer.parseInt(v.getValue());
|
|
|
- portToVars.computeIfAbsent(port, k -> new ArrayList<>()).add(v.getName());
|
|
|
+ if (isPortVariable(v.getName()) && v.getValue() != null) {
|
|
|
+ for (String token : v.getValue().split(",")) {
|
|
|
+ String trimmed = token.trim();
|
|
|
+ if (isValidPort(trimmed)) {
|
|
|
+ int port = Integer.parseInt(trimmed);
|
|
|
+ portToVars.computeIfAbsent(port, k -> new ArrayList<>()).add(v.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -173,13 +180,16 @@ public class PortService {
|
|
|
return false;
|
|
|
}
|
|
|
return config.getVariables().stream()
|
|
|
- .anyMatch(v -> isPortVariable(v.getName()) && isValidPort(v.getValue()));
|
|
|
+ .anyMatch(v -> isPortVariable(v.getName()) && v.getValue() != null
|
|
|
+ && Arrays.stream(v.getValue().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .anyMatch(this::isValidPort));
|
|
|
}
|
|
|
|
|
|
// ========== 私有方法 ==========
|
|
|
|
|
|
/**
|
|
|
- * 从服务配置中提取所有端口号
|
|
|
+ * 从服务配置中提取所有端口号(支持单端口变量和逗号分隔的多端口变量)
|
|
|
*/
|
|
|
private List<Integer> extractPorts(ServiceConfig config) {
|
|
|
List<Integer> ports = new ArrayList<>();
|
|
|
@@ -187,8 +197,13 @@ public class PortService {
|
|
|
return ports;
|
|
|
}
|
|
|
for (CustomVariable v : config.getVariables()) {
|
|
|
- if (isPortVariable(v.getName()) && isValidPort(v.getValue())) {
|
|
|
- ports.add(Integer.parseInt(v.getValue()));
|
|
|
+ if (isPortVariable(v.getName()) && v.getValue() != null) {
|
|
|
+ for (String token : v.getValue().split(",")) {
|
|
|
+ String trimmed = token.trim();
|
|
|
+ if (isValidPort(trimmed)) {
|
|
|
+ ports.add(Integer.parseInt(trimmed));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return ports;
|