use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeStatService method save.
/**
* 报错结果
*
* @param modelList 节点
* @param systemMonitor 系统监控
* @param statusData 状态数据
*/
private void save(List<NodeModel> modelList, JSONObject systemMonitor, JSONObject statusData) {
this.saveSystemMonitor(modelList, systemMonitor);
//
for (NodeModel nodeModel : modelList) {
NodeStatModel nodeStatModel = this.create(nodeModel);
if (nodeModel.isOpenStatus()) {
if (systemMonitor != null) {
nodeStatModel.setOccupyMemory(ObjectUtil.defaultIfNull(systemMonitor.getDouble("memory"), -1D));
nodeStatModel.setOccupyMemoryUsed(ObjectUtil.defaultIfNull(systemMonitor.getDouble("memoryUsed"), -1D));
nodeStatModel.setOccupyDisk(ObjectUtil.defaultIfNull(systemMonitor.getDouble("disk"), -1D));
nodeStatModel.setOccupyCpu(ObjectUtil.defaultIfNull(systemMonitor.getDouble("cpu"), -1D));
}
//
nodeStatModel.setNetworkTime(statusData.getIntValue("networkTime"));
nodeStatModel.setJpomVersion(statusData.getString("jpomVersion"));
nodeStatModel.setOsName(statusData.getString("osName"));
String runTime = statusData.getString("runTime");
String runTimeLong = statusData.getString("runTimeLong");
// 兼容数据
nodeStatModel.setUpTimeStr(StrUtil.emptyToDefault(runTimeLong, runTime));
nodeStatModel.setFailureMsg(StrUtil.emptyToDefault(statusData.getString("failureMsg"), StrUtil.EMPTY));
//
Integer statusInteger = statusData.getInteger("status");
if (statusInteger != null) {
nodeStatModel.setStatus(statusInteger);
} else {
nodeStatModel.setStatus(0);
}
} else {
nodeStatModel.setStatus(4);
nodeStatModel.setFailureMsg("节点禁用中");
}
this.upsert(nodeStatModel);
}
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeScriptExecuteLogServer method executeClearImpl.
@Override
protected void executeClearImpl(int h2DbLogStorageCount) {
super.autoLoopClear("createTimeMillis", h2DbLogStorageCount, null, executeLogModel -> {
try {
NodeModel nodeModel = nodeService.getByKey(executeLogModel.getNodeId());
JsonMessage<Object> jsonMessage = NodeForward.requestBySys(nodeModel, NodeUrl.SCRIPT_DEL_LOG, "id", executeLogModel.getScriptId(), "executeId", executeLogModel.getId());
if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
log.warn("{} {} {}", executeLogModel.getNodeId(), executeLogModel.getScriptName(), jsonMessage);
return false;
}
return true;
} catch (Exception e) {
DefaultSystemLog.getLog().error("自动清除数据错误 {} {}", executeLogModel.getNodeId(), executeLogModel.getScriptName(), e);
return false;
}
});
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeScriptExecuteLogServer method syncExecuteNodeInc.
/**
* 同步执行 同步节点信息(增量)
*
* @param nodeModel 节点信息
* @return json
*/
public Collection<String> syncExecuteNodeInc(NodeModel nodeModel) {
String nodeModelName = nodeModel.getName();
if (!nodeModel.isOpenStatus()) {
DefaultSystemLog.getLog().debug("{} 节点未启用", nodeModelName);
return null;
}
try {
JSONArray jsonArray = this.getLitDataArray(nodeModel);
if (CollUtil.isEmpty(jsonArray)) {
//
return null;
}
//
List<ScriptExecuteLogCacheModel> models = jsonArray.toJavaList(this.tClass).stream().filter(item -> {
// 检查对应的工作空间 是否存在
return workspaceService.exists(new WorkspaceModel(item.getWorkspaceId()));
}).filter(item -> {
// 避免重复同步
return StrUtil.equals(nodeModel.getWorkspaceId(), item.getWorkspaceId());
}).collect(Collectors.toList());
// 设置 临时缓存,便于放行检查
BaseServerController.resetInfo(UserModel.EMPTY);
//
models.forEach(NodeScriptExecuteLogServer.super::upsert);
String format = StrUtil.format("{} 节点拉取到 {} 个执行记录,更新 {} 个执行记录", nodeModelName, CollUtil.size(jsonArray), CollUtil.size(models));
DefaultSystemLog.getLog().debug(format);
return models.stream().map(BaseDbModel::getId).collect(Collectors.toList());
} catch (Exception e) {
this.checkException(e, nodeModelName);
return null;
} finally {
BaseServerController.removeEmpty();
}
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class ServerWebSocketInterceptor method checkNode.
private boolean checkNode(HttpServletRequest httpServletRequest, Map<String, Object> attributes, UserModel userModel) {
// 验证 node 权限
String nodeId = httpServletRequest.getParameter("nodeId");
if (!JpomApplication.SYSTEM_ID.equals(nodeId)) {
NodeService nodeService = SpringUtil.getBean(NodeService.class);
NodeModel nodeModel = nodeService.getByKey(nodeId, userModel);
if (nodeModel == null) {
return false;
}
//
attributes.put("nodeInfo", nodeModel);
}
return true;
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeScriptHandler method createLog.
/**
* 创建执行日志
*
* @param attributes 参数属性
* @return 执行ID
*/
private String createLog(Map<String, Object> attributes) {
NodeModel nodeInfo = (NodeModel) attributes.get("nodeInfo");
UserModel userModel = (UserModel) attributes.get("userInfo");
ScriptCacheModel dataItem = (ScriptCacheModel) attributes.get("dataItem");
NodeScriptExecuteLogServer logServer = SpringUtil.getBean(NodeScriptExecuteLogServer.class);
NodeScriptServer nodeScriptServer = SpringUtil.getBean(NodeScriptServer.class);
//
try {
BaseServerController.resetInfo(userModel);
//
ScriptCacheModel scriptCacheModel = new ScriptCacheModel();
scriptCacheModel.setId(dataItem.getId());
scriptCacheModel.setLastRunUser(userModel.getId());
nodeScriptServer.update(scriptCacheModel);
//
ScriptExecuteLogCacheModel scriptExecuteLogCacheModel = new ScriptExecuteLogCacheModel();
scriptExecuteLogCacheModel.setScriptId(dataItem.getScriptId());
scriptExecuteLogCacheModel.setNodeId(nodeInfo.getId());
scriptExecuteLogCacheModel.setScriptName(dataItem.getName());
scriptExecuteLogCacheModel.setTriggerExecType(0);
scriptExecuteLogCacheModel.setWorkspaceId(nodeInfo.getWorkspaceId());
logServer.insert(scriptExecuteLogCacheModel);
return scriptExecuteLogCacheModel.getId();
} finally {
BaseServerController.removeAll();
}
}
Aggregations