Skip to content

Commit fdb23da

Browse files
authored
server: Use max secondary storage defined on the account during upload (#7441)
1 parent b32ba95 commit fdb23da

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,18 @@ public long findDefaultResourceLimitForDomain(ResourceType resourceType) {
547547
return resourceLimit;
548548
}
549549

550+
@Override
551+
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type) {
552+
long maxSecondaryStorageForAccount = findCorrectResourceLimitForAccount(account, type);
553+
long maxSecondaryStorageForDomain = findCorrectResourceLimitForDomain(domain, type);
554+
555+
if (maxSecondaryStorageForDomain == Resource.RESOURCE_UNLIMITED || maxSecondaryStorageForAccount == Resource.RESOURCE_UNLIMITED) {
556+
return Math.max(maxSecondaryStorageForDomain, maxSecondaryStorageForAccount);
557+
}
558+
559+
return Math.min(maxSecondaryStorageForDomain, maxSecondaryStorageForAccount);
560+
}
561+
550562
@Override
551563
@DB
552564
public void checkResourceLimit(final Account account, final ResourceType type, long... count) throws ResourceAllocationException {

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

Lines changed: 11 additions & 7 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
@@ -486,13 +490,13 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
486490
//using the existing max upload size configuration
487491
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
488492
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
489-
command.setAccountId(vol.getAccountId());
490-
Account account = _accountDao.findById(vol.getAccountId());
491-
if (account.getType().equals(Account.Type.PROJECT)) {
492-
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
493-
} else {
494-
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
495-
}
493+
494+
long accountId = vol.getAccountId();
495+
Account account = _accountDao.findById(accountId);
496+
Domain domain = domainDao.findById(account.getDomainId());
497+
498+
command.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
499+
command.setAccountId(accountId);
496500
Gson gson = new GsonBuilder().create();
497501
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
498502
response.setMetadata(metadata);

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

Lines changed: 8 additions & 8 deletions
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;
@@ -93,7 +94,6 @@
9394
import com.cloud.storage.download.DownloadMonitor;
9495
import com.cloud.template.VirtualMachineTemplate.State;
9596
import com.cloud.user.Account;
96-
import com.cloud.user.ResourceLimitService;
9797
import com.cloud.utils.Pair;
9898
import com.cloud.utils.UriUtils;
9999
import com.cloud.utils.db.DB;
@@ -402,13 +402,13 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus
402402
templateOnStore.getDataStore().getRole().toString());
403403
//using the existing max template size configuration
404404
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
405-
payload.setAccountId(template.getAccountId());
406-
Account account = _accountDao.findById(template.getAccountId());
407-
if (account.getType().equals(Account.Type.PROJECT)) {
408-
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
409-
} else {
410-
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
411-
}
405+
406+
Long accountId = template.getAccountId();
407+
Account account = _accountDao.findById(accountId);
408+
Domain domain = _domainDao.findById(account.getDomainId());
409+
410+
payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
411+
payload.setAccountId(accountId);
412412
payload.setRemoteEndPoint(ep.getPublicAddr());
413413
payload.setRequiresHvm(template.requiresHvm());
414414
payload.setDescription(template.getDisplayText());

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)