Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/src/main/java/com/cloud/user/ResourceLimitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public interface ResourceLimitService {
*/
public long findDefaultResourceLimitForDomain(ResourceType resourceType);

/**
* Finds the resource limit for a specified account, domain and type.
*
* @param domain
* @param type
* @return resource limit
*/
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type);

/**
* Increments the resource count
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,18 @@ public long findDefaultResourceLimitForDomain(ResourceType resourceType) {
return resourceLimit;
}

@Override
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type) {
long maxSecondaryStorageForAccount = findCorrectResourceLimitForAccount(account, type);
long maxSecondaryStorageForDomain = findCorrectResourceLimitForDomain(domain, type);

if (maxSecondaryStorageForDomain == Resource.RESOURCE_UNLIMITED || maxSecondaryStorageForAccount == Resource.RESOURCE_UNLIMITED) {
return Math.max(maxSecondaryStorageForDomain, maxSecondaryStorageForAccount);
}

return Math.min(maxSecondaryStorageForDomain, maxSecondaryStorageForAccount);
}

@Override
@DB
public void checkResourceLimit(final Account account, final ResourceType type, long... count) throws ResourceAllocationException {
Expand Down
18 changes: 11 additions & 7 deletions server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.inject.Inject;

import com.cloud.domain.dao.DomainDao;
import org.apache.cloudstack.api.ApiConstants.IoDriverPolicy;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.InternalIdentity;
Expand Down Expand Up @@ -331,6 +332,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Inject
protected SnapshotHelper snapshotHelper;

@Inject
protected DomainDao domainDao;

@Inject
protected ProjectManager projectManager;
@Inject
Expand Down Expand Up @@ -486,13 +490,13 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
//using the existing max upload size configuration
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
command.setAccountId(vol.getAccountId());
Account account = _accountDao.findById(vol.getAccountId());
if (account.getType().equals(Account.Type.PROJECT)) {
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
} else {
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
}

long accountId = vol.getAccountId();
Account account = _accountDao.findById(accountId);
Domain domain = domainDao.findById(account.getDomainId());

command.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
command.setAccountId(accountId);
Gson gson = new GsonBuilder().create();
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
response.setMetadata(metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.inject.Inject;

import com.cloud.domain.Domain;
import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer;
import org.apache.cloudstack.agent.directdownload.CheckUrlCommand;
import org.apache.cloudstack.annotation.AnnotationService;
Expand Down Expand Up @@ -93,7 +94,6 @@
import com.cloud.storage.download.DownloadMonitor;
import com.cloud.template.VirtualMachineTemplate.State;
import com.cloud.user.Account;
import com.cloud.user.ResourceLimitService;
import com.cloud.utils.Pair;
import com.cloud.utils.UriUtils;
import com.cloud.utils.db.DB;
Expand Down Expand Up @@ -402,13 +402,13 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus
templateOnStore.getDataStore().getRole().toString());
//using the existing max template size configuration
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
payload.setAccountId(template.getAccountId());
Account account = _accountDao.findById(template.getAccountId());
if (account.getType().equals(Account.Type.PROJECT)) {
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
} else {
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
}

Long accountId = template.getAccountId();
Account account = _accountDao.findById(accountId);
Domain domain = _domainDao.findById(account.getDomainId());

payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
payload.setAccountId(accountId);
payload.setRemoteEndPoint(ep.getPublicAddr());
payload.setRequiresHvm(template.requiresHvm());
payload.setDescription(template.getDisplayText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public long findDefaultResourceLimitForDomain(ResourceType resourceType) {
return 0;
}

@Override
public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type) {
return 0;
}

/* (non-Javadoc)
* @see com.cloud.user.ResourceLimitService#incrementResourceCount(long, com.cloud.configuration.Resource.ResourceType, java.lang.Long[])
*/
Expand Down