ofri masad has uploaded a new change for review. Change subject: core: Quota refactor - QuotaManager step 4 ......................................................................
core: Quota refactor - QuotaManager step 4 Added refortor of validateAndSetClusterQuota Change-Id: Idab2217b358b5dc53e721297ed16290c4370a363 Signed-off-by: Ofri Masad <oma...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java 1 file changed, 119 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/8779/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java index 08ce434..019bfca 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java @@ -639,6 +639,84 @@ return true; } + private boolean checkQuotaClusterLimits(QuotaEnforcementTypeEnum quotaEnforcementTypeEnum, + Quota quota, + QuotaVdsGroup quotaVdsGroup, + long memToAdd, + int vcpuToAdd, + ArrayList<String> canDoActionMessages, + AuditLogableBase auditLogableBase) { + if (quotaVdsGroup.getVirtualCpu() == 0 || quotaVdsGroup.getMemSizeMB() == 0) { + return false; + } + + double vcpuToAddPercentage = (double) vcpuToAdd / (double) quotaVdsGroup.getVirtualCpu() * 100; + double vcpuCurrentPercentage = + (double) quotaVdsGroup.getVirtualCpuUsage() / (double) quotaVdsGroup.getVirtualCpu() * 100; + double newVcpuPercent = vcpuToAddPercentage + vcpuCurrentPercentage; + double memToAddPercentage = (double) memToAdd / (double) quotaVdsGroup.getMemSizeMB() * 100; + double memCurrentPercentage = + (double) quotaVdsGroup.getMemSizeMBUsage() / (double) quotaVdsGroup.getMemSizeMB() * 100; + double newMemoryPercent = memToAddPercentage + memCurrentPercentage; + long newMemory = memToAdd + quotaVdsGroup.getMemSizeMBUsage(); + int newVcpu = vcpuToAdd + quotaVdsGroup.getVirtualCpuUsage(); + + long memLimit = quotaVdsGroup.getMemSizeMB(); + int cpuLimit = quotaVdsGroup.getVirtualCpu(); + + if (memLimit == QuotaVdsGroup.UNLIMITED_MEM && cpuLimit == QuotaVdsGroup.UNLIMITED_VCPU) { // if both cpu and + // mem are unlimited + // cache + cacheNewValues(quotaVdsGroup, newMemory, newVcpu); + return true; + } else if (newVcpuPercent <= quota.getThresholdVdsGroupPercentage() // if cpu and mem usages are under the limit + && newMemoryPercent <= quota.getThresholdVdsGroupPercentage()) { + // cache + cacheNewValues(quotaVdsGroup, newMemory, newVcpu); + return true; + } else if (newVcpuPercent <= 100 + && newMemoryPercent <= 100) { // passed the threshold (not the quota limit) + AUDIT_LOGGER.auditLogVdsGroup(auditLogableBase, + AuditLogType.USER_EXCEEDED_QUOTA_VDS_GROUP_THRESHOLD, + quota.getQuotaName(), + vcpuCurrentPercentage + vcpuToAddPercentage, + vcpuToAddPercentage, + memCurrentPercentage + memToAddPercentage, + memToAddPercentage, + newVcpuPercent > quota.getThresholdVdsGroupPercentage(), + newMemoryPercent > quota.getThresholdVdsGroupPercentage()); + } else if (newVcpuPercent <= quota.getGraceVdsGroupPercentage() + 100 + && newMemoryPercent <= quota.getGraceVdsGroupPercentage() + 100) { // passed the quota limit (not the + // grace) + AUDIT_LOGGER.auditLogVdsGroup(auditLogableBase, + AuditLogType.USER_EXCEEDED_QUOTA_VDS_GROUP_LIMIT, + quota.getQuotaName(), + vcpuCurrentPercentage + vcpuToAddPercentage, + vcpuToAddPercentage, + memCurrentPercentage + memToAddPercentage, + memToAddPercentage, + newVcpuPercent > 100, + newMemoryPercent > 100); + } else { + AUDIT_LOGGER.auditLogVdsGroup(auditLogableBase, + AuditLogType.USER_EXCEEDED_QUOTA_VDS_GROUP_GRACE_LIMIT, + quota.getQuotaName(), + vcpuCurrentPercentage, + vcpuToAddPercentage, + memCurrentPercentage, + memToAddPercentage, + newVcpuPercent > quota.getGraceVdsGroupPercentage() + 100, + newMemoryPercent > quota.getGraceVdsGroupPercentage() + 100); + if (QuotaEnforcementTypeEnum.HARD_ENFORCEMENT.equals(quotaEnforcementTypeEnum)) { + canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_VDS_GROUP_LIMIT_EXCEEDED.toString()); + return false; + } + } + // cache + cacheNewValues(quotaVdsGroup, newMemory, newVcpu); + return true; + } + private void cacheNewValues(QuotaVdsGroup quotaVdsGroup, long newMemory, int newVcpu) { quotaVdsGroup.setVirtualCpuUsage(newVcpu); quotaVdsGroup.setMemSizeMBUsage(newMemory); @@ -712,6 +790,45 @@ AuditLogDirector.log(logPair.getSecond(), logPair.getFirst()); } } + + } + + public boolean validateAndSetClusterQuota(QuotaConsumptionParameters parameters) { + Pair<AuditLogType, AuditLogableBase> logPair = new Pair<AuditLogType, AuditLogableBase>(); + + synchronized (storagePoolQuotaMap.get(parameters.getStoragePoolGuid())) { + for (QuotaVdsConsumptionParameter parameter : parameters.getQuotaVdsConsumptionParameters()) { + Quota quota = parameter.getQuota(); + QuotaVdsGroup quotaVdsGroup = null; + + if (quota.getGlobalQuotaVdsGroup() != null) { // global cluster quota + quotaVdsGroup = quota.getGlobalQuotaVdsGroup(); + } else { + for (QuotaVdsGroup vdsGroup : quota.getQuotaVdsGroups()) { + if (vdsGroup.getVdsGroupId().equals(parameter.getVdsGroupId())) { + quotaVdsGroup = vdsGroup; + break; + } + } + } + if (quotaVdsGroup == null) { + parameters.getCanDoActionMessages().add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString()); + return false; + } + + boolean success = checkQuotaClusterLimits(parameters.getStorage_pool().getQuotaEnforcementType(), + quota, + quotaVdsGroup, + parameter.getRequestedMemory(), + parameter.getRequestedCpu(), + parameters.getCanDoActionMessages(), + parameters.getAuditLogable()); + if (!success) { + return false; + } + } + } + return true; } @@ -926,13 +1043,13 @@ boolean result = validateAndSetStorageQuotaHelper(parameters); if (result) { - //TODO result = validate and set for vds + result = validateAndSetClusterQuota(parameters); if (result) { return true; } else { QuotaConsumptionParameters revertedParams = revertParametersQuantities(parameters); validateAndSetStorageQuotaHelper(revertedParams); - //TODO validate and set for vds + validateAndSetClusterQuota(parameters); } } else { //roll back storage request -- To view, visit http://gerrit.ovirt.org/8779 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idab2217b358b5dc53e721297ed16290c4370a363 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <oma...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches