@@ -44,7 +44,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
4444 private GenericSearchBuilder <NicVO , String > IpSearch ;
4545 private SearchBuilder <NicVO > NonReleasedSearch ;
4646 private GenericSearchBuilder <NicVO , Integer > deviceIdSearch ;
47- private GenericSearchBuilder <NicVO , Integer > CountByForStartingVms ;
47+ private GenericSearchBuilder <NicVO , Integer > CountByForNonStoppedVms ;
4848 private SearchBuilder <NicVO > PeerRouterSearch ;
4949
5050 @ Inject
@@ -91,14 +91,16 @@ protected void init() {
9191 deviceIdSearch .and ("instance" , deviceIdSearch .entity ().getInstanceId (), Op .EQ );
9292 deviceIdSearch .done ();
9393
94- CountByForStartingVms = createSearchBuilder (Integer .class );
95- CountByForStartingVms .select (null , Func .COUNT , CountByForStartingVms .entity ().getId ());
96- CountByForStartingVms .and ("networkId" , CountByForStartingVms .entity ().getNetworkId (), Op .EQ );
97- CountByForStartingVms .and ("removed" , CountByForStartingVms .entity ().getRemoved (), Op .NULL );
94+ CountByForNonStoppedVms = createSearchBuilder (Integer .class );
95+ CountByForNonStoppedVms .select (null , Func .COUNT , CountByForNonStoppedVms .entity ().getId ());
96+ CountByForNonStoppedVms .and ("vmType" , CountByForNonStoppedVms .entity ().getVmType (), Op .EQ );
97+ CountByForNonStoppedVms .and ("vmTypeNEQ" , CountByForNonStoppedVms .entity ().getVmType (), Op .NEQ );
98+ CountByForNonStoppedVms .and ("networkId" , CountByForNonStoppedVms .entity ().getNetworkId (), Op .EQ );
99+ CountByForNonStoppedVms .and ("removed" , CountByForNonStoppedVms .entity ().getRemoved (), Op .NULL );
98100 SearchBuilder <VMInstanceVO > join1 = _vmDao .createSearchBuilder ();
99- join1 .and ("state" , join1 .entity ().getState (), Op .EQ );
100- CountByForStartingVms .join ("vm" , join1 , CountByForStartingVms .entity ().getInstanceId (), join1 .entity ().getId (), JoinBuilder .JoinType .INNER );
101- CountByForStartingVms .done ();
101+ join1 .and ("state" , join1 .entity ().getState (), Op .IN );
102+ CountByForNonStoppedVms .join ("vm" , join1 , CountByForNonStoppedVms .entity ().getInstanceId (), join1 .entity ().getId (), JoinBuilder .JoinType .INNER );
103+ CountByForNonStoppedVms .done ();
102104
103105 PeerRouterSearch = createSearchBuilder ();
104106 PeerRouterSearch .and ("instanceId" , PeerRouterSearch .entity ().getInstanceId (), Op .NEQ );
@@ -346,10 +348,21 @@ public List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, Virtu
346348 }
347349
348350 @ Override
349- public int countNicsForStartingVms (long networkId ) {
350- SearchCriteria <Integer > sc = CountByForStartingVms .create ();
351+ public int countNicsForNonStoppedVms (long networkId ) {
352+ SearchCriteria <Integer > sc = CountByForNonStoppedVms .create ();
351353 sc .setParameters ("networkId" , networkId );
352- sc .setJoinParameters ("vm" , "state" , VirtualMachine .State .Starting );
354+ sc .setParameters ("vmType" , VirtualMachine .Type .User );
355+ sc .setJoinParameters ("vm" , "state" , new Object [] {VirtualMachine .State .Starting , VirtualMachine .State .Running , VirtualMachine .State .Stopping , VirtualMachine .State .Migrating });
356+ List <Integer > results = customSearch (sc , null );
357+ return results .get (0 );
358+ }
359+
360+ @ Override
361+ public int countNicsForNonStoppedRunningVrs (long networkId ) {
362+ SearchCriteria <Integer > sc = CountByForNonStoppedVms .create ();
363+ sc .setParameters ("networkId" , networkId );
364+ sc .setParameters ("vmTypeNEQ" , VirtualMachine .Type .User );
365+ sc .setJoinParameters ("vm" , "state" , new Object [] {VirtualMachine .State .Starting , VirtualMachine .State .Stopping , VirtualMachine .State .Migrating });
353366 List <Integer > results = customSearch (sc , null );
354367 return results .get (0 );
355368 }
0 commit comments