mirror of https://github.com/apache/cloudstack.git
Bug 13127: API error text refer to database ids instead of uuids
Description: Modify Exception handling to enable addition of multiple uuids in a single exception thrown by API functions. Both XML and JSON outputs will store all uuids and Fieldnames. This will make it easier to provide more information when an exception occurs - for example, a zone id, a cluster id, host id, and then a specific property id.
This commit is contained in:
parent
094f01be41
commit
bea85d47a7
|
|
@ -15,10 +15,11 @@ package com.cloud.api.response;
|
|||
import com.cloud.utils.IdentityProxy;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ExceptionResponse extends BaseResponse {
|
||||
@SerializedName("uuid") @Param(description="uuid associated with this error")
|
||||
private IdentityProxy id;
|
||||
private ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
|
||||
@SerializedName("errorcode") @Param(description="numeric code associated with this error")
|
||||
private Integer errorCode;
|
||||
|
|
@ -41,16 +42,13 @@ public class ExceptionResponse extends BaseResponse {
|
|||
public void setErrorText(String errorText) {
|
||||
this.errorText = errorText;
|
||||
}
|
||||
|
||||
public void setProxyObject(String table_name, String idFieldName, Long id) {
|
||||
this.id = new IdentityProxy();
|
||||
this.id.setTableName(table_name);
|
||||
this.id.setValue(id);
|
||||
this.id.setidFieldName(idFieldName);
|
||||
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
return;
|
||||
}
|
||||
|
||||
public IdentityProxy getProxyObject() {
|
||||
return id;
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package com.cloud.exception;
|
||||
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* CloudException is a generic exception class that has an IdentityProxy
|
||||
|
|
@ -30,37 +31,26 @@ import com.cloud.utils.IdentityProxy;
|
|||
|
||||
public class CloudException extends Exception {
|
||||
|
||||
protected IdentityProxy id;
|
||||
|
||||
public CloudException(String table_name, Long id) {
|
||||
this.id = new IdentityProxy();
|
||||
this.id.setTableName(table_name);
|
||||
this.id.setValue(id);
|
||||
}
|
||||
protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
|
||||
public CloudException(String message) {
|
||||
super(message);
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CloudException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CloudException() {
|
||||
//this.id = new IdentityProxy(); ??
|
||||
//this.id = NULL; ??
|
||||
super();
|
||||
}
|
||||
|
||||
public void setProxyObject(String table_name, String idFieldName, Long id) {
|
||||
this.id = new IdentityProxy();
|
||||
this.id.setTableName(table_name);
|
||||
this.id.setValue(id);
|
||||
this.id.setidFieldName(idFieldName);
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
return;
|
||||
}
|
||||
|
||||
public IdentityProxy getIdProxy() {
|
||||
return id;
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,13 +140,17 @@ public class ApiDispatcher {
|
|||
InvalidParameterValueException ref = (InvalidParameterValueException) t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
IdentityProxy id = ref.getProxyObject();
|
||||
if (id != null) {
|
||||
ex.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
s_logger.info(t.getMessage() + " db_id: " + id.getValue());
|
||||
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());
|
||||
}
|
||||
}
|
||||
throw ex;
|
||||
} else if(t instanceof IllegalArgumentException) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
|
||||
|
|
@ -154,22 +158,30 @@ public class ApiDispatcher {
|
|||
PermissionDeniedException ref = (PermissionDeniedException)t;
|
||||
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
IdentityProxy id = ref.getProxyObject();
|
||||
if (id != null) {
|
||||
ex.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
s_logger.info("PermissionDenied: " + t.getMessage() + "uuid: " + id.getValue());
|
||||
} else {
|
||||
s_logger.info("PermissionDenied: " + t.getMessage());
|
||||
}
|
||||
throw ex;
|
||||
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());
|
||||
}
|
||||
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.
|
||||
IdentityProxy id = ref.getProxyObject();
|
||||
if (id != null) {
|
||||
ex.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
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());
|
||||
}
|
||||
|
|
@ -178,10 +190,14 @@ public class ApiDispatcher {
|
|||
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.
|
||||
IdentityProxy id = ref.getIdProxy();
|
||||
if (id != null) {
|
||||
ex.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
s_logger.info(t.getMessage() + "db_id: " + id.getValue());
|
||||
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());
|
||||
}
|
||||
|
|
@ -190,10 +206,14 @@ public class ApiDispatcher {
|
|||
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.
|
||||
IdentityProxy id = ref.getIdProxy();
|
||||
if (id != null) {
|
||||
ex.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + ref.getIdProxy().getValue());
|
||||
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);
|
||||
}
|
||||
|
|
@ -202,10 +222,14 @@ public class ApiDispatcher {
|
|||
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.
|
||||
IdentityProxy id = ref.getIdProxy();
|
||||
if (id != null) {
|
||||
ex.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
s_logger.warn("Exception: " + t.getMessage() + "db_id: " + ref.getIdProxy().getValue());
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -430,18 +430,26 @@ public class ApiServer implements HttpRequestHandler {
|
|||
InvalidParameterValueException ref = (InvalidParameterValueException)ex;
|
||||
ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
IdentityProxy id = ref.getProxyObject();
|
||||
if (id != null) {
|
||||
e.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
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 obj = idList.get(i);
|
||||
e.addProxyObject(obj.getTableName(), obj.getValue(), obj.getidFieldName());
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
} else if (ex instanceof PermissionDeniedException) {
|
||||
PermissionDeniedException ref = (PermissionDeniedException)ex;
|
||||
ServerApiException e = new ServerApiException(BaseCmd.ACCOUNT_ERROR, ex.getMessage());
|
||||
// copy over the IdentityProxy information as well and throw the serverapiexception.
|
||||
IdentityProxy id = ref.getProxyObject();
|
||||
if (id != null) {
|
||||
e.setProxyObject(id.getTableName(), id.getidFieldName(), id.getValue());
|
||||
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 obj = idList.get(i);
|
||||
e.addProxyObject(obj.getTableName(), obj.getValue(), obj.getidFieldName());
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
} else if (ex instanceof ServerApiException) {
|
||||
|
|
@ -1029,32 +1037,41 @@ public class ApiServer implements HttpRequestHandler {
|
|||
apiResponse.setErrorCode(errorCode);
|
||||
apiResponse.setErrorText(errorText);
|
||||
apiResponse.setResponseName(responseName);
|
||||
// Also copy over the IdentityProxy object into this new apiResponse, from
|
||||
// Also copy over the IdentityProxy object List into this new apiResponse, from
|
||||
// the exception caught. When invoked from handle(), the exception here can
|
||||
// be either ServerApiException, PermissionDeniedException or InvalidParameterValue
|
||||
// Exception. When invoked from ApiServlet's processRequest(), this can be
|
||||
// a standard exception like NumberFormatException. We'll leave standard ones alone.
|
||||
// a standard exception like NumberFormatException. We'll leave the standard ones alone.
|
||||
if (ex != null) {
|
||||
if (ex instanceof ServerApiException || ex instanceof PermissionDeniedException
|
||||
|| ex instanceof InvalidParameterValueException) {
|
||||
// Cast the exception appropriately and retrieve the IdentityProxy
|
||||
if (ex instanceof ServerApiException) {
|
||||
if (ex instanceof ServerApiException) {
|
||||
ServerApiException ref = (ServerApiException) ex;
|
||||
IdentityProxy uuidproxy = ref.getProxyObject();
|
||||
if (uuidproxy != null) {
|
||||
apiResponse.setProxyObject(uuidproxy.getTableName(), uuidproxy.getidFieldName(), uuidproxy.getValue());
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
for (int i=0; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
}
|
||||
}
|
||||
} else if (ex instanceof PermissionDeniedException) {
|
||||
PermissionDeniedException ref = (PermissionDeniedException) ex;
|
||||
IdentityProxy uuidproxy = ref.getProxyObject();
|
||||
if (uuidproxy != null) {
|
||||
apiResponse.setProxyObject(uuidproxy.getTableName(), uuidproxy.getidFieldName(), uuidproxy.getValue());
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
for (int i=0; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
}
|
||||
}
|
||||
} else if (ex instanceof InvalidParameterValueException) {
|
||||
InvalidParameterValueException ref = (InvalidParameterValueException) ex;
|
||||
IdentityProxy uuidproxy = ref.getProxyObject();
|
||||
if (uuidproxy != null) {
|
||||
apiResponse.setProxyObject(uuidproxy.getTableName(), uuidproxy.getidFieldName(), uuidproxy.getValue());
|
||||
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
|
||||
if (idList != null) {
|
||||
for (int i=0; i < idList.size(); i++) {
|
||||
IdentityProxy id = idList.get(i);
|
||||
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
package com.cloud.api;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.cloud.uuididentity.dao.IdentityDao;
|
||||
import com.cloud.uuididentity.dao.IdentityDaoImpl;
|
||||
|
|
@ -51,7 +52,7 @@ public class IdentityTypeAdapter implements JsonSerializer<IdentityProxy>, JsonD
|
|||
return new Gson().toJsonTree(src);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IdentityProxy deserialize(JsonElement src, Type srcType,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
|
|
|
|||
|
|
@ -89,19 +89,36 @@ public class ApiResponseSerializer {
|
|||
}
|
||||
} else if (result instanceof SuccessResponse) {
|
||||
sb.append("{ \"success\" : \"" + ((SuccessResponse) result).getSuccess() + "\"} ");
|
||||
} else if (result instanceof ExceptionResponse) {
|
||||
// Convert into json the whole exception object and not just the error text.
|
||||
String jsonErrorText = gson.toJson((ExceptionResponse) result);
|
||||
jsonErrorText = unescape(jsonErrorText);
|
||||
sb.append(jsonErrorText);
|
||||
// Since the IdentityTypeAdapter only converts the uuid, let's append the idFieldName explicitly.
|
||||
IdentityProxy ref = ((ExceptionResponse) result).getProxyObject();
|
||||
if (ref != null) {
|
||||
// bump off the } at the end. We'll re-add it after the idFieldName.
|
||||
sb.deleteCharAt(sb.length()-1);
|
||||
String idFieldName = ref.getidFieldName();
|
||||
if (idFieldName != null) {
|
||||
sb.append(",\"uuidProperty\":" + "\"" + idFieldName + "\"}");
|
||||
} else if (result instanceof ExceptionResponse) {
|
||||
String jsonErrorText = gson.toJson(((ExceptionResponse) result).getErrorText());
|
||||
jsonErrorText = unescape(jsonErrorText);
|
||||
sb.append("{\"errorcode\" : " + ((ExceptionResponse) result).getErrorCode() + ", \"errortext\" : " + jsonErrorText + "}");
|
||||
// Since the IdentityTypeAdapter only converts the uuid, let's append each idFieldName explicitly.
|
||||
// Iterate through the list of IdentityProxy objects if any, in the exception.
|
||||
ArrayList<IdentityProxy> idListref = ((ExceptionResponse) result).getIdProxyList();
|
||||
if (idListref != null) {
|
||||
// Get each uuid from the list IdentityProxy objects.
|
||||
if (!idListref.isEmpty()) {
|
||||
// bump off the } at the end. We'll re-add it after the idFieldName.
|
||||
sb.deleteCharAt(sb.length()-1);
|
||||
sb.append(",");
|
||||
for (int i=0; i < idListref.size(); i++) {
|
||||
IdentityProxy id = idListref.get(i);
|
||||
String idFieldName = id.getidFieldName();
|
||||
String jsonuuidText = gson.toJson(id);
|
||||
jsonuuidText = unescape(jsonuuidText);
|
||||
sb.append("{\"uuid\":" + jsonuuidText);
|
||||
if (idFieldName != null) {
|
||||
sb.append(",\"uuidProperty\":" + "\"" + idFieldName + "\"" + "}");
|
||||
}
|
||||
if(i < (idListref.size()-1)) {
|
||||
// more elements to come
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
// At the end of this, we'll have a response that looks like {"errorcode: " <blah>, "errortext" : <blah>, {"uuid":<blah>, "uuidProperty":<blah>} {"uuid":<blah>, "uuidProperty":<blah>}}
|
||||
// re-add the } at the end.
|
||||
sb.append("}");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -117,7 +134,7 @@ public class ApiResponseSerializer {
|
|||
sb.append("{ }");
|
||||
}
|
||||
}
|
||||
sb.append(" }");
|
||||
sb.append(" }");
|
||||
return sb.toString();
|
||||
}
|
||||
return null;
|
||||
|
|
@ -216,29 +233,24 @@ public class ApiResponseSerializer {
|
|||
subObj.setObjectName(serializedName.value());
|
||||
}
|
||||
serializeResponseObjXML(sb, subObj);
|
||||
} else if (value instanceof IdentityProxy) {
|
||||
IdentityProxy idProxy = (IdentityProxy)value;
|
||||
String id = (idProxy.getValue() != null ? String.valueOf(idProxy.getValue()) : "");
|
||||
if(!id.isEmpty()) {
|
||||
IdentityDao identityDao = new IdentityDaoImpl();
|
||||
id = identityDao.getIdentityUuid(idProxy.getTableName(), id);
|
||||
}
|
||||
if(id != null && !id.isEmpty())
|
||||
sb.append("<" + serializedName.value() + ">" + id + "</" + serializedName.value() + ">");
|
||||
// Append the new idFieldName property also.
|
||||
String idFieldName = idProxy.getidFieldName();
|
||||
if (idFieldName != null) {
|
||||
sb.append("<" + "uuidProperty" + ">" + idFieldName + "</" + "uuidProperty" + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (fieldValue instanceof Date) {
|
||||
sb.append("<" + serializedName.value() + ">" + BaseCmd.getDateString((Date) fieldValue) + "</" + serializedName.value() + ">");
|
||||
} else if (fieldValue instanceof IdentityProxy) {
|
||||
IdentityProxy idProxy = (IdentityProxy)fieldValue;
|
||||
String id = (idProxy.getValue() != null ? String.valueOf(idProxy.getValue()) : "");
|
||||
if(!id.isEmpty()) {
|
||||
IdentityDao identityDao = new IdentityDaoImpl();
|
||||
if(idProxy.getTableName() != null) {
|
||||
id = identityDao.getIdentityUuid(idProxy.getTableName(), id);
|
||||
} else {
|
||||
s_logger.warn("IdentityProxy sanity check issue, invalid IdentityProxy table name found in class: " + obj.getClass().getName());
|
||||
}
|
||||
}
|
||||
if(id != null && !id.isEmpty())
|
||||
sb.append("<" + serializedName.value() + ">" + id + "</" + serializedName.value() + ">");
|
||||
// Append the new idFieldName property also.
|
||||
String idFieldName = idProxy.getidFieldName();
|
||||
if (idFieldName != null) {
|
||||
sb.append("<" + "uuidProperty" + ">" + idFieldName + "</" + "uuidProperty" + ">");
|
||||
}
|
||||
sb.append("<" + serializedName.value() + ">" + BaseCmd.getDateString((Date) fieldValue) + "</" + serializedName.value() + ">");
|
||||
} else {
|
||||
String resultString = escapeSpecialXmlChars(fieldValue.toString());
|
||||
if (!(obj instanceof ExceptionResponse)) {
|
||||
|
|
|
|||
|
|
@ -400,12 +400,12 @@ 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.setProxyObject("Pod", "podId", podId);
|
||||
ex.addProxyObject("Pod", podId, "podId");
|
||||
throw ex;
|
||||
}
|
||||
s_logger.warn(errorMessage.toString());
|
||||
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
|
||||
ex.setProxyObject("data_center", "dcId", dcId);
|
||||
ex.addProxyObject("data_center", dcId, "dcId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -492,7 +492,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
// this ownerId comes from owner or type Account. See the class "AccountVO" and the annotations in that class
|
||||
// to get the table name and field name that is queried to fill this ownerid.
|
||||
ConcurrentOperationException ex = new ConcurrentOperationException("Unable to lock account");
|
||||
ex.setProxyObject("account", "ownerId", ownerId);
|
||||
ex.addProxyObject("account", ownerId, "ownerId");
|
||||
throw ex;
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -574,7 +574,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (domainId != null) {
|
||||
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
||||
PermissionDeniedException ex = new PermissionDeniedException("Invalid domain id given, permission denied");
|
||||
ex.setProxyObject("domain", "domainId", domainId);
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
if (accountName != null) {
|
||||
|
|
@ -583,7 +583,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
account = userAccount;
|
||||
} else {
|
||||
PermissionDeniedException ex = new PermissionDeniedException("Unable to find account " + accountName + " in specified domain, permission denied");
|
||||
ex.setProxyObject("domain", "domainId", domainId);
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
@ -679,7 +679,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
} else {
|
||||
CloudRuntimeException ex = new CloudRuntimeException("Multiple generic soure NAT IPs provided for network");
|
||||
// see the IPAddressVO.java class.
|
||||
ex.setProxyObject("user_ip_address", "networkId", ip.getAssociatedWithNetworkId());
|
||||
ex.addProxyObject("user_ip_address", ip.getAssociatedWithNetworkId(), "networkId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
@ -986,7 +986,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
Network network = _networksDao.findById(networkId);
|
||||
if (network == null) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Network id is invalid");
|
||||
ex.setProxyObject("networks", "networkId", networkId);
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
}
|
||||
|
||||
// check permissions
|
||||
|
|
@ -1019,7 +1019,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
|
||||
// zone is of type DataCenter. See DataCenterVO.java.
|
||||
PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled");
|
||||
ex.setProxyObject("data_center", "zoneId", zone.getId());
|
||||
ex.addProxyObject("data_center", zone.getId(), "zoneId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -1065,7 +1065,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
if (ip == null) {
|
||||
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId());
|
||||
ex.setProxyObject("data_center", "zoneId", zone.getId());
|
||||
ex.addProxyObject("data_center", zone.getId(), "zoneId");
|
||||
throw ex;
|
||||
}
|
||||
UserContext.current().setEventDetails("Ip Id: " + ip.getId());
|
||||
|
|
@ -1509,7 +1509,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (networks.size() < 1) {
|
||||
// see networkOfferingVO.java
|
||||
CloudRuntimeException ex = new CloudRuntimeException("Unable to convert network offering to network profile");
|
||||
ex.setProxyObject("network_offerings", "networkOfferingId", offering.getId());
|
||||
ex.addProxyObject("network_offerings", offering.getId(), "networkOfferingId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -1714,7 +1714,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (network == null) {
|
||||
// see NetworkVO.java
|
||||
ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
|
||||
ex.setProxyObject("networks", "networkId", networkId);
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -1791,7 +1791,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (!isProviderEnabledInPhysicalNetwork(getPhysicalNetworkId(network), "VirtualRouter")) {
|
||||
// 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.setProxyObject("networks", "physicalNetworkId", network.getPhysicalNetworkId());
|
||||
ex.addProxyObject("networks", network.getPhysicalNetworkId(), "physicalNetworkId");
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Asking " + element.getName() + " to implemenet " + network);
|
||||
|
|
@ -1808,7 +1808,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
|
||||
// see DataCenterVO.java
|
||||
ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
|
||||
ex.setProxyObject("data_center", "dataCenterId", network.getDataCenterId());
|
||||
ex.addProxyObject("data_center", network.getDataCenterId(), "dataCenterId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
@ -2015,7 +2015,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
IPAddressVO ipVO = _ipAddressDao.findById(ipAddressId);
|
||||
if (ipVO == null) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find ip address by id");
|
||||
ex.setProxyObject("user_ip_address", "ipAddressId", ipAddressId);
|
||||
ex.addProxyObject("user_ip_address", ipAddressId, "ipAddressId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2044,7 +2044,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (_accountVlanMapDao.findAccountVlanMap(ipVO.getAllocatedToAccountId(), ipVO.getVlanId()) != null) {
|
||||
//see IPaddressVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Sepcified IP address uuid belongs to Account wide IP pool and cannot be disassociated");
|
||||
ex.setProxyObject("user_ip_address", "ipAddressId", ipAddressId);
|
||||
ex.addProxyObject("user_ip_address", ipAddressId, "ipAddressId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2090,7 +2090,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
String mac = _networksDao.getNextAvailableMacAddress(networkId);
|
||||
if (mac == null) {
|
||||
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId);
|
||||
ex.setProxyObject("networks", "networkId", networkId);
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
return mac;
|
||||
|
|
@ -2188,7 +2188,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
if (cidrSubnet.equals(ntwkCidrSubnet)) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Warning: The specified existing network has conflict CIDR subnets with new network!");
|
||||
ex.setProxyObject("networks", "networkId", networkId);
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
@ -2220,7 +2220,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
|
||||
if (ntwkOff == null || ntwkOff.isSystemOnly()) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id");
|
||||
ex.setProxyObject("network_offerings", "networkOfferingId", networkOfferingId);
|
||||
ex.addProxyObject("network_offerings", networkOfferingId, "networkOfferingId");
|
||||
throw ex;
|
||||
}
|
||||
// validate physical network and zone
|
||||
|
|
@ -2230,7 +2230,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
|
||||
if (pNtwk == null) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network having the given id");
|
||||
ex.setProxyObject("physical_network", "physicalNetworkId", physicalNetworkId);
|
||||
ex.addProxyObject("physical_network", physicalNetworkId, "physicalNetworkId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
@ -2243,7 +2243,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
|
||||
// See DataCenterVO.java
|
||||
PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled");
|
||||
ex.setProxyObject("data_center", "zoneId", zone.getId());
|
||||
ex.addProxyObject("data_center", zone.getId(), "zoneId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2301,7 +2301,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (domain == null) {
|
||||
// see DomainVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain by specified if");
|
||||
ex.setProxyObject("domain", "domainId", domainId);
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
_accountMgr.checkAccess(caller, domain);
|
||||
|
|
@ -2446,7 +2446,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (ntwkOff.getState() != NetworkOffering.State.Enabled) {
|
||||
// see NetworkOfferingVO
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Can't use specified network offering id as its stat is not " + NetworkOffering.State.Enabled);
|
||||
ex.setProxyObject("network_offerings", "networkOfferingId", networkOfferingId);
|
||||
ex.addProxyObject("network_offerings", networkOfferingId, "networkOfferingId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2454,7 +2454,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (pNtwk.getState() != PhysicalNetwork.State.Enabled) {
|
||||
// see PhysicalNetworkVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Specified physical network id is in incorrect state:" + pNtwk.getState());
|
||||
ex.setProxyObject("physical_network", "physicalNetworkId", pNtwk.getId());
|
||||
ex.addProxyObject("physical_network", pNtwk.getId(), "physicalNetworkId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2672,7 +2672,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (domain == null) {
|
||||
// see DomainVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Specified domain id doesn't exist in the system");
|
||||
ex.setProxyObject("domain", "domainId", domainId);
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2682,7 +2682,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (owner == null) {
|
||||
// see DomainVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
|
||||
ex.setProxyObject("domain", "domainId", domainId);
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -2711,13 +2711,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (project == null) {
|
||||
// see ProjectVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project by specified id");
|
||||
ex.setProxyObject("projects", "projectId", projectId);
|
||||
ex.addProxyObject("projects", projectId, "projectId");
|
||||
throw ex;
|
||||
}
|
||||
if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) {
|
||||
// see ProjectVO.java
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project id");
|
||||
ex.setProxyObject("projects", "projectId", projectId);
|
||||
ex.addProxyObject("projects", projectId, "projectId");
|
||||
throw ex;
|
||||
}
|
||||
permittedAccounts.add(project.getProjectAccountId());
|
||||
|
|
@ -3323,7 +3323,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
NetworkVO network = _networksDao.findById(networkId);
|
||||
if (network == null) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist");
|
||||
ex.setProxyObject("networks", "networkId", networkId);
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
@ -4035,7 +4035,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
// see NetworkVO.java
|
||||
//throw new InvalidParameterValueException("Network id=" + networkId + "doesn't exist in the system");
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Specified network id doesn't exist in the system");
|
||||
ex.setProxyObject("networks", "networkId", networkId);
|
||||
ex.addProxyObject("networks", networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1889,7 +1889,8 @@ 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.setProxyObject("domain", "domainId", domainId);
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
ex.addProxyObject("domain", domainId, "domainId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ public class IdentityProxy {
|
|||
_tableName = tableName;
|
||||
}
|
||||
|
||||
public IdentityProxy(String tableName, Long id, String fieldName) {
|
||||
_tableName = tableName;
|
||||
_value = id;
|
||||
_idFieldName = fieldName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return _tableName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package com.cloud.utils.exception;
|
||||
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* RuntimeCloudException is a generic exception class that has an IdentityProxy
|
||||
|
|
@ -30,14 +31,13 @@ import com.cloud.utils.IdentityProxy;
|
|||
|
||||
public class RuntimeCloudException extends RuntimeException {
|
||||
|
||||
protected IdentityProxy id;
|
||||
protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
|
||||
public void addProxyObject(String tableName, Long id, String idFieldName) {
|
||||
idList.add(new IdentityProxy(tableName, id, idFieldName));
|
||||
return;
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String table_name, Long id) {
|
||||
this.id = new IdentityProxy();
|
||||
this.id.setTableName(table_name);
|
||||
this.id.setValue(id);
|
||||
}
|
||||
|
||||
public RuntimeCloudException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
|
@ -47,20 +47,10 @@ public class RuntimeCloudException extends RuntimeException {
|
|||
}
|
||||
|
||||
public RuntimeCloudException() {
|
||||
//this.id = new IdentityProxy(); ??
|
||||
//this.id = NULL; ??
|
||||
super();
|
||||
}
|
||||
|
||||
public void setProxyObject(String table_name, String idFieldName, Long id) {
|
||||
this.id = new IdentityProxy();
|
||||
this.id.setTableName(table_name);
|
||||
this.id.setValue(id);
|
||||
this.id.setidFieldName(idFieldName);
|
||||
return;
|
||||
}
|
||||
|
||||
public IdentityProxy getProxyObject() {
|
||||
return id;
|
||||
public ArrayList<IdentityProxy> getIdProxyList() {
|
||||
return idList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue