From 1338e6458cef89f9637deec78f40ea55a6e9d4fb Mon Sep 17 00:00:00 2001 From: v-zhangjc9 Date: Tue, 22 Oct 2024 08:59:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(cli):=20=E5=A2=9E=E5=8A=A0=E4=B8=BB?= =?UTF-8?q?=E6=9C=BA=E6=98=AF=E5=90=A6=E5=90=AF=E7=94=A8=E7=9A=84=E8=83=BD?= =?UTF-8?q?=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lanyuanxiaoyao/service/cli/core/HostInfo.java | 12 +++++++++++- .../service/cli/runner/HostInfoWrapper.java | 4 ++++ .../service/cli/runner/RunnerApplication.java | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java b/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java index 0c556d1..99ca708 100644 --- a/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java +++ b/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java @@ -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 + '\'' + diff --git a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/HostInfoWrapper.java b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/HostInfoWrapper.java index f06956f..1482e9d 100644 --- a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/HostInfoWrapper.java +++ b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/HostInfoWrapper.java @@ -26,6 +26,10 @@ public class HostInfoWrapper { return hostInfo.getIp(); } + public Boolean getEnabled() { + return hostInfo.getEnabled(); + } + public Boolean getUseAuthority() { return hostInfo.getUseAuthority(); } diff --git a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java index 6a91104..5ff4b38 100644 --- a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java +++ b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java @@ -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 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);