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 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),
|
||||
public_ip("public_ip", 1, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
||||
volume("volume", 2, ResourceOwnerType.Account, ResourceOwnerType.Domain),
|
||||
|
||||
@ -20,6 +20,7 @@ import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.dc.VsphereStoragePolicyVO;
|
||||
import com.cloud.dc.dao.VsphereStoragePolicyDao;
|
||||
import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
||||
@ -28,6 +29,7 @@ import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeDetailVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDetailsDao;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.vm.VmDetailConstants;
|
||||
|
||||
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
|
||||
@ -88,6 +90,8 @@ public class VolumeObject implements VolumeInfo {
|
||||
@Inject
|
||||
ObjectInDataStoreManager objectInStoreMgr;
|
||||
@Inject
|
||||
ResourceLimitService resourceLimitMgr;
|
||||
@Inject
|
||||
VMInstanceDao vmInstanceDao;
|
||||
@Inject
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
|
||||
|
||||
@ -709,6 +729,7 @@ public class VolumeObject implements VolumeInfo {
|
||||
VolumeObjectTO newVolume = (VolumeObjectTO)createObjectAnswer.getData();
|
||||
VolumeVO volumeVo = volumeDao.findById(getId());
|
||||
updateVolumeInfo(newVolume, volumeVo, true, setFormat);
|
||||
updateResourceCount(newVolume, volumeVo);
|
||||
}
|
||||
|
||||
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.vo.AccountJoinVO;
|
||||
import com.cloud.api.query.vo.UserAccountJoinVO;
|
||||
import com.cloud.configuration.Resource;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
@ -85,9 +86,9 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
||||
|
||||
//get resource limits for projects
|
||||
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();
|
||||
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.setProjectTotal(projectTotal);
|
||||
accountResponse.setProjectAvailable(projectAvail);
|
||||
@ -118,15 +119,15 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
||||
public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceLimitAndCountResponse response) {
|
||||
// Get resource limits and counts
|
||||
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();
|
||||
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.setVmTotal(vmTotal);
|
||||
response.setVmAvailable(vmAvail);
|
||||
|
||||
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 ips = ipLimit - ipTotal;
|
||||
@ -139,32 +140,32 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
||||
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.setIpTotal(ipTotal);
|
||||
response.setIpAvailable(ipAvail);
|
||||
|
||||
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();
|
||||
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.setVolumeTotal(volumeTotal);
|
||||
response.setVolumeAvailable(volumeAvail);
|
||||
|
||||
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();
|
||||
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.setSnapshotTotal(snapshotTotal);
|
||||
response.setSnapshotAvailable(snapshotAvail);
|
||||
|
||||
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();
|
||||
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.setTemplateTotal(templateTotal);
|
||||
response.setTemplateAvailable(templateAvail);
|
||||
@ -175,45 +176,45 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
||||
|
||||
//get resource limits for networks
|
||||
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();
|
||||
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.setNetworkTotal(networkTotal);
|
||||
response.setNetworkAvailable(networkAvail);
|
||||
|
||||
//get resource limits for vpcs
|
||||
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();
|
||||
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.setVpcTotal(vpcTotal);
|
||||
response.setVpcAvailable(vpcAvail);
|
||||
|
||||
//get resource limits for cpu cores
|
||||
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();
|
||||
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.setCpuTotal(cpuTotal);
|
||||
response.setCpuAvailable(cpuAvail);
|
||||
|
||||
//get resource limits for 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();
|
||||
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.setMemoryTotal(memoryTotal);
|
||||
response.setMemoryAvailable(memoryAvail);
|
||||
|
||||
//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);
|
||||
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);
|
||||
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.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
|
||||
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));
|
||||
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);
|
||||
|
||||
response.setSecondaryStorageLimit(secondaryStorageLimitDisplay);
|
||||
|
||||
@ -20,6 +20,7 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import com.cloud.configuration.Resource;
|
||||
import com.cloud.user.AccountManager;
|
||||
import org.apache.cloudstack.annotation.AnnotationService;
|
||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||
@ -94,9 +95,9 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
|
||||
|
||||
//get resource limits for projects
|
||||
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();
|
||||
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.setProjectTotal(projectTotal);
|
||||
domainResponse.setProjectAvailable(projectAvail);
|
||||
@ -112,95 +113,95 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
|
||||
public void setResourceLimits(DomainJoinVO domain, boolean fullView, ResourceLimitAndCountResponse response) {
|
||||
// Get resource limits and counts
|
||||
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();
|
||||
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.setVmTotal(vmTotal);
|
||||
response.setVmAvailable(vmAvail);
|
||||
|
||||
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();
|
||||
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.setIpTotal(ipTotal);
|
||||
response.setIpAvailable(ipAvail);
|
||||
|
||||
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();
|
||||
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.setVolumeTotal(volumeTotal);
|
||||
response.setVolumeAvailable(volumeAvail);
|
||||
|
||||
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();
|
||||
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.setSnapshotTotal(snapshotTotal);
|
||||
response.setSnapshotAvailable(snapshotAvail);
|
||||
|
||||
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();
|
||||
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.setTemplateTotal(templateTotal);
|
||||
response.setTemplateAvailable(templateAvail);
|
||||
|
||||
//get resource limits for networks
|
||||
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();
|
||||
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.setNetworkTotal(networkTotal);
|
||||
response.setNetworkAvailable(networkAvail);
|
||||
|
||||
//get resource limits for vpcs
|
||||
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();
|
||||
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.setVpcTotal(vpcTotal);
|
||||
response.setVpcAvailable(vpcAvail);
|
||||
|
||||
//get resource limits for cpu cores
|
||||
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();
|
||||
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.setCpuTotal(cpuTotal);
|
||||
response.setCpuAvailable(cpuAvail);
|
||||
|
||||
//get resource limits for memory
|
||||
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();
|
||||
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.setMemoryTotal(memoryTotal);
|
||||
response.setMemoryAvailable(memoryAvail);
|
||||
|
||||
//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());
|
||||
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);
|
||||
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.setPrimaryStorageTotal(primaryStorageTotal);
|
||||
response.setPrimaryStorageAvailable(primaryStorageAvail);
|
||||
|
||||
//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());
|
||||
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));
|
||||
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.setSecondaryStorageTotal(secondaryStorageTotal);
|
||||
response.setSecondaryStorageAvailable(secondaryStorageAvail);
|
||||
|
||||
@ -498,7 +498,9 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
||||
Long resourceLimit = null;
|
||||
resourceLimit = domainResourceLimitMap.get(resourceType);
|
||||
if (resourceLimit != null && (resourceType == ResourceType.primary_storage || resourceType == ResourceType.secondary_storage)) {
|
||||
if (! Long.valueOf(Resource.RESOURCE_UNLIMITED).equals(resourceLimit)) {
|
||||
resourceLimit = resourceLimit * ResourceType.bytesToGiB;
|
||||
}
|
||||
} else {
|
||||
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
|
||||
protected long recalculateDomainResourceCount(final long domainId, final ResourceType type) {
|
||||
return Transaction.execute(new TransactionCallback<Long>() {
|
||||
@ -1112,22 +1122,19 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
||||
protected void runInContext() {
|
||||
s_logger.info("Started resource counters recalculation periodic task.");
|
||||
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
|
||||
// and accounts of the sub-domains also. so just loop through immediate children of root domain
|
||||
for (Domain domain : domains) {
|
||||
for (ResourceType type : ResourceCount.ResourceType.values()) {
|
||||
if (type.supportsOwner(ResourceOwnerType.Domain)) {
|
||||
recalculateDomainResourceCount(Domain.ROOT_DOMAIN, type);
|
||||
for (Domain domain : domains) {
|
||||
recalculateDomainResourceCount(domain.getId(), type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run through the accounts in the root domain
|
||||
List<AccountVO> accounts = _accountDao.findActiveAccountsForDomain(Domain.ROOT_DOMAIN);
|
||||
for (AccountVO account : accounts) {
|
||||
for (ResourceType type : ResourceCount.ResourceType.values()) {
|
||||
if (type.supportsOwner(ResourceOwnerType.Account)) {
|
||||
// run through the accounts in the root domain
|
||||
for (AccountVO account : accounts) {
|
||||
recalculateAccountResourceCount(account.getId(), type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1440,6 +1440,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
||||
final VolumeVO volumeNow = _volsDao.findById(volumeId);
|
||||
if (currentSize == volumeNow.getSize() && currentSize != 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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user