Search in sources :

Example 31 with NodeProjectInfoModel

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

the class LogBackController method logSize.

@RequestMapping(value = "logSize", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String logSize(String id, String copyId) {
    NodeProjectInfoModel nodeProjectInfoModel = getProjectInfoModel();
    JSONObject jsonObject = new JSONObject();
    // 
    NodeProjectInfoModel.JavaCopyItem copyItem = nodeProjectInfoModel.findCopyItem(copyId);
    // 获取日志备份路径
    File logBack = copyItem == null ? nodeProjectInfoModel.getLogBack() : nodeProjectInfoModel.getLogBack(copyItem);
    boolean logBackBool = logBack.exists() && logBack.isDirectory();
    jsonObject.put("logBack", logBackBool);
    String info = projectInfoService.getLogSize(nodeProjectInfoModel, copyItem);
    jsonObject.put("logSize", info);
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with NodeProjectInfoModel

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

the class LogBackController method console.

@RequestMapping(value = "logBack", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String console(String copyId) {
    // 查询项目路径
    NodeProjectInfoModel pim = getProjectInfoModel();
    NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId);
    JSONObject jsonObject = new JSONObject();
    File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem);
    if (logBack.exists() && logBack.isDirectory()) {
        File[] filesAll = logBack.listFiles();
        if (filesAll != null) {
            JSONArray jsonArray = FileUtils.parseInfo(filesAll, true, null);
            jsonObject.put("array", jsonArray);
        }
    }
    jsonObject.put("id", pim.getId());
    jsonObject.put("logPath", copyItem == null ? pim.getLog() : pim.getLog(copyItem));
    jsonObject.put("logBackPath", logBack.getAbsolutePath());
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with NodeProjectInfoModel

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

the class ProjectStatusController method restart.

@RequestMapping(value = "restart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String restart(@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.restart, 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 34 with NodeProjectInfoModel

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

the class AgentWebSocketConsoleHandle method onOpen.

@OnOpen
public void onOpen(Session session) {
    try {
        if (super.checkAuthorize(session)) {
            return;
        }
        String projectId = super.getParameters(session, "projectId");
        String copyId = super.getParameters(session, "copyId");
        // 判断项目
        if (!JpomApplication.SYSTEM_ID.equals(projectId)) {
            if (projectInfoService == null) {
                projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
            }
            NodeProjectInfoModel nodeProjectInfoModel = this.checkProject(projectId, copyId, session);
            if (nodeProjectInfoModel == null) {
                return;
            }
            // 
            SocketSessionUtil.send(session, "连接成功:" + nodeProjectInfoModel.getName());
        }
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("socket 错误", e);
        try {
            SocketSessionUtil.send(session, JsonMessage.getString(500, "系统错误!"));
            session.close();
        } catch (IOException e1) {
            DefaultSystemLog.getLog().error(e1.getMessage(), e1);
        }
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) ProjectInfoService(io.jpom.service.manage.ProjectInfoService) IOException(java.io.IOException) IOException(java.io.IOException)

Example 35 with NodeProjectInfoModel

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

the class AgentWebSocketConsoleHandle method onMessage.

@OnMessage
public void onMessage(String message, Session session) throws Exception {
    JSONObject json = JSONObject.parseObject(message);
    String op = json.getString("op");
    ConsoleCommandOp consoleCommandOp = ConsoleCommandOp.valueOf(op);
    if (silentMsg(consoleCommandOp, session)) {
        return;
    }
    String projectId = json.getString("projectId");
    String copyId = json.getString("copyId");
    NodeProjectInfoModel nodeProjectInfoModel = this.checkProject(projectId, copyId, session);
    if (nodeProjectInfoModel == null) {
        return;
    }
    runMsg(consoleCommandOp, session, nodeProjectInfoModel, copyId, json);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel)

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