feat(cli): 增加主机是否启用的能力

This commit is contained in:
v-zhangjc9
2024-10-22 08:59:13 +08:00
parent 9fd46b3a20
commit 1338e6458c
3 changed files with 26 additions and 1 deletions

View File

@@ -26,6 +26,10 @@ public class HostInfoWrapper {
return hostInfo.getIp();
}
public Boolean getEnabled() {
return hostInfo.getEnabled();
}
public Boolean getUseAuthority() {
return hostInfo.getUseAuthority();
}

View File

@@ -82,6 +82,7 @@ public class RunnerApplication implements ApplicationRunner {
return serviceInfo.getReplicas() == 0
? hostInfoList
.stream()
.filter(HostInfoWrapper::getEnabled)
.map(HostInfoWrapper::getIp)
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList())
@@ -89,6 +90,7 @@ public class RunnerApplication implements ApplicationRunner {
RandomUtil.randomEleList(
hostInfoList
.stream()
.filter(HostInfoWrapper::getEnabled)
.map(HostInfoWrapper::getIp)
.collect(Collectors.toList()
), serviceInfo.getReplicas()
@@ -148,6 +150,15 @@ public class RunnerApplication implements ApplicationRunner {
selectedHosts = selectHosts(serviceInfo);
deployPlans.put(serviceInfo.getName(), selectedHosts);
}
// 排除不可用的主机
List<String> validIps = hostInfoList.stream()
.filter(HostInfoWrapper::getEnabled)
.map(HostInfoWrapper::getIp)
.collect(Collectors.toList());
selectedHosts = selectedHosts
.stream()
.filter(validIps::contains)
.collect(Collectors.toList());
} else {
selectedHosts = selectHosts(serviceInfo);
deployPlans.put(serviceInfo.getName(), selectedHosts);