Search in sources :

Example 46 with NodeModel

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);
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeStatModel(io.jpom.model.stat.NodeStatModel)

Example 47 with NodeModel

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;
        }
    });
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject)

Example 48 with NodeModel

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();
    }
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) NodeForward(io.jpom.common.forward.NodeForward) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) Collection(java.util.Collection) NodeModel(io.jpom.model.data.NodeModel) BaseNodeService(io.jpom.service.h2db.BaseNodeService) Collectors(java.util.stream.Collectors) NodeUrl(io.jpom.common.forward.NodeUrl) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) NodeService(io.jpom.service.node.NodeService) JSONObject(com.alibaba.fastjson.JSONObject) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel) UserModel(io.jpom.model.data.UserModel) BaseServerController(io.jpom.common.BaseServerController) HttpStatus(cn.hutool.http.HttpStatus) BaseDbModel(io.jpom.model.BaseDbModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) JSONArray(com.alibaba.fastjson.JSONArray) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel)

Example 49 with NodeModel

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;
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeService(io.jpom.service.node.NodeService)

Example 50 with NodeModel

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();
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) NodeScriptServer(io.jpom.service.node.script.NodeScriptServer) NodeScriptExecuteLogServer(io.jpom.service.node.script.NodeScriptExecuteLogServer) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel) ScriptCacheModel(io.jpom.model.node.ScriptCacheModel)

Aggregations

NodeModel (io.jpom.model.data.NodeModel)67 JSONObject (com.alibaba.fastjson.JSONObject)29 Feature (io.jpom.permission.Feature)23 MethodFeature (io.jpom.permission.MethodFeature)23 ClassFeature (io.jpom.permission.ClassFeature)22 UserModel (io.jpom.model.data.UserModel)18 StrUtil (cn.hutool.core.util.StrUtil)13 NodeService (io.jpom.service.node.NodeService)13 Collectors (java.util.stream.Collectors)13 CollUtil (cn.hutool.core.collection.CollUtil)12 JsonMessage (cn.jiangzeyin.common.JsonMessage)12 List (java.util.List)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)10 NodeForward (io.jpom.common.forward.NodeForward)9 NodeUrl (io.jpom.common.forward.NodeUrl)9 JSONArray (com.alibaba.fastjson.JSONArray)8 BaseServerController (io.jpom.common.BaseServerController)8 Assert (org.springframework.util.Assert)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8