if (projectFinal != null) {
message =
"Maximum number of resources of type '" + type + "' for project name=" + projectFinal.getName() + " in domain id=" + account.getDomainId() +
" has been exceeded.";
}
throw new ResourceAllocationException(message, type);
}
// check all domains in the account's domain hierarchy
Long domainId = null;
if (projectFinal != null) {
domainId = projectFinal.getDomainId();
} else {
domainId = account.getDomainId();
}
while (domainId != null) {
DomainVO domain = _domainDao.findById(domainId);
// no limit check if it is ROOT domain
if (domainId != Domain.ROOT_DOMAIN) {
ResourceLimitVO domainLimit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) {
long domainCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type);
if ((domainCount + numResources) > domainLimit.getMax().longValue()) {
throw new ResourceAllocationException("Maximum number of resources of type '" + type + "' for domain id=" + domainId +
" has been exceeded.", type);
}
}
}
domainId = domain.getParent();