Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d45b7753ed | |
|
|
25709cccb5 | |
|
|
f908ea5038 |
11
pom.xml
11
pom.xml
|
|
@ -15,7 +15,6 @@
|
|||
<description>browser(websocket) -> webssh(ssh) -> pod</description>
|
||||
|
||||
<properties>
|
||||
<swagger2.version>2.6.1</swagger2.version>
|
||||
<java.version>1.8</java.version>
|
||||
<jsch.version>0.1.54</jsch.version>
|
||||
<fastjson.version>1.2.20</fastjson.version>
|
||||
|
|
@ -62,16 +61,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger2.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
|
@ -16,8 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
import net.educoder.bridge.common.constant.ApiResultCsts;
|
||||
import net.educoder.bridge.common.model.ApiResult;
|
||||
import net.educoder.bridge.common.utils.Base64Util;
|
||||
|
|
@ -132,7 +130,7 @@ public class GitGontroller {
|
|||
* 删除私密版本库
|
||||
*/
|
||||
@RequestMapping(path = "/deleteSecret", method = { RequestMethod.POST })
|
||||
public ApiResult<?> deleteSecret(@ApiParam(name = "secretRepospace", required = true, value = "私密版本库路径") @RequestParam String secretRepospace) {
|
||||
public ApiResult<?> deleteSecret(@RequestParam String secretRepospace) {
|
||||
logger.info("[start]deleteSecret: secretRepospace: {}", secretRepospace);
|
||||
ApiResult<?> result = new ApiResult<>();
|
||||
|
||||
|
|
@ -146,7 +144,6 @@ public class GitGontroller {
|
|||
* tpm版本库已更新,同步
|
||||
*/
|
||||
@RequestMapping(path = "/resetTpmRepository", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "tpm版本库已更新,同步操作", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public ApiResult<?> reset(@RequestBody GitResetRequestParam param) {
|
||||
logger.info("[start]tpm版本库已更新,同步到tpi版本库 {}", param);
|
||||
|
||||
|
|
@ -179,7 +176,7 @@ public class GitGontroller {
|
|||
* 删除私密版本库
|
||||
*/
|
||||
@RequestMapping(path = "/clearWorkspace", method = { RequestMethod.POST })
|
||||
public ApiResult<?> clearWorkspace(@ApiParam(name = "tpiWorkspace", required = true, value = "实训工作空间") @RequestParam String tpiWorkspace) {
|
||||
public ApiResult<?> clearWorkspace(@RequestParam String tpiWorkspace) {
|
||||
logger.info("[start]clearWorkspace: tpiWorkspace: {}", tpiWorkspace);
|
||||
ApiResult<?> result = new ApiResult<>();
|
||||
|
||||
|
|
@ -237,9 +234,9 @@ public class GitGontroller {
|
|||
* 导入jupyter tpm文件
|
||||
*/
|
||||
@RequestMapping(path = "/updateJupyterTpm", method = { RequestMethod.POST })
|
||||
public ApiResult<?> updateJupyterTpm(@ApiParam(name = "tpiID", required = true, value = "tpiID") @RequestParam String tpiID,
|
||||
@ApiParam(name = "content", required = true, value = "文件内容") @RequestParam String content,
|
||||
@ApiParam(name = "tpiWorkspace", required = true, value = "工作空间") @RequestParam String tpiWorkspace) {
|
||||
public ApiResult<?> updateJupyterTpm(@RequestParam String tpiID,
|
||||
@RequestParam String content,
|
||||
@RequestParam String tpiWorkspace) {
|
||||
logger.info("[start]updateJupyterTpm tpiID: {}, content: {}, tpiWorkspace", tpiID, content, tpiWorkspace);
|
||||
ApiResult<?> result = new ApiResult<>();
|
||||
gitService.updateJupyterTpm(tpiID, content, tpiWorkspace);
|
||||
|
|
|
|||
|
|
@ -1,42 +1,30 @@
|
|||
package net.educoder.bridge.git.model;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
/**
|
||||
* git信息
|
||||
*/
|
||||
@ApiModel(value = "gitPullRequestParam", description = "git pull接口传参")
|
||||
public class GitPullRequestParam {
|
||||
|
||||
@ApiModelProperty(name = "tpiId", required = true, value = "实训实例的ID")
|
||||
private String tpiId;
|
||||
|
||||
@ApiModelProperty(name = "tpiGitURL", required = true, value = "git项目地址")
|
||||
private String tpiGitURL;
|
||||
|
||||
@ApiModelProperty(name = "tpiWorkspace", required = true, value = "实训工作空间")
|
||||
private String tpiWorkspace;
|
||||
|
||||
@ApiModelProperty(name = "tpiRepoName", required = true, value = "实训项目名")
|
||||
private String tpiRepoName;
|
||||
|
||||
@ApiModelProperty(name = "tpiProtectspace", required = true, value = "实训保护空间")
|
||||
private String tpiProtectspace;
|
||||
|
||||
@ApiModelProperty(name = "tpmScript", required = false, value = "实训评测脚本")
|
||||
private String tpmScript;
|
||||
|
||||
@ApiModelProperty(name = "secretDir", required = false, value = "私密版本库路径")
|
||||
private String secretDir;
|
||||
|
||||
@ApiModelProperty(name = "secretGitUrl", required = false, value = "私密版本库项目地址")
|
||||
private String secretGitUrl;
|
||||
|
||||
@ApiModelProperty(name = "contentModified", required = false, value = "文件是否修改的标志")
|
||||
private Integer contentModified;
|
||||
|
||||
@ApiModelProperty(name = "file", required = false, value = "需要传文件的实训,给出文件存放路径(一个目录)及文件类型")
|
||||
private String file;
|
||||
|
||||
public String getTpiId() {
|
||||
|
|
|
|||
|
|
@ -1,30 +1,22 @@
|
|||
package net.educoder.bridge.git.model;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
/**
|
||||
* git信息
|
||||
*/
|
||||
@ApiModel(value = "gitResetRequestParam", description = "git reset接口传参")
|
||||
public class GitResetRequestParam {
|
||||
|
||||
@ApiModelProperty(name = "tpiId", required = true, value = "实训实例的ID")
|
||||
private String tpiId;
|
||||
|
||||
@ApiModelProperty(name = "tpiGitURL", required = true, value = "tpi git项目地址")
|
||||
private String tpiGitURL;
|
||||
|
||||
@ApiModelProperty(name = "tpmGitURL", required = true, value = "tpm git项目地址")
|
||||
private String tpmGitURL;
|
||||
|
||||
@ApiModelProperty(name = "tpiWorkspace", required = true, value = "实训工作空间")
|
||||
private String tpiWorkspace;
|
||||
|
||||
@ApiModelProperty(name = "tpiRepoName", required = true, value = "实训项目名")
|
||||
private String tpiRepoName;
|
||||
|
||||
@ApiModelProperty(name = "tpiRepoPath", required = true, value = "实训项目名")
|
||||
private String tpiRepoPath;
|
||||
|
||||
public String getTpiId() {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,20 @@
|
|||
package net.educoder.bridge.git.model;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
/**
|
||||
* git信息
|
||||
*/
|
||||
@ApiModel(value = "ojRequestParam", description = "oj接口传参")
|
||||
public class OjRequestParam {
|
||||
|
||||
@ApiModelProperty(name = "tpiID", required = true, value = "实训实例的ID")
|
||||
private String tpiID;
|
||||
|
||||
@ApiModelProperty(name = "codeFileName", required = false, value = "代码文件名")
|
||||
private String codeFileName;
|
||||
|
||||
@ApiModelProperty(name = "codeFileContent", required = false, value = "代码文件内容")
|
||||
private String codeFileContent;
|
||||
|
||||
@ApiModelProperty(name = "tpiWorkspace", required = false, value = "工作空间")
|
||||
private String tpiWorkspace;
|
||||
|
||||
@ApiModelProperty(name = "codeFilePath", required = true, value = "代码文件路径")
|
||||
private String codeFilePath;
|
||||
|
||||
public String getTpiID() {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -63,9 +62,6 @@ public class EducoderGuacamoleWebSocketTunnelHandler extends GuacamoleWebSocketT
|
|||
return tpiId + "-" + NumberUtils.toInt(position, 1);
|
||||
}
|
||||
|
||||
public String generateUniqId(String envId, String tpiId, String tpiType) {
|
||||
return tpiId + "-" + envId + "-" + tpiType;
|
||||
}
|
||||
@Override
|
||||
GuacamoleTunnel createTunnel(WebSocketSession session) throws GuacamoleException {
|
||||
Properties properties = new Properties();
|
||||
|
|
@ -75,10 +71,8 @@ public class EducoderGuacamoleWebSocketTunnelHandler extends GuacamoleWebSocketT
|
|||
e.printStackTrace();
|
||||
}
|
||||
String tpiID = properties.getProperty("tpiID");
|
||||
String envId = properties.getProperty("envId");
|
||||
String tpiType = properties.getProperty("tpiType");
|
||||
//生成唯一键
|
||||
String uniqId = generateUniqId(envId, tpiID, tpiType);
|
||||
String uniqId = generateUniqId(tpiID);
|
||||
WindowsInfo windowsInfo = getWindowsInfo(uniqId);
|
||||
|
||||
|
||||
|
|
@ -100,7 +94,7 @@ public class EducoderGuacamoleWebSocketTunnelHandler extends GuacamoleWebSocketT
|
|||
socket = new ConfiguredGuacamoleSocket(new InetGuacamoleSocket(guacamoleServer, guacamoleServerPort),
|
||||
config);
|
||||
}catch (Exception e){
|
||||
logger.error("createTunnel is Exception uniqueId:{}", uniqId, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Return a new tunnel which uses the connected socket
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public abstract class GuacamoleWebSocketTunnelHandler implements WebSocketHandler, SubProtocolCapable {
|
||||
|
||||
/**
|
||||
|
|
@ -67,11 +65,62 @@ public abstract class GuacamoleWebSocketTunnelHandler implements WebSocketHandle
|
|||
}
|
||||
Thread readThread = new Thread() {
|
||||
|
||||
AtomicBoolean flag = new AtomicBoolean(true);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
process(session, flag);
|
||||
|
||||
StringBuilder buffer = new StringBuilder(BUFFER_SIZE);
|
||||
GuacamoleReader reader = tunnel.acquireReader();
|
||||
char[] readMessage;
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
|
||||
// Attempt to read
|
||||
while ((readMessage = reader.read()) != null) {
|
||||
|
||||
// Buffer message
|
||||
buffer.append(readMessage);
|
||||
|
||||
// Flush if we expect to wait or buffer is getting
|
||||
// full
|
||||
if (!reader.available() || buffer.length() >= BUFFER_SIZE) {
|
||||
session.sendMessage(new TextMessage(buffer));
|
||||
buffer.setLength(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No more data
|
||||
String message = Integer.toString(GuacamoleStatus.SUCCESS.getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session,
|
||||
new CloseStatus(GuacamoleStatus.SUCCESS.getWebSocketCode(), message));
|
||||
}
|
||||
|
||||
// Catch any thrown guacamole exception and attempt
|
||||
// to pass within the WebSocket connection, logging
|
||||
// each error appropriately.
|
||||
catch (GuacamoleClientException e) {
|
||||
logger.info("WebSocket connection terminated: {}", e.getMessage());
|
||||
logger.debug("WebSocket connection terminated due to client error.", e);
|
||||
String message = Integer.toString(e.getStatus().getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session, new CloseStatus(e.getStatus().getWebSocketCode(), message));
|
||||
} catch (GuacamoleConnectionClosedException e) {
|
||||
logger.debug("Connection to guacd closed.", e);
|
||||
String message = Integer.toString(GuacamoleStatus.SUCCESS.getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session,
|
||||
new CloseStatus(GuacamoleStatus.SUCCESS.getWebSocketCode(), message));
|
||||
} catch (GuacamoleException e) {
|
||||
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
||||
logger.debug("Internal error during connection to guacd.", e);
|
||||
String message = Integer.toString(e.getStatus().getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session, new CloseStatus(e.getStatus().getWebSocketCode(), message));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.debug("I/O error prevents further reads.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -133,68 +182,4 @@ public abstract class GuacamoleWebSocketTunnelHandler implements WebSocketHandle
|
|||
return false;
|
||||
}
|
||||
|
||||
private void process(WebSocketSession session, AtomicBoolean flag) {
|
||||
|
||||
if (flag.get()) {
|
||||
StringBuilder buffer = new StringBuilder(BUFFER_SIZE);
|
||||
GuacamoleReader reader = tunnel.acquireReader();
|
||||
char[] readMessage;
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
|
||||
// Attempt to read
|
||||
while ((readMessage = reader.read()) != null) {
|
||||
|
||||
// Buffer message
|
||||
buffer.append(readMessage);
|
||||
|
||||
// Flush if we expect to wait or buffer is getting
|
||||
// full
|
||||
if (!reader.available() || buffer.length() >= BUFFER_SIZE) {
|
||||
session.sendMessage(new TextMessage(buffer));
|
||||
buffer.setLength(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No more data
|
||||
String message = Integer.toString(GuacamoleStatus.SUCCESS.getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session,
|
||||
new CloseStatus(GuacamoleStatus.SUCCESS.getWebSocketCode(), message));
|
||||
}
|
||||
|
||||
// Catch any thrown guacamole exception and attempt
|
||||
// to pass within the WebSocket connection, logging
|
||||
// each error appropriately.
|
||||
catch (GuacamoleClientException e) {
|
||||
logger.info("WebSocket connection terminated: {}", e.getMessage());
|
||||
String message = Integer.toString(e.getStatus().getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session, new CloseStatus(e.getStatus().getWebSocketCode(), message));
|
||||
} catch (GuacamoleConnectionClosedException e) {
|
||||
logger.error("Connection to guacd closed.", e);
|
||||
if(flag.getAndSet(false)) {
|
||||
process(session, flag);
|
||||
}else {
|
||||
String message = Integer.toString(GuacamoleStatus.SUCCESS.getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session,
|
||||
new CloseStatus(GuacamoleStatus.SUCCESS.getWebSocketCode(), message));
|
||||
}
|
||||
} catch (GuacamoleException e) {
|
||||
logger.error("Connection to guacd terminated abnormally ", e);
|
||||
if(flag.getAndSet(false)) {
|
||||
process(session, flag);
|
||||
}else{
|
||||
String message = Integer.toString(e.getStatus().getGuacamoleStatusCode());
|
||||
afterConnectionClosed(session, new CloseStatus(e.getStatus().getWebSocketCode(), message));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.debug("I/O error prevents further reads.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -50,12 +50,6 @@ public class RunOnlyHandler extends TextWebSocketHandler {
|
|||
JSONObject msg = JSON.parseObject(payload);
|
||||
if (LOG_TYPE.equals(msg.getString(TYPE))) {
|
||||
String runOnlyResultKey = RUN_ONLY_RESULT_KEY_PREFIX + msg.getString(DATA);
|
||||
// webssh先收到请求,需要等待一会
|
||||
int i = 0;
|
||||
while (!redisHelper.hasKey(runOnlyResultKey) && i < 5 * 10) {
|
||||
ThreadUtil.sleepSilently(100);
|
||||
i++;
|
||||
}
|
||||
String runOnlyResult = redisHelper.get(runOnlyResultKey);
|
||||
while (CASE_OUTPUT_SEPARATOR.equals(runOnlyResult) && redisHelper.hasKey(runOnlyResultKey)) {
|
||||
ThreadUtil.sleepSilently(100);
|
||||
|
|
|
|||
|
|
@ -1,21 +1,86 @@
|
|||
package net.educoder.bridge.webssh.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ConnectInfo {
|
||||
private String host;
|
||||
private String port;
|
||||
private String username;
|
||||
private String secret;
|
||||
private String myshixun_id;
|
||||
private String gameid;
|
||||
|
||||
private int rows;
|
||||
private int columns;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public String getTpiID() {
|
||||
return myshixun_id;
|
||||
public int getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(int rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public int getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(int columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return Integer.parseInt(port);
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
public String getGameid() {
|
||||
return gameid;
|
||||
}
|
||||
|
||||
public void setGameid(String gameid) {
|
||||
this.gameid = gameid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,11 @@ import net.educoder.bridge.common.utils.Base64Util;
|
|||
|
||||
@Service
|
||||
public class JchService {
|
||||
@Autowired
|
||||
private WebsshService websshService;
|
||||
|
||||
@Autowired
|
||||
private WebsshOverTimeService overTimeService;
|
||||
|
||||
private static List<WebscoketObj> sessionQueue = new CopyOnWriteArrayList<>();
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
|
@ -66,19 +70,22 @@ public class JchService {
|
|||
|
||||
/**
|
||||
* 处理客户端发过来的数据
|
||||
*
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void recv(String buffer, WebSocketSession session) {
|
||||
logger.debug("webssh收到数据:{}", buffer);
|
||||
WebscoketObj webscoketObj = findBySession(session);
|
||||
boolean overtime = Boolean.FALSE;
|
||||
|
||||
try {
|
||||
// logger.debug("recv函数,进程:{},sessionID:{},信息:{}",
|
||||
// Thread.currentThread().getId(), session.getId(), buffer);
|
||||
JSONObject object = JSONObject.parseObject(buffer);
|
||||
String tp = object.getString("tp");
|
||||
if ("init".equals(tp)) {
|
||||
// 初始化连接
|
||||
// {"tp":"init","data":{"host":"106.75.96.108","port":"41080","username":"root","secret":"123123","myshixun_id":"1080","rows":"30"}}
|
||||
// {"tp":"init","data":{"host":"106.75.96.108","port":"41080","username":"root","secret":"123123","gameid":"1080","rows":"30"}}
|
||||
ConnectInfo connectInfo = object.getObject("data", ConnectInfo.class);
|
||||
if (webscoketObj != null) {
|
||||
WebscoketObj finalWebscoketObj = webscoketObj;
|
||||
|
|
@ -91,6 +98,7 @@ public class JchService {
|
|||
});
|
||||
}
|
||||
} else if ("client".equals(tp)) {
|
||||
overtime = Boolean.TRUE;
|
||||
String data = object.getString("data");
|
||||
if (webscoketObj != null) {
|
||||
transTossh(webscoketObj.getOutputStream(), data);
|
||||
|
|
@ -106,10 +114,12 @@ public class JchService {
|
|||
connectInfo.getWidth(), connectInfo.getHeight());
|
||||
}
|
||||
} else if ("overtime".equals(tp)) {
|
||||
overtime = Boolean.TRUE;
|
||||
ConnectInfo connectInfo = webscoketObj.getConnectInfo();
|
||||
logger.info("前端主动延长pod存活时间, 不需要通过此接口进行延长了:{}, tpiID:{},host:{},端口:{}", session.getId(),
|
||||
connectInfo.getTpiID(), connectInfo.getHost(), connectInfo.getPort());
|
||||
|
||||
if (webscoketObj.getConnectInfo() != null) {
|
||||
logger.info("前端主动延长pod存活时间, websocket:{}, tpiID:{},host:{},端口:{}", session.getId(),
|
||||
connectInfo.getGameid(), connectInfo.getHost(), connectInfo.getPort());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("转发 websocket {}命令到ssh出错: ", session.getId(), e);
|
||||
|
|
@ -117,7 +127,15 @@ public class JchService {
|
|||
closeByWebsocket(session);
|
||||
}
|
||||
|
||||
|
||||
// 延长pod存活时间
|
||||
try {
|
||||
if (webscoketObj.getConnectInfo() != null && overtime) {
|
||||
String gameId = webscoketObj.getConnectInfo().getGameid();
|
||||
overTimeService.websshOverTime(gameId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("pod 接收消息出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void transTossh(OutputStream outputStream, String data) throws IOException {
|
||||
|
|
@ -128,7 +146,7 @@ public class JchService {
|
|||
}
|
||||
|
||||
private void connectTossh(WebscoketObj webscoketObj, ConnectInfo connectInfo, WebSocketSession webSocketSession) {
|
||||
Session session = null;
|
||||
Session session = null;
|
||||
try {
|
||||
JSch jsch = new JSch();
|
||||
JSch.setLogger(jschLogger);
|
||||
|
|
@ -136,7 +154,7 @@ public class JchService {
|
|||
// 启动线程
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session = jsch.getSession(connectInfo.getUsername(), connectInfo.getHost(), Integer.parseInt(connectInfo.getPort()));
|
||||
session = jsch.getSession(connectInfo.getUsername(), connectInfo.getHost(), connectInfo.getPort());
|
||||
|
||||
session.setConfig(config);
|
||||
session.setPassword(connectInfo.getSecret());
|
||||
|
|
@ -190,7 +208,8 @@ public class JchService {
|
|||
|
||||
webscoketObj.setConnectInfo(connectInfo);
|
||||
|
||||
logger.info("websocket {} open,连接: tpiId:{},host:{},端口:{}", webSocketSession.getId(), connectInfo.getTpiID(),
|
||||
websshService.active("" + connectInfo.getGameid());
|
||||
logger.info("websocket {} open,连接: tpiId:{},host:{},端口:{}", webSocketSession.getId(), connectInfo.getGameid(),
|
||||
connectInfo.getHost(), connectInfo.getPort());
|
||||
|
||||
// 循环读取
|
||||
|
|
@ -201,7 +220,7 @@ public class JchService {
|
|||
String str = webSocketSession.isOpen() ? "is not" : "is";
|
||||
str = webscoketObj.getSession().getId() + " " + str;
|
||||
str = String.format("websocket %s closed.ssh读取终止,连接: tpiId:%s,host:%s,端口:%s", str,
|
||||
connectInfo.getTpiID(), connectInfo.getHost(), connectInfo.getPort());
|
||||
connectInfo.getGameid(), connectInfo.getHost(), connectInfo.getPort());
|
||||
if (webSocketSession.isOpen()) {
|
||||
logger.error(str);
|
||||
} else {
|
||||
|
|
@ -213,7 +232,7 @@ public class JchService {
|
|||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("连接关闭: websocketId:" + webscoketObj.getSession().getId() + ", tpiId:" + connectInfo.getTpiID()
|
||||
logger.error("连接关闭: websocketId:" + webscoketObj.getSession().getId() + ", tpiId:" + connectInfo.getGameid()
|
||||
+ ", host:" + connectInfo.getHost() + ",端口: " + connectInfo.getPort(), e);
|
||||
} finally {
|
||||
if (session != null) {
|
||||
|
|
@ -275,7 +294,7 @@ public class JchService {
|
|||
}
|
||||
this._close(webscoketObj);
|
||||
}
|
||||
|
||||
|
||||
public void closeByWebsocket(WebSocketSession session) {
|
||||
WebscoketObj webscoketObj = findBySession(session);
|
||||
sessionQueue.remove(webscoketObj);
|
||||
|
|
@ -284,20 +303,20 @@ public class JchService {
|
|||
return;
|
||||
} else {
|
||||
ConnectInfo info = webscoketObj.getConnectInfo();
|
||||
logger.info("websocket {}连接中断 tpiId {} ", session.getId(), info.getTpiID());
|
||||
logger.info("websocket {}连接中断 tpiId {} ", session.getId(), info.getGameid());
|
||||
this._close(webscoketObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过gameId来匹配
|
||||
*
|
||||
*
|
||||
* @param gameId
|
||||
*/
|
||||
public int findExistConnectByGameId(String gameId) {
|
||||
|
||||
long count = sessionQueue.stream().filter(webscoketObj -> webscoketObj.getConnectInfo() != null
|
||||
&& gameId.equals(webscoketObj.getConnectInfo().getTpiID())).count();
|
||||
&& gameId.equals(webscoketObj.getConnectInfo().getGameid())).count();
|
||||
logger.debug("当前gameID对应的websocket数目:{}", count);
|
||||
return (int) count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import javax.annotation.PostConstruct;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//@Service
|
||||
@Service
|
||||
public class WebsshOverTimeService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
// @Autowired
|
||||
@Autowired
|
||||
private WebsshService websshService;
|
||||
|
||||
private static ConcurrentHashMap<String, String> recvGameIdMap = new ConcurrentHashMap<>();
|
||||
|
|
@ -45,7 +45,7 @@ public class WebsshOverTimeService {
|
|||
}
|
||||
if (recvGameIds.length() > 0) {
|
||||
recvGameIds.setLength(recvGameIds.length() - 1);
|
||||
// websshService.overTime(recvGameIds.toString());
|
||||
websshService.overTime(recvGameIds.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("发送接收到websocket消息 tpi失败", e);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@
|
|||
<!-- 屏蔽框架输出 -->
|
||||
<logger name="org.slf4j" level="ERROR" />
|
||||
<logger name="org.springframework" level="ERROR" />
|
||||
<logger name="io.swagger" level="ERROR" />
|
||||
<logger name="ch.qos.logback" level="OFF" />
|
||||
<logger name="springfox.documentation" level="ERROR" />
|
||||
<logger name="com.spotify.docker.client" level="ERROR" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue