mirror of https://github.com/apache/cloudstack.git
Bug 14060: Include a CloudStack error code in an Exception Response
Bug 13127: API error text refer to database ids instead of uuids Code-Reviewers: Ewan Mellor, Kelven Yang Description: 1. A new class CSExceptionErrorCode has been added to utils. It contains a list of error codes for each type of Exception class. Use fully qualified package paths for Exceptions in CSExceptionErrorCode. We log any exception name not found in the list of error codes for exceptions. 2. Whenever we throw an exception exobj anywhere in the CS code, the CSErrorCode is set in the base class constructor. 3. We add a new field csErrorCode in classes CloudException, RuntimeCloudException, ExecutionException and ExceptionResponse. 4. Two places in ApiServer.java were wrongly modified when putting in changes for bug 13127 to not throw an exception. This has been corrected in this commit.
This commit is contained in:
parent
220e9136d5
commit
f601db1304
|
|
@ -24,8 +24,8 @@ public class ExceptionResponse extends BaseResponse {
|
|||
@SerializedName("errorcode") @Param(description="numeric code associated with this error")
|
||||
private Integer errorCode;
|
||||
|
||||
@SerializedName("cserrorcode") @Param(description="cloudstack error code associated with this error")
|
||||
private Integer cserrorCode;
|
||||
@SerializedName("cserrorcode") @Param(description="cloudstack exception error code associated with this error")
|
||||
private Integer csErrorCode;
|
||||
|
||||
@SerializedName("errortext") @Param(description="the text associated with this error")
|
||||
private String errorText = "Command failed due to Internal Server Error";
|
||||
|
|
@ -54,4 +54,8 @@ public class ExceptionResponse extends BaseResponse {
|
|||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
|
||||
public void setCSErrorCode(int cserrcode) {
|
||||
this.csErrorCode = cserrcode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.exception;
|
|||
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import java.util.ArrayList;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
||||
/**
|
||||
* CloudException is a generic exception class that has an IdentityProxy
|
||||
|
|
@ -31,18 +32,26 @@ import java.util.ArrayList;
|
|||
|
||||
public class CloudException extends Exception {
|
||||
|
||||
// This holds a list of uuids and their names. Add uuid:fieldname pairs
|
||||
// if required, to this list before throwing an exception, using addProxyObject().
|
||||
protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
|
||||
// This holds an error code. Set this before throwing an exception, if applicable.
|
||||
protected Integer csErrorCode;
|
||||
|
||||
public CloudException(String message) {
|
||||
super(message);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public CloudException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public CloudException() {
|
||||
super();
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
|
|
@ -52,5 +61,13 @@ public class CloudException extends Exception {
|
|||
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCSErrorCode(int cserrcode) {
|
||||
this.csErrorCode = cserrcode;
|
||||
}
|
||||
|
||||
public int getCSErrorCode() {
|
||||
return this.csErrorCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import com.cloud.user.UserContext;
|
|||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.uuididentity.dao.IdentityDao;
|
||||
|
||||
|
|
@ -150,7 +151,9 @@ public class ApiDispatcher {
|
|||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if(t instanceof IllegalArgumentException) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
|
|
@ -168,8 +171,10 @@ public class ApiDispatcher {
|
|||
}
|
||||
} else {
|
||||
s_logger.info("PermissionDenied: " + t.getMessage());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof AccountLimitException) {
|
||||
AccountLimitException ref = (AccountLimitException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
|
||||
|
|
@ -185,6 +190,8 @@ public class ApiDispatcher {
|
|||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof InsufficientCapacityException) {
|
||||
InsufficientCapacityException ref = (InsufficientCapacityException)t;
|
||||
|
|
@ -201,6 +208,8 @@ public class ApiDispatcher {
|
|||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof ResourceAllocationException) {
|
||||
ResourceAllocationException ref = (ResourceAllocationException)t;
|
||||
|
|
@ -217,6 +226,8 @@ public class ApiDispatcher {
|
|||
} else {
|
||||
s_logger.warn("Exception: ", t);
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof ResourceUnavailableException) {
|
||||
ResourceUnavailableException ref = (ResourceUnavailableException)t;
|
||||
|
|
@ -233,19 +244,24 @@ public class ApiDispatcher {
|
|||
} else {
|
||||
s_logger.warn("Exception: ", t);
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof AsyncCommandQueued) {
|
||||
} else if (t instanceof AsyncCommandQueued) {
|
||||
throw (AsyncCommandQueued) t;
|
||||
} else if (t instanceof ServerApiException) {
|
||||
s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
|
||||
throw (ServerApiException) t;
|
||||
} else {
|
||||
s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t);
|
||||
ServerApiException ex;
|
||||
if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
|
||||
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
|
||||
}
|
||||
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
|
||||
}
|
||||
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -261,7 +277,9 @@ public class ApiDispatcher {
|
|||
}
|
||||
|
||||
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
|
||||
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
|
||||
throw ex;
|
||||
} else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,8 @@ import com.cloud.utils.db.SearchCriteria;
|
|||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.encoding.Base64;
|
||||
import com.cloud.uuididentity.dao.IdentityDao;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
||||
|
||||
public class ApiServer implements HttpRequestHandler {
|
||||
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
|
||||
|
|
@ -428,7 +430,7 @@ public class ApiServer implements HttpRequestHandler {
|
|||
} catch (Exception ex) {
|
||||
if (ex instanceof InvalidParameterValueException) {
|
||||
InvalidParameterValueException ref = (InvalidParameterValueException)ex;
|
||||
ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
|
||||
ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
|
|
@ -437,7 +439,9 @@ public class ApiServer implements HttpRequestHandler {
|
|||
IdentityProxy obj = idList.get(i);
|
||||
e.addProxyObject(obj.getTableName(), obj.getValue(), obj.getidFieldName());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Also copy over the cserror code and the function/layer in which it was thrown.
|
||||
e.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw e;
|
||||
} else if (ex instanceof PermissionDeniedException) {
|
||||
PermissionDeniedException ref = (PermissionDeniedException)ex;
|
||||
|
|
@ -451,12 +455,15 @@ public class ApiServer implements HttpRequestHandler {
|
|||
e.addProxyObject(obj.getTableName(), obj.getValue(), obj.getidFieldName());
|
||||
}
|
||||
}
|
||||
e.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw e;
|
||||
} else if (ex instanceof ServerApiException) {
|
||||
throw (ServerApiException) ex;
|
||||
} else {
|
||||
s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal server error, unable to execute request.");
|
||||
ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal server error, unable to execute request.");
|
||||
e.setCSErrorCode(CSExceptionErrorCode.getCSErrCode("ServerApiException"));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
|
|
@ -1055,6 +1062,8 @@ public class ApiServer implements HttpRequestHandler {
|
|||
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
}
|
||||
}
|
||||
// Also copy over the cserror code and the function/layer in which it was thrown.
|
||||
apiResponse.setCSErrorCode(ref.getCSErrorCode());
|
||||
} else if (ex instanceof PermissionDeniedException) {
|
||||
PermissionDeniedException ref = (PermissionDeniedException) ex;
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
|
|
@ -1064,6 +1073,8 @@ public class ApiServer implements HttpRequestHandler {
|
|||
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
}
|
||||
}
|
||||
// Also copy over the cserror code and the function/layer in which it was thrown.
|
||||
apiResponse.setCSErrorCode(ref.getCSErrorCode());
|
||||
} else if (ex instanceof InvalidParameterValueException) {
|
||||
InvalidParameterValueException ref = (InvalidParameterValueException) ex;
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
|
|
@ -1073,6 +1084,8 @@ public class ApiServer implements HttpRequestHandler {
|
|||
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
}
|
||||
}
|
||||
// Also copy over the cserror code and the function/layer in which it was thrown.
|
||||
apiResponse.setCSErrorCode(ref.getCSErrorCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ import com.cloud.utils.db.SearchBuilder;
|
|||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
|
@ -400,7 +401,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (podId != null) {
|
||||
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
|
||||
// for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object.
|
||||
ex.addProxyObject("Pod", podId, "podId");
|
||||
ex.addProxyObject("Pod", podId, "podId");
|
||||
throw ex;
|
||||
}
|
||||
s_logger.warn(errorMessage.toString());
|
||||
|
|
@ -987,6 +988,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (network == null) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Network id is invalid");
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
// check permissions
|
||||
|
|
@ -1792,6 +1794,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
// see NetworkVO.java.
|
||||
CloudRuntimeException ex = new CloudRuntimeException("Service provider " + element.getProvider().getName() + "either doesn't exist or is not enabled in specified physical network id");
|
||||
ex.addProxyObject("networks", network.getPhysicalNetworkId(), "physicalNetworkId");
|
||||
throw ex;
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Asking " + element.getName() + " to implemenet " + network);
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ import com.cloud.vm.dao.NicDao;
|
|||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
|
@ -1889,7 +1890,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
if (!domains.isEmpty() && !sameDomain) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Failed to update specified domain id with name '" + domainName + "' since it already exists in the system");
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* Copyright (C) 2012 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.utils.exception;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
/**
|
||||
* CSExceptionErrorCode lists the CloudStack error codes that correspond
|
||||
* to a each exception thrown by the CloudStack API.
|
||||
*/
|
||||
|
||||
public class CSExceptionErrorCode {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(CSExceptionErrorCode.class.getName());
|
||||
|
||||
// Declare a hashmap of CloudStack Error Codes for Exceptions.
|
||||
protected static final HashMap<String, Integer> ExceptionErrorCodeMap;
|
||||
|
||||
static {
|
||||
try {
|
||||
ExceptionErrorCodeMap = new HashMap<String, Integer>();
|
||||
ExceptionErrorCodeMap.put("com.cloud.utils.exception.CloudRuntimeException", 4250);
|
||||
ExceptionErrorCodeMap.put("com.cloud.utils.exception.ExceptionUtil", 4255);
|
||||
ExceptionErrorCodeMap.put("com.cloud.utils.exception.ExecutionException", 4260);
|
||||
ExceptionErrorCodeMap.put("com.cloud.utils.exception.HypervisorVersionChangedException", 4265);
|
||||
ExceptionErrorCodeMap.put("com.cloud.utils.exception.RuntimeCloudException", 4270);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.CloudException", 4275);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.AccountLimitException", 4280);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.AgentUnavailableException", 4285);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.CloudAuthenticationException", 4290);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.CloudExecutionException", 4295);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ConcurrentOperationException", 4300);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ConflictingNetworkSettingsException", 4305);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.DiscoveredWithErrorException", 4310);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.HAStateException", 4315);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientAddressCapacityException", 4320);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientCapacityException", 4325);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientNetworkCapacityException", 4330);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientServerCapacityException", 4335);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientStorageCapacityException", 4340);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InternalErrorException", 4345);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InvalidParameterValueException", 4350);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ManagementServerException", 4355);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.NetworkRuleConflictException", 4360);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.PermissionDeniedException", 4365);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ResourceAllocationException", 4370);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ResourceInUseException", 4375);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ResourceUnavailableException", 4380);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.StorageUnavailableException", 4385);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.UnsupportedServiceException", 4390);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4395);
|
||||
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.AccountLimitException", 4400);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.AgentUnavailableException", 4405);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.CloudAuthenticationException", 4410);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.CloudException", 4415);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.CloudExecutionException", 4420);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ConcurrentOperationException", 4425);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ConflictingNetworkSettingsException", 4430);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ConnectionException", 4435);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.DiscoveredWithErrorException", 4440);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.DiscoveryException", 4445);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.HAStateException", 4450);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientAddressCapacityException", 4455);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientCapacityException", 4460);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientNetworkCapacityException", 4465);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientServerCapacityException", 4470);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientStorageCapacityException", 4475);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientVirtualNetworkCapcityException", 4480);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InternalErrorException", 4485);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.InvalidParameterValueException", 4490);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ManagementServerException", 4495);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.NetworkRuleConflictException", 4500);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.PermissionDeniedException", 4505);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ResourceAllocationException", 4510);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ResourceInUseException", 4515);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.ResourceUnavailableException", 4520);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.StorageUnavailableException", 4525);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.UnsupportedServiceException", 4530);
|
||||
ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4535);
|
||||
|
||||
// Have a special error code for ServerApiException when it is
|
||||
// thrown in a standalone manner when failing to detect any of the above
|
||||
// standard exceptions.
|
||||
ExceptionErrorCodeMap.put("ServerApiException", 9999);
|
||||
} catch (Exception e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<String, Integer> getErrCodeList() {
|
||||
return ExceptionErrorCodeMap;
|
||||
}
|
||||
|
||||
public static int getCSErrCode(String exceptionName) {
|
||||
if (ExceptionErrorCodeMap.containsKey(exceptionName)) {
|
||||
return ExceptionErrorCodeMap.get(exceptionName);
|
||||
} else {
|
||||
s_logger.info("Could not find exception: " + exceptionName + " in error code list for exceptions");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCurMethodName() {
|
||||
StackTraceElement stackTraceCalls[] = (new Throwable()).getStackTrace();
|
||||
return stackTraceCalls[1].toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
package com.cloud.utils.exception;
|
||||
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
||||
/**
|
||||
* a public method.
|
||||
|
|
@ -21,12 +22,23 @@ import com.cloud.utils.SerialVersionUID;
|
|||
public class ExecutionException extends Exception {
|
||||
private static final long serialVersionUID = SerialVersionUID.ExecutionException;
|
||||
|
||||
// This holds an error code. Set this before throwing an exception, if applicable.
|
||||
protected int csErrorCode;
|
||||
|
||||
public ExecutionException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public ExecutionException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
|
||||
public void setCSErrorCode(int cserrcode) {
|
||||
this.csErrorCode = cserrcode;
|
||||
}
|
||||
|
||||
public int getCSErrorCode() {
|
||||
return this.csErrorCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,26 +31,42 @@ import java.util.ArrayList;
|
|||
|
||||
public class RuntimeCloudException extends RuntimeException {
|
||||
|
||||
// This holds a list of uuids and their names. Add uuid:fieldname pairs
|
||||
// if required, to this list before throwing an exception, using addProxyObject().
|
||||
protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
|
||||
// This holds an error code. Set this before throwing an exception, if applicable.
|
||||
protected int csErrorCode;
|
||||
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
return;
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String message) {
|
||||
super(message);
|
||||
super(message);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public RuntimeCloudException() {
|
||||
super();
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
|
||||
public void setCSErrorCode(int cserrcode) {
|
||||
this.csErrorCode = cserrcode;
|
||||
}
|
||||
|
||||
public int getCSErrorCode() {
|
||||
return this.csErrorCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue