diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java index 4a07455832a..0c556c843d9 100644 --- a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -244,6 +244,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N GarbageCollectedSearch = createSearchBuilder(Long.class); GarbageCollectedSearch.selectFields(GarbageCollectedSearch.entity().getId()); SearchBuilder join7 = _ntwkOpDao.createSearchBuilder(); + join7.and("activenics", join7.entity().getActiveNicsCount(), Op.EQ); join7.and("gc", join7.entity().isGarbageCollected(), Op.EQ); join7.and("check", join7.entity().isCheckForGc(), Op.EQ); GarbageCollectedSearch.join("ntwkOpGC", join7, GarbageCollectedSearch.entity().getId(), join7.entity().getId(), JoinBuilder.JoinType.INNER); @@ -437,6 +438,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N public List findNetworksToGarbageCollect() { SearchCriteria sc = GarbageCollectedSearch.create(); sc.setJoinParameters("ntwkOffGC", "isPersistent", false); + sc.setJoinParameters("ntwkOpGC", "activenics", 0); sc.setJoinParameters("ntwkOpGC", "gc", true); sc.setJoinParameters("ntwkOpGC", "check", true); return customSearch(sc, null); diff --git a/engine/schema/src/com/cloud/vm/dao/NicDao.java b/engine/schema/src/com/cloud/vm/dao/NicDao.java index 9f153f8eeb4..a7ad01692cf 100644 --- a/engine/schema/src/com/cloud/vm/dao/NicDao.java +++ b/engine/schema/src/com/cloud/vm/dao/NicDao.java @@ -74,6 +74,4 @@ public interface NicDao extends GenericDao { List listByNetworkIdTypeAndGatewayAndBroadcastUri(long networkId, VirtualMachine.Type vmType, String gateway, URI broadcastUri); int countNicsForStartingVms(long networkId); - - int countNicsForRunningVms(long networkId); } diff --git a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java index ca44b631e4f..2a9a6025071 100644 --- a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java @@ -46,7 +46,6 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { private SearchBuilder NonReleasedSearch; private GenericSearchBuilder CountBy; private GenericSearchBuilder CountByForStartingVms; - private GenericSearchBuilder CountByForRunningVms; @Inject VMInstanceDao _vmDao; @@ -96,17 +95,6 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { join1.and("state", join1.entity().getState(), Op.EQ); CountByForStartingVms.join("vm", join1, CountByForStartingVms.entity().getInstanceId(), join1.entity().getId(), JoinBuilder.JoinType.INNER); CountByForStartingVms.done(); - - CountByForRunningVms = createSearchBuilder(Integer.class); - CountByForRunningVms.select(null, Func.COUNT, CountByForRunningVms.entity().getId()); - CountByForRunningVms.and("networkId", CountByForRunningVms.entity().getNetworkId(), Op.EQ); - CountByForRunningVms.and("removed", CountByForRunningVms.entity().getRemoved(), Op.NULL); - SearchBuilder join2 = _vmDao.createSearchBuilder(); - join2.and("state", join2.entity().getState(), Op.EQ); - join2.and("type", join2.entity().getType(), Op.EQ); - CountByForRunningVms.join("vm", join2, CountByForRunningVms.entity().getInstanceId(), join2.entity().getId(), JoinBuilder.JoinType.INNER); - CountByForRunningVms.done(); - } @Override @@ -303,14 +291,4 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { List results = customSearch(sc, null); return results.get(0); } - - @Override - public int countNicsForRunningVms(long networkId) { - SearchCriteria sc = CountByForRunningVms.create(); - sc.setParameters("networkId", networkId); - sc.setJoinParameters("vm", "state", VirtualMachine.State.Running); - sc.setJoinParameters("vm", "type", VirtualMachine.Type.User); - List results = customSearch(sc, null); - return results.get(0); - } } diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java index 1fd354df6d3..60882124fcc 100644 --- a/server/src/com/cloud/network/NetworkModelImpl.java +++ b/server/src/com/cloud/network/NetworkModelImpl.java @@ -2232,13 +2232,6 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { return false; } - // Due to VMSync issue, there can be cases where nic count is zero, but there can be VM's running in the network - // so add extra guard to check if network GC is actially required. - if (_nicDao.countNicsForRunningVms(networkId) > 0) { - s_logger.debug("Network id=" + networkId + " is not ready for GC as it has vms that are Running at the moment"); - return false; - } - return true; }