Search in sources :

Example 1 with ProjectInfoService

use of io.jpom.service.manage.ProjectInfoService 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 ProjectInfoService

use of io.jpom.service.manage.ProjectInfoService in project Jpom by dromara.

the class AbstractProjectCommander method getJpomNameByPid.

/**
 * 根据指定进程id获取Jpom 名称
 *
 * @param pid 进程id
 * @return false 不是来自Jpom
 * @throws IOException 异常
 */
public String getJpomNameByPid(int pid) throws IOException {
    String name = PID_JPOM_NAME.get(pid);
    if (name != null) {
        return name;
    }
    String virtualMachine = JvmUtil.getPidJpsInfoInfo(pid);
    if (virtualMachine == null) {
        return StrUtil.DASHED;
    }
    String tag = JvmUtil.parseCommandJpomTag(virtualMachine);
    DefaultSystemLog.getLog().debug("getJpomNameByPid pid: {} {} {}", pid, tag, virtualMachine);
    ProjectInfoService projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
    NodeProjectInfoModel item = projectInfoService.getItem(tag);
    if (item == null) {
        return StrUtil.DASHED;
    }
    name = item.getName();
    if (name != null) {
        PID_JPOM_NAME.put(pid, name);
        return name;
    }
    return StrUtil.DASHED;
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) ProjectInfoService(io.jpom.service.manage.ProjectInfoService)

Example 3 with ProjectInfoService

use of io.jpom.service.manage.ProjectInfoService 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)

Aggregations

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