Search in sources :

Example 1 with NodeProjectInfoModel

use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.

the class AutoStartProject method start.

@PreLoadMethod
private static void start() {
    ProjectInfoService projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
    List<NodeProjectInfoModel> list = projectInfoService.list();
    if (CollUtil.isEmpty(list)) {
        return;
    }
    list = list.stream().filter(nodeProjectInfoModel -> nodeProjectInfoModel.getAutoStart() != null && nodeProjectInfoModel.getAutoStart()).collect(Collectors.toList());
    List<NodeProjectInfoModel> finalList = list;
    ThreadUtil.execute(() -> {
        AbstractProjectCommander instance = AbstractProjectCommander.getInstance();
        for (NodeProjectInfoModel nodeProjectInfoModel : finalList) {
            try {
                if (!instance.isRun(nodeProjectInfoModel, null)) {
                    instance.start(nodeProjectInfoModel, null);
                }
                List<NodeProjectInfoModel.JavaCopyItem> javaCopyItemList = nodeProjectInfoModel.getJavaCopyItemList();
                if (javaCopyItemList != null) {
                    for (NodeProjectInfoModel.JavaCopyItem javaCopyItem : javaCopyItemList) {
                        if (!instance.isRun(nodeProjectInfoModel, javaCopyItem)) {
                            instance.start(nodeProjectInfoModel, javaCopyItem);
                        }
                    }
                }
            } catch (Exception e) {
                DefaultSystemLog.getLog().warn("自动启动项目失败:{} {}", nodeProjectInfoModel.getId(), e.getMessage());
            }
        }
    });
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) ProjectInfoService(io.jpom.service.manage.ProjectInfoService) AbstractProjectCommander(io.jpom.common.commander.AbstractProjectCommander) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Example 2 with NodeProjectInfoModel

use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.

the class AgentWebSocketConsoleHandle method checkProject.

private NodeProjectInfoModel checkProject(String projectId, String copyId, Session session) throws IOException {
    NodeProjectInfoModel nodeProjectInfoModel = projectInfoService.getItem(projectId);
    if (nodeProjectInfoModel == null) {
        SocketSessionUtil.send(session, "没有对应项目:" + projectId);
        session.close();
        return null;
    }
    // 判断副本集
    if (StrUtil.isNotEmpty(copyId)) {
        NodeProjectInfoModel.JavaCopyItem copyItem = nodeProjectInfoModel.findCopyItem(copyId);
        if (copyItem == null) {
            SocketSessionUtil.send(session, "获取项目信息错误,没有对应副本:" + copyId);
            session.close();
            return null;
        }
    }
    return nodeProjectInfoModel;
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel)

Example 3 with NodeProjectInfoModel

use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.

the class ProjectStatusController method getProjectPort.

/**
 * 获取项目的运行端口
 *
 * @param id      项目id
 * @param copyIds 副本 ids ["aa","ss"]
 * @return obj
 */
@RequestMapping(value = "getProjectCopyPort", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getProjectPort(String id, String copyIds) {
    if (StrUtil.isEmpty(copyIds) || StrUtil.isEmpty(id)) {
        return JsonMessage.getString(400, "");
    }
    NodeProjectInfoModel nodeProjectInfoModel = getProjectInfoModel();
    JSONArray jsonArray = JSONArray.parseArray(copyIds);
    JSONObject jsonObject = new JSONObject();
    JSONObject itemObj;
    for (Object object : jsonArray) {
        String item = object.toString();
        NodeProjectInfoModel.JavaCopyItem copyItem = nodeProjectInfoModel.findCopyItem(item);
        int pid;
        try {
            pid = AbstractProjectCommander.getInstance().getPid(nodeProjectInfoModel, copyItem);
            if (pid <= 0) {
                Assert.state(JvmUtil.jpsNormal, "当前服务器 jps 命令异常,请检查 jdk 是否完整,以及 java 环境变量是否配置正确");
                continue;
            }
        } catch (Exception e) {
            DefaultSystemLog.getLog().error("获取端口错误", e);
            continue;
        }
        itemObj = new JSONObject();
        String port = AbstractProjectCommander.getInstance().getMainPort(pid);
        itemObj.put("port", port);
        itemObj.put("pid", pid);
        jsonObject.put(item, itemObj);
    }
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with NodeProjectInfoModel

use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.

the class ProjectStatusController method stop.

@RequestMapping(value = "stop", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String stop(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确") String id, String copyId) {
    NodeProjectInfoModel item = projectInfoService.getItem(id);
    Assert.notNull(item, "没有找到对应的项目");
    NodeProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(copyId);
    String result;
    try {
        result = consoleService.execCommand(ConsoleCommandOp.stop, item, copyItem);
        boolean status = AbstractProjectCommander.getInstance().isRun(item, copyItem);
        if (!status) {
            return JsonMessage.getString(200, result);
        }
        return JsonMessage.getString(201, "关闭项目失败:" + result);
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("获取项目pid 失败", e);
        result = "error:" + e.getMessage();
        return JsonMessage.getString(500, "关闭项目异常:" + result);
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NodeProjectInfoModel

use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.

the class ProjectStatusController method start.

@RequestMapping(value = "start", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String start(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确") String id, String copyId) {
    NodeProjectInfoModel item = projectInfoService.getItem(id);
    Assert.notNull(item, "没有找到对应的项目");
    NodeProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(copyId);
    String result;
    try {
        result = consoleService.execCommand(ConsoleCommandOp.start, item, copyItem);
        boolean status = AbstractProjectCommander.getInstance().isRun(item, copyItem);
        if (status) {
            return JsonMessage.getString(200, result);
        }
        return JsonMessage.getString(201, "启动项目失败:" + result);
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("获取项目pid 失败", e);
        result = "error:" + e.getMessage();
        return JsonMessage.getString(500, "启动项目异常:" + result);
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)40 File (java.io.File)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 JSONObject (com.alibaba.fastjson.JSONObject)11 JSONArray (com.alibaba.fastjson.JSONArray)7 AgentWhitelist (io.jpom.model.data.AgentWhitelist)6 AbstractProjectCommander (io.jpom.common.commander.AbstractProjectCommander)5 Charset (java.nio.charset.Charset)5 DiffFileVo (io.jpom.controller.manage.vo.DiffFileVo)4 ConsoleService (io.jpom.service.manage.ConsoleService)4 CollStreamUtil (cn.hutool.core.collection.CollStreamUtil)3 CollUtil (cn.hutool.core.collection.CollUtil)3 Convert (cn.hutool.core.convert.Convert)3 FileUtil (cn.hutool.core.io.FileUtil)3 ThreadUtil (cn.hutool.core.thread.ThreadUtil)3 ArrayUtil (cn.hutool.core.util.ArrayUtil)3 BooleanUtil (cn.hutool.core.util.BooleanUtil)3 StrUtil (cn.hutool.core.util.StrUtil)3 SecureUtil (cn.hutool.crypto.SecureUtil)3 ServletUtil (cn.hutool.extra.servlet.ServletUtil)3