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:
Vijayendra Bhamidipati 2012-02-22 18:29:00 -08:00
parent bfe1122bc6
commit 59631452b9
10 changed files with 197 additions and 158 deletions

View File

@ -20,10 +20,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;
@ -46,16 +47,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;
}
}

View File

@ -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;
}
}

View File

@ -145,13 +145,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());
@ -159,22 +163,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());
}
@ -183,10 +195,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());
}
@ -195,10 +211,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);
}
@ -207,10 +227,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);
}

View File

@ -431,18 +431,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) {
@ -1008,32 +1016,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());
}
}
}
}

View File

@ -18,6 +18,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;
@ -56,7 +57,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 {

View File

@ -95,19 +95,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 {
@ -123,7 +140,7 @@ public class ApiResponseSerializer {
sb.append("{ }");
}
}
sb.append(" }");
sb.append(" }");
return sb.toString();
}
return null;
@ -222,29 +239,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)) {

View File

@ -403,12 +403,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;
}
@ -495,7 +495,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()) {
@ -577,7 +577,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) {
@ -586,7 +586,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;
}
}
@ -682,7 +682,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;
}
}
@ -970,7 +970,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
@ -1003,7 +1003,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;
}
@ -1049,7 +1049,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());
@ -1463,7 +1463,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;
}
@ -1668,7 +1668,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;
}
@ -1745,7 +1745,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);
@ -1762,7 +1762,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;
}
}
@ -1958,7 +1958,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;
}
@ -1987,7 +1987,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;
}
@ -2033,7 +2033,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;
@ -2131,7 +2131,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;
}
}
@ -2163,7 +2163,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
if (networkOffering == null || networkOffering.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
@ -2173,7 +2173,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;
}
}
@ -2186,7 +2186,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;
}
@ -2244,7 +2244,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);
@ -2383,7 +2383,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (networkOffering.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;
}
@ -2391,7 +2391,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;
}
@ -2605,7 +2605,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;
}
@ -2615,7 +2615,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;
}
@ -2644,13 +2644,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());
@ -3256,7 +3256,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;
}
@ -3943,7 +3943,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;
}

View File

@ -1837,7 +1837,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;
}
}

View File

@ -29,6 +29,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;
}

View File

@ -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;
}
}