@@ -46,6 +46,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
4646 private SearchBuilder <NicVO > NonReleasedSearch ;
4747 private GenericSearchBuilder <NicVO , Integer > CountBy ;
4848 private GenericSearchBuilder <NicVO , Integer > CountByForStartingVms ;
49+ private GenericSearchBuilder <NicVO , Integer > CountByForRunningVms ;
4950
5051 @ Inject
5152 VMInstanceDao _vmDao ;
@@ -95,6 +96,17 @@ protected void init() {
9596 join1 .and ("state" , join1 .entity ().getState (), Op .EQ );
9697 CountByForStartingVms .join ("vm" , join1 , CountByForStartingVms .entity ().getInstanceId (), join1 .entity ().getId (), JoinBuilder .JoinType .INNER );
9798 CountByForStartingVms .done ();
99+
100+ CountByForRunningVms = createSearchBuilder (Integer .class );
101+ CountByForRunningVms .select (null , Func .COUNT , CountByForRunningVms .entity ().getId ());
102+ CountByForRunningVms .and ("networkId" , CountByForRunningVms .entity ().getNetworkId (), Op .EQ );
103+ CountByForRunningVms .and ("removed" , CountByForRunningVms .entity ().getRemoved (), Op .NULL );
104+ SearchBuilder <VMInstanceVO > join2 = _vmDao .createSearchBuilder ();
105+ join2 .and ("state" , join2 .entity ().getState (), Op .EQ );
106+ join2 .and ("type" , join2 .entity ().getType (), Op .EQ );
107+ CountByForRunningVms .join ("vm" , join2 , CountByForRunningVms .entity ().getInstanceId (), join2 .entity ().getId (), JoinBuilder .JoinType .INNER );
108+ CountByForRunningVms .done ();
109+
98110 }
99111
100112 @ Override
@@ -287,4 +299,13 @@ public int countNicsForStartingVms(long networkId) {
287299 return results .get (0 );
288300 }
289301
302+ @ Override
303+ public int countNicsForRunningVms (long networkId ) {
304+ SearchCriteria <Integer > sc = CountByForRunningVms .create ();
305+ sc .setParameters ("networkId" , networkId );
306+ sc .setJoinParameters ("vm" , "state" , VirtualMachine .State .Running );
307+ sc .setJoinParameters ("vm" , "type" , VirtualMachine .Type .User );
308+ List <Integer > results = customSearch (sc , null );
309+ return results .get (0 );
310+ }
290311}
0 commit comments