Skip to content

Commit

Permalink
关闭websocket功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Dahai committed Aug 19, 2023
1 parent 8c8200a commit 4c752c2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 项目介绍
DHorse是一个轻量级的云应用管理平台,界面简洁、操作简单,不需要懂容器、k8s的概念,具有多环境管理、应用部署、服务治理、多云管理等功能。
DHorse是一个轻量级的云应用管理平台,界面简洁、操作简单,不需要理解容器、k8s的概念,具有多环境管理、应用部署、服务治理、多云管理等功能。

## 主要特性
* 简洁的操作界面
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.dhorse.api.response.model.GlobalConfigAgg.TraceTemplate;
import org.dhorse.infrastructure.repository.po.AffinityTolerationPO;
import org.dhorse.infrastructure.repository.po.AppEnvPO;
import org.dhorse.infrastructure.strategy.cluster.K8sClusterHelper;
import org.dhorse.infrastructure.utils.Constants;
import org.dhorse.infrastructure.utils.DeploymentContext;
import org.dhorse.infrastructure.utils.JsonUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Locale;
import java.util.Set;

import org.dhorse.infrastructure.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.dhorse.rest.websocket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.websocket.OnClose;
Expand Down Expand Up @@ -57,10 +56,5 @@ public void onOpen(@PathParam("replicaname") String replicaName,
public void onClose(Session session) {
logger.info("Close socket, id : {}", session.getId());
WebSocketCache.removeReplicaLog(session.getId());
try {
session.close();
} catch (IOException e) {
logger.error("Failed to close websocket", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void remove(WebSocketSession session) {
session.close();
session = null;
} catch (IOException e) {
e.printStackTrace();
logger.error("Failed to close session", e);
}
}

Expand All @@ -67,6 +67,8 @@ public static void removeReplicaLog(String key) {
return;
}
try {
is.getBaos().close();
is.setBaos(null);
is.getWatch().close();
is.getClient().close();
is.getSession().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ private void terminal(String payload, WebSocketSession session) {
}
} else if ("command".equals(replicaTerminalParam.getOperate())) {
transToSSH(sshContext, replicaTerminalParam.getCommand());
} else {
logger.warn("Unsupported operation, websocket session id : {}", session.getId());
close(session);
}
}

Expand All @@ -111,6 +108,7 @@ private boolean doConnect(SSHContext sshContext, String bash) {
.withTTY()
.exec(bash);
sshContext.setWatch(watch);
//解决打开终端后,不能显示连接符的问题
try {
Thread.sleep(300);
} catch (InterruptedException e) {
Expand All @@ -125,19 +123,21 @@ private boolean doConnect(SSHContext sshContext, String bash) {
}

private void close(WebSocketSession session) {
SSHContext sshContext = sshMap.get(session.getId());
SSHContext sshContext = sshMap.remove(session.getId());
if (sshContext == null) {
return;
}
sshContext = sshMap.remove(session.getId());
sshContext.setBaos(null);
((ExecWatch)sshContext.getWatch()).close();
try {
sshContext.getBaos().close();
sshContext.setBaos(null);
((ExecWatch)sshContext.getWatch()).close();
//解决关闭终端后,报Socket closed异常的问题
Thread.sleep(50);
} catch (InterruptedException e) {
//忽略
sshContext.getClient().close();
session.close();
} catch (Exception e) {
logger.error("Failed to close WebSocketSession", e);
}
sshContext.getClient().close();
}

private void transToSSH(SSHContext sshContext, String command) {
Expand All @@ -151,6 +151,7 @@ private void transToSSH(SSHContext sshContext, String command) {
} catch (IOException e) {
logger.error("Failed to interact with terminal", e);
}
//解决在终端输入命令后,不能正常展示的问题
try {
Thread.sleep(70);
} catch (InterruptedException e) {
Expand Down

0 comments on commit 4c752c2

Please sign in to comment.