Skip to content

Commit 1cf1786

Browse files
[Quota] Add API to list preset variables (#8372)
* Add API for listing Quota preset variables * Add new line at EOF * Address review * Remove usage types * Remove usage types from quotatypes * Remove unused imports * Add space for preset variable definition description Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com> --------- Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
1 parent cb48202 commit 1cf1786

File tree

20 files changed

+444
-2
lines changed

20 files changed

+444
-2
lines changed

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
package org.apache.cloudstack.quota.activationrule.presetvariables;
1919

20-
public class Account extends GenericPresetVariable{
20+
public class Account extends GenericPresetVariable {
21+
@PresetVariableDefinition(description = "Role of the account. This field will not exist if the account is a project.")
22+
2123
private Role role;
2224

2325
public Role getRole() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/BackupOffering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.cloudstack.quota.activationrule.presetvariables;
2121

2222
public class BackupOffering extends GenericPresetVariable {
23+
@PresetVariableDefinition(description = "External ID of the backup offering that generated the backup.")
2324
private String externalId;
2425

2526
public String getExternalId() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cloudstack.quota.activationrule.presetvariables;
1919

2020
public class ComputeOffering extends GenericPresetVariable {
21+
@PresetVariableDefinition(description = "A boolean informing if the compute offering is customized or not.")
2122
private boolean customized;
2223

2324
public boolean isCustomized() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputingResources.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
import org.apache.commons.lang3.builder.ToStringStyle;
2222

2323
public class ComputingResources {
24+
@PresetVariableDefinition(description = "Current VM's memory (in MiB).")
2425
private Integer memory;
26+
27+
@PresetVariableDefinition(description = "Current VM's vCPUs.")
2528
private Integer cpuNumber;
29+
30+
@PresetVariableDefinition(description = "Current VM's CPU speed (in MHz).")
2631
private Integer cpuSpeed;
2732

2833
public Integer getMemory() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Domain.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cloudstack.quota.activationrule.presetvariables;
1919

2020
public class Domain extends GenericPresetVariable {
21+
@PresetVariableDefinition(description = "Path of the domain owner of the resource.")
2122
private String path;
2223

2324
public String getPath() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/GenericPresetVariable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
2424

2525
public class GenericPresetVariable {
26+
@PresetVariableDefinition(description = "ID of the resource.")
2627
private String id;
28+
29+
@PresetVariableDefinition(description = "Name of the resource.")
2730
private String name;
31+
2832
protected transient Set<String> fieldNamesToIncludeInToString = new HashSet<>();
2933

3034
public String getId() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Host.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import java.util.List;
2121

2222
public class Host extends GenericPresetVariable {
23+
@PresetVariableDefinition(description = "List of tags of the host where the VM is running (i.e.: [\"a\", \"b\"]).")
2324
private List<String> tags;
2425

26+
@PresetVariableDefinition(description = "Whether the tag is a rule interpreted in JavaScript.")
2527
private Boolean isTagARule;
2628

2729
public List<String> getTags() {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.quota.activationrule.presetvariables;
18+
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.Target;
21+
22+
import static java.lang.annotation.ElementType.FIELD;
23+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
24+
25+
/**
26+
* Describes the preset variable and indicates to which Quota usage types it is loaded.
27+
*/
28+
@Target(FIELD)
29+
@Retention(RUNTIME)
30+
public @interface PresetVariableDefinition {
31+
/**
32+
* An array indicating for which Quota usage types the preset variable is loaded.
33+
* @return an array with the usage types for which the preset variable is loaded.
34+
*/
35+
int[] supportedTypes() default 0;
36+
37+
/**
38+
* A {@link String} describing the preset variable.
39+
* @return the description of the preset variable.
40+
*/
41+
String description() default "";
42+
}

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariables.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@
1919

2020
public class PresetVariables {
2121

22+
@PresetVariableDefinition(description = "Account owner of the resource.")
2223
private Account account;
24+
25+
@PresetVariableDefinition(description = "Domain owner of the resource.")
2326
private Domain domain;
27+
28+
@PresetVariableDefinition(description = "Project owner of the resource. This field will not exist if the resource belongs to an account.")
2429
private GenericPresetVariable project;
30+
31+
@PresetVariableDefinition(description = "Type of the record used. Examples for this are: VirtualMachine, DomainRouter, SourceNat, KVM.")
2532
private String resourceType;
33+
34+
@PresetVariableDefinition(description = "Data related to the resource being processed.")
2635
private Value value;
36+
37+
@PresetVariableDefinition(description = "Zone where the resource is.")
2738
private GenericPresetVariable zone;
2839

2940
public Account getAccount() {

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Role.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.cloudstack.acl.RoleType;
2121

2222
public class Role extends GenericPresetVariable {
23+
@PresetVariableDefinition(description = "Role type of the resource's owner.")
2324
private RoleType type;
2425

2526
public RoleType getType() {

0 commit comments

Comments
 (0)