Search in sources :

Example 1 with AbstractProjectCommander

use of io.jpom.common.commander.AbstractProjectCommander 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 AbstractProjectCommander

use of io.jpom.common.commander.AbstractProjectCommander in project Jpom by dromara.

the class ConsoleService method execCommand.

/**
 * 执行shell命令
 *
 * @param consoleCommandOp     执行的操作
 * @param nodeProjectInfoModel 项目信息
 * @param copyItem             副本信息
 * @return 执行结果
 * @throws Exception 异常
 */
public String execCommand(ConsoleCommandOp consoleCommandOp, NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem copyItem) throws Exception {
    String result;
    AbstractProjectCommander abstractProjectCommander = AbstractProjectCommander.getInstance();
    // 执行命令
    switch(consoleCommandOp) {
        case restart:
            result = abstractProjectCommander.restart(nodeProjectInfoModel, copyItem);
            break;
        case start:
            result = abstractProjectCommander.start(nodeProjectInfoModel, copyItem);
            break;
        case stop:
            result = abstractProjectCommander.stop(nodeProjectInfoModel, copyItem);
            break;
        case status:
            {
                result = abstractProjectCommander.status(nodeProjectInfoModel, copyItem);
                break;
            }
        case top:
        case showlog:
        default:
            throw new IllegalArgumentException(consoleCommandOp + " error");
    }
    // 通知日志刷新
    if (consoleCommandOp == ConsoleCommandOp.start || consoleCommandOp == ConsoleCommandOp.restart) {
        // 修改 run lib 使用情况
        NodeProjectInfoModel modify = projectInfoService.getItem(nodeProjectInfoModel.getId());
        // 
        if (copyItem != null) {
            NodeProjectInfoModel.JavaCopyItem copyItem1 = modify.findCopyItem(copyItem.getId());
            copyItem1.setModifyTime(DateUtil.now());
        }
        modify.setRunLibDesc(nodeProjectInfoModel.getUseLibDesc());
        try {
            projectInfoService.updateItem(modify);
        } catch (Exception ignored) {
        }
    }
    return result;
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) AbstractProjectCommander(io.jpom.common.commander.AbstractProjectCommander)

Aggregations

AbstractProjectCommander (io.jpom.common.commander.AbstractProjectCommander)2 NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)2 PreLoadMethod (cn.jiangzeyin.common.PreLoadMethod)1 ProjectInfoService (io.jpom.service.manage.ProjectInfoService)1