@@ -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 );
@@ -338,10 +340,21 @@ public List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, Virtu
338340 }
339341
340342 @ Override
341- public int countNicsForStartingVms (long networkId ) {
342- SearchCriteria <Integer > sc = CountByForStartingVms .create ();
343+ public int countNicsForNonStoppedVms (long networkId ) {
344+ SearchCriteria <Integer > sc = CountByForNonStoppedVms .create ();
343345 sc .setParameters ("networkId" , networkId );
344- sc .setJoinParameters ("vm" , "state" , VirtualMachine .State .Starting );
346+ sc .setParameters ("vmType" , VirtualMachine .Type .User );
347+ sc .setJoinParameters ("vm" , "state" , new Object [] {VirtualMachine .State .Starting , VirtualMachine .State .Running , VirtualMachine .State .Stopping , VirtualMachine .State .Migrating });
348+ List <Integer > results = customSearch (sc , null );
349+ return results .get (0 );
350+ }
351+
352+ @ Override
353+ public int countNicsForNonStoppedRunningVrs (long networkId ) {
354+ SearchCriteria <Integer > sc = CountByForNonStoppedVms .create ();
355+ sc .setParameters ("networkId" , networkId );
356+ sc .setParameters ("vmTypeNEQ" , VirtualMachine .Type .User );
357+ sc .setJoinParameters ("vm" , "state" , new Object [] {VirtualMachine .State .Starting , VirtualMachine .State .Stopping , VirtualMachine .State .Migrating });
345358 List <Integer > results = customSearch (sc , null );
346359 return results .get (0 );
347360 }
0 commit comments