diff --git a/console/src/main/java/org/zstack/console/ManagementServerConsoleProxyBackend.java b/console/src/main/java/org/zstack/console/ManagementServerConsoleProxyBackend.java index 664d2a127fa..f54778651e1 100755 --- a/console/src/main/java/org/zstack/console/ManagementServerConsoleProxyBackend.java +++ b/console/src/main/java/org/zstack/console/ManagementServerConsoleProxyBackend.java @@ -480,11 +480,34 @@ private void handle(UpdateConsoleProxyAgentMsg msg) { ConsoleProxyAgentVO vo; String oldProxyIp; int oldProxyPort; - int newProxyPort = msg.getConsoleProxyPort() == 0 ? CoreGlobalProperty.CONSOLE_PROXY_PORT : msg.getConsoleProxyPort(); + int newProxyPort = msg.getConsoleProxyPort() == null ? CoreGlobalProperty.CONSOLE_PROXY_PORT : msg.getConsoleProxyPort(); @Override public void setup() { + flow(new NoRollbackFlow() { + String __name__ = "verify-console-proxy-port"; + @Override + public void run(FlowTrigger trigger, Map data) { + if (msg.getConsoleProxyPort() == null) { + trigger.next(); + return; + } + + ShellUtils.ShellRunner runner = new ShellUtils.ShellRunner(); + runner.setCommand(String.format("netstat -nltp4 | grep -E '%d\\s+'", msg.getConsoleProxyPort())); + runner.setVerbose(false); + runner.setWithSudo(true); + runner.setSuppressTraceLog(true); + ShellResult res = runner.run(); + String stdout = res.getStdout(); + if (res.getRetCode() == 0) { + trigger.fail(argerr("there is other process using the port: %s", stdout)); + } else { + trigger.next(); + } + } + }); flow(new Flow() { String __name__ = "update-console-proxy-agent-vo"; @Override diff --git a/core/src/main/java/org/zstack/core/CoreGlobalProperty.java b/core/src/main/java/org/zstack/core/CoreGlobalProperty.java index ff1759b1cb1..393face30d3 100755 --- a/core/src/main/java/org/zstack/core/CoreGlobalProperty.java +++ b/core/src/main/java/org/zstack/core/CoreGlobalProperty.java @@ -61,11 +61,11 @@ public class CoreGlobalProperty { public static boolean IS_UPGRADE_START; @GlobalProperty(name = "shadowEntityOn", defaultValue = "false") public static boolean SHADOW_ENTITY_ON; - @NumberRange({1024, 49151}) + @NumberRange({1, 65535}) @GlobalProperty(name = "consoleProxyPort", defaultValue = "4900") public static int CONSOLE_PROXY_PORT; // for vnc @GlobalProperty(name = "httpConsoleProxyPort", defaultValue = "4901") - @NumberRange({1024, 49151}) + @NumberRange({1, 65535}) public static int HTTP_CONSOLE_PROXY_PORT; // for terminal @GlobalProperty(name = "consoleProxyCertFile", defaultValue = "") public static String CONSOLE_PROXY_CERT_FILE; diff --git a/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsg.java b/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsg.java index 16c44692e0f..b9f2792ea65 100755 --- a/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsg.java +++ b/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsg.java @@ -18,14 +18,14 @@ public class APIUpdateConsoleProxyAgentMsg extends APIMessage implements Console private String uuid; @APIParam private String consoleProxyOverriddenIp; - @APIParam(required = false) - private int consoleProxyPort; + @APIParam(required = false, numberRange={1, 65535}) + private Integer consoleProxyPort; - public int getConsoleProxyPort() { + public Integer getConsoleProxyPort() { return consoleProxyPort; } - public void setConsoleProxyPort(int consoleProxyPort) { + public void setConsoleProxyPort(Integer consoleProxyPort) { this.consoleProxyPort = consoleProxyPort; } diff --git a/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsgDoc_zh_cn.groovy b/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsgDoc_zh_cn.groovy index acaa07c57f0..914e5a128c3 100644 --- a/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsgDoc_zh_cn.groovy +++ b/header/src/main/java/org/zstack/header/console/APIUpdateConsoleProxyAgentMsgDoc_zh_cn.groovy @@ -62,7 +62,7 @@ doc { enclosedIn "updateConsoleProxyAgent" desc "" location "body" - type "int" + type "Integer" optional true since "4.1.0" } diff --git a/sdk/src/main/java/org/zstack/sdk/UpdateConsoleProxyAgentAction.java b/sdk/src/main/java/org/zstack/sdk/UpdateConsoleProxyAgentAction.java index 4e34b0ea324..da6a400c4b6 100644 --- a/sdk/src/main/java/org/zstack/sdk/UpdateConsoleProxyAgentAction.java +++ b/sdk/src/main/java/org/zstack/sdk/UpdateConsoleProxyAgentAction.java @@ -31,8 +31,8 @@ public Result throwExceptionIfError() { @Param(required = true, nonempty = false, nullElements = false, emptyString = true, noTrim = false) public java.lang.String consoleProxyOverriddenIp; - @Param(required = false, nonempty = false, nullElements = false, emptyString = true, noTrim = false) - public int consoleProxyPort = 0; + @Param(required = false, nonempty = false, nullElements = false, emptyString = true, numberRange = {1L,65535L}, noTrim = false) + public java.lang.Integer consoleProxyPort; @Param(required = false) public java.util.List systemTags; diff --git a/test/src/test/groovy/org/zstack/test/integration/console/ConsoleProxyCase.groovy b/test/src/test/groovy/org/zstack/test/integration/console/ConsoleProxyCase.groovy index a02602cc64d..94f1fb161d0 100644 --- a/test/src/test/groovy/org/zstack/test/integration/console/ConsoleProxyCase.groovy +++ b/test/src/test/groovy/org/zstack/test/integration/console/ConsoleProxyCase.groovy @@ -195,6 +195,14 @@ class ConsoleProxyCase extends SubCase { } ConsoleProxyAgentVO agent = dbf.listAll(ConsoleProxyAgentVO)[0] + + updateConsoleProxyAgent { + uuid = agent.uuid + consoleProxyOverriddenIp = "127.0.0.2" + } + agent = dbf.reload(agent) + assert agent.consoleProxyOverriddenIp == "127.0.0.2" + updateConsoleProxyAgent { uuid = agent.uuid consoleProxyOverriddenIp = "127.0.0.1"