Skip to content

Commit 97e2f7b

Browse files
committed
Address copilot comments
1 parent 6aee0d9 commit 97e2f7b

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,20 +2291,22 @@ protected void validateExistingHostLocationImmutable(final HostVO host, final bo
22912291
if (newHost || host == null || host.getType() != Host.Type.Routing) {
22922292
return;
22932293
}
2294-
final Long existingDcId = host.getDataCenterId();
2294+
final long existingDcId = host.getDataCenterId();
22952295
final Long existingPodId = host.getPodId();
22962296
final Long existingClusterId = host.getClusterId();
2297-
if (existingDcId == null || existingPodId == null || existingClusterId == null) {
2297+
if (existingPodId == null || existingClusterId == null) {
22982298
return;
22992299
}
23002300
if (existingDcId == dcId && Objects.equals(existingPodId, podId) && Objects.equals(existingClusterId, clusterId)) {
23012301
return;
23022302
}
23032303
final String identity = host.getUuid() != null ? host.getUuid() : host.getGuid();
23042304
final String ip = startup != null ? startup.getPrivateIpAddress() : "unknown";
2305-
throw new InvalidParameterValueException(String.format(
2306-
"Host %s (ip: %s) is already registered in [zone: %d, pod: %d, cluster: %d] and cannot be re-added or reconnected with [zone: %d, pod: %s, cluster: %s]. Zone, pod and cluster of an existing host are immutable.",
2307-
identity, ip, existingDcId, existingPodId, existingClusterId, dcId, podId, clusterId));
2305+
throw new InvalidParameterValueException(
2306+
String.format("Host %s (ip: %s) is already registered in [zone: %s, pod: %s, cluster: %s] and cannot " +
2307+
"be re-added or reconnected with [zone: %s, pod: %s, cluster: %s]. Zone, pod and " +
2308+
"cluster of an existing host are immutable.",
2309+
identity, ip, existingDcId, existingPodId, existingClusterId, dcId, podId, clusterId));
23082310
}
23092311

23102312
protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags,
@@ -2618,19 +2620,23 @@ void checkForDuplicateHost(final String url) {
26182620
String ipAddress = null;
26192621
try {
26202622
hostIpOrName = new URI(UriUtils.encodeURIComponent(url)).getHost();
2623+
if (StringUtils.isBlank(hostIpOrName)) {
2624+
return;
2625+
}
26212626
InetAddress ip = InetAddress.getByName(hostIpOrName);
26222627
ipAddress = ip.getHostAddress();
26232628
} catch (final URISyntaxException | UnknownHostException ignore) {
26242629
// unparseable URL or unknown host - discoverer will reject it shortly anyway
2625-
}
2626-
if (StringUtils.isBlank(hostIpOrName)) {
26272630
return;
26282631
}
2629-
final HostVO existingByIp = _hostDao.findByIp(ipAddress);
2630-
if (existingByIp != null) {
2631-
throw new InvalidParameterValueException(String.format(
2632-
"A host with IP address / hostname '%s' (%s) already exists (id: %s). Remove it before adding again.",
2633-
hostIpOrName, ipAddress, existingByIp.getUuid()));
2632+
2633+
if (StringUtils.isNotBlank(ipAddress)) {
2634+
final HostVO existingByIp = _hostDao.findByIp(ipAddress);
2635+
if (existingByIp != null) {
2636+
throw new InvalidParameterValueException(String.format(
2637+
"A host with IP address '%s' (%s) already exists (id: %s). Remove it before adding again.",
2638+
ipAddress, hostIpOrName, existingByIp));
2639+
}
26342640
}
26352641
}
26362642

0 commit comments

Comments
 (0)