18
18
19
19
import java .util .List ;
20
20
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
+
21
25
import com .cloud .configuration .Resource .ResourceType ;
22
26
import com .cloud .configuration .ResourceCount ;
23
27
import com .cloud .configuration .ResourceLimit ;
24
28
import com .cloud .domain .Domain ;
25
29
import 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 ;
28
33
29
34
public interface ResourceLimitService {
30
35
@@ -34,6 +39,13 @@ public interface ResourceLimitService {
34
39
"The default maximum secondary storage space (in GiB) that can be used for a project" , false );
35
40
static final ConfigKey <Long > ResourceCountCheckInterval = new ConfigKey <>("Advanced" , Long .class , "resourcecount.check.interval" , "300" ,
36
41
"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 );
37
49
38
50
/**
39
51
* 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 {
46
58
* TODO
47
59
* @param max
48
60
* TODO
61
+ * @param tag
62
+ * tag for the resource type
49
63
*
50
64
* @return the updated/created resource limit
51
65
*/
52
- ResourceLimit updateResourceLimit (Long accountId , Long domainId , Integer resourceType , Long max );
66
+ ResourceLimit updateResourceLimit (Long accountId , Long domainId , Integer resourceType , Long max , String tag );
53
67
54
68
/**
55
69
* Updates an existing resource count details for the account/domain
56
70
*
57
71
* @param accountId
58
- * TODO
72
+ * Id of the account for which resource recalculation to be done
59
73
* @param domainId
60
- * TODO
74
+ * Id of the domain for which resource recalculation to be doneDO
61
75
* @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
63
79
* @return the updated/created resource counts
64
80
*/
81
+ List <? extends ResourceCount > recalculateResourceCount (Long accountId , Long domainId , Integer typeId , String tag );
65
82
List <? extends ResourceCount > recalculateResourceCount (Long accountId , Long domainId , Integer typeId );
66
83
67
84
/**
@@ -77,17 +94,18 @@ public interface ResourceLimitService {
77
94
* TODO
78
95
* @return a list of limits that match the criteria
79
96
*/
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 );
81
98
82
99
/**
83
100
* Finds the resource limit for a specified account and type. If the account has an infinite limit, will check
84
101
* the account's parent domain, and if that limit is also infinite, will return the ROOT domain's limit.
85
102
*
86
103
* @param account
87
104
* @param type
105
+ * @param tag
88
106
* @return resource limit
89
107
*/
90
- public long findCorrectResourceLimitForAccount (Account account , ResourceType type );
108
+ public long findCorrectResourceLimitForAccount (Account account , ResourceType type , String tag );
91
109
92
110
/**
93
111
* 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 {
105
123
*
106
124
* @param domain
107
125
* @param type
126
+ * @param tag
108
127
* @return resource limit
109
128
*/
110
- public long findCorrectResourceLimitForDomain (Domain domain , ResourceType type );
129
+ public long findCorrectResourceLimitForDomain (Domain domain , ResourceType type , String tag );
111
130
112
131
/**
113
132
* Finds the default resource limit for a specified type.
@@ -122,9 +141,10 @@ public interface ResourceLimitService {
122
141
*
123
142
* @param domain
124
143
* @param type
144
+ * @param tag
125
145
* @return resource limit
126
146
*/
127
- public long findCorrectResourceLimitForAccountAndDomain (Account account , Domain domain , ResourceType type );
147
+ public long findCorrectResourceLimitForAccountAndDomain (Account account , Domain domain , ResourceType type , String tag );
128
148
129
149
/**
130
150
* Increments the resource count
@@ -134,6 +154,7 @@ public interface ResourceLimitService {
134
154
* @param delta
135
155
*/
136
156
public void incrementResourceCount (long accountId , ResourceType type , Long ... delta );
157
+ public void incrementResourceCountWithTag (long accountId , ResourceType type , String tag , Long ... delta );
137
158
138
159
/**
139
160
* Decrements the resource count
@@ -143,6 +164,7 @@ public interface ResourceLimitService {
143
164
* @param delta
144
165
*/
145
166
public void decrementResourceCount (long accountId , ResourceType type , Long ... delta );
167
+ public void decrementResourceCountWithTag (long accountId , ResourceType type , String tag , Long ... delta );
146
168
147
169
/**
148
170
* Checks if a limit has been exceeded for an account
@@ -155,15 +177,17 @@ public interface ResourceLimitService {
155
177
* @throws ResourceAllocationException
156
178
*/
157
179
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 ;
158
181
159
182
/**
160
183
* Gets the count of resources for a resource type and account
161
184
*
162
185
* @param account
163
186
* @param type
187
+ * @param tag
164
188
* @return count of resources
165
189
*/
166
- public long getResourceCount (Account account , ResourceType type );
190
+ public long getResourceCount (Account account , ResourceType type , String tag );
167
191
168
192
/**
169
193
* Checks if a limit has been exceeded for an account if displayResource flag is on
@@ -208,15 +232,25 @@ public interface ResourceLimitService {
208
232
*/
209
233
void decrementResourceCount (long accountId , ResourceType type , Boolean displayResource , Long ... delta );
210
234
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 );
221
255
222
256
}
0 commit comments