mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: Use max secondary storage defined on the account during upload (#7441)
This commit is contained in:
parent
b32ba953cf
commit
fdb23dae40
@ -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
|
||||
*
|
||||
|
||||
@ -547,6 +547,18 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
||||
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 {
|
||||
|
||||
@ -34,6 +34,7 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
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;
|
||||
@ -331,6 +332,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
||||
@Inject
|
||||
protected SnapshotHelper snapshotHelper;
|
||||
|
||||
@Inject
|
||||
protected DomainDao domainDao;
|
||||
|
||||
@Inject
|
||||
protected ProjectManager projectManager;
|
||||
@Inject
|
||||
@ -486,13 +490,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
||||
//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);
|
||||
|
||||
@ -28,6 +28,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
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;
|
||||
@ -93,7 +94,6 @@ import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||
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;
|
||||
@ -402,13 +402,13 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
||||
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());
|
||||
|
||||
@ -93,6 +93,11 @@ public class MockResourceLimitManagerImpl extends ManagerBase implements Resourc
|
||||
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[])
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user