forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceLimitService.java
More file actions
142 lines (128 loc) · 4.63 KB
/
ResourceLimitService.java
File metadata and controls
142 lines (128 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// 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 com.cloud.user;
import java.util.List;
import com.cloud.configuration.Resource.ResourceType;
import com.cloud.configuration.ResourceCount;
import com.cloud.configuration.ResourceLimit;
import com.cloud.domain.Domain;
import com.cloud.exception.ResourceAllocationException;
public interface ResourceLimitService {
/**
* Updates an existing resource limit with the specified details. If a limit doesn't exist, will create one.
*
* @param accountId
* TODO
* @param domainId
* TODO
* @param resourceType
* TODO
* @param max
* TODO
*
* @return the updated/created resource limit
*/
ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max);
/**
* Updates an existing resource count details for the account/domain
*
* @param accountId
* TODO
* @param domainId
* TODO
* @param typeId
* TODO
* @return the updated/created resource counts
*/
List<? extends ResourceCount> recalculateResourceCount(Long accountId, Long domainId, Integer typeId);
/**
* Search for resource limits for the given id and/or account and/or type and/or domain.
*
* @param id
* TODO
* @param accountId
* TODO
* @param domainId
* TODO
* @param type
* TODO
* @return a list of limits that match the criteria
*/
public List<? extends ResourceLimit> searchForLimits(Long id, Long accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal);
/**
* Finds the resource limit for a specified account and type. If the account has an infinite limit, will check
* the account's parent domain, and if that limit is also infinite, will return the ROOT domain's limit.
*
* @param account
* @param type
* @return resource limit
*/
public long findCorrectResourceLimitForAccount(Account account, ResourceType type);
/**
* This call should be used when we have already queried resource limit for an account. This is to handle
* some corner cases where queried limit may be null.
* @param accountType
* @param limit
* @param type
* @return
*/
public long findCorrectResourceLimitForAccount(short accountType, Long limit, ResourceType type);
/**
* Finds the resource limit for a specified domain and type. If the domain has an infinite limit, will check
* up the domain hierarchy
*
* @param account
* @param type
* @return resource limit
*/
public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type);
/**
* Increments the resource count
*
* @param accountId
* @param type
* @param delta
*/
public void incrementResourceCount(long accountId, ResourceType type, Long... delta);
/**
* Decrements the resource count
*
* @param accountId
* @param type
* @param delta
*/
public void decrementResourceCount(long accountId, ResourceType type, Long... delta);
/**
* Checks if a limit has been exceeded for an account
*
* @param account
* @param type
* @param count
* the number of resources being allocated, count will be added to current allocation and compared
* against maximum allowed allocation
* @throws ResourceAllocationException
*/
public void checkResourceLimit(Account account, ResourceCount.ResourceType type, long... count) throws ResourceAllocationException;
/**
* Gets the count of resources for a resource type and account
*
* @param account
* @param type
* @return count of resources
*/
public long getResourceCount(Account account, ResourceType type);
}