Skip to content

Commit b6443a2

Browse files
oscaralvaroOscar Sandoval
andauthored
increase log detail for limit checking, fix getDomainReservation() (#7506)
In troubleshooting ops issues we see logs like: Maximum domain resource limits of Type 'user_vm' for Domain Id = 763 is exceeded: Domain Resource Limit = (1 bytes) 1, Current Domain Resource Amount = (0 bytes) 0, Requested Resource Amount = (1 bytes) 1." However there is one missing value (currentResourceReservation) that is used in the calculation of limit check but it is not logged, which leads to confusion. Above we see we are using “0” and requested 1, with our limit being 1, but was rejected. Without logging all the values used in the calculation we don’t understand why it failed. Additionally, if we had this log above it would be clearer that a second bug is occurring. When we query for domain level resource reservations in “getDomainReservation” the actual SearchBuilder is the listAccountAndTypeSearch, not the listDomainAndTypeSearch. As a result, when we call getDomainReservation the query returns any outstanding domain reservation for any account, as domain ID is not a valid filter for the account search. This PR: Increases detailed information in log for checking resource limit to include reservations information for functions: checkDomainResourceLimit() and checkAccountResourceLimit Fixes getDomainReservation() to use listDomainAndTypeSearch instead of listAccountAndTypeSearch Co-authored-by: Oscar Sandoval <osandovalocana@apple.com>
1 parent a0eb0aa commit b6443a2

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public long getAccountReservation(Long accountId, Resource.ResourceType resource
6363
@Override
6464
public long getDomainReservation(Long domainId, Resource.ResourceType resourceType) {
6565
long total = 0;
66-
SearchCriteria<ReservationVO> sc = listAccountAndTypeSearch.create();
66+
SearchCriteria<ReservationVO> sc = listDomainAndTypeSearch.create();
6767
sc.setParameters(DOMAIN_ID, domainId);
6868
sc.setParameters(RESOURCE_TYPE, resourceType);
6969
List<ReservationVO> reservations = listBy(sc);

server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,25 @@ private void checkDomainResourceLimit(final Account account, final Project proje
433433
long currentDomainResourceCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type);
434434
long currentResourceReservation = reservationDao.getDomainReservation(domainId, type);
435435
long requestedDomainResourceCount = currentDomainResourceCount + currentResourceReservation + numResources;
436-
String messageSuffix = " domain resource limits of Type '" + type + "'" + " for Domain Id = " + domainId + " is exceeded: Domain Resource Limit = " + toHumanReadableSize(domainResourceLimit)
437-
+ ", Current Domain Resource Amount = " + toHumanReadableSize(currentDomainResourceCount) + ", Requested Resource Amount = " + toHumanReadableSize(numResources) + ".";
436+
437+
String convDomainResourceLimit = String.valueOf(domainResourceLimit);
438+
String convCurrentDomainResourceCount = String.valueOf(currentDomainResourceCount);
439+
String convCurrentResourceReservation = String.valueOf(currentResourceReservation);
440+
String convNumResources = String.valueOf(numResources);
441+
442+
if (type == ResourceType.secondary_storage || type == ResourceType.primary_storage){
443+
convDomainResourceLimit = toHumanReadableSize(domainResourceLimit);
444+
convCurrentDomainResourceCount = toHumanReadableSize(currentDomainResourceCount);
445+
convCurrentResourceReservation = toHumanReadableSize(currentResourceReservation);
446+
convNumResources = toHumanReadableSize(numResources);
447+
}
448+
449+
String messageSuffix = String.format(
450+
" domain resource limits of Type '%s' for Domain Id = %s is exceeded: Domain Resource Limit = %s, " +
451+
"Current Domain Resource Amount = %s, Current Resource Reservation = %s, Requested Resource Amount = %s.",
452+
type, domainId, convDomainResourceLimit,
453+
convCurrentDomainResourceCount, convCurrentResourceReservation, convNumResources
454+
);
438455

439456
if (s_logger.isDebugEnabled()) {
440457
s_logger.debug("Checking if" + messageSuffix);
@@ -460,17 +477,22 @@ private void checkAccountResourceLimit(final Account account, final Project proj
460477

461478
String convertedAccountResourceLimit = String.valueOf(accountResourceLimit);
462479
String convertedCurrentResourceCount = String.valueOf(currentResourceCount);
480+
String convertedCurrentResourceReservation = String.valueOf(currentResourceReservation);
463481
String convertedNumResources = String.valueOf(numResources);
464482

465483
if (type == ResourceType.secondary_storage || type == ResourceType.primary_storage){
466484
convertedAccountResourceLimit = toHumanReadableSize(accountResourceLimit);
467485
convertedCurrentResourceCount = toHumanReadableSize(currentResourceCount);
486+
convertedCurrentResourceReservation = toHumanReadableSize(currentResourceReservation);
468487
convertedNumResources = toHumanReadableSize(numResources);
469488
}
470489

471-
String messageSuffix = " amount of resources of Type = '" + type + "' for " + (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName())
472-
+ " in Domain Id = " + account.getDomainId() + " is exceeded: Account Resource Limit = " + convertedAccountResourceLimit + ", Current Account Resource Amount = " + convertedCurrentResourceCount
473-
+ ", Requested Resource Amount = " + convertedNumResources + ".";
490+
String messageSuffix = String.format(
491+
" amount of resources of Type = '%s' for %s in Domain Id = %s is exceeded: " +
492+
"Account Resource Limit = %s, Current Account Resource Amount = %s, Current Account Resource Reservation = %s, Requested Resource Amount = %s.",
493+
type, (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName()), account.getDomainId(),
494+
convertedAccountResourceLimit, convertedCurrentResourceCount, convertedCurrentResourceReservation, convertedNumResources
495+
);
474496

475497
if (s_logger.isDebugEnabled()) {
476498
s_logger.debug("Checking if" + messageSuffix);

0 commit comments

Comments
 (0)