Skip to content

Commit 62d3503

Browse files
nvazquezLocharla, Sandeep
authored andcommitted
Fix issue with multiple KVM Host entries in host table (apache#12589)
1 parent 0c09e48 commit 62d3503

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
@@ -167,6 +167,8 @@ public interface ResourceManager extends ResourceService, Configurable {
167167

168168
public HostVO findHostByGuid(String guid);
169169

170+
HostVO findHostByGuidPrefix(String guid);
171+
170172
public HostVO findHostByName(String name);
171173

172174
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
@@ -3149,15 +3149,26 @@ private boolean checkCIDR(final HostPodVO pod, final String serverPrivateIP, fin
31493149
private HostVO getNewHost(StartupCommand[] startupCommands) {
31503150
StartupCommand startupCommand = startupCommands[0];
31513151

3152-
HostVO host = findHostByGuid(startupCommand.getGuid());
3152+
String fullGuid = startupCommand.getGuid();
3153+
logger.debug(String.format("Trying to find Host by guid %s", fullGuid));
3154+
HostVO host = findHostByGuid(fullGuid);
31533155

31543156
if (host != null) {
3157+
logger.debug(String.format("Found Host by guid %s: %s", fullGuid, host));
31553158
return host;
31563159
}
31573160

3158-
host = findHostByGuid(startupCommand.getGuidWithoutResource());
3161+
String guidPrefix = startupCommand.getGuidWithoutResource();
3162+
logger.debug(String.format("Trying to find Host by guid prefix %s", guidPrefix));
3163+
host = findHostByGuidPrefix(guidPrefix);
31593164

3160-
return host; // even when host == null!
3165+
if (host != null) {
3166+
logger.debug(String.format("Found Host by guid prefix %s: %s", guidPrefix, host));
3167+
return host;
3168+
}
3169+
3170+
logger.debug(String.format("Could not find Host by guid %s", fullGuid));
3171+
return null;
31613172
}
31623173

31633174
protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags,
@@ -4209,13 +4220,23 @@ public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
42094220
public HostVO findHostByGuid(final String guid) {
42104221
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
42114222
sc.and(sc.entity().getGuid(), Op.EQ, guid);
4223+
sc.and(sc.entity().getRemoved(), Op.NULL);
4224+
return sc.find();
4225+
}
4226+
4227+
@Override
4228+
public HostVO findHostByGuidPrefix(String guid) {
4229+
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
4230+
sc.and(sc.entity().getGuid(), Op.LIKE, guid + "%");
4231+
sc.and(sc.entity().getRemoved(), Op.NULL);
42124232
return sc.find();
42134233
}
42144234

42154235
@Override
42164236
public HostVO findHostByName(final String name) {
42174237
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
42184238
sc.and(sc.entity().getName(), Op.EQ, name);
4239+
sc.and(sc.entity().getRemoved(), Op.NULL);
42194240
return sc.find();
42204241
}
42214242

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)