use of io.jpom.model.AgentFileModel 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.AgentFileModel in project Jpom by dromara.
the class NodeUpdateController method checkVersion.
/**
* 检查版本更新
*
* @return json
* @see RemoteVersion
* @see AgentFileModel
*/
@GetMapping(value = "check_version.json", produces = MediaType.APPLICATION_JSON_VALUE)
public String checkVersion() {
RemoteVersion remoteVersion = RemoteVersion.cacheInfo();
AgentFileModel agentFileModel = systemParametersServer.getConfig(AgentFileModel.ID, AgentFileModel.class, agentFileModel1 -> {
if (agentFileModel1 == null || !FileUtil.exist(agentFileModel1.getSavePath())) {
return null;
}
return agentFileModel1;
});
JSONObject jsonObject = new JSONObject();
if (remoteVersion == null) {
jsonObject.put("upgrade", false);
} else {
String tagName = StrUtil.removePrefixIgnoreCase(remoteVersion.getTagName(), "v");
jsonObject.put("tagName", tagName);
if (agentFileModel == null) {
jsonObject.put("upgrade", true);
} else {
String version = StrUtil.removePrefixIgnoreCase(agentFileModel.getVersion(), "v");
jsonObject.put("upgrade", StrUtil.compareVersion(version, tagName) < 0);
}
}
return JsonMessage.getString(200, "", jsonObject);
}
use of io.jpom.model.AgentFileModel in project Jpom by dromara.
the class NodeUpdateController method saveAgentFile.
private void saveAgentFile(Tuple data) {
File file = data.get(3);
AgentFileModel agentFileModel = new AgentFileModel();
agentFileModel.setName(file.getName());
agentFileModel.setSize(file.length());
agentFileModel.setSavePath(FileUtil.getAbsolutePath(file));
//
agentFileModel.setVersion(data.get(0));
agentFileModel.setTimeStamp(data.get(1));
systemParametersServer.upsert(AgentFileModel.ID, agentFileModel, AgentFileModel.ID);
// 删除历史包 @author jzy 2021-08-03
String saveDir = ServerConfigBean.getInstance().getAgentPath().getAbsolutePath();
List<File> files = FileUtil.loopFiles(saveDir, pathname -> !FileUtil.equals(pathname, file));
for (File file1 : files) {
FileUtil.del(file1);
}
}
use of io.jpom.model.AgentFileModel in project Jpom by dromara.
the class NodeUpdateHandler method updateNode.
/**
* 更新节点
*
* @param model 参数
*/
private void updateNode(WebSocketMessageModel model, WebSocketSession session) {
JSONObject params = (JSONObject) model.getParams();
JSONArray ids = params.getJSONArray("ids");
if (CollUtil.isEmpty(ids)) {
return;
}
String protocol = params.getString("protocol");
boolean http = StrUtil.equalsIgnoreCase(protocol, "http");
try {
AgentFileModel agentFileModel = systemParametersServer.getConfig(AgentFileModel.ID, AgentFileModel.class);
//
if (agentFileModel == null || !FileUtil.exist(agentFileModel.getSavePath())) {
this.onError(session, "Agent JAR包不存在");
return;
}
JsonMessage<Tuple> error = JpomManifest.checkJpomJar(agentFileModel.getSavePath(), Type.Agent, false);
if (error.getCode() != HttpStatus.HTTP_OK) {
this.onError(session, "Agent JAR 损坏请重新上传," + error.getMsg());
return;
}
for (int i = 0; i < ids.size(); i++) {
int finalI = i;
ThreadUtil.execute(() -> this.updateNodeItem(ids.getString(finalI), session, agentFileModel, http));
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("升级失败", e);
}
}
Aggregations