mirror of https://github.com/apache/cloudstack.git
Bug CS-15372: IdentityProxy info should be copied over during exception handling in API layer for create(), like it is done in execute().
Description: 1. Added exception processing for uuid lists in exceptions, for commands of type BaseAsyncCreateCmd. 2. Added nullpointer check in addProxyObject(). 3. Miscellaneous whitespace reformatting for git patching.
This commit is contained in:
parent
9775675d97
commit
73a3c8f496
|
|
@ -1,83 +1,88 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, 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.exception;
|
||||
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import java.util.ArrayList;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
import com.cloud.utils.AnnotationHelper;
|
||||
|
||||
/**
|
||||
* CloudException is a generic exception class that has an IdentityProxy
|
||||
* object in it to enable on the fly conversion of database ids to uuids
|
||||
* by the API response serializer. Any exceptions that are thrown by
|
||||
* command invocations must extend this class, or the RuntimeCloudException
|
||||
* class, which extends RuntimeException instead of Exception like this
|
||||
* class does.
|
||||
*/
|
||||
|
||||
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 void addProxyObject(Object voObj, Long id, String idFieldName) {
|
||||
// Get the VO object's table name.
|
||||
String tablename = AnnotationHelper.getTableName(voObj);
|
||||
if (tablename != null) {
|
||||
addProxyObject(tablename, id, idFieldName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public CloudException() {
|
||||
super();
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
return;
|
||||
}
|
||||
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
|
||||
public void setCSErrorCode(int cserrcode) {
|
||||
this.csErrorCode = cserrcode;
|
||||
}
|
||||
|
||||
public int getCSErrorCode() {
|
||||
return this.csErrorCode;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, 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.exception;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.cloud.utils.AnnotationHelper;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
||||
/**
|
||||
* CloudException is a generic exception class that has an IdentityProxy
|
||||
* object in it to enable on the fly conversion of database ids to uuids
|
||||
* by the API response serializer. Any exceptions that are thrown by
|
||||
* command invocations must extend this class, or the RuntimeCloudException
|
||||
* class, which extends RuntimeException instead of Exception like this
|
||||
* class does.
|
||||
*/
|
||||
|
||||
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 void addProxyObject(Object voObj, Long id, String idFieldName) {
|
||||
// Get the VO object's table name.
|
||||
if (voObj != null) {
|
||||
String tablename = AnnotationHelper.getTableName(voObj);
|
||||
if (tablename != null) {
|
||||
addProxyObject(tablename, id, idFieldName);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public CloudException() {
|
||||
super();
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
if (tableName != null) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
|
||||
public void setCSErrorCode(int cserrcode) {
|
||||
this.csErrorCode = cserrcode;
|
||||
}
|
||||
|
||||
public int getCSErrorCode() {
|
||||
return this.csErrorCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ import com.cloud.exception.InvalidParameterValueException;
|
|||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
|
@ -79,24 +79,122 @@ public class ApiDispatcher {
|
|||
ctx.setAccountId(cmd.getEntityOwnerId());
|
||||
cmd.create();
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) {
|
||||
if (t instanceof InvalidParameterValueException) {
|
||||
InvalidParameterValueException ref = (InvalidParameterValueException) t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + " db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if(t instanceof IllegalArgumentException) {
|
||||
s_logger.info(t.getMessage());
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
} else if (t instanceof PermissionDeniedException) {
|
||||
s_logger.info("PermissionDenied: " + t.getMessage());
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
|
||||
PermissionDeniedException ref = (PermissionDeniedException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info("PermissionDenied: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info("PermissionDenied: " + t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof AccountLimitException) {
|
||||
s_logger.info(t.getMessage());
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
|
||||
AccountLimitException ref = (AccountLimitException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof InsufficientCapacityException) {
|
||||
s_logger.info(t.getMessage());
|
||||
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
|
||||
InsufficientCapacityException ref = (InsufficientCapacityException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof ResourceAllocationException) {
|
||||
s_logger.info(t.getMessage());
|
||||
throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
|
||||
ResourceAllocationException ref = (ResourceAllocationException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Exception: ", t);
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof ResourceUnavailableException) {
|
||||
s_logger.warn("Exception: ", t);
|
||||
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
|
||||
ResourceUnavailableException ref = (ResourceUnavailableException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Exception: ", t);
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof AsyncCommandQueued) {
|
||||
throw (AsyncCommandQueued) t;
|
||||
} else if (t instanceof ServerApiException) {
|
||||
|
|
@ -104,11 +202,14 @@ public class ApiDispatcher {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -135,117 +236,117 @@ public class ApiDispatcher {
|
|||
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof InvalidParameterValueException) {
|
||||
// earlier, we'd log the db id as part of the log message, but now since we've pushed
|
||||
// the id into a IdentityProxy object, we would need to dump that object alongwith the
|
||||
// message.
|
||||
InvalidParameterValueException ref = (InvalidParameterValueException) t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
// earlier, we'd log the db id as part of the log message, but now since we've pushed
|
||||
// the id into a IdentityProxy object, we would need to dump that object alongwith the
|
||||
// message.
|
||||
InvalidParameterValueException ref = (InvalidParameterValueException) t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + " db_id: " + id.getValue());
|
||||
}
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + " db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if(t instanceof IllegalArgumentException) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
} else if (t instanceof PermissionDeniedException) {
|
||||
PermissionDeniedException ref = (PermissionDeniedException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
|
||||
PermissionDeniedException ref = (PermissionDeniedException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info("PermissionDenied: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info("PermissionDenied: " + t.getMessage());
|
||||
}
|
||||
// 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());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info("PermissionDenied: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
s_logger.info("PermissionDenied: " + t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
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());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} 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;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
|
||||
InsufficientCapacityException ref = (InsufficientCapacityException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.info(t.getMessage());
|
||||
s_logger.info(t.getMessage());
|
||||
}
|
||||
// Also copy over the cserror code
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof ResourceAllocationException) {
|
||||
ResourceAllocationException ref = (ResourceAllocationException)t;
|
||||
ResourceAllocationException ref = (ResourceAllocationException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Exception: ", t);
|
||||
s_logger.warn("Exception: ", t);
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof ResourceUnavailableException) {
|
||||
ResourceUnavailableException ref = (ResourceUnavailableException)t;
|
||||
ResourceUnavailableException ref = (ResourceUnavailableException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
// Iterate through entire arraylist and copy over each proxy id.
|
||||
for (int i = 0 ; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Exception: ", t);
|
||||
s_logger.warn("Exception: ", t);
|
||||
}
|
||||
// Also copy over the cserror code.
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
ex.setCSErrorCode(ref.getCSErrorCode());
|
||||
throw ex;
|
||||
} else if (t instanceof AsyncCommandQueued) {
|
||||
throw (AsyncCommandQueued) t;
|
||||
|
|
@ -256,12 +357,12 @@ public class ApiDispatcher {
|
|||
s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t);
|
||||
ServerApiException ex;
|
||||
if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
|
||||
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
|
||||
} else {
|
||||
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
|
||||
}
|
||||
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
|
||||
throw ex;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -279,7 +380,7 @@ public class ApiDispatcher {
|
|||
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
|
||||
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
|
||||
throw ex;
|
||||
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");
|
||||
}
|
||||
|
|
@ -408,7 +509,7 @@ public class ApiDispatcher {
|
|||
|
||||
listParam.add(val);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case SHORT:
|
||||
listParam.add(Short.valueOf(token));
|
||||
case STRING:
|
||||
|
|
@ -500,8 +601,8 @@ public class ApiDispatcher {
|
|||
clazz = clazz.getSuperclass();
|
||||
} while (clazz != Object.class && clazz != null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static Long getIdentiyId(String tableName, String token) {
|
||||
return s_instance._identityDao.getIdentityId(tableName, token);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,82 +1,87 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, 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 com.cloud.utils.AnnotationHelper;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* RuntimeCloudException is a generic exception class that has an IdentityProxy
|
||||
* object in it to enable on the fly conversion of database ids to uuids
|
||||
* by the API response serializer. Any exceptions that are thrown by
|
||||
* command invocations must extend this class, or the CloudException
|
||||
* class, which extends Exception instead of RuntimeException like this
|
||||
* class does.
|
||||
*/
|
||||
|
||||
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);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public void addProxyObject(Object voObj, Long id, String idFieldName) {
|
||||
// Get the VO object's table name.
|
||||
String tablename = AnnotationHelper.getTableName(voObj);
|
||||
if (tablename != null) {
|
||||
addProxyObject(tablename, id, idFieldName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, 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.ArrayList;
|
||||
|
||||
import com.cloud.utils.AnnotationHelper;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
|
||||
/**
|
||||
* RuntimeCloudException is a generic exception class that has an IdentityProxy
|
||||
* object in it to enable on the fly conversion of database ids to uuids
|
||||
* by the API response serializer. Any exceptions that are thrown by
|
||||
* command invocations must extend this class, or the CloudException
|
||||
* class, which extends Exception instead of RuntimeException like this
|
||||
* class does.
|
||||
*/
|
||||
|
||||
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) {
|
||||
if (tableName != null) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String message) {
|
||||
super(message);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public void addProxyObject(Object voObj, Long id, String idFieldName) {
|
||||
// Get the VO object's table name.
|
||||
if (voObj != null) {
|
||||
String tablename = AnnotationHelper.getTableName(voObj);
|
||||
if (tablename != null) {
|
||||
addProxyObject(tablename, id, idFieldName);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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