mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-4566: fix incorrect values in resource_count table for resource limitation
There are three issues in resource_count table (1) expunge a vm, the public_ip decreases and becomes -1 in basic zone. (2) recover a vm, the volume increase. (3) restore a vm, the volume decrease.
This commit is contained in:
parent
62b09c9253
commit
a16fd4781c
|
|
@ -773,7 +773,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||
}
|
||||
addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
|
||||
|
||||
if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) {
|
||||
if (vlanUse != VlanType.DirectAttached) {
|
||||
addr.setAssociatedWithNetworkId(guestNetworkId);
|
||||
addr.setVpcId(vpcId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1471,8 +1471,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
|
||||
//Update Resource Count for the given account
|
||||
_resourceLimitMgr.incrementResourceCount(account.getId(),
|
||||
ResourceType.volume, new Long(volumes.size()));
|
||||
resourceCountIncrement(account.getId(), new Long(serviceOffering.getCpu()),
|
||||
new Long(serviceOffering.getRamSize()));
|
||||
txn.commit();
|
||||
|
|
@ -4837,6 +4835,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
} else {
|
||||
newVol = volumeMgr.allocateDuplicateVolume(root, null);
|
||||
}
|
||||
// Save usage event and update resource count for user vm volumes
|
||||
if (vm instanceof UserVm) {
|
||||
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume);
|
||||
}
|
||||
|
||||
_volsDao.attachVolume(newVol.getId(), vmId, newVol.getDeviceId());
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ import com.cloud.user.Account;
|
|||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
|
|
@ -112,6 +113,7 @@ public class UserVmManagerTest {
|
|||
@Mock ServiceOfferingDao _offeringDao;
|
||||
@Mock
|
||||
EntityManager _entityMgr;
|
||||
@Mock ResourceLimitService _resourceLimitMgr;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
|
|
@ -130,6 +132,7 @@ public class UserVmManagerTest {
|
|||
_userVmMgr._configMgr = _configMgr;
|
||||
_userVmMgr._offeringDao= _offeringDao;
|
||||
_userVmMgr._capacityMgr = _capacityMgr;
|
||||
_userVmMgr._resourceLimitMgr = _resourceLimitMgr;
|
||||
_userVmMgr._scaleRetry = 2;
|
||||
_userVmMgr._entityMgr = _entityMgr;
|
||||
|
||||
|
|
@ -568,4 +571,4 @@ public class UserVmManagerTest {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue