Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
Quota UI rework#13449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Quota UI rework #13449
Changes from all commits
e33560519e60ab6cda0d4617bd6454ce551cc7db60c2b19a86fb87082b4600a14a9f8b38ec52641594056d45bd199c7753b0d32671bd57cd67b0a017cae3fc820ac3eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,14 +21,13 @@ | ||
| import org.apache.cloudstack.api.ACL; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.AccountResponse; | ||
| import org.apache.cloudstack.api.response.DomainResponse; | ||
| import org.apache.cloudstack.api.response.ProjectResponse; | ||
| import org.apache.cloudstack.api.response.QuotaCreditsResponse; | ||
| import org.apache.cloudstack.api.response.QuotaResponseBuilder; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.quota.QuotaService; | ||
| import javax.inject.Inject; | ||
| @@ -42,22 +41,35 @@ public class QuotaCreditsCmd extends BaseCmd { | ||
| @Inject | ||
| QuotaService _quotaService; | ||
| @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which quota credits need to be added") | ||
| @Deprecated | ||
| @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Name of the Account for which Quota credits will be added. Deprecated, please use '" + | ||
| ApiConstants.ACCOUNT_ID + "' instead.") | ||
| private String accountName; | ||
| @ACL | ||
| @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added") | ||
| @Deprecated | ||
| @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, | ||
| description = "Domain of the Account specified by '" + ApiConstants.ACCOUNT + "' for which Quota credits will be added. " + | ||
| "Deprecated, please use '" + ApiConstants.ACCOUNT_ID + "' instead.") | ||
| private Long domainId; | ||
| @Parameter(name = ApiConstants.VALUE, type = CommandType.DOUBLE, required = true, description = "Value of the credits to be added+, subtracted-") | ||
| @ACL | ||
| @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, | ||
| description = "ID of the Account for which Quota credits will be added. Cannot be specified with '" + ApiConstants.PROJECT_ID + "'.") | ||
| private Long accountId; | ||
| @ACL | ||
| @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, | ||
| description = "ID of the Project for which Quota credits will be added. Cannot be specified with '" + ApiConstants.ACCOUNT_ID + "'.") | ||
| private Long projectId; | ||
| @Parameter(name = ApiConstants.VALUE, type = CommandType.DOUBLE, required = true, description = "Amount of credits to be added (in case of a positive value) or subtracted (in case of a negative value).") | ||
| private Double value; | ||
| @Parameter(name = "min_balance", type = CommandType.DOUBLE, required = false, description = "Minimum balance threshold of the Account") | ||
| @Parameter(name = "min_balance", type = CommandType.DOUBLE, description = "An email will be sent to the Account when the Quota credits get below this threshold.") | ||
| private Double minBalance; | ||
| @Parameter(name = "quota_enforce", type = CommandType.BOOLEAN, required = false, description = "Account for which quota enforce is set to false will not be locked when there is no credit balance") | ||
| @Parameter(name = "quota_enforce", type = CommandType.BOOLEAN, description = "Whether to lock the Account when Quota credits are below zero.") | ||
winterhazel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| private Boolean quotaEnforce; | ||
| public Double getMinBalance() { | ||
| @@ -100,42 +112,28 @@ public void setValue(Double value) { | ||
| this.value = value; | ||
| } | ||
| public Long getAccountId() { | ||
| return accountId; | ||
| } | ||
| public Long getProjectId() { | ||
| return projectId; | ||
| } | ||
| public QuotaCreditsCmd() { | ||
| super(); | ||
| } | ||
| @Override | ||
| public void execute() { | ||
| Long accountId = null; | ||
| Account account = _accountService.getActiveAccountByName(accountName, domainId); | ||
| if (account != null) { | ||
| accountId = account.getAccountId(); | ||
| } | ||
| if (accountId == null) { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The Account does not exists or has been removed/disabled"); | ||
| } | ||
| if (getValue() == null) { | ||
| throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please send a valid non-empty quota value"); | ||
| } | ||
| if (getQuotaEnforce() != null) { | ||
| _quotaService.setLockAccount(accountId, getQuotaEnforce()); | ||
| } | ||
| if (getMinBalance() != null) { | ||
| _quotaService.setMinBalance(accountId, getMinBalance()); | ||
| } | ||
| final QuotaCreditsResponse response = _responseBuilder.addQuotaCredits(accountId, getDomainId(), getValue(), CallContext.current().getCallingUserId(), getQuotaEnforce()); | ||
| QuotaCreditsResponse response = _responseBuilder.addQuotaCredits(this); | ||
| response.setResponseName(getCommandName()); | ||
| response.setObjectName("quotacredits"); | ||
| setResponseObject(response); | ||
| } | ||
| @Override | ||
| public long getEntityOwnerId() { | ||
| Account account = _accountService.getActiveAccountByName(accountName, domainId); | ||
| if (account != null) { | ||
| return account.getAccountId(); | ||
| } | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
winterhazel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,16 +18,18 @@ | ||
| import com.cloud.utils.Pair; | ||
| import org.apache.cloudstack.api.ACL; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.AccountResponse; | ||
| import org.apache.cloudstack.api.response.DomainResponse; | ||
| import org.apache.cloudstack.api.response.ListResponse; | ||
| import org.apache.cloudstack.api.response.ProjectResponse; | ||
| import org.apache.cloudstack.api.response.QuotaCreditsResponse; | ||
| import org.apache.cloudstack.api.response.QuotaResponseBuilder; | ||
| import org.apache.commons.lang3.BooleanUtils; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
| import org.apache.commons.lang3.time.DateUtils; | ||
| @@ -44,13 +46,16 @@ public class QuotaCreditsListCmd extends BaseCmd { | ||
| @Inject | ||
| QuotaResponseBuilder quotaResponseBuilder; | ||
| @ACL | ||
| @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "ID of the account for which the credit statement will be generated.") | ||
| @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, | ||
| description = "ID of the Account for which the credit statement will be generated. Cannot be specified with '" + ApiConstants.PROJECT_ID + "'.") | ||
| private Long accountId; | ||
| @ACL | ||
| @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "ID of the domain for which credit statement will be generated. " + | ||
| "Available only for administrators.") | ||
| @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, | ||
| description = "ID of the Project for which the credit statement will be generated. Cannot be specified with '" + ApiConstants.ACCOUNT_ID + "'.") | ||
| private Long projectId; | ||
| @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "ID of the Domain for which credit statement will be generated. " + | ||
winterhazel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "Available only for administrators.", authorized = {RoleType.Admin, RoleType.DomainAdmin}) | ||
| private Long domainId; | ||
| @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End date of the credit statement. If not provided, the current date will be " + | ||
| @@ -97,14 +102,18 @@ public void setStartDate(Date startDate) { | ||
| this.startDate = startDate; | ||
| } | ||
| public Boolean getRecursive() { | ||
| return recursive; | ||
| public boolean isRecursive() { | ||
| return BooleanUtils.isTrue(recursive); | ||
| } | ||
| public void setRecursive(Boolean recursive) { | ||
| this.recursive = recursive; | ||
| } | ||
| public Long getProjectId() { | ||
| return projectId; | ||
| } | ||
| @Override | ||
| public void execute() { | ||
| Pair<List<QuotaCreditsResponse>, Integer> responses = quotaResponseBuilder.createQuotaCreditsListResponse(this); | ||
| @@ -116,7 +125,10 @@ public void execute() { | ||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return -1; | ||
| if (ObjectUtils.allNull(accountId, projectId)) { | ||
| return -1; | ||
| } | ||
| return _accountService.finalizeAccountId(accountId, null, null, projectId); | ||
winterhazel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.