From aecfe6d500dd3fa1b6bcef53f58dae7fa87c0447 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 12 Jun 2019 12:47:24 +0530 Subject: [PATCH] server: save GUID for KVM cluster (#3398) When a KVM host is added to a cluster, the cluster GUID is null. In case the KVM host fails to be added, the GUID is not set to null and if any other hosts are added an exception is thrown by the resource manager that does not allow addition of hosts to a cluster with existing hosts whose GUID is null. In case of KVM, other hosts may be added in parallel therefore this restriction can be safely removed. Signed-off-by: Rohit Yadav --- .../kvm/discoverer/LibvirtServerDiscoverer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java b/server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java index 0b8b40b1b9b..6c9bcace90f 100644 --- a/server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java +++ b/server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java @@ -210,6 +210,12 @@ public abstract class LibvirtServerDiscoverer extends DiscovererBase implements return null; } + // Set cluster GUID based on cluster ID if null + if (cluster.getGuid() == null) { + cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString()); + _clusterDao.update(clusterId, cluster); + } + Map> resources = new HashMap>(); Map details = new HashMap(); if (!uri.getScheme().equals("http")) { @@ -230,8 +236,9 @@ public abstract class LibvirtServerDiscoverer extends DiscovererBase implements if (existingHosts != null) { for (HostVO existingHost : existingHosts) { if (existingHost.getGuid().toLowerCase().startsWith(guid.toLowerCase())) { - s_logger.debug("Skipping " + agentIp + " because " + guid + " is already in the database for resource " + existingHost.getGuid()); - return null; + final String msg = "Skipping host " + agentIp + " because " + guid + " is already in the database for resource " + existingHost.getGuid() + " with ID " + existingHost.getUuid(); + s_logger.debug(msg); + throw new CloudRuntimeException(msg); } } } @@ -326,12 +333,6 @@ public abstract class LibvirtServerDiscoverer extends DiscovererBase implements details.put("guid", connectedHost.getGuid()); - // place a place holder guid derived from cluster ID - if (cluster.getGuid() == null) { - cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString()); - _clusterDao.update(clusterId, cluster); - } - // save user name and password _hostDao.loadDetails(connectedHost); Map hostDetails = connectedHost.getDetails();