@@ -2261,15 +2261,26 @@ private boolean checkCIDR(final HostPodVO pod, final String serverPrivateIP, fin
22612261 private HostVO getNewHost (StartupCommand [] startupCommands ) {
22622262 StartupCommand startupCommand = startupCommands [0 ];
22632263
2264- HostVO host = findHostByGuid (startupCommand .getGuid ());
2264+ String fullGuid = startupCommand .getGuid ();
2265+ logger .debug (String .format ("Trying to find Host by guid %s" , fullGuid ));
2266+ HostVO host = findHostByGuid (fullGuid );
22652267
22662268 if (host != null ) {
2269+ logger .debug (String .format ("Found Host by guid %s: %s" , fullGuid , host ));
22672270 return host ;
22682271 }
22692272
2270- host = findHostByGuid (startupCommand .getGuidWithoutResource ());
2273+ String guidPrefix = startupCommand .getGuidWithoutResource ();
2274+ logger .debug (String .format ("Trying to find Host by guid prefix %s" , guidPrefix ));
2275+ host = findHostByGuidPrefix (guidPrefix );
22712276
2272- return host ; // even when host == null!
2277+ if (host != null ) {
2278+ logger .debug (String .format ("Found Host by guid prefix %s: %s" , guidPrefix , host ));
2279+ return host ;
2280+ }
2281+
2282+ logger .debug (String .format ("Could not find Host by guid %s" , fullGuid ));
2283+ return null ;
22732284 }
22742285
22752286 protected HostVO createHostVO (final StartupCommand [] cmds , final ServerResource resource , final Map <String , String > details , List <String > hostTags ,
@@ -3296,13 +3307,23 @@ public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
32963307 public HostVO findHostByGuid (final String guid ) {
32973308 final QueryBuilder <HostVO > sc = QueryBuilder .create (HostVO .class );
32983309 sc .and (sc .entity ().getGuid (), Op .EQ , guid );
3310+ sc .and (sc .entity ().getRemoved (), Op .NULL );
3311+ return sc .find ();
3312+ }
3313+
3314+ @ Override
3315+ public HostVO findHostByGuidPrefix (String guid ) {
3316+ final QueryBuilder <HostVO > sc = QueryBuilder .create (HostVO .class );
3317+ sc .and (sc .entity ().getGuid (), Op .LIKE , guid + "%" );
3318+ sc .and (sc .entity ().getRemoved (), Op .NULL );
32993319 return sc .find ();
33003320 }
33013321
33023322 @ Override
33033323 public HostVO findHostByName (final String name ) {
33043324 final QueryBuilder <HostVO > sc = QueryBuilder .create (HostVO .class );
33053325 sc .and (sc .entity ().getName (), Op .EQ , name );
3326+ sc .and (sc .entity ().getRemoved (), Op .NULL );
33063327 return sc .find ();
33073328 }
33083329
0 commit comments