|
35 | 35 | import com.cloud.exception.ConcurrentOperationException; |
36 | 36 | import com.cloud.exception.InsufficientCapacityException; |
37 | 37 | import com.cloud.exception.InvalidParameterValueException; |
38 | | -import com.cloud.exception.PermissionDeniedException; |
39 | 38 | import com.cloud.exception.ResourceAllocationException; |
40 | 39 | import com.cloud.exception.ResourceUnavailableException; |
41 | 40 | import com.cloud.network.NetworkService; |
|
56 | 55 | import com.cloud.user.AccountService; |
57 | 56 | import com.cloud.user.DomainService; |
58 | 57 | import com.cloud.user.ResourceLimitService; |
59 | | -import com.cloud.user.UserContext; |
60 | 58 | import com.cloud.utils.Pair; |
61 | 59 | import com.cloud.utils.component.ComponentLocator; |
62 | 60 | import com.cloud.vm.BareMetalVmService; |
@@ -194,124 +192,6 @@ public static String getDateString(Date date) { |
194 | 192 | return formattedString; |
195 | 193 | } |
196 | 194 |
|
197 | | - protected Account getValidOwner(String accountName, Long domainId) { |
198 | | - Account owner = null; |
199 | | - if (accountName != null) { |
200 | | - owner = _responseGenerator.findAccountByNameDomain(accountName, domainId); |
201 | | - } else { |
202 | | - owner = UserContext.current().getCaller(); |
203 | | - } |
204 | | - if (owner == null) { |
205 | | - throw new InvalidParameterValueException("Invalid value for owner specified: " + accountName); |
206 | | - } |
207 | | - if (owner.getState() == Account.State.disabled || owner.getState() == Account.State.locked) { |
208 | | - throw new PermissionDeniedException("Account disabled."); |
209 | | - } |
210 | | - return owner; |
211 | | - } |
212 | | - |
213 | | - public Map<String, Object> validateParams(Map<String, String> params, boolean decode) { |
214 | | -// List<Pair<Enum, Boolean>> properties = getProperties(); |
215 | | - |
216 | | - // step 1 - all parameter names passed in will be converted to lowercase |
217 | | - Map<String, Object> processedParams = lowercaseParams(params, decode); |
218 | | - return processedParams; |
219 | | - |
220 | | - /* |
221 | | - // step 2 - make sure all required params exist, and all existing params adhere to the appropriate data type |
222 | | - Map<String, Object> validatedParams = new HashMap<String, Object>(); |
223 | | - for (Pair<Enum, Boolean> propertyPair : properties) { |
224 | | - Properties prop = (Properties)propertyPair.first(); |
225 | | - Object param = processedParams.get(prop.getName()); |
226 | | - // possible validation errors are |
227 | | - // - NULL (not specified) |
228 | | - // - MALFORMED |
229 | | - if (param != null) { |
230 | | - short propertyType = prop.getDataType(); |
231 | | - String decodedParam = null; |
232 | | - if ((propertyType != TYPE_OBJECT) && (propertyType != TYPE_OBJECT_MAP)) { |
233 | | - decodedParam = (String)param; |
234 | | - if (decode) { |
235 | | - try { |
236 | | - decodedParam = URLDecoder.decode((String)param, "UTF-8"); |
237 | | - } catch (UnsupportedEncodingException usex) { |
238 | | - s_logger.warn(prop.getName() + " could not be decoded, value = " + param); |
239 | | - throw new ServerApiException(PARAM_ERROR, prop.getName() + " could not be decoded"); |
240 | | - } |
241 | | - } |
242 | | - } |
243 | | -
|
244 | | - switch (propertyType) { |
245 | | - case TYPE_INT: |
246 | | - try { |
247 | | - validatedParams.put(prop.getName(), Integer.valueOf(Integer.parseInt(decodedParam))); |
248 | | - } catch (NumberFormatException ex) { |
249 | | - s_logger.warn(prop.getName() + " (type is int) is malformed, value = " + decodedParam); |
250 | | - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, prop.getName() + " is malformed"); |
251 | | - } |
252 | | - break; |
253 | | - case TYPE_LONG: |
254 | | - try { |
255 | | - validatedParams.put(prop.getName(), Long.valueOf(Long.parseLong(decodedParam))); |
256 | | - } catch (NumberFormatException ex) { |
257 | | - s_logger.warn(prop.getName() + " (type is long) is malformed, value = " + decodedParam); |
258 | | - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, prop.getName() + " is malformed"); |
259 | | - } |
260 | | - break; |
261 | | - case TYPE_DATE: |
262 | | - try { |
263 | | - synchronized(_format) { // SimpleDataFormat is not thread safe, synchronize on it to avoid parse errors |
264 | | - validatedParams.put(prop.getName(), _format.parse(decodedParam)); |
265 | | - } |
266 | | - } catch (ParseException ex) { |
267 | | - s_logger.warn(prop.getName() + " (type is date) is malformed, value = " + decodedParam); |
268 | | - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, prop.getName() + " uses an unsupported date format"); |
269 | | - } |
270 | | - break; |
271 | | - case TYPE_TZDATE: |
272 | | - try { |
273 | | - validatedParams.put(prop.getName(), DateUtil.parseTZDateString(decodedParam)); |
274 | | - } catch (ParseException ex) { |
275 | | - s_logger.warn(prop.getName() + " (type is date) is malformed, value = " + decodedParam); |
276 | | - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, prop.getName() + " uses an unsupported date format"); |
277 | | - } |
278 | | - break; |
279 | | - case TYPE_FLOAT: |
280 | | - try { |
281 | | - validatedParams.put(prop.getName(), Float.valueOf(Float.parseFloat(decodedParam))); |
282 | | - } catch (NumberFormatException ex) { |
283 | | - s_logger.warn(prop.getName() + " (type is float) is malformed, value = " + decodedParam); |
284 | | - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, prop.getName() + " is malformed"); |
285 | | - } |
286 | | - break; |
287 | | - case TYPE_BOOLEAN: |
288 | | - validatedParams.put(prop.getName(), Boolean.valueOf(Boolean.parseBoolean(decodedParam))); |
289 | | - break; |
290 | | - case TYPE_STRING: |
291 | | - validatedParams.put(prop.getName(), decodedParam); |
292 | | - break; |
293 | | - default: |
294 | | - validatedParams.put(prop.getName(), param); |
295 | | - break; |
296 | | - } |
297 | | - } else if (propertyPair.second().booleanValue() == true) { |
298 | | - s_logger.warn("missing parameter, " + prop.getTagName() + " is not specified"); |
299 | | - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, prop.getTagName() + " is not specified"); |
300 | | - } |
301 | | - } |
302 | | -
|
303 | | - return validatedParams; |
304 | | - */ |
305 | | - } |
306 | | - |
307 | | - private Map<String, Object> lowercaseParams(Map<String, String> params, boolean decode) { |
308 | | - Map<String, Object> lowercaseParams = new HashMap<String, Object>(); |
309 | | - for (String key : params.keySet()) { |
310 | | - lowercaseParams.put(key.toLowerCase(), params.get(key)); |
311 | | - } |
312 | | - return lowercaseParams; |
313 | | - } |
314 | | - |
315 | 195 | // FIXME: move this to a utils method so that maps can be unpacked and integer/long values can be appropriately cast |
316 | 196 | @SuppressWarnings({"unchecked", "rawtypes"}) |
317 | 197 | public Map<String, Object> unpackParams(Map<String, String> params) { |
@@ -584,7 +464,7 @@ public Long getAccountId(String accountName, Long domainId, Long projectId) { |
584 | 464 | } |
585 | 465 |
|
586 | 466 | Domain domain = _domainService.getDomain(domainId); |
587 | | - if (domain == null || domain.getType() == Domain.Type.Project) { |
| 467 | + if (domain == null) { |
588 | 468 | throw new InvalidParameterValueException("Unable to find domain by id=" + domainId); |
589 | 469 | } |
590 | 470 |
|
|
0 commit comments