Skip to content

Commit

Permalink
vipshop#662 check connect string when create or update zkCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
cmzdandan committed Mar 2, 2020
1 parent 743fb33 commit cdf9ec2
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,29 @@ public void restart() {
}
}

private void checkConnectString(String connectString) throws SaturnJobConsoleException {
String[] connectStrs = connectString.split(",");
for (String connectStr: connectStrs) {
if(!connectStr.contains(":")) {
throw new SaturnJobConsoleException("连接字符串格式不正确,IP端口应该用英文冒号隔开");
}
String[] ipPort = connectStr.split(":");
if(ipPort.length != 2) {
throw new SaturnJobConsoleException("连接字符串格式不正确,请按示例输入正确的连接字符串");
}
boolean isLegalIP = ipPort[0].matches(
"((25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))");
if(!isLegalIP) {
throw new SaturnJobConsoleException("连接字符串中有非法IP");
}
boolean isLegalPort = ipPort[1].matches(
"^[1-9]$|(^[1-9][0-9]$)|(^[1-9][0-9][0-9]$)|(^[1-9][0-9][0-9][0-9]$)|(^[1-6][0-5][0-5][0-3][0-5]$)");
if(!isLegalPort) {
throw new SaturnJobConsoleException("连接字符串中有非法端口号");
}
}
}

private void updateExecutorConfigToZkIfNecessary(ZkCluster zkCluster) {
try {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = zkCluster.getCuratorFrameworkOp();
Expand Down Expand Up @@ -1091,6 +1114,7 @@ public void createZkCluster(String zkClusterKey, String alias, String connectStr
throw new SaturnJobConsoleException(SaturnJobConsoleException.ERROR_CODE_BAD_REQUEST,
String.format("ZK cluster[%s]已经存在", zkClusterKey));
}
checkConnectString(connectString);
zkClusterInfoService.createZkCluster(zkClusterKey, alias, connectString, description, "");
notifyRefreshRegCenter();
}
Expand All @@ -1104,6 +1128,7 @@ public void updateZkCluster(String zkClusterKey, String connectString, String de
throw new SaturnJobConsoleException(SaturnJobConsoleException.ERROR_CODE_NOT_EXISTED,
String.format("ZK cluster[%s]不存在", zkClusterKey));
}
checkConnectString(connectString);
// cannot change alias but connectString and description
zkClusterInfo.setConnectString(connectString);
zkClusterInfo.setDescription(description);
Expand Down

0 comments on commit cdf9ec2

Please sign in to comment.