mirror of https://github.com/apache/cloudstack.git
refactor
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
ab203d8741
commit
bb6518f0d7
|
|
@ -32,7 +32,7 @@ import org.apache.cloudstack.api.response.TemplateResponse;
|
|||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.context.ResponseMessageResolver;
|
||||
import org.apache.cloudstack.error.Exceptions;
|
||||
|
||||
import com.cloud.configuration.Resource;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
|
|
@ -166,10 +166,10 @@ public class DeployVMCmd extends BaseDeployVMCmd {
|
|||
protected void handleCreateResourceAllocationException(ResourceAllocationException ex) {
|
||||
Object cause = CallContext.current().getErrorContextParameters().get("resourceLimitCause");
|
||||
if (Resource.ResourceOwnerType.Account.equals(cause)) {
|
||||
throw ResponseMessageResolver.serverApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR,
|
||||
throw Exceptions.serverApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR,
|
||||
"vm.deploy.resourcelimit.exceeded.account");
|
||||
} else if (Resource.ResourceOwnerType.Domain.equals(cause)) {
|
||||
throw ResponseMessageResolver.serverApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR,
|
||||
throw Exceptions.serverApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR,
|
||||
"vm.deploy.resourcelimit.exceeded.domain");
|
||||
}
|
||||
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
|
||||
|
|
|
|||
|
|
@ -30,10 +30,8 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.ExceptionResponse;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
|
@ -41,8 +39,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -370,36 +366,4 @@ public class ResponseMessageResolver {
|
|||
response.setErrorText(expand(template, stringMap));
|
||||
response.setErrorMetadata(stringMap);
|
||||
}
|
||||
|
||||
public static InvalidParameterValueException invalidParameterValueException(String errorKey, Map<String, Object> metadata) {
|
||||
return new InvalidParameterValueException(errorKey, metadata);
|
||||
}
|
||||
|
||||
public static InvalidParameterValueException invalidParameterValueException(String errorKey) {
|
||||
return invalidParameterValueException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static PermissionDeniedException permissionDeniedException(String errorKey, Map<String, Object> metadata) {
|
||||
return new PermissionDeniedException(errorKey, metadata);
|
||||
}
|
||||
|
||||
public static PermissionDeniedException permissionDeniedException(String errorKey) {
|
||||
return permissionDeniedException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static ServerApiException serverApiException(ApiErrorCode errorCode, String errorKey) {
|
||||
return new ServerApiException(errorCode, errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey, Map<String, Object> metadata) {
|
||||
return new CloudRuntimeException(resolve(errorKey, metadata));
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey) {
|
||||
return new CloudRuntimeException(resolve(errorKey, Collections.emptyMap()));
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey, Map<String, Object> metadata, Throwable th) {
|
||||
return new CloudRuntimeException(resolve(errorKey, metadata), th);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
// 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 org.apache.cloudstack.error;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.context.ResponseMessageResolver;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class Exceptions {
|
||||
|
||||
public static InvalidParameterValueException invalidParameterValueException(String errorKey, Map<String, Object> metadata) {
|
||||
return new InvalidParameterValueException(errorKey, metadata);
|
||||
}
|
||||
|
||||
public static InvalidParameterValueException invalidParameterValueException(String errorKey) {
|
||||
return invalidParameterValueException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static PermissionDeniedException permissionDeniedException(String errorKey, Map<String, Object> metadata) {
|
||||
return new PermissionDeniedException(errorKey, metadata);
|
||||
}
|
||||
|
||||
public static PermissionDeniedException permissionDeniedException(String errorKey) {
|
||||
return permissionDeniedException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static ServerApiException serverApiException(ApiErrorCode errorCode, String errorKey, Map<String, Object> metadata) {
|
||||
return new ServerApiException(errorCode, errorKey, metadata);
|
||||
}
|
||||
|
||||
public static ServerApiException serverApiException(ApiErrorCode errorCode, String errorKey) {
|
||||
return serverApiException(errorCode, errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey, Map<String, Object> metadata) {
|
||||
return new CloudRuntimeException(ResponseMessageResolver.resolve(errorKey, metadata));
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey) {
|
||||
return new CloudRuntimeException(ResponseMessageResolver.resolve(errorKey, Collections.emptyMap()));
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey, Map<String, Object> metadata, Throwable th) {
|
||||
return new CloudRuntimeException(ResponseMessageResolver.resolve(errorKey, metadata), th);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue