Skip to content

Commit 5d53639

Browse files
author
keshav
committed
Changed usage code to look up stats by network ID.
1 parent 1ff550f commit 5d53639

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public void processStopOrRebootAnswer(final DomainRouterVO router, Answer answer
423423
final Transaction txn = Transaction.currentTxn();
424424
try {
425425
txn.start();
426-
final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), null, router.getId(), router.getType().toString());
426+
final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), router.getNetworkId(), null, router.getId(), router.getType().toString());
427427
if (userStats != null) {
428428
final RebootAnswer sa = (RebootAnswer) answer;
429429
final Long received = sa.getBytesReceived();
@@ -644,7 +644,7 @@ public void run() {
644644
continue;
645645
}
646646
txn.start();
647-
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(), router.getDataCenterId(), null, router.getId(), router.getType().toString());
647+
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(), router.getDataCenterId(), router.getNetworkId(), null, router.getId(), router.getType().toString());
648648
if (stats == null) {
649649
s_logger.warn("unable to find stats for account: " + router.getAccountId());
650650
continue;
@@ -761,7 +761,7 @@ public DomainRouterVO deployVirtualRouter(Network guestNetwork, DeployDestinatio
761761
}
762762

763763
// Creating stats entry for router
764-
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, null, router.getId(), router.getType().toString());
764+
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, router.getNetworkId(), null, router.getId(), router.getType().toString());
765765
if (stats == null) {
766766
if (s_logger.isDebugEnabled()) {
767767
s_logger.debug("Creating user statistics for the account: " + owner.getId() + " Router Id: " + router.getId());
@@ -846,7 +846,7 @@ public DomainRouterVO deployDhcp(Network guestNetwork, DeployDestination dest, A
846846
router = this.start(router, _accountService.getSystemUser(), _accountService.getSystemAccount(), params);
847847
}
848848
// Creating stats entry for router
849-
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, null, router.getId(), router.getType().toString());
849+
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, router.getNetworkId(), null, router.getId(), router.getType().toString());
850850
if (stats == null) {
851851
if (s_logger.isDebugEnabled()) {
852852
s_logger.debug("Creating user statistics for the account: " + owner.getId() + " Router Id: " + router.getId());

‎server/src/com/cloud/user/dao/UserStatisticsDao.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.cloud.utils.db.GenericDao;
2626

2727
public interface UserStatisticsDao extends GenericDao<UserStatisticsVO, Long> {
28-
UserStatisticsVO findBy(long accountId, long dcId, String publicIp, Long deviceId, String deviceType);
28+
UserStatisticsVO findBy(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType);
2929

30-
UserStatisticsVO lock(long accountId, long dcId, String publicIp, Long hostId, String deviceType);
30+
UserStatisticsVO lock(long accountId, long dcId, long networkId, String publicIp, Long hostId, String deviceType);
3131

3232
List<UserStatisticsVO> listBy(long accountId);
3333

‎server/src/com/cloud/user/dao/UserStatisticsDaoImpl.java‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,45 @@ public class UserStatisticsDaoImpl extends GenericDaoBase<UserStatisticsVO, Long
4343
"FROM user_statistics us, account a " +
4444
"WHERE us.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " +
4545
"ORDER BY us.id";
46-
private final SearchBuilder<UserStatisticsVO> AccountDcIpDeviceSearch;
46+
private final SearchBuilder<UserStatisticsVO> AllFieldsSearch;
4747
private final SearchBuilder<UserStatisticsVO> AccountSearch;
4848

4949
public UserStatisticsDaoImpl() {
5050
AccountSearch = createSearchBuilder();
5151
AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
5252
AccountSearch.done();
5353

54-
AccountDcIpDeviceSearch = createSearchBuilder();
55-
AccountDcIpDeviceSearch.and("account", AccountDcIpDeviceSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
56-
AccountDcIpDeviceSearch.and("dc", AccountDcIpDeviceSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
57-
AccountDcIpDeviceSearch.and("ip", AccountDcIpDeviceSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
58-
AccountDcIpDeviceSearch.and("device", AccountDcIpDeviceSearch.entity().getDeviceId(), SearchCriteria.Op.EQ);
59-
AccountDcIpDeviceSearch.and("deviceType", AccountDcIpDeviceSearch.entity().getDeviceType(), SearchCriteria.Op.EQ);
60-
AccountDcIpDeviceSearch.done();
54+
AllFieldsSearch = createSearchBuilder();
55+
AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
56+
AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
57+
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
58+
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
59+
AllFieldsSearch.and("device", AllFieldsSearch.entity().getDeviceId(), SearchCriteria.Op.EQ);
60+
AllFieldsSearch.and("deviceType", AllFieldsSearch.entity().getDeviceType(), SearchCriteria.Op.EQ);
61+
AllFieldsSearch.done();
6162
}
6263

6364
@Override
64-
public UserStatisticsVO findBy(long accountId, long dcId, String publicIp, Long deviceId, String deviceType) {
65-
SearchCriteria<UserStatisticsVO> sc = AccountDcIpDeviceSearch.create();
65+
public UserStatisticsVO findBy(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) {
66+
SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create();
6667
sc.setParameters("account", accountId);
6768
sc.setParameters("dc", dcId);
69+
sc.setParameters("network", networkId);
6870
sc.setParameters("ip", publicIp);
6971
sc.setParameters("device", deviceId);
70-
sc.setParameters("deviceType", deviceType);
72+
sc.setParameters("deviceType", deviceType);
7173
return findOneBy(sc);
7274
}
7375

7476
@Override
75-
public UserStatisticsVO lock(long accountId, long dcId, String publicIp, Long deviceId, String deviceType) {
76-
SearchCriteria<UserStatisticsVO> sc = AccountDcIpDeviceSearch.create();
77+
public UserStatisticsVO lock(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) {
78+
SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create();
7779
sc.setParameters("account", accountId);
7880
sc.setParameters("dc", dcId);
81+
sc.setParameters("network", networkId);
7982
sc.setParameters("ip", publicIp);
8083
sc.setParameters("device", deviceId);
81-
sc.setParameters("deviceType", deviceType);
84+
sc.setParameters("deviceType", deviceType);
8285
return lockOneRandomRow(sc, true);
8386
}
8487

0 commit comments

Comments
 (0)