diff --git a/compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java b/compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java index e5065e0f06a..14eef9d3457 100755 --- a/compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java +++ b/compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java @@ -924,7 +924,19 @@ public String getName() { }); } - private void getStartingCandidateHosts(final NeedReplyMessage msg, final ReturnValueCompletion completion) { + private void getStartingCandidateHosts(final NeedReplyMessage msg, + final ReturnValueCompletion completion) { + HostAllocationPurpose purpose = msg instanceof GetVmStartingCandidateClustersHostsMsg + ? ((GetVmStartingCandidateClustersHostsMsg) msg).getPurpose() + : HostAllocationPurpose.ALLOCATE; + getStartingCandidateHosts(msg, purpose, Collections.emptySet(), Collections.emptyList(), completion); + } + + protected void getStartingCandidateHosts(final NeedReplyMessage msg, + final HostAllocationPurpose purpose, + final Set requiredPrimaryStorageUuids, + final List avoidHostUuids, + final ReturnValueCompletion completion) { refreshVO(); ErrorCode err = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR); if (err != null) { @@ -932,11 +944,7 @@ private void getStartingCandidateHosts(final NeedReplyMessage msg, final ReturnV } final DesignatedAllocateHostMsg amsg = new DesignatedAllocateHostMsg(); - if (msg instanceof GetVmStartingCandidateClustersHostsMsg) { - // propagate allocation purpose so downstream filters know this is a - // candidate-listing call rather than a real allocation - amsg.setPurpose(((GetVmStartingCandidateClustersHostsMsg) msg).getPurpose()); - } + amsg.setPurpose(purpose); amsg.setCpuCapacity(self.getCpuNum()); amsg.setMemoryCapacity(self.getMemorySize()); amsg.setVmInstance(VmInstanceInventory.valueOf(self)); @@ -950,6 +958,12 @@ private void getStartingCandidateHosts(final NeedReplyMessage msg, final ReturnV amsg.setDryRun(true); amsg.setListAllHosts(true); amsg.setAllowNoL3Networks(true); + if (requiredPrimaryStorageUuids != null && !requiredPrimaryStorageUuids.isEmpty()) { + amsg.setRequiredPrimaryStorageUuids(requiredPrimaryStorageUuids); + } + if (avoidHostUuids != null && !avoidHostUuids.isEmpty()) { + amsg.setAvoidHostUuids(avoidHostUuids); + } bus.send(amsg, new CloudBusCallBack(completion) { @Override @@ -957,7 +971,7 @@ public void run(MessageReply re) { if (!re.isSuccess()) { completion.fail(re.getError()); } else { - completion.success(re); + completion.success(re.castReply()); } } }); diff --git a/conf/i18n/globalErrorCodeMapping/global-error-en_US.json b/conf/i18n/globalErrorCodeMapping/global-error-en_US.json index 8fda69f4152..aeeee2b0529 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-en_US.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-en_US.json @@ -3266,6 +3266,22 @@ "ORG_ZSTACK_STORAGE_PRIMARY_LOCAL_10054": "The host [UUID:%s] is not associated with the local primary storage [UUID:%s].", "ORG_ZSTACK_KVM_10040": "failed to increase VM CPU count, error details: %s", "ORG_ZSTACK_HA_10018": "the VM[uuid:%s] volume stored location primary storage is undergoing maintenance", + "ORG_ZSTACK_HA_10041": "HA network-group conditional stop refused for VM[uuid:%s] because the feature is unavailable", + "ORG_ZSTACK_HA_10042": "HA network-group conditional stop refused because the VM inventory is missing", + "ORG_ZSTACK_HA_10043": "HA network-group conditional stop refused for VM[uuid:%s] because its HA level is not NeverStop", + "ORG_ZSTACK_HA_10044": "HA network-group conditional stop refused for VM[uuid:%s] because INHIBIT_HA is set", + "ORG_ZSTACK_HA_10045": "HA network-group conditional stop refused for VM[uuid:%s] because it is not associated with an enabled HA network group", + "ORG_ZSTACK_HA_10046": "Cannot enable HA network group[uuid:%s] because no cluster can satisfy minAvailableCount[%s]", + "ORG_ZSTACK_HA_10047": "HA network-group conditional stop refused for VM[uuid:%s] because hypervisor[%s] is not KVM", + "ORG_ZSTACK_HA_10048": "HA start refused for VM[uuid:%s] because INHIBIT_HA was created while HA was in progress", + "ORG_ZSTACK_HA_10049": "HA network-group conditional stop refused for VM[uuid:%s] because message deadline[%s] is missing, invalid, or expired", + "ORG_ZSTACK_HA_10050": "HA network-group conditional stop refused for VM[uuid:%s] because its state is [%s] instead of Running", + "ORG_ZSTACK_HA_10051": "HA network-group conditional stop refused for VM[uuid:%s] because source host[uuid:%s] does not match current host[uuid:%s]", + "ORG_ZSTACK_HA_10052": "HA network-group conditional stop cannot precheck VM[uuid:%s] because a root/data volume primary storage is missing", + "ORG_ZSTACK_HA_10053": "HA network-group conditional stop refused for VM[uuid:%s] because no starting candidate host is available", + "ORG_ZSTACK_HA_10054": "HA network-group conditional stop cannot precheck candidate hosts for VM[uuid:%s]: %s", + "ORG_ZSTACK_HA_10055": "HA network-group conditional stop for VM[uuid:%s] failed without a classified global error: %s", + "ORG_ZSTACK_HA_10056": "HA network-group conditional stop refused for VM[uuid:%s] because no enabled network group remains Down on source host[uuid:%s]", "ORG_ZSTACK_KVM_10043": "unable to connect to KVM[ip:%s, username:%s, SSH port:%d] to perform DNS validation; please verify the credentials.", "ORG_ZSTACK_STORAGE_PRIMARY_LOCAL_10050": "Unable to live migrate VM [uuid:%s] with data volumes on local storage. Data volumes must be detached first.", "ORG_ZSTACK_ZWATCH_THIRDPARTY_ZAKU_10001": "The query object is null. Please ensure that your query parameters are properly initialized before executing the cloud computing task.", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json b/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json index 0c36ae4980b..71a2406ebb9 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json @@ -3266,6 +3266,22 @@ "ORG_ZSTACK_STORAGE_PRIMARY_LOCAL_10054": "主机[UUID:%s]不属于本地主要存储[UUID:%s]", "ORG_ZSTACK_KVM_10040": "失败增加虚拟机CPU,错误详情: %s", "ORG_ZSTACK_HA_10018": "该虚拟机[uuid:%s]的卷存储位置处于维护状态,请联系管理员解决", + "ORG_ZSTACK_HA_10041": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,该功能当前不可用", + "ORG_ZSTACK_HA_10042": "拒绝执行业务网络高可用组条件停止,虚拟机清单不存在", + "ORG_ZSTACK_HA_10043": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,其高可用级别不是 NeverStop", + "ORG_ZSTACK_HA_10044": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,已设置 INHIBIT_HA", + "ORG_ZSTACK_HA_10045": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,其未关联已启用的业务网络高可用组", + "ORG_ZSTACK_HA_10046": "无法启用业务网络高可用组[uuid:%s],没有集群能够满足最小可用数量[%s]", + "ORG_ZSTACK_HA_10047": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,其虚拟化类型[%s]不是 KVM", + "ORG_ZSTACK_HA_10048": "拒绝对虚拟机[uuid:%s]执行高可用启动,因为高可用处理期间已创建 INHIBIT_HA", + "ORG_ZSTACK_HA_10049": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,消息截止时间[%s]缺失、无效或已过期", + "ORG_ZSTACK_HA_10050": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,其状态为[%s]而非运行中", + "ORG_ZSTACK_HA_10051": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,源主机[uuid:%s]与当前主机[uuid:%s]不一致", + "ORG_ZSTACK_HA_10052": "无法预检查虚拟机[uuid:%s]的业务网络高可用组条件停止,根卷或数据卷缺少主存储", + "ORG_ZSTACK_HA_10053": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,没有可用的启动候选主机", + "ORG_ZSTACK_HA_10054": "无法预检查虚拟机[uuid:%s]的业务网络高可用组条件停止候选主机:%s", + "ORG_ZSTACK_HA_10055": "虚拟机[uuid:%s]的业务网络高可用组条件停止失败,且错误未关联全局错误码:%s", + "ORG_ZSTACK_HA_10056": "拒绝对虚拟机[uuid:%s]执行业务网络高可用组条件停止,源主机[uuid:%s]上已无处于故障状态的已启用业务网络高可用组", "ORG_ZSTACK_KVM_10043": "无法连接到 KVM[ip:%s, 用户名:%s, SSH端口:%d] 执行 DNS 检查,请检查用户名/密码是否正确;%s", "ORG_ZSTACK_STORAGE_PRIMARY_LOCAL_10050": "无法将带有本地存储数据卷的虚拟机[uuid:%s]进行在线迁移。首先需要先分离所有数据卷。", "ORG_ZSTACK_ZWATCH_THIRDPARTY_ZAKU_10001": "查询对象为空", diff --git a/header/src/main/java/org/zstack/header/allocator/HostAllocationPurpose.java b/header/src/main/java/org/zstack/header/allocator/HostAllocationPurpose.java index b9893311b21..73ef02c0b4c 100644 --- a/header/src/main/java/org/zstack/header/allocator/HostAllocationPurpose.java +++ b/header/src/main/java/org/zstack/header/allocator/HostAllocationPurpose.java @@ -13,5 +13,7 @@ */ public enum HostAllocationPurpose { ALLOCATE, - LIST_CANDIDATES + LIST_CANDIDATES, + HA_PRECHECK, + HA_START } diff --git a/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java b/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java index 9fc175de2c1..1e7848e0693 100644 --- a/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java +++ b/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java @@ -1942,6 +1942,38 @@ public class CloudOperationsErrorCode { public static final String ORG_ZSTACK_HA_10036 = "ORG_ZSTACK_HA_10036"; + public static final String ORG_ZSTACK_HA_10041 = "ORG_ZSTACK_HA_10041"; + + public static final String ORG_ZSTACK_HA_10042 = "ORG_ZSTACK_HA_10042"; + + public static final String ORG_ZSTACK_HA_10043 = "ORG_ZSTACK_HA_10043"; + + public static final String ORG_ZSTACK_HA_10044 = "ORG_ZSTACK_HA_10044"; + + public static final String ORG_ZSTACK_HA_10045 = "ORG_ZSTACK_HA_10045"; + + public static final String ORG_ZSTACK_HA_10046 = "ORG_ZSTACK_HA_10046"; + + public static final String ORG_ZSTACK_HA_10047 = "ORG_ZSTACK_HA_10047"; + + public static final String ORG_ZSTACK_HA_10048 = "ORG_ZSTACK_HA_10048"; + + public static final String ORG_ZSTACK_HA_10049 = "ORG_ZSTACK_HA_10049"; + + public static final String ORG_ZSTACK_HA_10050 = "ORG_ZSTACK_HA_10050"; + + public static final String ORG_ZSTACK_HA_10051 = "ORG_ZSTACK_HA_10051"; + + public static final String ORG_ZSTACK_HA_10052 = "ORG_ZSTACK_HA_10052"; + + public static final String ORG_ZSTACK_HA_10053 = "ORG_ZSTACK_HA_10053"; + + public static final String ORG_ZSTACK_HA_10054 = "ORG_ZSTACK_HA_10054"; + + public static final String ORG_ZSTACK_HA_10055 = "ORG_ZSTACK_HA_10055"; + + public static final String ORG_ZSTACK_HA_10056 = "ORG_ZSTACK_HA_10056"; + public static final String ORG_ZSTACK_NETWORK_SERVICE_SLB_10000 = "ORG_ZSTACK_NETWORK_SERVICE_SLB_10000"; public static final String ORG_ZSTACK_NETWORK_SERVICE_SLB_10001 = "ORG_ZSTACK_NETWORK_SERVICE_SLB_10001";