Skip to content

Commit 4fb9dc2

Browse files
committed
add check for domain
1 parent 84dcaf6 commit 4fb9dc2

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

api/src/main/java/com/cloud/user/ResourceLimitService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ public interface ResourceLimitService {
117117
*/
118118
public long findDefaultResourceLimitForDomain(ResourceType resourceType);
119119

120+
/**
121+
* Finds the resource limit for a specified account, domain and type.
122+
*
123+
* @param domain
124+
* @param type
125+
* @return resource limit
126+
*/
127+
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type);
128+
120129
/**
121130
* Increments the resource count
122131
*

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ public long findDefaultResourceLimitForDomain(ResourceType resourceType) {
534534
return resourceLimit;
535535
}
536536

537+
@Override
538+
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type) {
539+
long maxSecondaryStorageForAccount = findCorrectResourceLimitForAccount(account, type);
540+
long maxSecondaryStorageForDomain = findCorrectResourceLimitForDomain(domain, type);
541+
542+
return Math.min(maxSecondaryStorageForDomain, maxSecondaryStorageForAccount);
543+
}
544+
537545
@Override
538546
@DB
539547
public void checkResourceLimit(final Account account, final ResourceType type, long... count) throws ResourceAllocationException {

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import javax.inject.Inject;
3636

37+
import com.cloud.domain.dao.DomainDao;
3738
import org.apache.cloudstack.api.ApiConstants.IoDriverPolicy;
3839
import org.apache.cloudstack.api.ApiErrorCode;
3940
import org.apache.cloudstack.api.InternalIdentity;
@@ -331,6 +332,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
331332
@Inject
332333
protected SnapshotHelper snapshotHelper;
333334

335+
@Inject
336+
protected DomainDao domainDao;
337+
334338
@Inject
335339
protected ProjectManager projectManager;
336340
@Inject
@@ -487,10 +491,11 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
487491
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
488492
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
489493

490-
Long accountId = vol.getAccountId();
494+
long accountId = vol.getAccountId();
491495
Account account = _accountDao.findById(accountId);
496+
Domain domain = domainDao.findById(account.getDomainId());
492497

493-
command.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccount(account, ResourceType.secondary_storage));
498+
command.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
494499
command.setAccountId(accountId);
495500
Gson gson = new GsonBuilder().create();
496501
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);

server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import javax.inject.Inject;
3030

31+
import com.cloud.domain.Domain;
3132
import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer;
3233
import org.apache.cloudstack.agent.directdownload.CheckUrlCommand;
3334
import org.apache.cloudstack.annotation.AnnotationService;
@@ -404,8 +405,9 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus
404405

405406
Long accountId = template.getAccountId();
406407
Account account = _accountDao.findById(accountId);
408+
Domain domain = _domainDao.findById(account.getDomainId());
407409

408-
payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccount(account, ResourceType.secondary_storage));
410+
payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
409411
payload.setAccountId(accountId);
410412
payload.setRemoteEndPoint(ep.getPublicAddr());
411413
payload.setRequiresHvm(template.requiresHvm());

server/src/test/java/com/cloud/vpc/MockResourceLimitManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public long findDefaultResourceLimitForDomain(ResourceType resourceType) {
9393
return 0;
9494
}
9595

96+
@Override
97+
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type) {
98+
return 0;
99+
}
100+
96101
/* (non-Javadoc)
97102
* @see com.cloud.user.ResourceLimitService#incrementResourceCount(long, com.cloud.configuration.Resource.ResourceType, java.lang.Long[])
98103
*/

0 commit comments

Comments
 (0)