use of io.jpom.model.data.UploadFileModel in project Jpom by dromara.
the class AgentWebSocketUpdateHandle method onMessage.
@OnMessage
public void onMessage(String message, Session session) throws Exception {
WebSocketMessageModel model = WebSocketMessageModel.getInstance(message);
switch(model.getCommand()) {
case "getVersion":
model.setData(JSONObject.toJSONString(JpomManifest.getInstance()));
break;
case "upload":
AgentFileModel agentFileModel = ((JSONObject) model.getParams()).toJavaObject(AgentFileModel.class);
UploadFileModel uploadFileModel = new UploadFileModel();
uploadFileModel.setId(model.getNodeId());
uploadFileModel.setName(agentFileModel.getName());
uploadFileModel.setSize(agentFileModel.getSize());
uploadFileModel.setVersion(agentFileModel.getVersion());
uploadFileModel.setSavePath(AgentConfigBean.getInstance().getTempPath().getAbsolutePath());
uploadFileModel.remove();
UPLOAD_FILE_INFO.put(session.getId(), uploadFileModel);
break;
case "restart":
model.setData(restart(session));
break;
default:
break;
}
SocketSessionUtil.send(session, model.toString());
// session.sendMessage(new TextMessage(model.toString()));
}
use of io.jpom.model.data.UploadFileModel in project Jpom by dromara.
the class AgentWebSocketUpdateHandle method restart.
/**
* 重启
*
* @param session 回话
* @return 结果
*/
public String restart(Session session) {
String result = Const.UPGRADE_MSG;
try {
UploadFileModel uploadFile = UPLOAD_FILE_INFO.get(session.getId());
String filePath = uploadFile.getFilePath();
JsonMessage<Tuple> error = JpomManifest.checkJpomJar(filePath, Type.Agent);
if (error.getCode() != HttpStatus.HTTP_OK) {
return error.getMsg();
}
JpomManifest.releaseJar(filePath, uploadFile.getVersion());
JpomApplication.restart();
} catch (Exception e) {
result = "重启失败" + e.getMessage();
DefaultSystemLog.getLog().error("重启失败", e);
}
return result;
}
use of io.jpom.model.data.UploadFileModel in project Jpom by dromara.
the class AgentWebSocketUpdateHandle method onMessage.
@OnMessage
public void onMessage(byte[] message, Session session) throws Exception {
UploadFileModel uploadFileModel = UPLOAD_FILE_INFO.get(session.getId());
uploadFileModel.save(message);
// 更新进度
WebSocketMessageModel model = new WebSocketMessageModel("updateNode", uploadFileModel.getId());
model.setData(uploadFileModel);
SocketSessionUtil.send(session, model.toString());
// session.sendMessage(new TextMessage(model.toString()));
}
Aggregations