mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 11:58:01 +08:00
项目新建副本集,方便单机快速运行多个副本
This commit is contained in:
parent
34280947ec
commit
19be43ea09
@ -10,6 +10,8 @@
|
||||
4. 【Agent】 新增[JavaExtDirsCp] 运行模式 (感谢@TXpcmgr(Geiger))
|
||||
5. 【Server】 ssh 连接方式新增私钥证书连接
|
||||
6. 【Server】 ssh文件管理新增解压操作(感谢@TXpcmgr(Geiger)贡献)
|
||||
7. 【Agent】 项目新建副本集,方便单机快速运行多个副本
|
||||
8. 【Server】构建发布后操作支持副本集相关操作
|
||||
|
||||
### 解决BUG、优化功能
|
||||
|
||||
|
@ -52,9 +52,6 @@ public abstract class BaseAgentController extends BaseJpomController {
|
||||
return StrUtil.DASHED;
|
||||
}
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
if (request == null) {
|
||||
return StrUtil.DASHED;
|
||||
}
|
||||
return getUserName(request);
|
||||
}
|
||||
|
||||
|
@ -464,7 +464,7 @@ public abstract class AbstractProjectCommander {
|
||||
* @param result 查询信息
|
||||
* @return int
|
||||
*/
|
||||
protected static int parsePid(String result) {
|
||||
public static int parsePid(String result) {
|
||||
if (result.startsWith(AbstractProjectCommander.RUNNING_TAG)) {
|
||||
return Convert.toInt(result.split(":")[1]);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.jpom.controller.manage;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.PatternPool;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
@ -125,6 +126,7 @@ public class ManageEditProjectController extends BaseAgentController {
|
||||
ProjectInfoModel.JavaCopyItem javaCopyItem = new ProjectInfoModel.JavaCopyItem();
|
||||
javaCopyItem.setId(copyId);
|
||||
javaCopyItem.setParendId(id);
|
||||
javaCopyItem.setModifyTime(DateUtil.now());
|
||||
javaCopyItem.setJvm(StrUtil.emptyToDefault(jvm, StrUtil.EMPTY));
|
||||
javaCopyItem.setArgs(StrUtil.emptyToDefault(args, StrUtil.EMPTY));
|
||||
javaCopyItemList.add(javaCopyItem);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.jpom.controller.manage;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
@ -8,6 +10,9 @@ import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.controller.multipart.MultipartFileBuilder;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import io.jpom.common.BaseAgentController;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.data.ProjectInfoModel;
|
||||
import io.jpom.service.manage.ConsoleService;
|
||||
import io.jpom.socket.ConsoleCommandOp;
|
||||
@ -23,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 项目文件管理
|
||||
@ -112,15 +118,64 @@ public class ProjectFileControl extends BaseAgentController {
|
||||
projectInfoService.updateItem(pim);
|
||||
//
|
||||
String after = getParameter("after");
|
||||
if ("restart".equalsIgnoreCase(after)) {
|
||||
String result = consoleService.execCommand(ConsoleCommandOp.restart, pim, null);
|
||||
return JsonMessage.getString(200, "上传成功并重启:" + result);
|
||||
if (StrUtil.isNotEmpty(after)) {
|
||||
//
|
||||
List<ProjectInfoModel.JavaCopyItem> javaCopyItemList = pim.getJavaCopyItemList();
|
||||
//
|
||||
AfterOpt afterOpt = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(after, AfterOpt.No.getCode()));
|
||||
if ("restart".equalsIgnoreCase(after) || afterOpt == AfterOpt.Restart) {
|
||||
String result = consoleService.execCommand(ConsoleCommandOp.restart, pim, null);
|
||||
// 自动处理副本集
|
||||
if (javaCopyItemList != null) {
|
||||
ThreadUtil.execute(() -> javaCopyItemList.forEach(javaCopyItem -> {
|
||||
try {
|
||||
consoleService.execCommand(ConsoleCommandOp.restart, pim, javaCopyItem);
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.getLog().error("重启副本集失败", e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return JsonMessage.getString(200, "上传成功并重启:" + result);
|
||||
}
|
||||
if (afterOpt == AfterOpt.Order_Restart || afterOpt == AfterOpt.Order_Must_Restart) {
|
||||
boolean restart = this.restart(pim, null, afterOpt);
|
||||
if (javaCopyItemList != null) {
|
||||
ThreadUtil.execute(() -> {
|
||||
// 副本
|
||||
for (ProjectInfoModel.JavaCopyItem javaCopyItem : javaCopyItemList) {
|
||||
if (!this.restart(pim, javaCopyItem, afterOpt)) {
|
||||
return;
|
||||
}
|
||||
// 休眠30秒 等待之前项目正常启动
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(30);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JsonMessage.getString(200, "上传成功");
|
||||
}
|
||||
|
||||
|
||||
private boolean restart(ProjectInfoModel projectInfoModel, ProjectInfoModel.JavaCopyItem javaCopyItem, AfterOpt afterOpt) {
|
||||
try {
|
||||
String result = consoleService.execCommand(ConsoleCommandOp.restart, projectInfoModel, javaCopyItem);
|
||||
int pid = AbstractProjectCommander.parsePid(result);
|
||||
if (pid <= 0) {
|
||||
// 完整重启,不再继续剩余的节点项目
|
||||
return afterOpt != AfterOpt.Order_Must_Restart;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.getLog().error("重复失败", e);
|
||||
// 完整重启,不再继续剩余的节点项目
|
||||
return afterOpt != AfterOpt.Order_Must_Restart;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "deleteFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public String deleteFile(String filename, String type, String levelName) {
|
||||
ProjectInfoModel pim = getProjectInfoModel();
|
||||
|
@ -11,6 +11,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import io.jpom.common.BaseAgentController;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.model.data.ProjectInfoModel;
|
||||
import io.jpom.service.manage.ConsoleService;
|
||||
import io.jpom.socket.ConsoleCommandOp;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -27,6 +29,13 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping(value = "/manage/")
|
||||
public class ProjectStatusController extends BaseAgentController {
|
||||
|
||||
private final ConsoleService consoleService;
|
||||
|
||||
public ProjectStatusController(ConsoleService consoleService) {
|
||||
this.consoleService = consoleService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取项目的进程id
|
||||
*
|
||||
@ -126,16 +135,16 @@ public class ProjectStatusController extends BaseAgentController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "restart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public String restart(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确")) String id, String copyId) {
|
||||
public String restart(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确")) String id) {
|
||||
ProjectInfoModel item = projectInfoService.getItem(id);
|
||||
if (item == null) {
|
||||
return JsonMessage.getString(405, "没有找到对应的项目");
|
||||
}
|
||||
ProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(copyId);
|
||||
ProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(null);
|
||||
String tagId = copyItem == null ? item.getId() : copyItem.getTagId();
|
||||
String result;
|
||||
try {
|
||||
result = AbstractProjectCommander.getInstance().restart(item, copyItem);
|
||||
result = consoleService.execCommand(ConsoleCommandOp.restart, item, copyItem);
|
||||
boolean status = AbstractProjectCommander.getInstance().isRun(tagId);
|
||||
if (status) {
|
||||
return JsonMessage.getString(200, result);
|
||||
|
@ -429,7 +429,7 @@ public class ProjectInfoModel extends BaseModel {
|
||||
int size = javaCopyItemList.size();
|
||||
List<JavaCopyItem> collect = javaCopyItemList.stream().filter(javaCopyItem -> !StrUtil.equals(javaCopyItem.getId(), copyId)).collect(Collectors.toList());
|
||||
if (size - 1 == collect.size()) {
|
||||
this.setJavaCopyItemList(collect);
|
||||
this.javaCopyItemList = collect;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -455,6 +455,8 @@ public class ProjectInfoModel extends BaseModel {
|
||||
*/
|
||||
private String args;
|
||||
|
||||
private String modifyTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -481,6 +483,14 @@ public class ProjectInfoModel extends BaseModel {
|
||||
return StrUtil.format("{}:{}", id, copyId);
|
||||
}
|
||||
|
||||
public String getModifyTime() {
|
||||
return modifyTime;
|
||||
}
|
||||
|
||||
public void setModifyTime(String modifyTime) {
|
||||
this.modifyTime = modifyTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目是否正在运行
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.jpom.service.manage;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.model.data.ProjectInfoModel;
|
||||
import io.jpom.socket.ConsoleCommandOp;
|
||||
@ -55,6 +56,11 @@ public class ConsoleService {
|
||||
if (consoleCommandOp == ConsoleCommandOp.start || consoleCommandOp == ConsoleCommandOp.restart) {
|
||||
// 修改 run lib 使用情况
|
||||
ProjectInfoModel modify = projectInfoService.getItem(projectInfoModel.getId());
|
||||
//
|
||||
if (copyItem != null) {
|
||||
ProjectInfoModel.JavaCopyItem copyItem1 = modify.findCopyItem(copyItem.getId());
|
||||
copyItem1.setModifyTime(DateUtil.now());
|
||||
}
|
||||
modify.setRunLibDesc(projectInfoModel.getUseLibDesc());
|
||||
try {
|
||||
projectInfoService.updateItem(modify);
|
||||
|
42
modules/common/src/main/java/io/jpom/model/AfterOpt.java
Normal file
42
modules/common/src/main/java/io/jpom/model/AfterOpt.java
Normal file
@ -0,0 +1,42 @@
|
||||
package io.jpom.model;
|
||||
|
||||
/**
|
||||
* @author bwcx_jzy
|
||||
* @date 2020/3/21
|
||||
*/
|
||||
public enum AfterOpt implements BaseEnum {
|
||||
/**
|
||||
* 操作
|
||||
*/
|
||||
No(0, "不做任何操作"),
|
||||
/**
|
||||
* 并发执行项目分发
|
||||
*/
|
||||
Restart(1, "并发重启"),
|
||||
/**
|
||||
* 顺序执行项目分发
|
||||
*/
|
||||
Order_Must_Restart(2, "完整顺序重启(有重启失败将结束本次)"),
|
||||
/**
|
||||
* 顺序执行项目分发
|
||||
*/
|
||||
Order_Restart(3, "顺序重启(有重启失败将继续)"),
|
||||
;
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
AfterOpt(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ public class BaseBuildModule extends BaseModel {
|
||||
* 分发后的操作
|
||||
* 仅在项目发布类型生效
|
||||
*
|
||||
* @see io.jpom.model.AfterOpt
|
||||
* @see BuildModel#getAfterOpt()
|
||||
*/
|
||||
private int afterOpt;
|
||||
|
@ -8,6 +8,7 @@ import cn.hutool.http.HttpStatus;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.common.spring.SpringUtil;
|
||||
import com.jcraft.jsch.Session;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.data.BuildModel;
|
||||
import io.jpom.model.data.NodeModel;
|
||||
@ -20,7 +21,6 @@ import io.jpom.service.node.ssh.SshService;
|
||||
import io.jpom.system.JpomRuntimeException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -92,9 +92,9 @@ public class ReleaseManage extends BaseBuild {
|
||||
//
|
||||
this.doOutGiving();
|
||||
} else if (this.baseBuildModule.getReleaseMethod() == BuildModel.ReleaseMethod.Project.getCode()) {
|
||||
BuildModel.AfterOpt afterOpt = BaseEnum.getEnum(BuildModel.AfterOpt.class, this.baseBuildModule.getAfterOpt());
|
||||
AfterOpt afterOpt = BaseEnum.getEnum(AfterOpt.class, this.baseBuildModule.getAfterOpt());
|
||||
if (afterOpt == null) {
|
||||
afterOpt = BuildModel.AfterOpt.No;
|
||||
afterOpt = AfterOpt.No;
|
||||
}
|
||||
this.doProject(afterOpt, this.baseBuildModule.isClearOld());
|
||||
} else if (this.baseBuildModule.getReleaseMethod() == BuildModel.ReleaseMethod.Ssh.getCode()) {
|
||||
@ -126,7 +126,7 @@ public class ReleaseManage extends BaseBuild {
|
||||
this.log("没有找到对应的ssh项:" + releaseMethodDataId);
|
||||
return;
|
||||
}
|
||||
Session session = sshService.getSession(item);
|
||||
Session session = SshService.getSession(item);
|
||||
try (Sftp sftp = new Sftp(session, item.getCharsetT())) {
|
||||
if (this.baseBuildModule.isClearOld() && StrUtil.isNotEmpty(this.baseBuildModule.getReleasePath())) {
|
||||
sftp.delDir(this.baseBuildModule.getReleasePath());
|
||||
@ -189,7 +189,7 @@ public class ReleaseManage extends BaseBuild {
|
||||
*
|
||||
* @param afterOpt 后续操作
|
||||
*/
|
||||
private void doProject(BuildModel.AfterOpt afterOpt, boolean clearOld) {
|
||||
private void doProject(AfterOpt afterOpt, boolean clearOld) {
|
||||
String releaseMethodDataId = this.baseBuildModule.getReleaseMethodDataId();
|
||||
String[] strings = StrUtil.split(releaseMethodDataId, ":");
|
||||
if (strings == null || strings.length != 2) {
|
||||
@ -205,10 +205,10 @@ public class ReleaseManage extends BaseBuild {
|
||||
zipFile = this.resultFile;
|
||||
unZip = false;
|
||||
}
|
||||
JsonMessage jsonMessage = OutGivingRun.fileUpload(zipFile,
|
||||
JsonMessage<String> jsonMessage = OutGivingRun.fileUpload(zipFile,
|
||||
strings[1],
|
||||
unZip,
|
||||
afterOpt != BuildModel.AfterOpt.No,
|
||||
afterOpt,
|
||||
nodeModel, this.userModel, clearOld);
|
||||
if (jsonMessage.getCode() == HttpStatus.HTTP_OK) {
|
||||
this.log("发布项目包成功:" + jsonMessage.toString());
|
||||
@ -219,10 +219,8 @@ public class ReleaseManage extends BaseBuild {
|
||||
|
||||
/**
|
||||
* 分发包
|
||||
*
|
||||
* @throws IOException IO
|
||||
*/
|
||||
private void doOutGiving() throws IOException {
|
||||
private void doOutGiving() {
|
||||
String releaseMethodDataId = this.baseBuildModule.getReleaseMethodDataId();
|
||||
File zipFile = BuildUtil.isDirPackage(this.resultFile);
|
||||
boolean unZip = true;
|
||||
|
@ -14,6 +14,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import io.jpom.build.BuildUtil;
|
||||
import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.interceptor.OptLog;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.data.*;
|
||||
import io.jpom.model.log.UserOperateLogV1;
|
||||
@ -232,7 +233,7 @@ public class BuildListController extends BaseServerController {
|
||||
buildModel.setReleaseMethodDataId(String.format("%s:%s", releaseMethodDataId2Node, releaseMethodDataId2Project));
|
||||
//
|
||||
String afterOpt = getParameter("afterOpt");
|
||||
BuildModel.AfterOpt afterOpt1 = BaseEnum.getEnum(BuildModel.AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
if (afterOpt1 == null) {
|
||||
return JsonMessage.getString(400, "请选择打包后的操作");
|
||||
}
|
||||
@ -278,10 +279,10 @@ public class BuildListController extends BaseServerController {
|
||||
List<NodeModel> nodeModels = nodeService.listAndProject();
|
||||
setAttribute("nodeModels", nodeModels);
|
||||
//
|
||||
JSONArray jsonArray = BaseEnum.toJSONArray(BuildModel.AfterOpt.class);
|
||||
JSONArray jsonArray = BaseEnum.toJSONArray(AfterOpt.class);
|
||||
setAttribute("afterOpt", jsonArray);
|
||||
//
|
||||
JSONArray outAfterOpt = BaseEnum.toJSONArray(OutGivingModel.AfterOpt.class);
|
||||
JSONArray outAfterOpt = BaseEnum.toJSONArray(AfterOpt.class);
|
||||
setAttribute("outAfterOpt", outAfterOpt);
|
||||
//
|
||||
JSONArray repoTypes = BaseEnum.toJSONArray(BuildModel.RepoType.class);
|
||||
|
@ -9,6 +9,7 @@ import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.forward.NodeForward;
|
||||
import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.common.interceptor.OptLog;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.data.NodeModel;
|
||||
import io.jpom.model.data.OutGivingModel;
|
||||
@ -79,7 +80,7 @@ public class OutGivingController extends BaseServerController {
|
||||
String reqId = nodeService.cacheNodeList(nodeModels);
|
||||
setAttribute("reqId", reqId);
|
||||
|
||||
JSONArray afterOpt = BaseEnum.toJSONArray(OutGivingModel.AfterOpt.class);
|
||||
JSONArray afterOpt = BaseEnum.toJSONArray(AfterOpt.class);
|
||||
setAttribute("afterOpt", afterOpt);
|
||||
return "outgiving/edit";
|
||||
}
|
||||
@ -185,7 +186,7 @@ public class OutGivingController extends BaseServerController {
|
||||
outGivingModel.setOutGivingNodeProjectList(outGivingNodeProjects);
|
||||
//
|
||||
String afterOpt = getParameter("afterOpt");
|
||||
OutGivingModel.AfterOpt afterOpt1 = BaseEnum.getEnum(OutGivingModel.AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
if (afterOpt1 == null) {
|
||||
return JsonMessage.getString(400, "请选择分发后的操作");
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.forward.NodeForward;
|
||||
import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.common.interceptor.OptLog;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.data.NodeModel;
|
||||
import io.jpom.model.data.OutGivingModel;
|
||||
@ -96,7 +97,7 @@ public class OutGivingProjectController extends BaseServerController {
|
||||
@Feature(method = MethodFeature.UPLOAD)
|
||||
public String addOutgiving(String id) {
|
||||
|
||||
JSONArray jsonArray = BaseEnum.toJSONArray(OutGivingModel.AfterOpt.class);
|
||||
JSONArray jsonArray = BaseEnum.toJSONArray(AfterOpt.class);
|
||||
setAttribute("afterOpt", jsonArray);
|
||||
//
|
||||
OutGivingModel outGivingModel = outGivingServer.getItem(id);
|
||||
@ -129,7 +130,7 @@ public class OutGivingProjectController extends BaseServerController {
|
||||
return JsonMessage.getString(400, "当前还在分发中,请等待分发结束");
|
||||
}
|
||||
}
|
||||
OutGivingModel.AfterOpt afterOpt1 = BaseEnum.getEnum(OutGivingModel.AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
if (afterOpt1 == null) {
|
||||
return JsonMessage.getString(400, "请选择分发后的操作");
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.forward.NodeForward;
|
||||
import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.common.interceptor.OptLog;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.RunMode;
|
||||
import io.jpom.model.data.*;
|
||||
@ -62,7 +63,7 @@ public class OutGivingProjectEditController extends BaseServerController {
|
||||
JSONArray runModes = (JSONArray) JSONArray.toJSON(RunMode.values());
|
||||
setAttribute("runModes", runModes);
|
||||
//
|
||||
JSONArray afterOpt = BaseEnum.toJSONArray(OutGivingModel.AfterOpt.class);
|
||||
JSONArray afterOpt = BaseEnum.toJSONArray(AfterOpt.class);
|
||||
setAttribute("afterOpt", afterOpt);
|
||||
// 权限
|
||||
List<NodeModel> nodeModels = nodeService.list();
|
||||
@ -311,7 +312,7 @@ public class OutGivingProjectEditController extends BaseServerController {
|
||||
}
|
||||
//
|
||||
String afterOpt = getParameter("afterOpt");
|
||||
OutGivingModel.AfterOpt afterOpt1 = BaseEnum.getEnum(OutGivingModel.AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
|
||||
if (afterOpt1 == null) {
|
||||
return JsonMessage.getString(400, "请选择分发后的操作");
|
||||
}
|
||||
|
@ -225,35 +225,6 @@ public class BuildModel extends BaseBuildModule {
|
||||
}
|
||||
}
|
||||
|
||||
public enum AfterOpt implements BaseEnum {
|
||||
/**
|
||||
* 操作
|
||||
*/
|
||||
No(0, "不做任何操作"),
|
||||
/**
|
||||
* 重启
|
||||
*/
|
||||
Restart(1, "重启"),
|
||||
;
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
AfterOpt(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仓库类型
|
||||
*/
|
||||
|
@ -3,7 +3,6 @@ package io.jpom.model.data;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.BaseModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -141,44 +140,4 @@ public class OutGivingModel extends BaseModel {
|
||||
});
|
||||
return delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分发后的操作
|
||||
*/
|
||||
public enum AfterOpt implements BaseEnum {
|
||||
/**
|
||||
* 操作
|
||||
*/
|
||||
No(0, "不做任何操作"),
|
||||
/**
|
||||
* 并发执行项目分发
|
||||
*/
|
||||
Restart(1, "并发重启"),
|
||||
/**
|
||||
* 顺序执行项目分发
|
||||
*/
|
||||
Order_Must_Restart(2, "完整顺序重启(有节点分发并重启失败将不再进行分发剩余节点)"),
|
||||
/**
|
||||
* 顺序执行项目分发
|
||||
*/
|
||||
Order_Restart(3, "顺序重启(有节点分发并重启失败将继续分发剩余节点)"),
|
||||
;
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
AfterOpt(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import cn.jiangzeyin.common.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.jpom.common.forward.NodeForward;
|
||||
import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.model.AfterOpt;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.data.NodeModel;
|
||||
import io.jpom.model.data.OutGivingModel;
|
||||
@ -37,7 +38,7 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
private OutGivingNodeProject outGivingNodeProject;
|
||||
private NodeModel nodeModel;
|
||||
private File file;
|
||||
private OutGivingModel.AfterOpt afterOpt;
|
||||
private AfterOpt afterOpt;
|
||||
private UserModel userModel;
|
||||
private boolean unzip;
|
||||
private boolean clearOld;
|
||||
@ -62,15 +63,15 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class);
|
||||
OutGivingModel item = outGivingServer.getItem(id);
|
||||
Objects.requireNonNull(item, "不存在分发");
|
||||
OutGivingModel.AfterOpt afterOpt = BaseEnum.getEnum(OutGivingModel.AfterOpt.class, item.getAfterOpt());
|
||||
AfterOpt afterOpt = BaseEnum.getEnum(AfterOpt.class, item.getAfterOpt());
|
||||
if (afterOpt == null) {
|
||||
afterOpt = OutGivingModel.AfterOpt.No;
|
||||
afterOpt = AfterOpt.No;
|
||||
}
|
||||
OutGivingModel.AfterOpt finalAfterOpt = afterOpt;
|
||||
AfterOpt finalAfterOpt = afterOpt;
|
||||
//
|
||||
List<OutGivingNodeProject> outGivingNodeProjects = item.getOutGivingNodeProjectList();
|
||||
// 开启线程
|
||||
if (afterOpt == OutGivingModel.AfterOpt.Order_Restart || afterOpt == OutGivingModel.AfterOpt.Order_Must_Restart) {
|
||||
if (afterOpt == AfterOpt.Order_Restart || afterOpt == AfterOpt.Order_Must_Restart) {
|
||||
ThreadUtil.execute(() -> {
|
||||
boolean cancel = false;
|
||||
for (OutGivingNodeProject outGivingNodeProject : outGivingNodeProjects) {
|
||||
@ -81,7 +82,7 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
OutGivingRun outGivingRun = new OutGivingRun(item, outGivingNodeProject, file, userModel, unzip);
|
||||
OutGivingNodeProject.Status status = outGivingRun.call();
|
||||
if (status != OutGivingNodeProject.Status.Ok) {
|
||||
if (finalAfterOpt == OutGivingModel.AfterOpt.Order_Must_Restart) {
|
||||
if (finalAfterOpt == AfterOpt.Order_Must_Restart) {
|
||||
// 完整重启,不再继续剩余的节点项目
|
||||
cancel = true;
|
||||
}
|
||||
@ -94,7 +95,7 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (afterOpt == OutGivingModel.AfterOpt.Restart || afterOpt == OutGivingModel.AfterOpt.No) {
|
||||
} else if (afterOpt == AfterOpt.Restart || afterOpt == AfterOpt.No) {
|
||||
|
||||
outGivingNodeProjects.forEach(outGivingNodeProject -> ThreadUtil.execAsync(
|
||||
new OutGivingRun(item, outGivingNodeProject, file, userModel, unzip)));
|
||||
@ -114,9 +115,9 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
this.clearOld = item.isClearOld();
|
||||
this.outGivingNodeProject = outGivingNodeProject;
|
||||
this.file = file;
|
||||
OutGivingModel.AfterOpt afterOpt = BaseEnum.getEnum(OutGivingModel.AfterOpt.class, item.getAfterOpt());
|
||||
AfterOpt afterOpt = BaseEnum.getEnum(AfterOpt.class, item.getAfterOpt());
|
||||
if (afterOpt == null) {
|
||||
afterOpt = OutGivingModel.AfterOpt.No;
|
||||
afterOpt = AfterOpt.No;
|
||||
}
|
||||
this.afterOpt = afterOpt;
|
||||
//
|
||||
@ -137,7 +138,7 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
JsonMessage<String> jsonMessage = fileUpload(file,
|
||||
this.outGivingNodeProject.getProjectId(),
|
||||
unzip,
|
||||
afterOpt != OutGivingModel.AfterOpt.No,
|
||||
afterOpt,
|
||||
this.nodeModel, this.userModel, this.clearOld);
|
||||
if (jsonMessage.getCode() == HttpStatus.HTTP_OK) {
|
||||
result = OutGivingNodeProject.Status.Ok;
|
||||
@ -163,14 +164,16 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
* @param file 需要上传的文件
|
||||
* @param projectId 项目id
|
||||
* @param unzip 是否需要解压
|
||||
* @param restart 是否需要重启
|
||||
* @param afterOpt 是否需要重启
|
||||
* @param nodeModel 节点
|
||||
* @param userModel 操作用户
|
||||
* @return json
|
||||
*/
|
||||
public static JsonMessage<String> fileUpload(File file, String projectId,
|
||||
boolean unzip, boolean restart,
|
||||
NodeModel nodeModel, UserModel userModel,
|
||||
boolean unzip,
|
||||
AfterOpt afterOpt,
|
||||
NodeModel nodeModel,
|
||||
UserModel userModel,
|
||||
boolean clearOld) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("file", file);
|
||||
@ -184,8 +187,8 @@ public class OutGivingRun implements Callable<OutGivingNodeProject.Status> {
|
||||
}
|
||||
}
|
||||
// 操作
|
||||
if (restart) {
|
||||
data.put("after", "restart");
|
||||
if (afterOpt != AfterOpt.No) {
|
||||
data.put("after", afterOpt.getCode());
|
||||
}
|
||||
return NodeForward.request(nodeModel, NodeUrl.Manage_File_Upload, userModel, data);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@
|
||||
{field: 'status', title: '状态', templet: "#status_templ",},
|
||||
{field: 'pid', title: '进程id', templet: "#pid_templ"},
|
||||
{field: 'port', title: '端口号', templet: "#port_templ"},
|
||||
{field: 'modifyTime', title: '最后修改时间'},
|
||||
{field: 'op', title: '操作', align: 'center', toolbar: '#bar_projects', fixed: 'right', width: "30%"}
|
||||
];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user