Search in sources :

Example 6 with NodeService

use of io.jpom.service.node.NodeService 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 7 with NodeService

use of io.jpom.service.node.NodeService in project Jpom by dromara.

the class LoadJsonConfigToDb method loadNodeInfo.

public void loadNodeInfo() {
    File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
    // 读取 node 文件内容
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.NODE);
    if (!FileUtil.exist(file)) {
        return;
    }
    try {
        JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
        JSONArray jsonArray = JsonFileUtil.formatToArray((JSONObject) json);
        List<NodeModel> nodeModels = jsonArray.toJavaList(NodeModel.class);
        if (nodeModels == null) {
            return;
        }
        nodeModels = nodeModels.stream().peek(nodeModel -> {
            // 
            nodeModel.setProtocol(StrUtil.emptyToDefault(nodeModel.getProtocol(), "http"));
        }).collect(Collectors.toList());
        NodeService nodeService = SpringUtil.getBean(NodeService.class);
        nodeService.insert(nodeModels);
        // 将 json 文件转移到备份目录
        FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
        DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("load node error ", e);
    }
}
Also used : NodeService(io.jpom.service.node.NodeService) JSONArray(com.alibaba.fastjson.JSONArray) JSON(com.alibaba.fastjson.JSON) File(java.io.File)

Example 8 with NodeService

use of io.jpom.service.node.NodeService in project Jpom by dromara.

the class CheckMonitor method init.

@PreLoadMethod
private static void init() {
    // 缓存检测调度
    CronUtils.upsert("cache_manger_schedule", "0 0/10 * * * ?", () -> {
        BuildUtil.reloadCacheSize();
        ConfigBean.getInstance().dataSize();
    });
    // 开启版本检测调度
    CronUtils.upsert("system_monitor", "0 0 0,12 * * ?", () -> {
        try {
            BackupInfoService backupInfoService = SpringUtil.getBean(BackupInfoService.class);
            backupInfoService.checkAutoBackup();
            // 
            RemoteVersion.loadRemoteInfo();
        } catch (Exception e) {
            DefaultSystemLog.getLog().error("系统调度执行出现错误", e);
        }
    });
    // 拉取 脚本模版日志
    CronUtils.upsert("pull_script_log", "0 0/1 * * * ?", () -> {
        NodeService nodeService = SpringUtil.getBean(NodeService.class);
        NodeScriptServer nodeScriptServer = SpringUtil.getBean(NodeScriptServer.class);
        List<String> nodeIds = nodeScriptServer.hasScriptNode();
        if (nodeIds == null) {
            return;
        }
        for (String nodeId : nodeIds) {
            NodeModel nodeModel = nodeService.getByKey(nodeId);
            if (nodeModel == null) {
                continue;
            }
            ThreadUtil.execute(() -> CheckMonitor.pullScriptLogItem(nodeModel));
        }
    });
    // 异步加载
    CheckMonitor.asyncLoad();
}
Also used : NodeModel(io.jpom.model.data.NodeModel) BackupInfoService(io.jpom.service.dblog.BackupInfoService) NodeScriptServer(io.jpom.service.node.script.NodeScriptServer) NodeService(io.jpom.service.node.NodeService) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Aggregations

NodeService (io.jpom.service.node.NodeService)8 NodeModel (io.jpom.model.data.NodeModel)6 File (java.io.File)2 UrlQuery (cn.hutool.core.net.url.UrlQuery)1 PreLoadMethod (cn.jiangzeyin.common.PreLoadMethod)1 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AfterOpt (io.jpom.model.AfterOpt)1 BaseNodeModel (io.jpom.model.BaseNodeModel)1 BaseWorkspaceModel (io.jpom.model.BaseWorkspaceModel)1 BackupInfoService (io.jpom.service.dblog.BackupInfoService)1 TableName (io.jpom.service.h2db.TableName)1 NodeScriptServer (io.jpom.service.node.script.NodeScriptServer)1 AgentException (io.jpom.system.AgentException)1 JpomRuntimeException (io.jpom.system.JpomRuntimeException)1