取消,webHook 配置no,

解决配置JVM、Args 获取不到项目运行状态
创建新判断id是否被占用
This commit is contained in:
jiangzeyin 2019-04-04 17:56:40 +08:00
parent 784f4f7c4a
commit d935172682
9 changed files with 106 additions and 36 deletions

View File

@ -1,5 +1,12 @@
# 版本日志
## 2.3
1. 解决配置JVM、ARGS时不能获取到程序运行信息bug(感谢@Agoni 、)
2. 添加创建项目判断项目id是否被占用
-----------------------------------------------------------
## 2.2
1. 解决批量上传文件造成卡死的问题

View File

@ -93,7 +93,7 @@ public abstract class AbstractCommander {
*/
public String stop(ProjectInfoModel projectInfoModel) throws Exception {
String token = projectInfoModel.getToken();
if (StrUtil.isNotEmpty(token) && !ProjectInfoModel.NO_TOKEN.equalsIgnoreCase(token)) {
if (StrUtil.isNotEmpty(token)) {
try {
return HttpUtil.createGet(token).execute().body();
} catch (Exception e) {
@ -177,6 +177,7 @@ public abstract class AbstractCommander {
}
private VirtualMachine getVirtualMachine(String tag) throws IOException, AttachNotSupportedException {
// 添加空格是为了防止startWith
tag = String.format("-Dapplication=%s ", tag);
// 通过VirtualMachine.list()列出所有的java进程
List<VirtualMachineDescriptor> descriptorList = VirtualMachine.list();
@ -185,9 +186,10 @@ public abstract class AbstractCommander {
VirtualMachine virtualMachine = VirtualMachine.attach(virtualMachineDescriptor);
Properties properties = virtualMachine.getAgentProperties();
String args = properties.getProperty("sun.jvm.args", "");
if (StrUtil.isEmpty(args)) {
args = properties.getProperty("sun.java.command", "");
if (StrUtil.containsIgnoreCase(args, tag)) {
return virtualMachine;
}
args = properties.getProperty("sun.java.command", "");
if (StrUtil.containsIgnoreCase(args, tag)) {
return virtualMachine;
}

View File

@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage;
import cn.keepbx.jpom.common.BaseController;
import cn.keepbx.jpom.common.commander.AbstractCommander;
import cn.keepbx.jpom.model.ProjectInfoModel;
import cn.keepbx.jpom.model.UserModel;
import cn.keepbx.jpom.service.manage.ProjectInfoService;
@ -103,6 +104,11 @@ public class EditProjectController extends BaseController {
} catch (Exception ignored) {
}
projectInfo.setRunMode(runMode1);
if (runMode1 == ProjectInfoModel.RunMode.ClassPath && StrUtil.isEmpty(projectInfo.getMainClass())) {
return JsonMessage.getString(401, "ClassPath 模式 MainClass必填");
}
//
if (!whitelistDirectoryService.checkProjectDirectory(whitelistDirectory)) {
return JsonMessage.getString(401, "请选择正确的项目路径,或者还没有配置白名单");
@ -147,14 +153,12 @@ public class EditProjectController extends BaseController {
}
//
String token = projectInfo.getToken();
if (!ProjectInfoModel.NO_TOKEN.equals(token)) {
if (!ReUtil.isMatch(PatternPool.URL_HTTP, token)) {
return JsonMessage.getString(401, "WebHooks 地址不合法");
}
if (StrUtil.isNotEmpty(token) && !ReUtil.isMatch(PatternPool.URL_HTTP, token)) {
return JsonMessage.getString(401, "WebHooks 地址不合法");
}
// 判断空格
if (id.contains(StrUtil.SPACE) || lib.contains(StrUtil.SPACE) || log.contains(StrUtil.SPACE) || token.contains(StrUtil.SPACE)) {
if (id.contains(StrUtil.SPACE) || lib.contains(StrUtil.SPACE) || log.contains(StrUtil.SPACE)) {
return JsonMessage.getString(401, "项目Id、项目Lib、WebHooks不能包含空格");
}
@ -173,6 +177,10 @@ public class EditProjectController extends BaseController {
if (!userName.isManage()) {
return JsonMessage.getString(400, "管理员才能创建项目!");
}
// 检查运行中的tag 是否被占用
if (AbstractCommander.getInstance().isRun(projectInfo.getId())) {
return JsonMessage.getString(400, "当前项目id已经被正在运行的程序占用");
}
projectInfo.setCreateTime(DateUtil.now());
this.modify(projectInfo);
projectInfoService.addItem(projectInfo);

View File

@ -115,13 +115,12 @@ public class ProjectFileControl extends BaseController {
/**
* 上传文件
*
* @param id 项目id
* @return json
*/
@RequestMapping(value = "upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@ProjectPermission(checkUpload = true)
public String upload(String id) throws Exception {
public String upload() throws Exception {
ProjectInfoModel pim = getProjectInfoModel();
MultipartFileBuilder multipartFileBuilder = createMultipart()
.addFieldName("file");

View File

@ -4,7 +4,6 @@ import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage;
import cn.keepbx.jpom.common.BaseController;
import cn.keepbx.jpom.common.commander.AbstractCommander;
import cn.keepbx.jpom.common.interceptor.ProjectPermission;
import cn.keepbx.jpom.model.ProjectInfoModel;
import cn.keepbx.jpom.model.UserModel;
@ -106,7 +105,7 @@ public class ProjectManageControl extends BaseController {
UserModel userModel = getUser();
try {
// 运行判断
if (AbstractCommander.getInstance().isRun(projectInfoModel.getId())) {
if (projectInfoModel.isStatus(true)) {
return JsonMessage.getString(401, "不能删除正在运行的项目");
}
String userId;

View File

@ -1,6 +1,7 @@
package cn.keepbx.jpom.model;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.keepbx.jpom.common.commander.AbstractCommander;
import com.alibaba.fastjson.JSONObject;
@ -12,8 +13,6 @@ import java.io.File;
* @author jiangzeyin
*/
public class ProjectInfoModel extends BaseModel {
public static final String NO_TOKEN = "no";
private String name;
/**
* 分组
@ -73,7 +72,7 @@ public class ProjectInfoModel extends BaseModel {
}
/**
* 项目是否正在运行不推荐直接使用
* 项目是否正在运行
*
* @param get 防止并发获取
* @return true 正在运行
@ -85,6 +84,7 @@ public class ProjectInfoModel extends BaseModel {
try {
status = AbstractCommander.getInstance().isRun(getId());
} catch (Exception e) {
DefaultSystemLog.ERROR().error("检查项目状态错误", e);
status = false;
}
return status;
@ -159,6 +159,9 @@ public class ProjectInfoModel extends BaseModel {
}
public String getMainClass() {
if (mainClass == null) {
return "";
}
return mainClass;
}
@ -224,13 +227,14 @@ public class ProjectInfoModel extends BaseModel {
}
/**
* 默认 是no
* 默认
*
* @return url token
*/
public String getToken() {
if (StrUtil.isEmpty(token)) {
token = NO_TOKEN;
// 兼容旧数据
if ("no".equalsIgnoreCase(this.token)) {
return "";
}
return token;
}

View File

@ -48,8 +48,8 @@
<div class="layui-inline">
<label class="layui-form-label">MainClass</label>
<div class="layui-input-block">
<input type="text" name="mainClass" placeholder="程序运行的 main 类" required
lay-verify="required" class="layui-input" value="#if($item)$!item.mainClass#end">
<input type="text" name="mainClass" placeholder="程序运行的 main 类(jar模式运行可以不填)" class="layui-input"
value="#if($item)$!item.mainClass#end">
</div>
</div>
@ -107,22 +107,6 @@
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">Jvm参数</label>
<div class="layui-input-block">
<input type="text" name="jvm" placeholder="jvm参数,非必填" class="layui-input"
value="#if($item)$!item.jvm#end">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">args</label>
<div class="layui-input-block">
<input type="text" name="args" placeholder="Main函数 args参数,非必填" class="layui-input"
value="#if($item)$!item.args#end">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">WebHooks</label>
@ -139,6 +123,22 @@
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">Jvm参数</label>
<div class="layui-input-block">
<textarea name="jvm" placeholder="jvm参数,非必填"
class="layui-textarea">#if($item)$!item.jvm#end</textarea>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">args参数</label>
<div class="layui-input-block">
<textarea name="args" placeholder="Main函数 args参数,非必填"
class="layui-textarea">#if($item)$!item.args#end</textarea>
</div>
</div>
</div>
<div class="layui-form-item" style="padding-left: 20%">
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitProject" id="project_submit">提交
</button>

View File

@ -0,0 +1,22 @@
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
/**
* Created by jiangzeyin on 2019/4/4.
*/
public class TestJvm {
public static void main(String[] args) throws IOException, AttachNotSupportedException {
List<VirtualMachineDescriptor> descriptorList = VirtualMachine.list();
for (VirtualMachineDescriptor virtualMachineDescriptor : descriptorList) {
// 根据虚拟机描述查询启动属性如果属性-Dapplication匹配说明项目已经启动并返回进程id
VirtualMachine virtualMachine = VirtualMachine.attach(virtualMachineDescriptor);
Properties properties = virtualMachine.getAgentProperties();
System.out.println(properties);
}
}
}

View File

@ -0,0 +1,29 @@
{
"msg": "查询成功!",
"code": 200,
"data": [
{
"jvm": "-Xms256m -Xmx512m -XX:MaxPermSize=256M",
"runLibDesc": "upload",
"lib": "/home/SpringCloud/auto-license",
"mainClass": "cn.phxg.LicenseServiceApplication",
"manager": true,
"log": "/home/SpringCloud/auto-license.log",
"runMode": "Jar",
"token": "",
"args": "--server.port=9099",
"absoluteLib": "/home/SpringCloud/auto-license",
"modifyUser": "系统管理员",
"absoluteLog": "/home/SpringCloud/auto-license.log",
"modifyTime": "2019-04-04 16:38:32",
"buildTag": "",
"createTime": "2019-04-04 14:21:40",
"name": "平台授权服务",
"id": "auto-license",
"logBack": "/home/SpringCloud/auto-license.log_back",
"useLibDesc": "upload",
"group": "私有云",
"status": false
}
]
}