-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Quota] Add API to list preset variables #8372
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
Merged
BryanMLima
merged 9 commits into
apache:main
from
scclouds:add-quota-preset-variables-list-api
Jun 13, 2024
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f35c1cb
Add API for listing Quota preset variables
BryanMLima b07d52a
Add new line at EOF
BryanMLima 3198f13
Address review
BryanMLima 2b10738
Merge branch 'main' of github.com:apache/cloudstack into add-quota-pr…
BryanMLima 779460d
Merge branch 'main' of github.com:apache/cloudstack into add-quota-pr…
BryanMLima 67aeac3
Remove usage types
BryanMLima 3793d12
Remove usage types from quotatypes
BryanMLima e1f44c8
Remove unused imports
BryanMLima 1daf286
Add space for preset variable definition description
BryanMLima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableDefinition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.quota.activationrule.presetvariables; | ||
|
|
||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.FIELD; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| /** | ||
| * Describes the preset variable and indicates to which Quota usage types it is loaded. | ||
| */ | ||
| @Target(FIELD) | ||
| @Retention(RUNTIME) | ||
| public @interface PresetVariableDefinition { | ||
| /** | ||
| * An array indicating for which Quota usage types the preset variable is loaded. | ||
| * @return an array with the usage types for which the preset variable is loaded. | ||
| */ | ||
| int[] supportedTypes() default 0; | ||
|
|
||
| /** | ||
| * A {@link String} describing the preset variable. | ||
| * @return the description of the preset variable. | ||
| */ | ||
| String description() default ""; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...se/quota/src/main/java/org/apache/cloudstack/api/command/QuotaPresetVariablesListCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //Licensed to the Apache Software Foundation (ASF) under one | ||
| //or more contributor license agreements. See the NOTICE file | ||
| //distributed with this work for additional information | ||
| //regarding copyright ownership. The ASF licenses this file | ||
| //to you under the Apache License, Version 2.0 (the | ||
| //"License"); you may not use this file except in compliance | ||
| //with the License. You may obtain a copy of the License at | ||
| // | ||
| //http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| //Unless required by applicable law or agreed to in writing, | ||
| //software distributed under the License is distributed on an | ||
| //"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| //KIND, either express or implied. See the License for the | ||
| //specific language governing permissions and limitations | ||
| //under the License. | ||
| package org.apache.cloudstack.api.command; | ||
|
|
||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import com.cloud.user.Account; | ||
| 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.ListResponse; | ||
| import org.apache.cloudstack.api.response.QuotaPresetVariablesItemResponse; | ||
| import org.apache.cloudstack.api.response.QuotaResponseBuilder; | ||
| import org.apache.cloudstack.quota.constant.QuotaTypes; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.List; | ||
|
|
||
| @APICommand(name = "quotaPresetVariablesList", responseObject = QuotaPresetVariablesItemResponse.class, description = "List the preset variables available for using in the " + | ||
| "Quota tariff activation rules given the usage type.", since = "4.20", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
| public class QuotaPresetVariablesListCmd extends BaseCmd { | ||
|
|
||
| @Inject | ||
| QuotaResponseBuilder quotaResponseBuilder; | ||
|
|
||
| @Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, required = true, description = "The usage type for which the preset variables will be retrieved.") | ||
| private Integer quotaType; | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| List<QuotaPresetVariablesItemResponse> responses = quotaResponseBuilder.listQuotaPresetVariables(this); | ||
| ListResponse<QuotaPresetVariablesItemResponse> listResponse = new ListResponse<>(); | ||
| listResponse.setResponses(responses); | ||
| listResponse.setResponseName(getCommandName()); | ||
| setResponseObject(listResponse); | ||
| } | ||
|
|
||
| public QuotaTypes getQuotaType() { | ||
| QuotaTypes quotaTypes = QuotaTypes.getQuotaType(quotaType); | ||
|
|
||
| if (quotaTypes == null) { | ||
| throw new InvalidParameterValueException(String.format("Usage type not found for value [%s].", quotaType)); | ||
| } | ||
|
|
||
| return quotaTypes; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...ta/src/main/java/org/apache/cloudstack/api/response/QuotaPresetVariablesItemResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //Licensed to the Apache Software Foundation (ASF) under one | ||
| //or more contributor license agreements. See the NOTICE file | ||
| //distributed with this work for additional information | ||
| //regarding copyright ownership. The ASF licenses this file | ||
| //to you under the Apache License, Version 2.0 (the | ||
| //"License"); you may not use this file except in compliance | ||
| //with the License. You may obtain a copy of the License at | ||
| // | ||
| //http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| //Unless required by applicable law or agreed to in writing, | ||
| //software distributed under the License is distributed on an | ||
| //"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| //KIND, either express or implied. See the License for the | ||
| //specific language governing permissions and limitations | ||
| //under the License. | ||
| package org.apache.cloudstack.api.response; | ||
|
|
||
| import com.cloud.serializer.Param; | ||
| import com.google.gson.annotations.SerializedName; | ||
| import org.apache.cloudstack.api.BaseResponse; | ||
|
|
||
| public class QuotaPresetVariablesItemResponse extends BaseResponse { | ||
| @SerializedName("variable") | ||
| @Param(description = "variable") | ||
| private String variable; | ||
|
|
||
| @SerializedName("description") | ||
| @Param(description = "description") | ||
| private String description; | ||
|
|
||
| public QuotaPresetVariablesItemResponse() { | ||
| super("variables"); | ||
| } | ||
|
|
||
| public void setVariable(String variable) { | ||
| this.variable = variable; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.