Skip to content

Commit

Permalink
Update token from agent
Browse files Browse the repository at this point in the history
Resolves ZSTAC-10215

Signed-off-by: AlanJager <[email protected]>
  • Loading branch information
AlanJager committed Mar 30, 2018
1 parent 02f1190 commit 927f32f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
34 changes: 21 additions & 13 deletions conf/globalConfig/consoleConfig.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<globalConfig xmlns="http://zstack.org/schema/zstack">
<config>
<category>console</category>
<name>proxy.idleTimeout</name>
<config>
<category>console</category>
<name>proxy.idleTimeout</name>
<description>The max time an idle console proxy process waits before exiting, in seconds</description>
<defaultValue>60</defaultValue>
<type>java.lang.Integer</type>
</config>
<defaultValue>60</defaultValue>
<type>java.lang.Integer</type>
</config>

<config>
<category>console</category>
<name>agent.ping.interval</name>
<config>
<category>console</category>
<name>agent.ping.interval</name>
<description>The interval to ping console proxy agents, in seconds</description>
<defaultValue>60</defaultValue>
<type>java.lang.Integer</type>
</config>
<defaultValue>60</defaultValue>
<type>java.lang.Integer</type>
</config>

<config>
<category>console</category>
<name>vnc.token.timeout</name>
<description>Timeout of VNC token, in seconds</description>
<defaultValue>1800</defaultValue>
<type>java.lang.Integer</type>
</config>
</globalConfig>
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void success(ConsoleProxyInventory ret) {
vo.setUuid(Platform.getUuid());
vo.setAgentType(ret.getAgentType());
vo.setStatus(ConsoleProxyStatus.Active);
vo.setToken(ret.getToken());
vo = dbf.persistAndRefresh(vo);

complete.success(ConsoleInventory.valueOf(vo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public class ConsoleGlobalConfig {

@GlobalConfigValidation(numberGreaterThan = 0)
public static GlobalConfig PING_INTERVAL = new GlobalConfig(CATEGORY, "agent.ping.interval");

@GlobalConfigValidation(numberGreaterThan = 0)
public static GlobalConfig VNC_TOKEN_TIMEOUT = new GlobalConfig(CATEGORY, "vnc.token.timeout");
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private void doEstablish(URI uri, final ReturnValueCompletion<ConsoleProxyInvent
final String targetHostname = uri.getHost();
final int targetPort = uri.getPort();

int timeout = ConsoleGlobalConfig.PROXY_IDLE_TIMEOUT.value(Integer.class);
int idleTimeout = ConsoleGlobalConfig.PROXY_IDLE_TIMEOUT.value(Integer.class);
int tokenTimeout = ConsoleGlobalConfig.VNC_TOKEN_TIMEOUT.value(Integer.class);

ConsoleProxyCommands.EstablishProxyCmd cmd = new ConsoleProxyCommands.EstablishProxyCmd();
cmd.setVmUuid(self.getVmInstanceUuid());
Expand All @@ -69,7 +70,8 @@ private void doEstablish(URI uri, final ReturnValueCompletion<ConsoleProxyInvent
cmd.setSslCertFile(CoreGlobalProperty.CONSOLE_PROXY_CERT_FILE);
cmd.setScheme(self.getScheme());
cmd.setToken(self.getToken());
cmd.setIdleTimeout(timeout);
cmd.setIdleTimeout(idleTimeout);
cmd.setVncTokenTimeout(tokenTimeout);

String agentUrl = URLBuilder.buildHttpUrl(self.getAgentIp(), agentPort, ConsoleConstants.CONSOLE_PROXY_ESTABLISH_PROXY_PATH);
restf.asyncJsonPost(agentUrl, cmd, new JsonAsyncRESTCallback<ConsoleProxyCommands.EstablishProxyRsp>(completion) {
Expand All @@ -84,6 +86,7 @@ public void success(ConsoleProxyCommands.EstablishProxyRsp ret) {
self.setTargetHostname(targetHostname);
self.setTargetPort(targetPort);
self.setProxyPort(ret.getProxyPort());
self.setToken(ret.getToken());
completion.success(self);
} else {
completion.fail(operr("operation error, because:%s", ret.getError()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public static class EstablishProxyCmd extends AgentCommand {
private String vmUuid;
private String scheme;
private int idleTimeout;
private int vncTokenTimeout;

public String getToken() {
return token;
Expand Down Expand Up @@ -251,10 +252,19 @@ public int getIdleTimeout() {
public void setIdleTimeout(int idleTimeout) {
this.idleTimeout = idleTimeout;
}

public int getVncTokenTimeout() {
return vncTokenTimeout;
}

public void setVncTokenTimeout(int vncTokenTimeout) {
this.vncTokenTimeout = vncTokenTimeout;
}
}

public static class EstablishProxyRsp extends AgentResponse {
private int proxyPort;
private String token;

public int getProxyPort() {
return proxyPort;
Expand All @@ -263,6 +273,14 @@ public int getProxyPort() {
public void setProxyPort(int proxyPort) {
this.proxyPort = proxyPort;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}
}

public static class PingCmd extends AgentCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package org.zstack.test.integration.storage.primary.nfs.capacity

import org.springframework.http.HttpEntity
import org.zstack.header.image.ImageConstant
import org.zstack.header.network.service.NetworkServiceType
import org.zstack.kvm.KVMConstant
import org.zstack.network.securitygroup.SecurityGroupConstant
import org.zstack.network.service.virtualrouter.VirtualRouterConstant
import org.zstack.sdk.*
import org.zstack.test.integration.storage.StorageTest
import org.zstack.testlib.EnvSpec
Expand Down

0 comments on commit 927f32f

Please sign in to comment.