Changed usage code to look up stats by network ID.

This commit is contained in:
keshav 2011-05-16 14:41:47 -07:00
parent 1ff550f4a6
commit 5d5363965d
3 changed files with 23 additions and 20 deletions

View File

@ -423,7 +423,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
final Transaction txn = Transaction.currentTxn();
try {
txn.start();
final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), null, router.getId(), router.getType().toString());
final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), router.getNetworkId(), null, router.getId(), router.getType().toString());
if (userStats != null) {
final RebootAnswer sa = (RebootAnswer) answer;
final Long received = sa.getBytesReceived();
@ -644,7 +644,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
continue;
}
txn.start();
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(), router.getDataCenterId(), null, router.getId(), router.getType().toString());
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(), router.getDataCenterId(), router.getNetworkId(), null, router.getId(), router.getType().toString());
if (stats == null) {
s_logger.warn("unable to find stats for account: " + router.getAccountId());
continue;
@ -761,7 +761,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
// Creating stats entry for router
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, null, router.getId(), router.getType().toString());
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, router.getNetworkId(), null, router.getId(), router.getType().toString());
if (stats == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating user statistics for the account: " + owner.getId() + " Router Id: " + router.getId());
@ -846,7 +846,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
router = this.start(router, _accountService.getSystemUser(), _accountService.getSystemAccount(), params);
}
// Creating stats entry for router
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, null, router.getId(), router.getType().toString());
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, router.getNetworkId(), null, router.getId(), router.getType().toString());
if (stats == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating user statistics for the account: " + owner.getId() + " Router Id: " + router.getId());

View File

@ -25,9 +25,9 @@ import com.cloud.user.UserStatisticsVO;
import com.cloud.utils.db.GenericDao;
public interface UserStatisticsDao extends GenericDao<UserStatisticsVO, Long> {
UserStatisticsVO findBy(long accountId, long dcId, String publicIp, Long deviceId, String deviceType);
UserStatisticsVO findBy(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType);
UserStatisticsVO lock(long accountId, long dcId, String publicIp, Long hostId, String deviceType);
UserStatisticsVO lock(long accountId, long dcId, long networkId, String publicIp, Long hostId, String deviceType);
List<UserStatisticsVO> listBy(long accountId);

View File

@ -43,7 +43,7 @@ public class UserStatisticsDaoImpl extends GenericDaoBase<UserStatisticsVO, Long
"FROM user_statistics us, account a " +
"WHERE us.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " +
"ORDER BY us.id";
private final SearchBuilder<UserStatisticsVO> AccountDcIpDeviceSearch;
private final SearchBuilder<UserStatisticsVO> AllFieldsSearch;
private final SearchBuilder<UserStatisticsVO> AccountSearch;
public UserStatisticsDaoImpl() {
@ -51,34 +51,37 @@ public class UserStatisticsDaoImpl extends GenericDaoBase<UserStatisticsVO, Long
AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AccountSearch.done();
AccountDcIpDeviceSearch = createSearchBuilder();
AccountDcIpDeviceSearch.and("account", AccountDcIpDeviceSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AccountDcIpDeviceSearch.and("dc", AccountDcIpDeviceSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
AccountDcIpDeviceSearch.and("ip", AccountDcIpDeviceSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
AccountDcIpDeviceSearch.and("device", AccountDcIpDeviceSearch.entity().getDeviceId(), SearchCriteria.Op.EQ);
AccountDcIpDeviceSearch.and("deviceType", AccountDcIpDeviceSearch.entity().getDeviceType(), SearchCriteria.Op.EQ);
AccountDcIpDeviceSearch.done();
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("device", AllFieldsSearch.entity().getDeviceId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("deviceType", AllFieldsSearch.entity().getDeviceType(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
}
@Override
public UserStatisticsVO findBy(long accountId, long dcId, String publicIp, Long deviceId, String deviceType) {
SearchCriteria<UserStatisticsVO> sc = AccountDcIpDeviceSearch.create();
public UserStatisticsVO findBy(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) {
SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create();
sc.setParameters("account", accountId);
sc.setParameters("dc", dcId);
sc.setParameters("network", networkId);
sc.setParameters("ip", publicIp);
sc.setParameters("device", deviceId);
sc.setParameters("deviceType", deviceType);
sc.setParameters("deviceType", deviceType);
return findOneBy(sc);
}
@Override
public UserStatisticsVO lock(long accountId, long dcId, String publicIp, Long deviceId, String deviceType) {
SearchCriteria<UserStatisticsVO> sc = AccountDcIpDeviceSearch.create();
public UserStatisticsVO lock(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) {
SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create();
sc.setParameters("account", accountId);
sc.setParameters("dc", dcId);
sc.setParameters("network", networkId);
sc.setParameters("ip", publicIp);
sc.setParameters("device", deviceId);
sc.setParameters("deviceType", deviceType);
sc.setParameters("deviceType", deviceType);
return lockOneRandomRow(sc, true);
}