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());
}
}
});
}
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;
}
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);
}
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);
}
}
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);
}
}
Aggregations