mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-03 04:18:21 +08:00
fix auto import local node Time Too soon
This commit is contained in:
parent
6cbaad10b6
commit
99e97cbf35
@ -23,7 +23,7 @@ import java.util.Map;
|
||||
* @author jiangzeyin
|
||||
* @date 2019/3/26
|
||||
*/
|
||||
@PreLoadClass
|
||||
@PreLoadClass(value = Integer.MIN_VALUE)
|
||||
public class CheckPath {
|
||||
/**
|
||||
* 待检查的类
|
||||
|
@ -20,8 +20,6 @@ import io.jpom.system.ConfigBean;
|
||||
import io.jpom.system.ServerConfigBean;
|
||||
import io.jpom.util.JsonFileUtil;
|
||||
import io.jpom.util.JvmUtil;
|
||||
import sun.jvmstat.monitor.MonitoredVm;
|
||||
import sun.jvmstat.monitor.VmIdentifier;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@ -35,71 +33,71 @@ import java.util.List;
|
||||
@PreLoadClass
|
||||
public class AutoImportLocalNode {
|
||||
|
||||
private static final String AGENT_MAIN_CLASS = "io.jpom.JpomAgentApplication";
|
||||
private static NodeService nodeService;
|
||||
private static final String AGENT_MAIN_CLASS = "io.jpom.JpomAgentApplication";
|
||||
private static NodeService nodeService;
|
||||
|
||||
@PreLoadMethod
|
||||
private static void install() {
|
||||
File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.INSTALL);
|
||||
if (file.exists()) {
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("installId", IdUtil.fastSimpleUUID());
|
||||
jsonObject.put("installTime", DateTime.now().toString());
|
||||
jsonObject.put("desc", "请勿删除此文件,服务端安装id和插件端互通关联");
|
||||
JsonFileUtil.saveJson(file.getAbsolutePath(), jsonObject);
|
||||
}
|
||||
@PreLoadMethod
|
||||
private static void install() {
|
||||
File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.INSTALL);
|
||||
if (file.exists()) {
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("installId", IdUtil.fastSimpleUUID());
|
||||
jsonObject.put("installTime", DateTime.now().toString());
|
||||
jsonObject.put("desc", "请勿删除此文件,服务端安装id和插件端互通关联");
|
||||
JsonFileUtil.saveJson(file.getAbsolutePath(), jsonObject);
|
||||
}
|
||||
|
||||
@PreLoadMethod
|
||||
private static void loadAgent() {
|
||||
nodeService = SpringUtil.getBean(NodeService.class);
|
||||
List<NodeModel> list = nodeService.list();
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
try {
|
||||
List<MonitoredVm> monitoredVms = JvmUtil.listMainClass(AGENT_MAIN_CLASS);
|
||||
monitoredVms.forEach(monitoredVm -> {
|
||||
VmIdentifier vmIdentifier = monitoredVm.getVmIdentifier();
|
||||
findPid(vmIdentifier.getUserInfo());
|
||||
});
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.getLog().error("自动添加本机节点错误", e);
|
||||
}
|
||||
}
|
||||
@PreLoadMethod
|
||||
private static void loadAgent() {
|
||||
nodeService = SpringUtil.getBean(NodeService.class);
|
||||
List<NodeModel> list = nodeService.list();
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
try {
|
||||
List<sun.jvmstat.monitor.MonitoredVm> monitoredVms = JvmUtil.listMainClass(AGENT_MAIN_CLASS);
|
||||
monitoredVms.forEach(monitoredVm -> {
|
||||
sun.jvmstat.monitor.VmIdentifier vmIdentifier = monitoredVm.getVmIdentifier();
|
||||
findPid(vmIdentifier.getUserInfo());
|
||||
});
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.getLog().error("自动添加本机节点错误", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void findPid(String pid) {
|
||||
File file = ConfigBean.getInstance().getApplicationJpomInfo(Type.Agent);
|
||||
if (!file.exists() || file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
// 比较进程id
|
||||
String json = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
|
||||
JpomManifest jpomManifest = JSONObject.parseObject(json, JpomManifest.class);
|
||||
if (!pid.equals(String.valueOf(jpomManifest.getPid()))) {
|
||||
return;
|
||||
}
|
||||
// 判断自动授权文件是否存在
|
||||
String path = ConfigBean.getInstance().getAgentAutoAuthorizeFile(jpomManifest.getDataPath());
|
||||
if (!FileUtil.exist(path)) {
|
||||
return;
|
||||
}
|
||||
json = FileUtil.readString(path, CharsetUtil.CHARSET_UTF_8);
|
||||
AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
|
||||
// 判断授权信息
|
||||
//
|
||||
NodeModel nodeModel = new NodeModel();
|
||||
nodeModel.setUrl(StrUtil.format("127.0.0.1:{}", jpomManifest.getPort()));
|
||||
nodeModel.setName("本机");
|
||||
nodeModel.setId("localhost");
|
||||
//
|
||||
nodeModel.setLoginPwd(autoUser.getAgentPwd());
|
||||
nodeModel.setLoginName(autoUser.getAgentName());
|
||||
//
|
||||
nodeModel.setOpenStatus(true);
|
||||
nodeService.addItem(nodeModel);
|
||||
Console.log("自动添加本机节点成功:" + nodeModel.getId());
|
||||
}
|
||||
private static void findPid(String pid) {
|
||||
File file = ConfigBean.getInstance().getApplicationJpomInfo(Type.Agent);
|
||||
if (!file.exists() || file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
// 比较进程id
|
||||
String json = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
|
||||
JpomManifest jpomManifest = JSONObject.parseObject(json, JpomManifest.class);
|
||||
if (!pid.equals(String.valueOf(jpomManifest.getPid()))) {
|
||||
return;
|
||||
}
|
||||
// 判断自动授权文件是否存在
|
||||
String path = ConfigBean.getInstance().getAgentAutoAuthorizeFile(jpomManifest.getDataPath());
|
||||
if (!FileUtil.exist(path)) {
|
||||
return;
|
||||
}
|
||||
json = FileUtil.readString(path, CharsetUtil.CHARSET_UTF_8);
|
||||
AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
|
||||
// 判断授权信息
|
||||
//
|
||||
NodeModel nodeModel = new NodeModel();
|
||||
nodeModel.setUrl(StrUtil.format("127.0.0.1:{}", jpomManifest.getPort()));
|
||||
nodeModel.setName("本机");
|
||||
nodeModel.setId("localhost");
|
||||
//
|
||||
nodeModel.setLoginPwd(autoUser.getAgentPwd());
|
||||
nodeModel.setLoginName(autoUser.getAgentName());
|
||||
//
|
||||
nodeModel.setOpenStatus(true);
|
||||
nodeService.addItem(nodeModel);
|
||||
Console.log("自动添加本机节点成功:" + nodeModel.getId());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user