1818
1919import java .util .List ;
2020
21+ import org .apache .cloudstack .api .response .AccountResponse ;
22+ import org .apache .cloudstack .api .response .DomainResponse ;
23+ import org .apache .cloudstack .framework .config .ConfigKey ;
24+
2125import com .cloud .configuration .Resource .ResourceType ;
2226import com .cloud .configuration .ResourceCount ;
2327import com .cloud .configuration .ResourceLimit ;
2428import com .cloud .domain .Domain ;
2529import com .cloud .exception .ResourceAllocationException ;
26- import org .apache .cloudstack .framework .config .ConfigKey ;
27- import org .apache .cloudstack .user .ResourceReservation ;
30+ import com .cloud .offering .DiskOffering ;
31+ import com .cloud .offering .ServiceOffering ;
32+ import com .cloud .template .VirtualMachineTemplate ;
2833
2934public interface ResourceLimitService {
3035
@@ -34,6 +39,13 @@ public interface ResourceLimitService {
3439 "The default maximum secondary storage space (in GiB) that can be used for a project" , false );
3540 static final ConfigKey <Long > ResourceCountCheckInterval = new ConfigKey <>("Advanced" , Long .class , "resourcecount.check.interval" , "300" ,
3641 "Time (in seconds) to wait before running resource recalculation and fixing task. Default is 300 seconds, Setting this to 0 disables execution of the task" , false );
42+ static final ConfigKey <String > ResourceLimitHostTags = new ConfigKey <>("Advanced" , String .class , "resource.limit.host.tags" , "" ,
43+ "A comma-separated list of tags for host resource limits" , true );
44+ static final ConfigKey <String > ResourceLimitStorageTags = new ConfigKey <>("Advanced" , String .class , "resource.limit.storage.tags" , "" ,
45+ "A comma-separated list of tags for storage resource limits" , true );
46+
47+ static final List <ResourceType > HostTagsSupportingTypes = List .of (ResourceType .user_vm , ResourceType .cpu , ResourceType .memory );
48+ static final List <ResourceType > StorageTagsSupportingTypes = List .of (ResourceType .volume , ResourceType .primary_storage );
3749
3850 /**
3951 * Updates an existing resource limit with the specified details. If a limit doesn't exist, will create one.
@@ -46,22 +58,27 @@ public interface ResourceLimitService {
4658 * TODO
4759 * @param max
4860 * TODO
61+ * @param tag
62+ * tag for the resource type
4963 *
5064 * @return the updated/created resource limit
5165 */
52- ResourceLimit updateResourceLimit (Long accountId , Long domainId , Integer resourceType , Long max );
66+ ResourceLimit updateResourceLimit (Long accountId , Long domainId , Integer resourceType , Long max , String tag );
5367
5468 /**
5569 * Updates an existing resource count details for the account/domain
5670 *
5771 * @param accountId
58- * TODO
72+ * Id of the account for which resource recalculation to be done
5973 * @param domainId
60- * TODO
74+ * Id of the domain for which resource recalculation to be doneDO
6175 * @param typeId
62- * TODO
76+ * type of the resource for which recalculation to be done
77+ * @param tag
78+ * tag for the resource type for which recalculation to be done
6379 * @return the updated/created resource counts
6480 */
81+ List <? extends ResourceCount > recalculateResourceCount (Long accountId , Long domainId , Integer typeId , String tag );
6582 List <? extends ResourceCount > recalculateResourceCount (Long accountId , Long domainId , Integer typeId );
6683
6784 /**
@@ -77,17 +94,18 @@ public interface ResourceLimitService {
7794 * TODO
7895 * @return a list of limits that match the criteria
7996 */
80- public List <? extends ResourceLimit > searchForLimits (Long id , Long accountId , Long domainId , ResourceType resourceType , Long startIndex , Long pageSizeVal );
97+ public List <? extends ResourceLimit > searchForLimits (Long id , Long accountId , Long domainId , ResourceType resourceType , String tag , Long startIndex , Long pageSizeVal );
8198
8299 /**
83100 * Finds the resource limit for a specified account and type. If the account has an infinite limit, will check
84101 * the account's parent domain, and if that limit is also infinite, will return the ROOT domain's limit.
85102 *
86103 * @param account
87104 * @param type
105+ * @param tag
88106 * @return resource limit
89107 */
90- public long findCorrectResourceLimitForAccount (Account account , ResourceType type );
108+ public long findCorrectResourceLimitForAccount (Account account , ResourceType type , String tag );
91109
92110 /**
93111 * This call should be used when we have already queried resource limit for an account. This is to handle
@@ -105,9 +123,10 @@ public interface ResourceLimitService {
105123 *
106124 * @param domain
107125 * @param type
126+ * @param tag
108127 * @return resource limit
109128 */
110- public long findCorrectResourceLimitForDomain (Domain domain , ResourceType type );
129+ public long findCorrectResourceLimitForDomain (Domain domain , ResourceType type , String tag );
111130
112131 /**
113132 * Finds the default resource limit for a specified type.
@@ -122,9 +141,10 @@ public interface ResourceLimitService {
122141 *
123142 * @param domain
124143 * @param type
144+ * @param tag
125145 * @return resource limit
126146 */
127- public long findCorrectResourceLimitForAccountAndDomain (Account account , Domain domain , ResourceType type );
147+ public long findCorrectResourceLimitForAccountAndDomain (Account account , Domain domain , ResourceType type , String tag );
128148
129149 /**
130150 * Increments the resource count
@@ -134,6 +154,7 @@ public interface ResourceLimitService {
134154 * @param delta
135155 */
136156 public void incrementResourceCount (long accountId , ResourceType type , Long ... delta );
157+ public void incrementResourceCountWithTag (long accountId , ResourceType type , String tag , Long ... delta );
137158
138159 /**
139160 * Decrements the resource count
@@ -143,6 +164,7 @@ public interface ResourceLimitService {
143164 * @param delta
144165 */
145166 public void decrementResourceCount (long accountId , ResourceType type , Long ... delta );
167+ public void decrementResourceCountWithTag (long accountId , ResourceType type , String tag , Long ... delta );
146168
147169 /**
148170 * Checks if a limit has been exceeded for an account
@@ -155,15 +177,17 @@ public interface ResourceLimitService {
155177 * @throws ResourceAllocationException
156178 */
157179 public void checkResourceLimit (Account account , ResourceCount .ResourceType type , long ... count ) throws ResourceAllocationException ;
180+ public void checkResourceLimitWithTag (Account account , ResourceCount .ResourceType type , String tag , long ... count ) throws ResourceAllocationException ;
158181
159182 /**
160183 * Gets the count of resources for a resource type and account
161184 *
162185 * @param account
163186 * @param type
187+ * @param tag
164188 * @return count of resources
165189 */
166- public long getResourceCount (Account account , ResourceType type );
190+ public long getResourceCount (Account account , ResourceType type , String tag );
167191
168192 /**
169193 * Checks if a limit has been exceeded for an account if displayResource flag is on
@@ -208,15 +232,25 @@ public interface ResourceLimitService {
208232 */
209233 void decrementResourceCount (long accountId , ResourceType type , Boolean displayResource , Long ... delta );
210234
211- /**
212- * Adds a reservation that will be counted in subsequent calls to {count}getResourceCount{code} until {code}this[code}
213- * is closed. It will create a reservation record that will be counted when resource limits are checked.
214- * @param account The account for which the reservation is.
215- * @param displayResource whether this resource is shown to users at all (if not it is not counted to limits)
216- * @param type resource type
217- * @param delta amount to reserve (will not be <+ 0)
218- * @return a {code}AutoClosable{Code} object representing the resource the user needs
219- */
220- ResourceReservation getReservation (Account account , Boolean displayResource , ResourceType type , Long delta ) throws ResourceAllocationException ;
235+ List <String > getResourceLimitHostTags ();
236+ List <String > getResourceLimitHostTags (ServiceOffering serviceOffering , VirtualMachineTemplate template );
237+ List <String > getResourceLimitStorageTags ();
238+ List <String > getResourceLimitStorageTags (DiskOffering diskOffering );
239+ void updateTaggedResourceLimitsAndCountsForAccounts (List <AccountResponse > responses , String tag );
240+ void updateTaggedResourceLimitsAndCountsForDomains (List <DomainResponse > responses , String tag );
241+ void checkVolumeResourceLimit (Account owner , Boolean display , Long size , DiskOffering diskOffering ) throws ResourceAllocationException ;
242+ void incrementVolumeResourceCount (long accountId , Boolean display , Long size , DiskOffering diskOffering );
243+ void decrementVolumeResourceCount (long accountId , Boolean display , Long size , DiskOffering diskOffering );
244+ void incrementVolumePrimaryStorageResourceCount (long accountId , Boolean display , Long size , DiskOffering diskOffering );
245+ void decrementVolumePrimaryStorageResourceCount (long accountId , Boolean display , Long size , DiskOffering diskOffering );
246+ void checkVmResourceLimit (Account owner , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template ) throws ResourceAllocationException ;
247+ void incrementVmResourceCount (long accountId , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template );
248+ void decrementVmResourceCount (long accountId , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template );
249+ void checkVmCpuResourceLimit (Account owner , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template , Long cpu ) throws ResourceAllocationException ;
250+ void incrementVmCpuResourceCount (long accountId , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template , Long cpu );
251+ void decrementVmCpuResourceCount (long accountId , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template , Long cpu );
252+ void checkVmMemoryResourceLimit (Account owner , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template , Long memory ) throws ResourceAllocationException ;
253+ void incrementVmMemoryResourceCount (long accountId , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template , Long memory );
254+ void decrementVmMemoryResourceCount (long accountId , Boolean display , ServiceOffering serviceOffering , VirtualMachineTemplate template , Long memory );
221255
222256}
0 commit comments