use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class AutoImportLocalNode method findPid.
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.setProtocol("http");
//
nodeModel.setLoginPwd(autoUser.getAgentPwd());
nodeModel.setLoginName(autoUser.getAgentName());
//
nodeModel.setOpenStatus(1);
nodeService.insertNotFill(nodeModel);
Console.log("Automatically add native node successfully:" + nodeModel.getId());
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class BaseProxyHandler method init.
/**
* 连接成功 初始化
*
* @param session 会话
* @param attributes 属性
* @throws URISyntaxException 异常
* @throws IOException IO
*/
protected void init(WebSocketSession session, Map<String, Object> attributes) throws URISyntaxException, IOException {
boolean init = (boolean) attributes.getOrDefault("init", false);
if (init) {
return;
}
NodeModel nodeModel = (NodeModel) attributes.get("nodeInfo");
UserModel userInfo = (UserModel) attributes.get("userInfo");
if (nodeModel != null) {
Object[] parameters = this.getParameters(attributes);
String url = NodeForward.getSocketUrl(nodeModel, nodeUrl, userInfo, parameters);
// 连接节点
ProxySession proxySession = new ProxySession(url, session);
session.getAttributes().put("proxySession", proxySession);
}
attributes.put("init", true);
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class MonitorItem method reqNodeStatus.
/**
* 检查节点节点对信息
*
* @param nodeModel 节点
* @param projects 项目
* @return true 所有项目都正常
*/
private boolean reqNodeStatus(NodeModel nodeModel, List<String> projects) {
if (projects == null || projects.isEmpty()) {
return true;
}
List<Boolean> collect = projects.stream().map(id -> {
//
String title;
String context;
try {
// 查询项目运行状态
JsonMessage<JSONObject> jsonMessage = NodeForward.requestBySys(nodeModel, NodeUrl.Manage_GetProjectStatus, "id", id, "getCopy", true);
if (jsonMessage.getCode() == HttpStatus.HTTP_OK) {
JSONObject jsonObject = jsonMessage.getData();
int pid = jsonObject.getIntValue("pId");
boolean runStatus = this.checkNotify(monitorModel, nodeModel, id, null, pid > 0);
// 检查副本
List<Boolean> booleanList = null;
JSONArray copys = jsonObject.getJSONArray("copys");
if (CollUtil.isNotEmpty(copys)) {
booleanList = copys.stream().map(o -> {
JSONObject jsonObject1 = (JSONObject) o;
String copyId = jsonObject1.getString("copyId");
boolean status = jsonObject1.getBooleanValue("status");
return MonitorItem.this.checkNotify(monitorModel, nodeModel, id, copyId, status);
}).filter(aBoolean -> !aBoolean).collect(Collectors.toList());
}
return runStatus && CollUtil.isEmpty(booleanList);
} else {
title = StrUtil.format("【{}】节点的状态码异常:{}", nodeModel.getName(), jsonMessage.getCode());
context = jsonMessage.toString();
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("监控 {} 节点异常 {}", nodeModel.getName(), e.getMessage());
//
title = StrUtil.format("【{}】节点的运行状态异常", nodeModel.getName());
context = ExceptionUtil.stacktraceToString(e);
}
// 获取上次状态
boolean pre = this.getPreStatus(monitorModel.getId(), nodeModel.getId(), id);
if (pre) {
// 上次正常
MonitorNotifyLog monitorNotifyLog = new MonitorNotifyLog();
monitorNotifyLog.setStatus(false);
monitorNotifyLog.setTitle(title);
monitorNotifyLog.setContent(context);
monitorNotifyLog.setCreateTime(System.currentTimeMillis());
monitorNotifyLog.setNodeId(nodeModel.getId());
monitorNotifyLog.setProjectId(id);
monitorNotifyLog.setMonitorId(monitorModel.getId());
//
this.notifyMsg(nodeModel, monitorNotifyLog);
}
return false;
}).filter(aBoolean -> !aBoolean).collect(Collectors.toList());
return CollUtil.isEmpty(collect);
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeStatService method checkList.
private void checkList(List<NodeModel> nodeModels) {
if (CollUtil.isEmpty(nodeModels)) {
return;
}
nodeModels.forEach(nodeModel -> {
//
nodeModel.setName(nodeModel.getUrl());
List<NodeModel> modelList = this.getListByUrl(nodeModel.getUrl());
boolean match = modelList.stream().allMatch(NodeModel::isOpenStatus);
if (!match) {
// 节点都关闭
try {
BaseServerController.resetInfo(UserModel.EMPTY);
this.save(modelList, 4, "节点禁用中");
} finally {
BaseServerController.removeEmpty();
}
return;
}
nodeModel.setOpenStatus(1);
nodeModel.setTimeOut(5);
//
ThreadUtil.execute(() -> {
try {
BaseServerController.resetInfo(UserModel.EMPTY);
JSONObject nodeTopInfo = this.getNodeTopInfo(nodeModel);
//
long timeMillis = SystemClock.now();
JsonMessage<Object> jsonMessage = NodeForward.requestBySys(nodeModel, NodeUrl.Status, "nodeId", nodeModel.getId());
int networkTime = (int) (System.currentTimeMillis() - timeMillis);
JSONObject jsonObject;
if (jsonMessage.getCode() == 200) {
jsonObject = jsonMessage.getData(JSONObject.class);
} else {
// 状态码错
jsonObject = new JSONObject();
jsonObject.put("status", 3);
jsonObject.put("failureMsg", jsonMessage.toString());
}
jsonObject.put("networkTime", networkTime);
if (nodeTopInfo != null) {
nodeTopInfo.put("networkTime", networkTime);
}
this.save(modelList, nodeTopInfo, jsonObject);
} catch (AuthorizeException agentException) {
this.save(modelList, 2, agentException.getMessage());
} catch (Exception e) {
this.save(modelList, 1, e.getMessage());
DefaultSystemLog.getLog().error("获取节点监控信息失败", e);
} finally {
BaseServerController.removeEmpty();
}
});
});
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class MonitorItem method execute.
@Override
public void execute() {
// 重新查询
this.monitorModel = monitorService.getByKey(monitorId);
List<MonitorModel.NodeProject> nodeProjects = monitorModel.projects();
//
List<Boolean> collect = nodeProjects.stream().map(nodeProject -> {
String nodeId = nodeProject.getNode();
NodeModel nodeModel = nodeService.getByKey(nodeId);
if (nodeModel == null) {
return true;
}
return this.reqNodeStatus(nodeModel, nodeProject.getProjects());
}).filter(aBoolean -> !aBoolean).collect(Collectors.toList());
boolean allRun = CollUtil.isEmpty(collect);
// 报警状态
monitorService.setAlarm(monitorModel.getId(), !allRun);
}
Aggregations