feat(cli): 增加主机是否启用的能力
This commit is contained in:
@@ -8,6 +8,7 @@ package com.lanyuanxiaoyao.service.cli.core;
|
||||
*/
|
||||
public class HostInfo {
|
||||
private String ip;
|
||||
private Boolean enabled = true;
|
||||
private Boolean useAuthority = false;
|
||||
private String username;
|
||||
private String password;
|
||||
@@ -20,6 +21,14 @@ public class HostInfo {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Boolean getUseAuthority() {
|
||||
return useAuthority;
|
||||
}
|
||||
@@ -47,7 +56,8 @@ public class HostInfo {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HostInfo{" +
|
||||
"ip='" + ip + '\'' +
|
||||
"enabled=" + enabled +
|
||||
", ip='" + ip + '\'' +
|
||||
", useAuthority=" + useAuthority +
|
||||
", username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
|
||||
@@ -26,6 +26,10 @@ public class HostInfoWrapper {
|
||||
return hostInfo.getIp();
|
||||
}
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return hostInfo.getEnabled();
|
||||
}
|
||||
|
||||
public Boolean getUseAuthority() {
|
||||
return hostInfo.getUseAuthority();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user