You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2022/08/16 08:41:49 UTC
[cloudstack] branch main updated: Updated resource counter to include correct size after volume creation/resize and other improvements (#6587)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 75da982d73 Updated resource counter to include correct size after volume creation/resize and other improvements (#6587)
75da982d73 is described below
commit 75da982d730591dd5a8da3b9838863839e28e51f
Author: Suresh Kumar Anaparti <su...@gmail.com>
AuthorDate: Tue Aug 16 14:11:42 2022 +0530
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 <su...@shapeblue.com>
Co-authored-by: Daan Hoogland <da...@onecht.net>
---
.../java/com/cloud/configuration/Resource.java | 5 ++-
.../cloudstack/storage/volume/VolumeObject.java | 21 ++++++++++
.../cloud/api/query/dao/AccountJoinDaoImpl.java | 49 +++++++++++-----------
.../com/cloud/api/query/dao/DomainJoinDaoImpl.java | 49 +++++++++++-----------
.../resourcelimit/ResourceLimitManagerImpl.java | 31 ++++++++------
.../com/cloud/storage/VolumeApiServiceImpl.java | 3 ++
6 files changed, 96 insertions(+), 62 deletions(-)
diff --git a/api/src/main/java/com/cloud/configuration/Resource.java b/api/src/main/java/com/cloud/configuration/Resource.java
index 76f2930e61..fefeeb15ef 100644
--- a/api/src/main/java/com/cloud/configuration/Resource.java
+++ b/api/src/main/java/com/cloud/configuration/Resource.java
@@ -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),
diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java
index 3875d8155c..8c23d61f69 100644
--- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java
+++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java
@@ -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) {
diff --git a/server/src/main/java/com/cloud/api/query/dao/AccountJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/AccountJoinDaoImpl.java
index c980ffd3ab..790758c627 100644
--- a/server/src/main/java/com/cloud/api/query/dao/AccountJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/AccountJoinDaoImpl.java
@@ -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);
diff --git a/server/src/main/java/com/cloud/api/query/dao/DomainJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/DomainJoinDaoImpl.java
index 529761a956..56f5417da3 100644
--- a/server/src/main/java/com/cloud/api/query/dao/DomainJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/DomainJoinDaoImpl.java
@@ -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);
diff --git a/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index 5991d53563..3afc47f418 100644
--- a/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -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)) {
- resourceLimit = resourceLimit * ResourceType.bytesToGiB;
+ 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)) {
+ 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)) {
+ if (type.supportsOwner(ResourceOwnerType.Account)) {
+ // run through the accounts in the root domain
+ for (AccountVO account : accounts) {
recalculateAccountResourceCount(account.getId(), type);
}
}
diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index 4b5e263494..9ce294d233 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -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);