Skip to content

Commit b7a62fc

Browse files
nvazquezdhslove
authored andcommitted
Fix issue with multiple KVM Host entries in host table (apache#12589)
1 parent 6c9286a commit b7a62fc

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

engine/components-api/src/main/java/com/cloud/resource/ResourceManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public interface ResourceManager extends ResourceService, Configurable {
169169

170170
public HostVO findHostByGuid(String guid);
171171

172+
HostVO findHostByGuidPrefix(String guid);
173+
172174
public HostVO findHostByName(String name);
173175

174176
HostStats getHostStatistics(Host host);

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,15 +3175,26 @@ private boolean checkCIDR(final HostPodVO pod, final String serverPrivateIP, fin
31753175
private HostVO getNewHost(StartupCommand[] startupCommands) {
31763176
StartupCommand startupCommand = startupCommands[0];
31773177

3178-
HostVO host = findHostByGuid(startupCommand.getGuid());
3178+
String fullGuid = startupCommand.getGuid();
3179+
logger.debug(String.format("Trying to find Host by guid %s", fullGuid));
3180+
HostVO host = findHostByGuid(fullGuid);
31793181

31803182
if (host != null) {
3183+
logger.debug(String.format("Found Host by guid %s: %s", fullGuid, host));
31813184
return host;
31823185
}
31833186

3184-
host = findHostByGuid(startupCommand.getGuidWithoutResource());
3187+
String guidPrefix = startupCommand.getGuidWithoutResource();
3188+
logger.debug(String.format("Trying to find Host by guid prefix %s", guidPrefix));
3189+
host = findHostByGuidPrefix(guidPrefix);
31853190

3186-
return host; // even when host == null!
3191+
if (host != null) {
3192+
logger.debug(String.format("Found Host by guid prefix %s: %s", guidPrefix, host));
3193+
return host;
3194+
}
3195+
3196+
logger.debug(String.format("Could not find Host by guid %s", fullGuid));
3197+
return null;
31873198
}
31883199

31893200
protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags,
@@ -4235,13 +4246,23 @@ public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
42354246
public HostVO findHostByGuid(final String guid) {
42364247
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
42374248
sc.and(sc.entity().getGuid(), Op.EQ, guid);
4249+
sc.and(sc.entity().getRemoved(), Op.NULL);
4250+
return sc.find();
4251+
}
4252+
4253+
@Override
4254+
public HostVO findHostByGuidPrefix(String guid) {
4255+
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
4256+
sc.and(sc.entity().getGuid(), Op.LIKE, guid + "%");
4257+
sc.and(sc.entity().getRemoved(), Op.NULL);
42384258
return sc.find();
42394259
}
42404260

42414261
@Override
42424262
public HostVO findHostByName(final String name) {
42434263
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
42444264
sc.and(sc.entity().getName(), Op.EQ, name);
4265+
sc.and(sc.entity().getRemoved(), Op.NULL);
42454266
return sc.find();
42464267
}
42474268

server/src/test/java/com/cloud/resource/MockResourceManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ public HostVO findHostByGuid(final String guid) {
474474
return null;
475475
}
476476

477+
@Override
478+
public HostVO findHostByGuidPrefix(String guid) {
479+
return null;
480+
}
481+
477482
/* (non-Javadoc)
478483
* @see com.cloud.resource.ResourceManager#findHostByName(java.lang.String)
479484
*/

0 commit comments

Comments
 (0)