fix 新增 docker 无法使用在线构建功能 #I6KTLQ

This commit is contained in:
bwcx_jzy 2023-03-08 09:14:47 +08:00
parent 525d0767a2
commit 8f2b47a583
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
9 changed files with 44 additions and 31 deletions

View File

@ -1,5 +1,14 @@
# 🚀 版本日志
## 2.10.28
### 🐞 解决BUG、优化功能
1. 【server】修复 新增 docker 无法使用在线构建功能
(感谢 [@失落的世界](https://gitee.com/marmotgo) [Gitee issues I6KTLQ](https://gitee.com/dromara/Jpom/issues/I6KTLQ)
------
## 2.10.27 (2023-03-06)
### 🐣 新增功能

View File

@ -742,7 +742,7 @@ public class BuildExecuteService {
// 根据 tag 查询
List<DockerInfoModel> dockerInfoModels = buildExecuteService
.dockerInfoService
.queryByTag(buildInfoModel.getWorkspaceId(), 1, fromTag);
.queryByTag(buildInfoModel.getWorkspaceId(), fromTag);
DockerInfoModel dockerInfoModel = CollUtil.getFirst(dockerInfoModels);
Assert.notNull(dockerInfoModel, "没有可用的 docker server");
logRecorder.system("use docker {}", dockerInfoModel.getName());

View File

@ -229,7 +229,7 @@ public class ReleaseManage {
// 根据 tag 查询
List<DockerInfoModel> dockerInfoModels = buildExecuteService
.dockerInfoService
.queryByTag(this.buildExtraModule.getWorkspaceId(), 1, fromTag);
.queryByTag(this.buildExtraModule.getWorkspaceId(), fromTag);
DockerInfoModel dockerInfoModel = CollUtil.getFirst(dockerInfoModels);
if (dockerInfoModel == null) {
logRecorder.systemError("没有可用的 docker server");

View File

@ -125,9 +125,7 @@ public class MachineDockerServer extends BaseDbService<MachineDockerModel> imple
machineDockerModel.setName(dockerInfoModel.getName());
machineDockerModel.setHost(dockerInfoModel.getHost());
machineDockerModel.setTlsVerify(dockerInfoModel.getTlsVerify());
machineDockerModel.setStatus(dockerInfoModel.getStatus());
machineDockerModel.setHeartbeatTimeout(dockerInfoModel.getHeartbeatTimeout());
machineDockerModel.setFailureMsg(dockerInfoModel.getFailureMsg());
//
machineDockerModel.setSwarmNodeId(dockerInfoModel.getSwarmNodeId());
machineDockerModel.setSwarmId(dockerInfoModel.getSwarmId());
@ -267,6 +265,8 @@ public class MachineDockerServer extends BaseDbService<MachineDockerModel> imple
String machineDockerId = dockerInfoModel.getMachineDockerId();
MachineDockerModel machineDockerModel = this.getByKey(machineDockerId, false);
Assert.notNull(machineDockerModel, "没有找到对应的 docker 信息");
Integer status = machineDockerModel.getStatus();
Assert.state(status != null && status == 1, "当前 " + machineDockerModel.getName() + " docker 不在线");
return machineDockerModel.toParameter();
}
@ -279,6 +279,8 @@ public class MachineDockerServer extends BaseDbService<MachineDockerModel> imple
public Map<String, Object> dockerParameter(String workspaceSwarmId) {
MachineDockerModel first = this.getMachineDocker(workspaceSwarmId);
Assert.notNull(first, "没有找到集群管理节点");
Integer status = first.getStatus();
Assert.state(status != null && status == 1, "当前 " + first.getName() + " docker 集群没有管理节点在线");
return first.toParameter();
}
@ -303,6 +305,11 @@ public class MachineDockerServer extends BaseDbService<MachineDockerModel> imple
dockerInfoModel.setSwarmId(swarmId);
dockerInfoModel.setSwarmControlAvailable(true);
List<MachineDockerModel> machineDockerModels = this.listByBean(dockerInfoModel, false);
if (machineDockerModels == null) {
return null;
}
// 跟进在线情况排序
machineDockerModels.sort((o1, o2) -> CompareUtil.compare(o2.getStatus(), o1.getStatus()));
return CollUtil.getFirst(machineDockerModels);
}
}

View File

@ -57,16 +57,6 @@ public class DockerInfoModel extends BaseWorkspaceModel {
*/
@PropIgnore
private Boolean certExist;
/**
* 状态 0 , 异常离线 1 正常
*/
@Deprecated
private Integer status;
/**
* 错误消息
*/
@Deprecated
private String failureMsg;
/**
* 集群节点ID
*/

View File

@ -61,19 +61,17 @@ public class DockerInfoService extends BaseWorkspaceService<DockerInfoModel> {
*
* @param workspaceId 工作空间
* @param tag tag
* @param status 状态
* @return list
*/
public List<DockerInfoModel> queryByTag(String workspaceId, Integer status, String tag) {
public List<DockerInfoModel> queryByTag(String workspaceId, String tag) {
Condition workspaceIdCondition = new Condition("workspaceId", workspaceId);
Condition statusCondition = new Condition("status", status);
if (StrUtil.isEmpty(tag)) {
return super.findByCondition(workspaceIdCondition, statusCondition);
return super.findByCondition(workspaceIdCondition);
} else {
Condition tagCondition = new Condition(" instr(tags,'" + StrUtil.wrap(tag, StrUtil.COLON) + "')", "");
tagCondition.setPlaceHolder(false);
tagCondition.setOperator("");
return super.findByCondition(workspaceIdCondition, statusCondition, tagCondition);
return super.findByCondition(workspaceIdCondition, tagCondition);
}
}

View File

@ -10,3 +10,5 @@ DROP,DOCKER_SWARM_INFO,swarmUpdatedAt,
DROP,DOCKER_SWARM_INFO,nodeAddr,
DROP,DOCKER_SWARM_INFO,status,
DROP,DOCKER_SWARM_INFO,failureMsg,
DROP,DOCKER_INFO,status
DROP,DOCKER_INFO,failureMsg

1 alterType,tableName,name,type,len,defaultValue,comment,notNull
10 DROP,DOCKER_SWARM_INFO,nodeAddr,
11 DROP,DOCKER_SWARM_INFO,status,
12 DROP,DOCKER_SWARM_INFO,failureMsg,
13 DROP,DOCKER_INFO,status
14 DROP,DOCKER_INFO,failureMsg

View File

@ -20,6 +20,7 @@
* 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.
*/
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.LineHandler;
import cn.hutool.core.thread.ThreadUtil;
@ -30,6 +31,7 @@ import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.ChannelShell;
import com.jcraft.jsch.Session;
import org.junit.Test;
import java.io.*;
@ -118,4 +120,9 @@ public class TestSSh {
channel.disconnect();
session.disconnect();
}
@Test
public void test2() {
}
}

View File

@ -36,19 +36,19 @@ import java.util.List;
*/
public class DockerInfoTest extends ApplicationStartTest {
@Resource
private DockerInfoService dockerInfoService;
@Resource
private DockerInfoService dockerInfoService;
@Test
public void testQueryTag() {
int sdfsd = dockerInfoService.countByTag(Const.WORKSPACE_DEFAULT_ID, "sdfsd");
@Test
public void testQueryTag() {
int sdfsd = dockerInfoService.countByTag(Const.WORKSPACE_DEFAULT_ID, "sdfsd");
System.out.println(sdfsd);
}
System.out.println(sdfsd);
}
@Test
public void testQueryTag2() {
List<DockerInfoModel> models = dockerInfoService.queryByTag(Const.WORKSPACE_DEFAULT_ID, 1, "sdfsd");
System.out.println(models);
}
@Test
public void testQueryTag2() {
List<DockerInfoModel> models = dockerInfoService.queryByTag(Const.WORKSPACE_DEFAULT_ID, "sdfsd");
System.out.println(models);
}
}