|
1 | 1 | package org.zstack.compute.allocator; |
2 | 2 |
|
3 | 3 | import org.apache.commons.collections.CollectionUtils; |
| 4 | +import org.apache.commons.lang.StringUtils; |
4 | 5 | import org.springframework.beans.factory.annotation.Autowire; |
5 | 6 | import org.springframework.beans.factory.annotation.Autowired; |
6 | 7 | import org.springframework.beans.factory.annotation.Configurable; |
@@ -81,30 +82,44 @@ public void allocate() { |
81 | 82 | List<String> clusterUuids = (List<String>) spec.getExtraData().get(HostAllocatorConstant.LocationSelector.cluster); |
82 | 83 | String hostUuid = (String) spec.getExtraData().get(HostAllocatorConstant.LocationSelector.host); |
83 | 84 |
|
84 | | - if (zoneUuid == null && CollectionUtils.isEmpty(clusterUuids) && hostUuid == null && spec.getHypervisorType() == null) { |
| 85 | + String hypervisorType = spec.getHypervisorType(); |
| 86 | + |
| 87 | + // normalize empty strings to null — treat empty string as "not specified" |
| 88 | + zoneUuid = StringUtils.isEmpty(zoneUuid) ? null : zoneUuid; |
| 89 | + hostUuid = StringUtils.isEmpty(hostUuid) ? null : hostUuid; |
| 90 | + hypervisorType = StringUtils.isEmpty(hypervisorType) ? null : hypervisorType; |
| 91 | + if (!CollectionUtils.isEmpty(clusterUuids)) { |
| 92 | + clusterUuids = new ArrayList<>(clusterUuids); |
| 93 | + clusterUuids.removeIf(s -> s == null || s.isEmpty()); |
| 94 | + if (clusterUuids.isEmpty()) { |
| 95 | + clusterUuids = null; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + if (zoneUuid == null && CollectionUtils.isEmpty(clusterUuids) && hostUuid == null && hypervisorType == null) { |
85 | 100 | next(candidates); |
86 | 101 | return; |
87 | 102 | } |
88 | 103 |
|
89 | 104 | if (amITheFirstFlow()) { |
90 | | - candidates = allocate(zoneUuid, clusterUuids, hostUuid, spec.getHypervisorType()); |
| 105 | + candidates = allocate(zoneUuid, clusterUuids, hostUuid, hypervisorType); |
91 | 106 | } else { |
92 | | - candidates = allocate(candidates, zoneUuid, clusterUuids, hostUuid, spec.getHypervisorType()); |
| 107 | + candidates = allocate(candidates, zoneUuid, clusterUuids, hostUuid, hypervisorType); |
93 | 108 | } |
94 | 109 |
|
95 | 110 | if (candidates.isEmpty()) { |
96 | 111 | StringBuilder args = new StringBuilder(); |
97 | 112 | if (zoneUuid != null) { |
98 | 113 | args.append(String.format("zoneUuid=%s", zoneUuid)).append(" "); |
99 | 114 | } |
100 | | - if (!clusterUuids.isEmpty()) { |
| 115 | + if (!CollectionUtils.isEmpty(clusterUuids)) { |
101 | 116 | args.append(String.format("clusterUuid in %s", clusterUuids)).append(" "); |
102 | 117 | } |
103 | 118 | if (hostUuid != null) { |
104 | 119 | args.append(String.format("hostUuid=%s", hostUuid)).append(" "); |
105 | 120 | } |
106 | | - if (spec.getHypervisorType() != null) { |
107 | | - args.append(String.format("hypervisorType=%s", spec.getHypervisorType())).append(" "); |
| 121 | + if (hypervisorType != null) { |
| 122 | + args.append(String.format("hypervisorType=%s", hypervisorType)).append(" "); |
108 | 123 | } |
109 | 124 | fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10036, "No host with %s found", args)); |
110 | 125 | } else { |
|
0 commit comments