Skip to content

Commit a0097d8

Browse files
Anurag Awasthiyadvr
authored andcommitted
engine/schema: count Starting along with Running VMs for user dispersing planner (#3462)
Consider running and starting VMs when considering load ona host for VM deployement for more accurate dispersion. Fixes: #3442
1 parent 92773ea commit a0097d8

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
122122

123123
List<Long> listHostIdsByVmCount(long dcId, Long podId, Long clusterId, long accountId);
124124

125-
Long countRunningByAccount(long accountId);
125+
Long countRunningAndStartingByAccount(long accountId);
126126

127127
Long countByZoneAndState(long zoneId, State state);
128128

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
8787
protected SearchBuilder<VMInstanceVO> HostNameAndZoneSearch;
8888
protected GenericSearchBuilder<VMInstanceVO, Long> FindIdsOfVirtualRoutersByAccount;
8989
protected GenericSearchBuilder<VMInstanceVO, Long> CountActiveByHost;
90-
protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByAccount;
90+
protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningAndStartingByAccount;
9191
protected GenericSearchBuilder<VMInstanceVO, Long> CountByZoneAndState;
9292
protected SearchBuilder<VMInstanceVO> NetworkTypeSearch;
9393
protected GenericSearchBuilder<VMInstanceVO, String> DistinctHostNameSearch;
@@ -245,11 +245,11 @@ protected void init() {
245245
CountActiveByHost.and("state", CountActiveByHost.entity().getState(), SearchCriteria.Op.IN);
246246
CountActiveByHost.done();
247247

248-
CountRunningByAccount = createSearchBuilder(Long.class);
249-
CountRunningByAccount.select(null, Func.COUNT, null);
250-
CountRunningByAccount.and("account", CountRunningByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
251-
CountRunningByAccount.and("state", CountRunningByAccount.entity().getState(), SearchCriteria.Op.EQ);
252-
CountRunningByAccount.done();
248+
CountRunningAndStartingByAccount = createSearchBuilder(Long.class);
249+
CountRunningAndStartingByAccount.select(null, Func.COUNT, null);
250+
CountRunningAndStartingByAccount.and("account", CountRunningAndStartingByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
251+
CountRunningAndStartingByAccount.and("states", CountRunningAndStartingByAccount.entity().getState(), SearchCriteria.Op.IN);
252+
CountRunningAndStartingByAccount.done();
253253

254254
CountByZoneAndState = createSearchBuilder(Long.class);
255255
CountByZoneAndState.select(null, Func.COUNT, null);
@@ -749,10 +749,10 @@ public HashMap<String, Long> countVgpuVMs(Long dcId, Long podId, Long clusterId)
749749
}
750750

751751
@Override
752-
public Long countRunningByAccount(long accountId) {
753-
SearchCriteria<Long> sc = CountRunningByAccount.create();
752+
public Long countRunningAndStartingByAccount(long accountId) {
753+
SearchCriteria<Long> sc = CountRunningAndStartingByAccount.create();
754754
sc.setParameters("account", accountId);
755-
sc.setParameters("state", State.Running);
755+
sc.setParameters("states", new Object[] {State.Starting, State.Running});
756756
return customSearch(sc, null).get(0);
757757
}
758758

plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private List<Long> orderByApplyingWeights(Pair<List<Long>, Map<Long, Double>> ca
146146
//normalize the vmCountMap
147147
LinkedHashMap<Long, Double> normalisedVmCountIdMap = new LinkedHashMap<Long, Double>();
148148

149-
Long totalVmsOfAccount = vmInstanceDao.countRunningByAccount(accountId);
149+
Long totalVmsOfAccount = vmInstanceDao.countRunningAndStartingByAccount(accountId);
150150
if (s_logger.isDebugEnabled()) {
151151
s_logger.debug("Total VMs for account: " + totalVmsOfAccount);
152152
}

0 commit comments

Comments
 (0)