Skip to content

Commit

Permalink
optimal 工作空间变量同步
Browse files Browse the repository at this point in the history
  • Loading branch information
bwcx-jzy committed Mar 8, 2022
1 parent eba848f commit c8fdff0
Show file tree
Hide file tree
Showing 17 changed files with 674 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ end_of_line = crlf
indent_style = space
indent_size = 2

[*.{java,xml}]
[*.{java,xml,sql}]
indent_style = space
indent_size = 4
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
1. 【server】监控新增 webhook 字段(感谢@[wxyShine](https://gitee.com/wxyShine)
2. 【server】新增自动添加本机 docker (感谢@💎ℳ๓₯㎕斌💎💘)
3. 【server】docker 镜像创建容器支持环境变量 (感谢@💎ℳ๓₯㎕斌💎💘)
4. 【server】工作空间变量新增同步到指定节点

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

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

------

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

------

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,84 @@
*/
package io.jpom.controller.system;

import cn.hutool.core.map.MapUtil;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorItem;
import com.alibaba.fastjson.JSONObject;
import io.jpom.common.BaseAgentController;
import io.jpom.model.system.WorkspaceEnvVarModel;
import io.jpom.model.system.WorkspaceModel;
import io.jpom.service.system.AgentWorkspaceService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @author jiangzeyin
* @date 2019/4/16
* @author lidaofu
* @since 2022/3/8
*/
@RestController
@RequestMapping(value = "/system/workspace_env")
public class AgentWorkspaceEnvVarController extends BaseAgentController {
@Resource
private AgentWorkspaceService agentWorkspaceService;

private final AgentWorkspaceService agentWorkspaceService;

public AgentWorkspaceEnvVarController(AgentWorkspaceService agentWorkspaceService) {
this.agentWorkspaceService = agentWorkspaceService;
}

/**
* 更新环境变量
* @param json 数据json
*
* @param name 名称
* @param value 值
* @param description 描述
* @return json
*/
@PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
public String updateWorkspaceEnvVar(@ValidatorItem String name,
@ValidatorItem String value,
@ValidatorItem String description) {
String workspaceId = getWorkspaceId();
synchronized (AgentWorkspaceEnvVarController.class) {
WorkspaceModel.WorkspaceEnvVarModel workspaceEnvVarModel = new WorkspaceModel.WorkspaceEnvVarModel();
workspaceEnvVarModel.setName(name);
workspaceEnvVarModel.setValue(value);
workspaceEnvVarModel.setDescription(description);
//
WorkspaceModel item = agentWorkspaceService.getItem(workspaceId);
if (null == item) {
item = new WorkspaceModel();
item.setVarData(MapUtil.of(name, workspaceEnvVarModel));
item.setName(workspaceId);
item.setId(workspaceId);
agentWorkspaceService.addItem(item);
} else {
item.put(name, workspaceEnvVarModel);
agentWorkspaceService.updateItem(item);
}
}
return JsonMessage.getString(200, "更新成功");
}


/**
* 删除环境变量
*
* @param name 名称
* @return json
*/
@PostMapping(value = "/updateWorkspaceEnvVar", produces = MediaType.APPLICATION_JSON_VALUE)
public String updateWorkspaceEnvVar(@ValidatorItem String json) {
@PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
public String delete(@ValidatorItem String name) {
String workspaceId = getWorkspaceId();
List<WorkspaceEnvVarModel> list = JSONObject.parseArray(json, WorkspaceEnvVarModel.class);
WorkspaceModel workspaceModel = new WorkspaceModel();
workspaceModel.setWorkspaceId(workspaceId);
workspaceModel.setList(list);
workspaceModel.setId(workspaceId);
WorkspaceModel item = agentWorkspaceService.getItem(workspaceId);
if (null==item){
agentWorkspaceService.addItem(workspaceModel);
}else {
agentWorkspaceService.updateItem(workspaceModel);
synchronized (AgentWorkspaceEnvVarController.class) {
//
WorkspaceModel item = agentWorkspaceService.getItem(workspaceId);
if (null != item) {
item.remove(name);
agentWorkspaceService.updateItem(item);
}
}
return JsonMessage.getString(200, "缓存更新成功!");
return JsonMessage.getString(200, "删除成功");
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,80 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Code Technology Studio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.jpom.model.system;

import io.jpom.model.BaseJsonModel;
import io.jpom.model.BaseModel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.HashMap;
import java.util.Map;

/**
* @author lidaofu
* @since 2022/3/8
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class WorkspaceModel extends BaseModel {

private String workspaceId;
private Map<String, WorkspaceEnvVarModel> varData;

private List<WorkspaceEnvVarModel> list;

public String getWorkspaceId() {
return workspaceId;
/**
* 更新变量
*
* @param name 变量名称
* @param workspaceEnvVarModel 变量信息
*/
public void put(String name, WorkspaceEnvVarModel workspaceEnvVarModel) {
if (varData == null) {
varData = new HashMap<>(2);
}
varData.put(name, workspaceEnvVarModel);
}

public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
/**
* 删除 变量
*
* @param name 名称
*/
public void remove(String name) {
if (varData == null) {
return;
}
varData.remove(name);
}

public List<WorkspaceEnvVarModel> getList() {
return list;
}
/**
* @author lidaofu
* @since 2022/3/8
*/
@Data
public static class WorkspaceEnvVarModel {

private String name;

private String value;

public void setList(List<WorkspaceEnvVarModel> list) {
this.list = list;
private String description;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Code Technology Studio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.jpom.service.system;

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

/**
* @ClassName AgentWorkspaceEnvVarService
* @Description
* @Author lidaofu
* @Date 2022/3/8 9:16
* @Version V1.0
* @author lidaofu
* @since 2022/3/8 9:16
**/
@Service
public class AgentWorkspaceService extends BaseOperService<WorkspaceModel> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Code Technology Studio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.jpom.controller;

import cn.hutool.core.io.FileUtil;
Expand Down
Loading

0 comments on commit c8fdff0

Please sign in to comment.