Skip to content

Commit c8fdff0

Browse files
committed
optimal 工作空间变量同步
1 parent eba848f commit c8fdff0

File tree

17 files changed

+674
-496
lines changed

17 files changed

+674
-496
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ end_of_line = crlf
2525
indent_style = space
2626
indent_size = 2
2727

28-
[*.{java,xml}]
28+
[*.{java,xml,sql}]
2929
indent_style = space
3030
indent_size = 4

CHANGELOG.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
1. 【server】监控新增 webhook 字段(感谢@[wxyShine](https://gitee.com/wxyShine)
88
2. 【server】新增自动添加本机 docker (感谢@💎ℳ๓₯㎕斌💎💘)
99
3. 【server】docker 镜像创建容器支持环境变量 (感谢@💎ℳ๓₯㎕斌💎💘)
10+
4. 【server】工作空间变量新增同步到指定节点
1011

1112
### 🐞 解决BUG、优化功能
1213

@@ -15,6 +16,7 @@
1516
3. 【server】备份数据不将 sql 输出到控制台
1617
4. 【server】取消信号量监听,会出现 kill pid 无法关闭进程的情况
1718
5. 【server】优化操作报警,能获取到更多到数据名称
19+
6. 【server】修护工作空间变量编辑使用默认工作空间相关问题(感谢@lidaofu
1820

1921
------
2022

@@ -125,8 +127,7 @@
125127
6. 【server】本地构建命令 容器构建支持引用工作空间变量
126128
7. 【server】修复构建触发器无法执行(感谢@[老诗人](https://gitee.com/laoshirenggo)
127129
8. 【server】服务端脚本新增工作空间环境变量
128-
9. 修复检查 Jpom
129-
包中没有释放资源(感谢@[大海](https://gitee.com/hasape) [Gitee issues I4T9L0](https://gitee.com/dromara/Jpom/issues/I4T9L0)
130+
9. 修复检查 Jpom 包中没有释放资源(感谢@[大海](https://gitee.com/hasape) [Gitee issues I4T9L0](https://gitee.com/dromara/Jpom/issues/I4T9L0)
130131

131132
------
132133

@@ -155,10 +156,10 @@
155156
8. 【server】本地构建模式模糊匹配支持匹配多个结果
156157
9. 【server】修复节点分发不能删除节点问题(感谢@a19920714liou [Gitee issues I4SHSP](https://gitee.com/dromara/Jpom/issues/I4SHSP)
157158
10. 【server】ssh 快捷安装插件端保存安装包避免多次上传 (感谢@a19920714liou [Gitee issues I4SHJC](https://gitee.com/dromara/Jpom/issues/I4SHJC)
158-
159+
159160
11. 【server】ssh 快捷安装插件端权限改为管理员
160161
12. 【server】构建 ssh 发布授权目录采用下拉模式,提升用户操作感知 (
161-
感谢@hjk2008 [Gitee issues I4SICE](https://gitee.com/dromara/Jpom/issues/I4SICE) )
162+
感谢@hjk2008 [Gitee issues I4SICE](https://gitee.com/dromara/Jpom/issues/I4SICE) )
162163
13. 【server】修复数据库自动备份失败问题
163164

164165
> 🙏 特别感谢:[💎ℳ๓₯㎕斌💎💘](https://gitee.com/weihongbin) 贡献容器构建相关架构
@@ -346,8 +347,7 @@
346347
9. 【server】发布命令(SSH发布命令、本地命令)支持变量替换:`#{BUILD_ID}``#{BUILD_NAME}``#{BUILD_RESULT_FILE}``#{BUILD_NUMBER_ID}`
347348
10. 【server】新增自动备份全量数据配置 `db.autoBackupIntervalDay` 默认一天备份一次,执行备份时间 凌晨0点或者中午12点
348349
11. 【agent】项目的 webhook 新增项目启动成功后通知,并且参数新增 `type` 指包括:`beforeStop`,`start`,`stop`,`beforeRestart`
349-
12. 【agent】项目新增自启动配置项,在 agent
350-
启动时候检查对应项目是否启动,未启动执行启动逻辑 [Gitee issues I4IJFK](https://gitee.com/dromara/Jpom/issues/I4IJFK)
350+
12. 【agent】项目新增自启动配置项,在 agent 启动时候检查对应项目是否启动,未启动执行启动逻辑 [Gitee issues I4IJFK](https://gitee.com/dromara/Jpom/issues/I4IJFK)
351351
13. 【server】构建新增 webhook,实时通知构建进度
352352
14. 【server】节点分发新增分发间隔时间配置
353353
15. 新增控制台日志配置数据 `consoleLog.charset` 避免部分服务器执行命令响应乱码 (感谢@……)
@@ -476,7 +476,7 @@
476476
19. 【server】节点分发支持 file 类型项目
477477
20. 【agent】项目新增配置日志文件输出到指定目录
478478
21. 【server】构建产物目录支持通配符`AntPathMatcher`模式 (感谢@saysay [Gitee issues I455FM](https://gitee.com/dromara/Jpom/issues/I455FM)
479-
479+
480480
22. 【server】新增 h2 数据库缓存大小配置 [CACHE_SIZE](http://www.h2database.com/html/features.html#cache_settings) `db.cacheSize
481481
23. 【server】构建触发器新增延迟执行参数(感谢@Steve.Liu)
482482
24. 【server】增加全局项目搜索功能
@@ -604,8 +604,7 @@
604604
11. 【server】项目控制台新增心跳消息,避免超过一定时间后无法操作的情况
605605
12. 【server】ssh 新增心跳消息,避免超过一定时间后无法操作的情况
606606
13. 【server】系统缓存中的文件占用空间大小调整为定时更新(10分钟)
607-
14. 【server】修复 bug:分发列表页面点击【创建分发项目】按钮之后不能正常显示【分发节点】感谢
608-
@xingenhi [点击查看提交记录](https://gitee.com/dromara/Jpom/commit/bd38528fbd3067d220b7569f08449d7796e07c74) [@Hotstrip](https://gitee.com/hotstrip)
607+
14. 【server】修复 bug:分发列表页面点击【创建分发项目】按钮之后不能正常显示【分发节点】感谢 @xingenhi [点击查看提交记录](https://gitee.com/dromara/Jpom/commit/bd38528fbd3067d220b7569f08449d7796e07c74) [@Hotstrip](https://gitee.com/hotstrip)
609608
15. 【server】fix: 编辑管理员时用户名不可修改
610609
16. 【server】折叠显示部分列表操作按钮(减少误操作)
611610

modules/agent/src/main/java/io/jpom/controller/system/AgentWorkspaceEnvVarController.java

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,84 @@
2222
*/
2323
package io.jpom.controller.system;
2424

25+
import cn.hutool.core.map.MapUtil;
2526
import cn.jiangzeyin.common.JsonMessage;
2627
import cn.jiangzeyin.common.validator.ValidatorItem;
27-
import com.alibaba.fastjson.JSONObject;
2828
import io.jpom.common.BaseAgentController;
29-
import io.jpom.model.system.WorkspaceEnvVarModel;
3029
import io.jpom.model.system.WorkspaceModel;
3130
import io.jpom.service.system.AgentWorkspaceService;
3231
import org.springframework.http.MediaType;
3332
import org.springframework.web.bind.annotation.PostMapping;
3433
import org.springframework.web.bind.annotation.RequestMapping;
3534
import org.springframework.web.bind.annotation.RestController;
3635

37-
import javax.annotation.Resource;
38-
import java.util.List;
39-
4036
/**
41-
* @author jiangzeyin
42-
* @date 2019/4/16
37+
* @author lidaofu
38+
* @since 2022/3/8
4339
*/
4440
@RestController
4541
@RequestMapping(value = "/system/workspace_env")
4642
public class AgentWorkspaceEnvVarController extends BaseAgentController {
47-
@Resource
48-
private AgentWorkspaceService agentWorkspaceService;
43+
44+
private final AgentWorkspaceService agentWorkspaceService;
45+
46+
public AgentWorkspaceEnvVarController(AgentWorkspaceService agentWorkspaceService) {
47+
this.agentWorkspaceService = agentWorkspaceService;
48+
}
4949

5050
/**
5151
* 更新环境变量
52-
* @param json 数据json
52+
*
53+
* @param name 名称
54+
* @param value 值
55+
* @param description 描述
56+
* @return json
57+
*/
58+
@PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
59+
public String updateWorkspaceEnvVar(@ValidatorItem String name,
60+
@ValidatorItem String value,
61+
@ValidatorItem String description) {
62+
String workspaceId = getWorkspaceId();
63+
synchronized (AgentWorkspaceEnvVarController.class) {
64+
WorkspaceModel.WorkspaceEnvVarModel workspaceEnvVarModel = new WorkspaceModel.WorkspaceEnvVarModel();
65+
workspaceEnvVarModel.setName(name);
66+
workspaceEnvVarModel.setValue(value);
67+
workspaceEnvVarModel.setDescription(description);
68+
//
69+
WorkspaceModel item = agentWorkspaceService.getItem(workspaceId);
70+
if (null == item) {
71+
item = new WorkspaceModel();
72+
item.setVarData(MapUtil.of(name, workspaceEnvVarModel));
73+
item.setName(workspaceId);
74+
item.setId(workspaceId);
75+
agentWorkspaceService.addItem(item);
76+
} else {
77+
item.put(name, workspaceEnvVarModel);
78+
agentWorkspaceService.updateItem(item);
79+
}
80+
}
81+
return JsonMessage.getString(200, "更新成功");
82+
}
83+
84+
85+
/**
86+
* 删除环境变量
87+
*
88+
* @param name 名称
5389
* @return json
5490
*/
55-
@PostMapping(value = "/updateWorkspaceEnvVar", produces = MediaType.APPLICATION_JSON_VALUE)
56-
public String updateWorkspaceEnvVar(@ValidatorItem String json) {
91+
@PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
92+
public String delete(@ValidatorItem String name) {
5793
String workspaceId = getWorkspaceId();
58-
List<WorkspaceEnvVarModel> list = JSONObject.parseArray(json, WorkspaceEnvVarModel.class);
59-
WorkspaceModel workspaceModel = new WorkspaceModel();
60-
workspaceModel.setWorkspaceId(workspaceId);
61-
workspaceModel.setList(list);
62-
workspaceModel.setId(workspaceId);
63-
WorkspaceModel item = agentWorkspaceService.getItem(workspaceId);
64-
if (null==item){
65-
agentWorkspaceService.addItem(workspaceModel);
66-
}else {
67-
agentWorkspaceService.updateItem(workspaceModel);
94+
synchronized (AgentWorkspaceEnvVarController.class) {
95+
//
96+
WorkspaceModel item = agentWorkspaceService.getItem(workspaceId);
97+
if (null != item) {
98+
item.remove(name);
99+
agentWorkspaceService.updateItem(item);
100+
}
68101
}
69-
return JsonMessage.getString(200, "缓存更新成功!");
102+
return JsonMessage.getString(200, "删除成功");
70103
}
71104

72105
}

modules/agent/src/main/java/io/jpom/model/system/WorkspaceEnvVarModel.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,80 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Code Technology Studio
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
123
package io.jpom.model.system;
224

3-
import io.jpom.model.BaseJsonModel;
425
import io.jpom.model.BaseModel;
26+
import lombok.Data;
27+
import lombok.EqualsAndHashCode;
528

6-
import java.util.List;
29+
import java.util.HashMap;
30+
import java.util.Map;
731

32+
/**
33+
* @author lidaofu
34+
* @since 2022/3/8
35+
*/
36+
@EqualsAndHashCode(callSuper = true)
37+
@Data
838
public class WorkspaceModel extends BaseModel {
939

10-
private String workspaceId;
40+
private Map<String, WorkspaceEnvVarModel> varData;
1141

12-
private List<WorkspaceEnvVarModel> list;
13-
14-
public String getWorkspaceId() {
15-
return workspaceId;
42+
/**
43+
* 更新变量
44+
*
45+
* @param name 变量名称
46+
* @param workspaceEnvVarModel 变量信息
47+
*/
48+
public void put(String name, WorkspaceEnvVarModel workspaceEnvVarModel) {
49+
if (varData == null) {
50+
varData = new HashMap<>(2);
51+
}
52+
varData.put(name, workspaceEnvVarModel);
1653
}
1754

18-
public void setWorkspaceId(String workspaceId) {
19-
this.workspaceId = workspaceId;
55+
/**
56+
* 删除 变量
57+
*
58+
* @param name 名称
59+
*/
60+
public void remove(String name) {
61+
if (varData == null) {
62+
return;
63+
}
64+
varData.remove(name);
2065
}
2166

22-
public List<WorkspaceEnvVarModel> getList() {
23-
return list;
24-
}
67+
/**
68+
* @author lidaofu
69+
* @since 2022/3/8
70+
*/
71+
@Data
72+
public static class WorkspaceEnvVarModel {
73+
74+
private String name;
75+
76+
private String value;
2577

26-
public void setList(List<WorkspaceEnvVarModel> list) {
27-
this.list = list;
78+
private String description;
2879
}
2980
}

modules/agent/src/main/java/io/jpom/service/system/AgentWorkspaceService.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Code Technology Studio
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
123
package io.jpom.service.system;
224

325
import io.jpom.model.system.WorkspaceModel;
@@ -6,11 +28,8 @@
628
import org.springframework.stereotype.Service;
729

830
/**
9-
* @ClassName AgentWorkspaceEnvVarService
10-
* @Description
11-
* @Author lidaofu
12-
* @Date 2022/3/8 9:16
13-
* @Version V1.0
31+
* @author lidaofu
32+
* @since 2022/3/8 9:16
1433
**/
1534
@Service
1635
public class AgentWorkspaceService extends BaseOperService<WorkspaceModel> {

modules/common/src/main/java/io/jpom/controller/RobotsController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Code Technology Studio
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
123
package io.jpom.controller;
224

325
import cn.hutool.core.io.FileUtil;

0 commit comments

Comments
 (0)