mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Updated resource counter to include correct size after volume creation/resize and other improvements (#6587)
* Updated resource counter to include correct size after volume creation/resize and other improvements - Recalculate resource counters for root domain in the periodic task - Update correct size in the primary_storage resource counter after volume creation/resize - Some code improvements * review and sonarcloud issues Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com> Co-authored-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
parent
152a274845
commit
75da982d73
@ -18,9 +18,10 @@ package com.cloud.configuration;
|
|||||||
|
|
||||||
public interface Resource {
|
public interface Resource {
|
||||||
|
|
||||||
public static final short RESOURCE_UNLIMITED = -1;
|
short RESOURCE_UNLIMITED = -1;
|
||||||
|
String UNLIMITED = "Unlimited";
|
||||||
|
|
||||||
public enum ResourceType { // Primary and Secondary storage are allocated_storage and not the physical storage.
|
enum ResourceType { // Primary and Secondary storage are allocated_storage and not the physical storage.
|
||||||
user_vm("user_vm", 0, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
user_vm("user_vm", 0, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
||||||
public_ip("public_ip", 1, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
public_ip("public_ip", 1, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
||||||
volume("volume", 2, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
volume("volume", 2, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.util.Date;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.configuration.Resource.ResourceType;
|
||||||
import com.cloud.dc.VsphereStoragePolicyVO;
|
import com.cloud.dc.VsphereStoragePolicyVO;
|
||||||
import com.cloud.dc.dao.VsphereStoragePolicyDao;
|
import com.cloud.dc.dao.VsphereStoragePolicyDao;
|
||||||
import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
||||||
@ -28,6 +29,7 @@ import com.cloud.storage.VMTemplateVO;
|
|||||||
import com.cloud.storage.VolumeDetailVO;
|
import com.cloud.storage.VolumeDetailVO;
|
||||||
import com.cloud.storage.dao.VMTemplateDao;
|
import com.cloud.storage.dao.VMTemplateDao;
|
||||||
import com.cloud.storage.dao.VolumeDetailsDao;
|
import com.cloud.storage.dao.VolumeDetailsDao;
|
||||||
|
import com.cloud.user.ResourceLimitService;
|
||||||
import com.cloud.vm.VmDetailConstants;
|
import com.cloud.vm.VmDetailConstants;
|
||||||
|
|
||||||
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
|
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
|
||||||
@ -88,6 +90,8 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
@Inject
|
@Inject
|
||||||
ObjectInDataStoreManager objectInStoreMgr;
|
ObjectInDataStoreManager objectInStoreMgr;
|
||||||
@Inject
|
@Inject
|
||||||
|
ResourceLimitService resourceLimitMgr;
|
||||||
|
@Inject
|
||||||
VMInstanceDao vmInstanceDao;
|
VMInstanceDao vmInstanceDao;
|
||||||
@Inject
|
@Inject
|
||||||
DiskOfferingDao diskOfferingDao;
|
DiskOfferingDao diskOfferingDao;
|
||||||
@ -678,6 +682,22 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
s_logger.debug(String.format("Updated %s from %s to %s ", volumeVo.getVolumeDescription(), previousValues, newValues));
|
s_logger.debug(String.format("Updated %s from %s to %s ", volumeVo.getVolumeDescription(), previousValues, newValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateResourceCount(VolumeObjectTO newVolume, VolumeVO oldVolume) {
|
||||||
|
if (newVolume == null || newVolume.getSize() == null || oldVolume == null || oldVolume.getSize() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long newVolumeSize = newVolume.getSize();
|
||||||
|
long oldVolumeSize = oldVolume.getSize();
|
||||||
|
if (newVolumeSize != oldVolumeSize) {
|
||||||
|
if (oldVolumeSize < newVolumeSize) {
|
||||||
|
resourceLimitMgr.incrementResourceCount(oldVolume.getAccountId(), ResourceType.primary_storage, oldVolume.isDisplayVolume(), newVolumeSize - oldVolumeSize);
|
||||||
|
} else {
|
||||||
|
resourceLimitMgr.decrementResourceCount(oldVolume.getAccountId(), ResourceType.primary_storage, oldVolume.isDisplayVolume(), oldVolumeSize - newVolumeSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void handleProcessEventCopyCmdAnswerNotPrimaryStore(VolumeObjectTO newVolume) {
|
protected void handleProcessEventCopyCmdAnswerNotPrimaryStore(VolumeObjectTO newVolume) {
|
||||||
VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
|
VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
|
||||||
|
|
||||||
@ -709,6 +729,7 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
VolumeObjectTO newVolume = (VolumeObjectTO)createObjectAnswer.getData();
|
VolumeObjectTO newVolume = (VolumeObjectTO)createObjectAnswer.getData();
|
||||||
VolumeVO volumeVo = volumeDao.findById(getId());
|
VolumeVO volumeVo = volumeDao.findById(getId());
|
||||||
updateVolumeInfo(newVolume, volumeVo, true, setFormat);
|
updateVolumeInfo(newVolume, volumeVo, true, setFormat);
|
||||||
|
updateResourceCount(newVolume, volumeVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleProcessEventAnswer(DownloadAnswer downloadAnswer) {
|
protected void handleProcessEventAnswer(DownloadAnswer downloadAnswer) {
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import com.cloud.api.ApiDBUtils;
|
|||||||
import com.cloud.api.query.ViewResponseHelper;
|
import com.cloud.api.query.ViewResponseHelper;
|
||||||
import com.cloud.api.query.vo.AccountJoinVO;
|
import com.cloud.api.query.vo.AccountJoinVO;
|
||||||
import com.cloud.api.query.vo.UserAccountJoinVO;
|
import com.cloud.api.query.vo.UserAccountJoinVO;
|
||||||
|
import com.cloud.configuration.Resource;
|
||||||
import com.cloud.configuration.Resource.ResourceType;
|
import com.cloud.configuration.Resource.ResourceType;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.AccountManager;
|
import com.cloud.user.AccountManager;
|
||||||
@ -85,9 +86,9 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
|||||||
|
|
||||||
//get resource limits for projects
|
//get resource limits for projects
|
||||||
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getId(), ResourceType.project);
|
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getId(), ResourceType.project);
|
||||||
String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
|
String projectLimitDisplay = (fullView || projectLimit == -1) ? Resource.UNLIMITED : String.valueOf(projectLimit);
|
||||||
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
|
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
|
||||||
String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
|
String projectAvail = (fullView || projectLimit == -1) ? Resource.UNLIMITED : String.valueOf(projectLimit - projectTotal);
|
||||||
accountResponse.setProjectLimit(projectLimitDisplay);
|
accountResponse.setProjectLimit(projectLimitDisplay);
|
||||||
accountResponse.setProjectTotal(projectTotal);
|
accountResponse.setProjectTotal(projectTotal);
|
||||||
accountResponse.setProjectAvailable(projectAvail);
|
accountResponse.setProjectAvailable(projectAvail);
|
||||||
@ -118,15 +119,15 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
|||||||
public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceLimitAndCountResponse response) {
|
public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceLimitAndCountResponse response) {
|
||||||
// Get resource limits and counts
|
// Get resource limits and counts
|
||||||
long vmLimit = ApiDBUtils.findCorrectResourceLimit(account.getVmLimit(), account.getId(), ResourceType.user_vm);
|
long vmLimit = ApiDBUtils.findCorrectResourceLimit(account.getVmLimit(), account.getId(), ResourceType.user_vm);
|
||||||
String vmLimitDisplay = (fullView || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
|
String vmLimitDisplay = (fullView || vmLimit == -1) ? Resource.UNLIMITED : String.valueOf(vmLimit);
|
||||||
long vmTotal = (account.getVmTotal() == null) ? 0 : account.getVmTotal();
|
long vmTotal = (account.getVmTotal() == null) ? 0 : account.getVmTotal();
|
||||||
String vmAvail = (fullView || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
|
String vmAvail = (fullView || vmLimit == -1) ? Resource.UNLIMITED : String.valueOf(vmLimit - vmTotal);
|
||||||
response.setVmLimit(vmLimitDisplay);
|
response.setVmLimit(vmLimitDisplay);
|
||||||
response.setVmTotal(vmTotal);
|
response.setVmTotal(vmTotal);
|
||||||
response.setVmAvailable(vmAvail);
|
response.setVmAvailable(vmAvail);
|
||||||
|
|
||||||
long ipLimit = ApiDBUtils.findCorrectResourceLimit(account.getIpLimit(), account.getId(), ResourceType.public_ip);
|
long ipLimit = ApiDBUtils.findCorrectResourceLimit(account.getIpLimit(), account.getId(), ResourceType.public_ip);
|
||||||
String ipLimitDisplay = (fullView || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
|
String ipLimitDisplay = (fullView || ipLimit == -1) ? Resource.UNLIMITED : String.valueOf(ipLimit);
|
||||||
long ipTotal = (account.getIpTotal() == null) ? 0 : account.getIpTotal();
|
long ipTotal = (account.getIpTotal() == null) ? 0 : account.getIpTotal();
|
||||||
|
|
||||||
Long ips = ipLimit - ipTotal;
|
Long ips = ipLimit - ipTotal;
|
||||||
@ -139,32 +140,32 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
|||||||
unlimited = false;
|
unlimited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ipAvail = ((fullView || ipLimit == -1) && unlimited) ? "Unlimited" : String.valueOf(ips);
|
String ipAvail = ((fullView || ipLimit == -1) && unlimited) ? Resource.UNLIMITED : String.valueOf(ips);
|
||||||
|
|
||||||
response.setIpLimit(ipLimitDisplay);
|
response.setIpLimit(ipLimitDisplay);
|
||||||
response.setIpTotal(ipTotal);
|
response.setIpTotal(ipTotal);
|
||||||
response.setIpAvailable(ipAvail);
|
response.setIpAvailable(ipAvail);
|
||||||
|
|
||||||
long volumeLimit = ApiDBUtils.findCorrectResourceLimit(account.getVolumeLimit(), account.getId(), ResourceType.volume);
|
long volumeLimit = ApiDBUtils.findCorrectResourceLimit(account.getVolumeLimit(), account.getId(), ResourceType.volume);
|
||||||
String volumeLimitDisplay = (fullView || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
|
String volumeLimitDisplay = (fullView || volumeLimit == -1) ? Resource.UNLIMITED : String.valueOf(volumeLimit);
|
||||||
long volumeTotal = (account.getVolumeTotal() == null) ? 0 : account.getVolumeTotal();
|
long volumeTotal = (account.getVolumeTotal() == null) ? 0 : account.getVolumeTotal();
|
||||||
String volumeAvail = (fullView || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
|
String volumeAvail = (fullView || volumeLimit == -1) ? Resource.UNLIMITED : String.valueOf(volumeLimit - volumeTotal);
|
||||||
response.setVolumeLimit(volumeLimitDisplay);
|
response.setVolumeLimit(volumeLimitDisplay);
|
||||||
response.setVolumeTotal(volumeTotal);
|
response.setVolumeTotal(volumeTotal);
|
||||||
response.setVolumeAvailable(volumeAvail);
|
response.setVolumeAvailable(volumeAvail);
|
||||||
|
|
||||||
long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(account.getSnapshotLimit(), account.getId(), ResourceType.snapshot);
|
long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(account.getSnapshotLimit(), account.getId(), ResourceType.snapshot);
|
||||||
String snapshotLimitDisplay = (fullView || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
|
String snapshotLimitDisplay = (fullView || snapshotLimit == -1) ? Resource.UNLIMITED : String.valueOf(snapshotLimit);
|
||||||
long snapshotTotal = (account.getSnapshotTotal() == null) ? 0 : account.getSnapshotTotal();
|
long snapshotTotal = (account.getSnapshotTotal() == null) ? 0 : account.getSnapshotTotal();
|
||||||
String snapshotAvail = (fullView || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
|
String snapshotAvail = (fullView || snapshotLimit == -1) ? Resource.UNLIMITED : String.valueOf(snapshotLimit - snapshotTotal);
|
||||||
response.setSnapshotLimit(snapshotLimitDisplay);
|
response.setSnapshotLimit(snapshotLimitDisplay);
|
||||||
response.setSnapshotTotal(snapshotTotal);
|
response.setSnapshotTotal(snapshotTotal);
|
||||||
response.setSnapshotAvailable(snapshotAvail);
|
response.setSnapshotAvailable(snapshotAvail);
|
||||||
|
|
||||||
Long templateLimit = ApiDBUtils.findCorrectResourceLimit(account.getTemplateLimit(), account.getId(), ResourceType.template);
|
Long templateLimit = ApiDBUtils.findCorrectResourceLimit(account.getTemplateLimit(), account.getId(), ResourceType.template);
|
||||||
String templateLimitDisplay = (fullView || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
|
String templateLimitDisplay = (fullView || templateLimit == -1) ? Resource.UNLIMITED : String.valueOf(templateLimit);
|
||||||
Long templateTotal = (account.getTemplateTotal() == null) ? 0 : account.getTemplateTotal();
|
Long templateTotal = (account.getTemplateTotal() == null) ? 0 : account.getTemplateTotal();
|
||||||
String templateAvail = (fullView || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
|
String templateAvail = (fullView || templateLimit == -1) ? Resource.UNLIMITED : String.valueOf(templateLimit - templateTotal);
|
||||||
response.setTemplateLimit(templateLimitDisplay);
|
response.setTemplateLimit(templateLimitDisplay);
|
||||||
response.setTemplateTotal(templateTotal);
|
response.setTemplateTotal(templateTotal);
|
||||||
response.setTemplateAvailable(templateAvail);
|
response.setTemplateAvailable(templateAvail);
|
||||||
@ -175,45 +176,45 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
|||||||
|
|
||||||
//get resource limits for networks
|
//get resource limits for networks
|
||||||
long networkLimit = ApiDBUtils.findCorrectResourceLimit(account.getNetworkLimit(), account.getId(), ResourceType.network);
|
long networkLimit = ApiDBUtils.findCorrectResourceLimit(account.getNetworkLimit(), account.getId(), ResourceType.network);
|
||||||
String networkLimitDisplay = (fullView || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
|
String networkLimitDisplay = (fullView || networkLimit == -1) ? Resource.UNLIMITED : String.valueOf(networkLimit);
|
||||||
long networkTotal = (account.getNetworkTotal() == null) ? 0 : account.getNetworkTotal();
|
long networkTotal = (account.getNetworkTotal() == null) ? 0 : account.getNetworkTotal();
|
||||||
String networkAvail = (fullView || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
|
String networkAvail = (fullView || networkLimit == -1) ? Resource.UNLIMITED : String.valueOf(networkLimit - networkTotal);
|
||||||
response.setNetworkLimit(networkLimitDisplay);
|
response.setNetworkLimit(networkLimitDisplay);
|
||||||
response.setNetworkTotal(networkTotal);
|
response.setNetworkTotal(networkTotal);
|
||||||
response.setNetworkAvailable(networkAvail);
|
response.setNetworkAvailable(networkAvail);
|
||||||
|
|
||||||
//get resource limits for vpcs
|
//get resource limits for vpcs
|
||||||
long vpcLimit = ApiDBUtils.findCorrectResourceLimit(account.getVpcLimit(), account.getId(), ResourceType.vpc);
|
long vpcLimit = ApiDBUtils.findCorrectResourceLimit(account.getVpcLimit(), account.getId(), ResourceType.vpc);
|
||||||
String vpcLimitDisplay = (fullView || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
|
String vpcLimitDisplay = (fullView || vpcLimit == -1) ? Resource.UNLIMITED : String.valueOf(vpcLimit);
|
||||||
long vpcTotal = (account.getVpcTotal() == null) ? 0 : account.getVpcTotal();
|
long vpcTotal = (account.getVpcTotal() == null) ? 0 : account.getVpcTotal();
|
||||||
String vpcAvail = (fullView || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
|
String vpcAvail = (fullView || vpcLimit == -1) ? Resource.UNLIMITED : String.valueOf(vpcLimit - vpcTotal);
|
||||||
response.setVpcLimit(vpcLimitDisplay);
|
response.setVpcLimit(vpcLimitDisplay);
|
||||||
response.setVpcTotal(vpcTotal);
|
response.setVpcTotal(vpcTotal);
|
||||||
response.setVpcAvailable(vpcAvail);
|
response.setVpcAvailable(vpcAvail);
|
||||||
|
|
||||||
//get resource limits for cpu cores
|
//get resource limits for cpu cores
|
||||||
long cpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getCpuLimit(), account.getId(), ResourceType.cpu);
|
long cpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getCpuLimit(), account.getId(), ResourceType.cpu);
|
||||||
String cpuLimitDisplay = (fullView || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit);
|
String cpuLimitDisplay = (fullView || cpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(cpuLimit);
|
||||||
long cpuTotal = (account.getCpuTotal() == null) ? 0 : account.getCpuTotal();
|
long cpuTotal = (account.getCpuTotal() == null) ? 0 : account.getCpuTotal();
|
||||||
String cpuAvail = (fullView || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit - cpuTotal);
|
String cpuAvail = (fullView || cpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(cpuLimit - cpuTotal);
|
||||||
response.setCpuLimit(cpuLimitDisplay);
|
response.setCpuLimit(cpuLimitDisplay);
|
||||||
response.setCpuTotal(cpuTotal);
|
response.setCpuTotal(cpuTotal);
|
||||||
response.setCpuAvailable(cpuAvail);
|
response.setCpuAvailable(cpuAvail);
|
||||||
|
|
||||||
//get resource limits for memory
|
//get resource limits for memory
|
||||||
long memoryLimit = ApiDBUtils.findCorrectResourceLimit(account.getMemoryLimit(), account.getId(), ResourceType.memory);
|
long memoryLimit = ApiDBUtils.findCorrectResourceLimit(account.getMemoryLimit(), account.getId(), ResourceType.memory);
|
||||||
String memoryLimitDisplay = (fullView || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit);
|
String memoryLimitDisplay = (fullView || memoryLimit == -1) ? Resource.UNLIMITED : String.valueOf(memoryLimit);
|
||||||
long memoryTotal = (account.getMemoryTotal() == null) ? 0 : account.getMemoryTotal();
|
long memoryTotal = (account.getMemoryTotal() == null) ? 0 : account.getMemoryTotal();
|
||||||
String memoryAvail = (fullView || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit - memoryTotal);
|
String memoryAvail = (fullView || memoryLimit == -1) ? Resource.UNLIMITED : String.valueOf(memoryLimit - memoryTotal);
|
||||||
response.setMemoryLimit(memoryLimitDisplay);
|
response.setMemoryLimit(memoryLimitDisplay);
|
||||||
response.setMemoryTotal(memoryTotal);
|
response.setMemoryTotal(memoryTotal);
|
||||||
response.setMemoryAvailable(memoryAvail);
|
response.setMemoryAvailable(memoryAvail);
|
||||||
|
|
||||||
//get resource limits for primary storage space and convert it from Bytes to GiB
|
//get resource limits for primary storage space and convert it from Bytes to GiB
|
||||||
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getPrimaryStorageLimit(), account.getId(), ResourceType.primary_storage);
|
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getPrimaryStorageLimit(), account.getId(), ResourceType.primary_storage);
|
||||||
String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
|
String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
|
||||||
long primaryStorageTotal = (account.getPrimaryStorageTotal() == null) ? 0 : (account.getPrimaryStorageTotal() / ResourceType.bytesToGiB);
|
long primaryStorageTotal = (account.getPrimaryStorageTotal() == null) ? 0 : (account.getPrimaryStorageTotal() / ResourceType.bytesToGiB);
|
||||||
String primaryStorageAvail = (fullView || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
|
String primaryStorageAvail = (fullView || primaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
|
||||||
|
|
||||||
response.setPrimaryStorageLimit(primaryStorageLimitDisplay);
|
response.setPrimaryStorageLimit(primaryStorageLimitDisplay);
|
||||||
response.setPrimaryStorageTotal(primaryStorageTotal);
|
response.setPrimaryStorageTotal(primaryStorageTotal);
|
||||||
@ -221,9 +222,9 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
|||||||
|
|
||||||
//get resource limits for secondary storage space and convert it from Bytes to GiB
|
//get resource limits for secondary storage space and convert it from Bytes to GiB
|
||||||
long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getSecondaryStorageLimit(), account.getId(), ResourceType.secondary_storage);
|
long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getSecondaryStorageLimit(), account.getId(), ResourceType.secondary_storage);
|
||||||
String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
|
String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
|
||||||
float secondaryStorageTotal = (account.getSecondaryStorageTotal() == null) ? 0 : (account.getSecondaryStorageTotal() / (ResourceType.bytesToGiB * 1f));
|
float secondaryStorageTotal = (account.getSecondaryStorageTotal() == null) ? 0 : (account.getSecondaryStorageTotal() / (ResourceType.bytesToGiB * 1f));
|
||||||
String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf((secondaryStorageLimit / ResourceType.bytesToGiB)
|
String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf(( (double)secondaryStorageLimit / ResourceType.bytesToGiB)
|
||||||
- secondaryStorageTotal);
|
- secondaryStorageTotal);
|
||||||
|
|
||||||
response.setSecondaryStorageLimit(secondaryStorageLimitDisplay);
|
response.setSecondaryStorageLimit(secondaryStorageLimitDisplay);
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.util.EnumSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
import com.cloud.configuration.Resource;
|
||||||
import com.cloud.user.AccountManager;
|
import com.cloud.user.AccountManager;
|
||||||
import org.apache.cloudstack.annotation.AnnotationService;
|
import org.apache.cloudstack.annotation.AnnotationService;
|
||||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||||
@ -94,9 +95,9 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
|
|||||||
|
|
||||||
//get resource limits for projects
|
//get resource limits for projects
|
||||||
long projectLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getProjectLimit(), ResourceType.project, domain.getId());
|
long projectLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getProjectLimit(), ResourceType.project, domain.getId());
|
||||||
String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
|
String projectLimitDisplay = (fullView || projectLimit == -1) ? Resource.UNLIMITED : String.valueOf(projectLimit);
|
||||||
long projectTotal = (domain.getProjectTotal() == null) ? 0 : domain.getProjectTotal();
|
long projectTotal = (domain.getProjectTotal() == null) ? 0 : domain.getProjectTotal();
|
||||||
String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
|
String projectAvail = (fullView || projectLimit == -1) ? Resource.UNLIMITED : String.valueOf(projectLimit - projectTotal);
|
||||||
domainResponse.setProjectLimit(projectLimitDisplay);
|
domainResponse.setProjectLimit(projectLimitDisplay);
|
||||||
domainResponse.setProjectTotal(projectTotal);
|
domainResponse.setProjectTotal(projectTotal);
|
||||||
domainResponse.setProjectAvailable(projectAvail);
|
domainResponse.setProjectAvailable(projectAvail);
|
||||||
@ -112,95 +113,95 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
|
|||||||
public void setResourceLimits(DomainJoinVO domain, boolean fullView, ResourceLimitAndCountResponse response) {
|
public void setResourceLimits(DomainJoinVO domain, boolean fullView, ResourceLimitAndCountResponse response) {
|
||||||
// Get resource limits and counts
|
// Get resource limits and counts
|
||||||
long vmLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getVmLimit(), fullView, ResourceType.user_vm, domain.getId());
|
long vmLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getVmLimit(), fullView, ResourceType.user_vm, domain.getId());
|
||||||
String vmLimitDisplay = (fullView || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
|
String vmLimitDisplay = (fullView || vmLimit == -1) ? Resource.UNLIMITED : String.valueOf(vmLimit);
|
||||||
long vmTotal = (domain.getVmTotal() == null) ? 0 : domain.getVmTotal();
|
long vmTotal = (domain.getVmTotal() == null) ? 0 : domain.getVmTotal();
|
||||||
String vmAvail = (fullView || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
|
String vmAvail = (fullView || vmLimit == -1) ? Resource.UNLIMITED : String.valueOf(vmLimit - vmTotal);
|
||||||
response.setVmLimit(vmLimitDisplay);
|
response.setVmLimit(vmLimitDisplay);
|
||||||
response.setVmTotal(vmTotal);
|
response.setVmTotal(vmTotal);
|
||||||
response.setVmAvailable(vmAvail);
|
response.setVmAvailable(vmAvail);
|
||||||
|
|
||||||
long ipLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getIpLimit(), ResourceType.public_ip, domain.getId());
|
long ipLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getIpLimit(), ResourceType.public_ip, domain.getId());
|
||||||
String ipLimitDisplay = (fullView || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
|
String ipLimitDisplay = (fullView || ipLimit == -1) ? Resource.UNLIMITED : String.valueOf(ipLimit);
|
||||||
long ipTotal = (domain.getIpTotal() == null) ? 0 : domain.getIpTotal();
|
long ipTotal = (domain.getIpTotal() == null) ? 0 : domain.getIpTotal();
|
||||||
String ipAvail = ((fullView || ipLimit == -1)) ? "Unlimited" : String.valueOf(ipLimit - ipTotal);
|
String ipAvail = (fullView || ipLimit == -1) ? Resource.UNLIMITED : String.valueOf(ipLimit - ipTotal);
|
||||||
response.setIpLimit(ipLimitDisplay);
|
response.setIpLimit(ipLimitDisplay);
|
||||||
response.setIpTotal(ipTotal);
|
response.setIpTotal(ipTotal);
|
||||||
response.setIpAvailable(ipAvail);
|
response.setIpAvailable(ipAvail);
|
||||||
|
|
||||||
long volumeLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getVolumeLimit(), ResourceType.volume, domain.getId());
|
long volumeLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getVolumeLimit(), ResourceType.volume, domain.getId());
|
||||||
String volumeLimitDisplay = (fullView || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
|
String volumeLimitDisplay = (fullView || volumeLimit == -1) ? Resource.UNLIMITED : String.valueOf(volumeLimit);
|
||||||
long volumeTotal = (domain.getVolumeTotal() == null) ? 0 : domain.getVolumeTotal();
|
long volumeTotal = (domain.getVolumeTotal() == null) ? 0 : domain.getVolumeTotal();
|
||||||
String volumeAvail = (fullView || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
|
String volumeAvail = (fullView || volumeLimit == -1) ? Resource.UNLIMITED : String.valueOf(volumeLimit - volumeTotal);
|
||||||
response.setVolumeLimit(volumeLimitDisplay);
|
response.setVolumeLimit(volumeLimitDisplay);
|
||||||
response.setVolumeTotal(volumeTotal);
|
response.setVolumeTotal(volumeTotal);
|
||||||
response.setVolumeAvailable(volumeAvail);
|
response.setVolumeAvailable(volumeAvail);
|
||||||
|
|
||||||
long snapshotLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getSnapshotLimit(), ResourceType.snapshot, domain.getId());
|
long snapshotLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getSnapshotLimit(), ResourceType.snapshot, domain.getId());
|
||||||
String snapshotLimitDisplay = (fullView || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
|
String snapshotLimitDisplay = (fullView || snapshotLimit == -1) ? Resource.UNLIMITED : String.valueOf(snapshotLimit);
|
||||||
long snapshotTotal = (domain.getSnapshotTotal() == null) ? 0 : domain.getSnapshotTotal();
|
long snapshotTotal = (domain.getSnapshotTotal() == null) ? 0 : domain.getSnapshotTotal();
|
||||||
String snapshotAvail = (fullView || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
|
String snapshotAvail = (fullView || snapshotLimit == -1) ? Resource.UNLIMITED : String.valueOf(snapshotLimit - snapshotTotal);
|
||||||
response.setSnapshotLimit(snapshotLimitDisplay);
|
response.setSnapshotLimit(snapshotLimitDisplay);
|
||||||
response.setSnapshotTotal(snapshotTotal);
|
response.setSnapshotTotal(snapshotTotal);
|
||||||
response.setSnapshotAvailable(snapshotAvail);
|
response.setSnapshotAvailable(snapshotAvail);
|
||||||
|
|
||||||
Long templateLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getTemplateLimit(), ResourceType.template, domain.getId());
|
Long templateLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getTemplateLimit(), ResourceType.template, domain.getId());
|
||||||
String templateLimitDisplay = (fullView || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
|
String templateLimitDisplay = (fullView || templateLimit == -1) ? Resource.UNLIMITED : String.valueOf(templateLimit);
|
||||||
Long templateTotal = (domain.getTemplateTotal() == null) ? 0 : domain.getTemplateTotal();
|
Long templateTotal = (domain.getTemplateTotal() == null) ? 0 : domain.getTemplateTotal();
|
||||||
String templateAvail = (fullView || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
|
String templateAvail = (fullView || templateLimit == -1) ? Resource.UNLIMITED : String.valueOf(templateLimit - templateTotal);
|
||||||
response.setTemplateLimit(templateLimitDisplay);
|
response.setTemplateLimit(templateLimitDisplay);
|
||||||
response.setTemplateTotal(templateTotal);
|
response.setTemplateTotal(templateTotal);
|
||||||
response.setTemplateAvailable(templateAvail);
|
response.setTemplateAvailable(templateAvail);
|
||||||
|
|
||||||
//get resource limits for networks
|
//get resource limits for networks
|
||||||
long networkLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getNetworkLimit(), ResourceType.network, domain.getId());
|
long networkLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getNetworkLimit(), ResourceType.network, domain.getId());
|
||||||
String networkLimitDisplay = (fullView || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
|
String networkLimitDisplay = (fullView || networkLimit == -1) ? Resource.UNLIMITED : String.valueOf(networkLimit);
|
||||||
long networkTotal = (domain.getNetworkTotal() == null) ? 0 : domain.getNetworkTotal();
|
long networkTotal = (domain.getNetworkTotal() == null) ? 0 : domain.getNetworkTotal();
|
||||||
String networkAvail = (fullView || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
|
String networkAvail = (fullView || networkLimit == -1) ? Resource.UNLIMITED : String.valueOf(networkLimit - networkTotal);
|
||||||
response.setNetworkLimit(networkLimitDisplay);
|
response.setNetworkLimit(networkLimitDisplay);
|
||||||
response.setNetworkTotal(networkTotal);
|
response.setNetworkTotal(networkTotal);
|
||||||
response.setNetworkAvailable(networkAvail);
|
response.setNetworkAvailable(networkAvail);
|
||||||
|
|
||||||
//get resource limits for vpcs
|
//get resource limits for vpcs
|
||||||
long vpcLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getVpcLimit(), ResourceType.vpc, domain.getId());
|
long vpcLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getVpcLimit(), ResourceType.vpc, domain.getId());
|
||||||
String vpcLimitDisplay = (fullView || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
|
String vpcLimitDisplay = (fullView || vpcLimit == -1) ? Resource.UNLIMITED : String.valueOf(vpcLimit);
|
||||||
long vpcTotal = (domain.getVpcTotal() == null) ? 0 : domain.getVpcTotal();
|
long vpcTotal = (domain.getVpcTotal() == null) ? 0 : domain.getVpcTotal();
|
||||||
String vpcAvail = (fullView || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
|
String vpcAvail = (fullView || vpcLimit == -1) ? Resource.UNLIMITED : String.valueOf(vpcLimit - vpcTotal);
|
||||||
response.setVpcLimit(vpcLimitDisplay);
|
response.setVpcLimit(vpcLimitDisplay);
|
||||||
response.setVpcTotal(vpcTotal);
|
response.setVpcTotal(vpcTotal);
|
||||||
response.setVpcAvailable(vpcAvail);
|
response.setVpcAvailable(vpcAvail);
|
||||||
|
|
||||||
//get resource limits for cpu cores
|
//get resource limits for cpu cores
|
||||||
long cpuLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getCpuLimit(), ResourceType.cpu, domain.getId());
|
long cpuLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getCpuLimit(), ResourceType.cpu, domain.getId());
|
||||||
String cpuLimitDisplay = (fullView || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit);
|
String cpuLimitDisplay = (fullView || cpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(cpuLimit);
|
||||||
long cpuTotal = (domain.getCpuTotal() == null) ? 0 : domain.getCpuTotal();
|
long cpuTotal = (domain.getCpuTotal() == null) ? 0 : domain.getCpuTotal();
|
||||||
String cpuAvail = (fullView || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit - cpuTotal);
|
String cpuAvail = (fullView || cpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(cpuLimit - cpuTotal);
|
||||||
response.setCpuLimit(cpuLimitDisplay);
|
response.setCpuLimit(cpuLimitDisplay);
|
||||||
response.setCpuTotal(cpuTotal);
|
response.setCpuTotal(cpuTotal);
|
||||||
response.setCpuAvailable(cpuAvail);
|
response.setCpuAvailable(cpuAvail);
|
||||||
|
|
||||||
//get resource limits for memory
|
//get resource limits for memory
|
||||||
long memoryLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getMemoryLimit(), ResourceType.memory, domain.getId());
|
long memoryLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getMemoryLimit(), ResourceType.memory, domain.getId());
|
||||||
String memoryLimitDisplay = (fullView || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit);
|
String memoryLimitDisplay = (fullView || memoryLimit == -1) ? Resource.UNLIMITED : String.valueOf(memoryLimit);
|
||||||
long memoryTotal = (domain.getMemoryTotal() == null) ? 0 : domain.getMemoryTotal();
|
long memoryTotal = (domain.getMemoryTotal() == null) ? 0 : domain.getMemoryTotal();
|
||||||
String memoryAvail = (fullView || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit - memoryTotal);
|
String memoryAvail = (fullView || memoryLimit == -1) ? Resource.UNLIMITED : String.valueOf(memoryLimit - memoryTotal);
|
||||||
response.setMemoryLimit(memoryLimitDisplay);
|
response.setMemoryLimit(memoryLimitDisplay);
|
||||||
response.setMemoryTotal(memoryTotal);
|
response.setMemoryTotal(memoryTotal);
|
||||||
response.setMemoryAvailable(memoryAvail);
|
response.setMemoryAvailable(memoryAvail);
|
||||||
|
|
||||||
//get resource limits for primary storage space and convert it from Bytes to GiB
|
//get resource limits for primary storage space and convert it from Bytes to GiB
|
||||||
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getPrimaryStorageLimit(), ResourceType.primary_storage, domain.getId());
|
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getPrimaryStorageLimit(), ResourceType.primary_storage, domain.getId());
|
||||||
String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
|
String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
|
||||||
long primaryStorageTotal = (domain.getPrimaryStorageTotal() == null) ? 0 : (domain.getPrimaryStorageTotal() / ResourceType.bytesToGiB);
|
long primaryStorageTotal = (domain.getPrimaryStorageTotal() == null) ? 0 : (domain.getPrimaryStorageTotal() / ResourceType.bytesToGiB);
|
||||||
String primaryStorageAvail = (fullView || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
|
String primaryStorageAvail = (fullView || primaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
|
||||||
response.setPrimaryStorageLimit(primaryStorageLimitDisplay);
|
response.setPrimaryStorageLimit(primaryStorageLimitDisplay);
|
||||||
response.setPrimaryStorageTotal(primaryStorageTotal);
|
response.setPrimaryStorageTotal(primaryStorageTotal);
|
||||||
response.setPrimaryStorageAvailable(primaryStorageAvail);
|
response.setPrimaryStorageAvailable(primaryStorageAvail);
|
||||||
|
|
||||||
//get resource limits for secondary storage space and convert it from Bytes to GiB
|
//get resource limits for secondary storage space and convert it from Bytes to GiB
|
||||||
long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getSecondaryStorageLimit(), ResourceType.secondary_storage, domain.getId());
|
long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getSecondaryStorageLimit(), ResourceType.secondary_storage, domain.getId());
|
||||||
String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
|
String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
|
||||||
float secondaryStorageTotal = (domain.getSecondaryStorageTotal() == null) ? 0 : (domain.getSecondaryStorageTotal() / (ResourceType.bytesToGiB * 1f));
|
float secondaryStorageTotal = (domain.getSecondaryStorageTotal() == null) ? 0 : (domain.getSecondaryStorageTotal() / (ResourceType.bytesToGiB * 1f));
|
||||||
String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf((secondaryStorageLimit / ResourceType.bytesToGiB) - secondaryStorageTotal);
|
String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1) ? Resource.UNLIMITED : String.valueOf(( (double)secondaryStorageLimit / ResourceType.bytesToGiB) - secondaryStorageTotal);
|
||||||
response.setSecondaryStorageLimit(secondaryStorageLimitDisplay);
|
response.setSecondaryStorageLimit(secondaryStorageLimitDisplay);
|
||||||
response.setSecondaryStorageTotal(secondaryStorageTotal);
|
response.setSecondaryStorageTotal(secondaryStorageTotal);
|
||||||
response.setSecondaryStorageAvailable(secondaryStorageAvail);
|
response.setSecondaryStorageAvailable(secondaryStorageAvail);
|
||||||
|
|||||||
@ -498,7 +498,9 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
Long resourceLimit = null;
|
Long resourceLimit = null;
|
||||||
resourceLimit = domainResourceLimitMap.get(resourceType);
|
resourceLimit = domainResourceLimitMap.get(resourceType);
|
||||||
if (resourceLimit != null && (resourceType == ResourceType.primary_storage || resourceType == ResourceType.secondary_storage)) {
|
if (resourceLimit != null && (resourceType == ResourceType.primary_storage || resourceType == ResourceType.secondary_storage)) {
|
||||||
resourceLimit = resourceLimit * ResourceType.bytesToGiB;
|
if (! Long.valueOf(Resource.RESOURCE_UNLIMITED).equals(resourceLimit)) {
|
||||||
|
resourceLimit = resourceLimit * ResourceType.bytesToGiB;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resourceLimit = Long.valueOf(Resource.RESOURCE_UNLIMITED);
|
resourceLimit = Long.valueOf(Resource.RESOURCE_UNLIMITED);
|
||||||
}
|
}
|
||||||
@ -847,6 +849,14 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will take care of re-calculation of resource counts for root and sub-domains
|
||||||
|
* and accounts of the sub-domains also. so just loop through immediate children of root domain
|
||||||
|
*
|
||||||
|
* @param domainId the domain level to start at
|
||||||
|
* @param type the resource type to do the recalculation for
|
||||||
|
* @return the resulting new resource count
|
||||||
|
*/
|
||||||
@DB
|
@DB
|
||||||
protected long recalculateDomainResourceCount(final long domainId, final ResourceType type) {
|
protected long recalculateDomainResourceCount(final long domainId, final ResourceType type) {
|
||||||
return Transaction.execute(new TransactionCallback<Long>() {
|
return Transaction.execute(new TransactionCallback<Long>() {
|
||||||
@ -1112,22 +1122,19 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
protected void runInContext() {
|
protected void runInContext() {
|
||||||
s_logger.info("Started resource counters recalculation periodic task.");
|
s_logger.info("Started resource counters recalculation periodic task.");
|
||||||
List<DomainVO> domains = _domainDao.findImmediateChildrenForParent(Domain.ROOT_DOMAIN);
|
List<DomainVO> domains = _domainDao.findImmediateChildrenForParent(Domain.ROOT_DOMAIN);
|
||||||
|
List<AccountVO> accounts = _accountDao.findActiveAccountsForDomain(Domain.ROOT_DOMAIN);
|
||||||
|
|
||||||
// recalculateDomainResourceCount will take care of re-calculation of resource counts for sub-domains
|
for (ResourceType type : ResourceCount.ResourceType.values()) {
|
||||||
// and accounts of the sub-domains also. so just loop through immediate children of root domain
|
if (type.supportsOwner(ResourceOwnerType.Domain)) {
|
||||||
for (Domain domain : domains) {
|
recalculateDomainResourceCount(Domain.ROOT_DOMAIN, type);
|
||||||
for (ResourceType type : ResourceCount.ResourceType.values()) {
|
for (Domain domain : domains) {
|
||||||
if (type.supportsOwner(ResourceOwnerType.Domain)) {
|
|
||||||
recalculateDomainResourceCount(domain.getId(), type);
|
recalculateDomainResourceCount(domain.getId(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// run through the accounts in the root domain
|
if (type.supportsOwner(ResourceOwnerType.Account)) {
|
||||||
List<AccountVO> accounts = _accountDao.findActiveAccountsForDomain(Domain.ROOT_DOMAIN);
|
// run through the accounts in the root domain
|
||||||
for (AccountVO account : accounts) {
|
for (AccountVO account : accounts) {
|
||||||
for (ResourceType type : ResourceCount.ResourceType.values()) {
|
|
||||||
if (type.supportsOwner(ResourceOwnerType.Account)) {
|
|
||||||
recalculateAccountResourceCount(account.getId(), type);
|
recalculateAccountResourceCount(account.getId(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1440,6 +1440,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
final VolumeVO volumeNow = _volsDao.findById(volumeId);
|
final VolumeVO volumeNow = _volsDao.findById(volumeId);
|
||||||
if (currentSize == volumeNow.getSize() && currentSize != newSize) {
|
if (currentSize == volumeNow.getSize() && currentSize != newSize) {
|
||||||
volume.setSize(newSize);
|
volume.setSize(newSize);
|
||||||
|
} else if (volumeNow.getSize() != newSize) {
|
||||||
|
// consider the updated size as the new size
|
||||||
|
newSize = volumeNow.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
_volsDao.update(volume.getId(), volume);
|
_volsDao.update(volume.getId(), volume);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user